本文整理了Java中org.restlet.Application.getCurrent()
方法的一些代码示例,展示了Application.getCurrent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Application.getCurrent()
方法的具体详情如下:
包路径:org.restlet.Application
类名称:Application
方法名:getCurrent
[英]This variable is stored internally as a thread local variable and updated each time a call enters an application. Warning: this method should only be used under duress. You should by default prefer obtaining the current application using methods such as org.restlet.resource.Resource#getApplication()
[中]该变量作为线程局部变量存储在内部,并在每次调用进入应用程序时更新。警告:此方法只能在胁迫下使用。默认情况下,您应该更喜欢使用org等方法获取当前应用程序。restlet。资源资源#获取应用程序()
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Default constructor. Note that the parent application is retrieved using
* the {@link Application#getCurrent()} method if available or is null.
*/
public Role() {
this(Application.getCurrent(), null, null);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Returns the parent application if it exists, or null.
*
* @return The parent application if it exists, or null.
*/
public Application getApplication() {
return Application.getCurrent();
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Returns the parent application if it exists, or null.
*
* @return The parent application if it exists, or null.
*/
public Application getApplication() {
return Application.getCurrent();
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Returns the parent application if it exists, or null.
*
* @return The parent application if it exists, or null.
*/
public Application getApplication() {
return Application.getCurrent();
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Constructor. Note that the parent application is retrieved using the
* {@link Application#getCurrent()} method.
*
* @param name
* The name.
* @deprecated Use {@link Role#Role(Application, String)} instead.
*/
@Deprecated
public Role(String name) {
this(Application.getCurrent(), name, null);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Constructor. Note that the parent application is retrieved using the
* {@link Application#getCurrent()} method.
*
* @param name
* The name.
* @param description
* The description.
* @deprecated Use {@link Role#Role(Application, String, String)} instead.
*/
@Deprecated
public Role(String name, String description) {
this(Application.getCurrent(), name, description);
}
代码示例来源:origin: ontopia/ontopia
public static Context getCurrentApplicationContext() {
Application application = Application.getCurrent();
if (application == null) {
return null;
}
return application.getContext();
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs
/**
* Constructor.
*/
public ConverterProvider() {
Application application = Application.getCurrent();
if (application != null) {
this.converterService = application.getConverterService();
}
if (this.converterService == null) {
this.converterService = new ConverterService();
}
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Returns the converter service.
*
* @return The converter service.
* @deprecated Since 1.1, the ConverterService is deprecated, with no
* replacement as it doesn't fit well with content negotiation.
* Most users prefer to handle those conversion in Resource
* subclasses.
*/
@Deprecated
private org.restlet.service.ConverterService getConverterService() {
org.restlet.service.ConverterService result = null;
final Application application = Application.getCurrent();
if (application != null) {
result = application.getConverterService();
} else {
result = new org.restlet.service.ConverterService();
}
return result;
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Returns the connector service associated to a request.
*
* @return The connector service associated to a request.
*/
public static org.restlet.service.ConnectorService getConnectorService() {
org.restlet.service.ConnectorService result = null;
org.restlet.Application application = org.restlet.Application
.getCurrent();
if (application != null) {
result = application.getConnectorService();
} else {
result = new org.restlet.service.ConnectorService();
}
return result;
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Returns the parent application. If it wasn't set, it attempts to retrieve
* the current one via {@link org.restlet.Application#getCurrent()} if it
* exists, or instantiates a new one as a last resort.
*
* @return The parent application if it exists, or a new one.
*/
public org.restlet.Application getApplication() {
org.restlet.Application result = this.application;
if (result == null) {
result = org.restlet.Application.getCurrent();
if (result == null) {
result = new org.restlet.Application(getContext());
}
this.application = result;
}
return result;
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs
/**
* Returns a boolean indicating whether the authenticated user is included
* in the specified logical "role". If the user has not been authenticated,
* the method returns <code>false</code>.
*
* @param roleName
* a <code>String</code> specifying the name of the role
* @return a <code>boolean</code> indicating whether the user making the
* request belongs to a given role; <code>false</code> if the user
* has not been authenticated
* @see SecurityContext#isUserInRole(String)
*/
public boolean isUserInRole(String roleName) {
Role role = Application.getCurrent().getRole(roleName);
return (role != null)
&& this.request.getClientInfo().getRoles().contains(role);
}
代码示例来源:origin: org.restlet/org.restlet
public void execute(final Runnable runnable) {
// Save the thread local variables
final Application currentApplication = Application.getCurrent();
final Context currentContext = Context.getCurrent();
final Integer currentVirtualHost = VirtualHost.getCurrent();
final Response currentResponse = Response.getCurrent();
executorService.execute(new Runnable() {
public void run() {
// Copy the thread local variables
Response.setCurrent(currentResponse);
Context.setCurrent(currentContext);
VirtualHost.setCurrent(currentVirtualHost);
Application.setCurrent(currentApplication);
try {
// Run the user task
runnable.run();
} finally {
// Reset the thread local variables
Response.setCurrent(null);
Context.setCurrent(null);
VirtualHost.setCurrent(-1);
Application.setCurrent(null);
}
}
});
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Representation getRepresentation(Status status, Request request,
Response response) {
// Create the data model
Map<String, String> dataModel = new ConcurrentHashMap<String, String>();
dataModel.put("applicationName", Application.getCurrent().getName());
dataModel.put("statusDescription", response.getStatus()
.getDescription());
dataModel.put("statusReasonPhrase", response.getStatus()
.getReasonPhrase());
// Load the FreeMarker template
Representation mailFtl = new ClientResource(
LocalReference.createClapReference(getClass().getPackage())
+ "/MailStatus.ftl").get();
// Wraps the bean with a FreeMarker representation
return new TemplateRepresentation(mailFtl, dataModel,
MediaType.TEXT_HTML);
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Representation getRepresentation(Status status, Request request,
Response response) {
// Create the data model
Map<String, String> dataModel = new TreeMap<String, String>();
dataModel.put("applicationName", Application.getCurrent().getName());
dataModel.put("statusReasonPhrase", response.getStatus()
.getReasonPhrase());
dataModel.put("statusDescription", response.getStatus()
.getDescription());
// Load the FreeMarker template
Representation mailFtl = new ClientResource(
LocalReference.createClapReference(getClass().getPackage())
+ "/MailStatus.ftl").get();
// Wraps the bean with a FreeMarker representation
return new TemplateRepresentation(mailFtl, dataModel,
MediaType.TEXT_HTML);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* In addition to the default behavior, it saves the current application
* instance into the current thread.
*
* @param request
* The request to handle.
* @param response
* The response to update.
*/
@Override
public void handle(Request request, Response response) {
Application current = Application.getCurrent();
// Save the current application
Application.setCurrent(getHelped());
// Actually handle call
try {
super.handle(request, response);
} finally {
// restaure the current application
Application.setCurrent(current);
}
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Returns the preferred variant according to the client preferences
* specified in the request.
*
* @return The preferred variant.
*/
public Variant getPreferredVariant() {
Variant result = null;
final List<Variant> variants = getVariants();
if ((variants != null) && (!variants.isEmpty())) {
Language language = null;
// Compute the preferred variant. Get the default language
// preference from the Application (if any).
final Application app = Application.getCurrent();
if (app != null) {
language = app.getMetadataService().getDefaultLanguage();
}
result = getRequest().getClientInfo().getPreferredVariant(variants,
language);
}
return result;
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Returns a reader from a writer representation.Internally, it uses a
* writer thread and a pipe stream.
*
* @param representation
* The representation to read from.
* @return The character reader.
* @throws IOException
*/
public static Reader getReader(final WriterRepresentation representation)
throws IOException {
final PipedWriter pipedWriter = new PipedWriter();
final PipedReader pipedReader = new PipedReader(pipedWriter);
final Application application = Application.getCurrent();
// Gets a thread that will handle the task of continuously
// writing the representation into the input side of the pipe
application.getTaskService().execute(new Runnable() {
public void run() {
try {
representation.write(pipedWriter);
pipedWriter.close();
} catch (IOException ioe) {
Context.getCurrentLogger().log(Level.FINE,
"Error while writing to the piped reader.", ioe);
}
}
});
return pipedReader;
}
代码示例来源:origin: org.restlet/org.restlet
/**
* Returns a readable byte channel based on the given representation's
* content and its write(WritableByteChannel) method. Internally, it uses a
* writer thread and a pipe channel.
*
* @param representation
* the representation to get the {@link OutputStream} from.
* @return A readable byte channel.
* @throws IOException
*/
public static ReadableByteChannel getChannel(
final Representation representation) throws IOException {
final Pipe pipe = Pipe.open();
final Application application = Application.getCurrent();
// Get a thread that will handle the task of continuously
// writing the representation into the input side of the pipe
application.getTaskService().execute(new Runnable() {
public void run() {
try {
final WritableByteChannel wbc = pipe.sink();
representation.write(wbc);
wbc.close();
} catch (IOException ioe) {
Context.getCurrentLogger().log(Level.FINE,
"Error while writing to the piped channel.", ioe);
}
}
});
return pipe.source();
}
代码示例来源:origin: org.restlet/org.restlet
final Application application = Application.getCurrent();
内容来源于网络,如有侵权,请联系作者删除!