Class ResourceBinder
java.lang.Object
org.exoplatform.services.rest.impl.ResourceBinder
- All Implemented Interfaces:
org.picocontainer.Startable
Lookup for root resource eXo container components at startup and
register/unregister resources via specified methods.
- Version:
- $Id: $
- Author:
- Andrey Parfonov
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected final org.exoplatform.container.ExoContainerDeprecated.Do not need container here any more.protected final StringThe name of the containerprotected final MethodInvokerFactoryProducer of methods invokers.protected final javax.ws.rs.ext.RuntimeDelegateDeprecated.protected final ResourceDescriptorVisitorValidator.protected static final Comparator<ObjectFactory<AbstractResourceDescriptor>> Resource's comparator.static final StringName of property which may contains resource expiration date.protected final List<ResourceListener> Resource listeners.protected final List<ObjectFactory<AbstractResourceDescriptor>> List of all available root resources. -
Constructor Summary
ConstructorsConstructorDescriptionResourceBinder(org.exoplatform.container.ExoContainerContext containerContext) ResourceBinder(org.exoplatform.container.ExoContainerContext containerContext, MethodInvokerFactory invokerFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddApplication(javax.ws.rs.core.Application application) Deprecated.UseApplicationRegistry.addApplication(Application)instead of using this method .voidaddResource(Class<?> resourceClass, javax.ws.rs.core.MultivaluedMap<String, String> properties) Register supplied class as per-request root resource if it has valid JAX-RS annotations and no one resource with the same UriPattern already registered.voidaddResource(Object resource, javax.ws.rs.core.MultivaluedMap<String, String> properties) Register supplied Object as singleton root resource if it has valid JAX-RS annotations and no one resource with the same UriPattern already registered.voidaddResource(ObjectFactory<AbstractResourceDescriptor> resourceFactory) Register supplied root resource if no one resource with the same UriPattern already registered.voidaddResourceListener(ResourceListener listener) Register new resource listener.booleanDeprecated.useaddResource(Class, MultivaluedMap)insteadbooleanDeprecated.useaddResource(Object, MultivaluedMap)insteadvoidclear()Clear the list of ResourceContainer description.getMatchedResource(String requestPath, List<String> parameterValues) Get root resource matched torequestPath.Deprecated.intgetSize()removeResource(Class clazz) Remove root resource of supplied class from root resource collection.removeResource(String path) Remove root resource with specified UriTemplate from root resource collection.voidstart()protected voidStart resource cleaner which periodically check all available resources and remove expired.voidstop()booleanDeprecated.booleanDeprecated.useremoveResource(String)instead
-
Field Details
-
RESOURCE_EXPIRED
Name of property which may contains resource expiration date. Date expected as string representation of java.util.Date in long format.- See Also:
-
RESOURCE_COMPARATOR
Resource's comparator. -
cleanerStop
protected boolean cleanerStop -
rdv
Validator. -
rd
Deprecated.- See Also:
-
invokerFactory
Producer of methods invokers. If not specified thenDefaultMethodInvokerwill be in use. -
rootResources
List of all available root resources. -
resourceListeners
Resource listeners. -
container
protected final org.exoplatform.container.ExoContainer containerDeprecated.Do not need container here any more. -
containerName
The name of the container
-
-
Constructor Details
-
ResourceBinder
public ResourceBinder(org.exoplatform.container.ExoContainerContext containerContext) throws Exception - Throws:
Exception
-
ResourceBinder
public ResourceBinder(org.exoplatform.container.ExoContainerContext containerContext, MethodInvokerFactory invokerFactory) throws Exception - Parameters:
containerContext- eXo container contextinvokerFactory- method invoker producer- Throws:
Exception- if can't set instance ofRuntimeDelegate- See Also:
-
-
Method Details
-
addApplication
public void addApplication(javax.ws.rs.core.Application application) Deprecated.UseApplicationRegistry.addApplication(Application)instead of using this method .- Parameters:
application- Application- See Also:
-
addResource
public void addResource(Class<?> resourceClass, javax.ws.rs.core.MultivaluedMap<String, String> properties) Register supplied class as per-request root resource if it has valid JAX-RS annotations and no one resource with the same UriPattern already registered.- Parameters:
resourceClass- class of candidate to be root resourceproperties- optional resource properties. It may contains additional info about resource, e.g. description of resource, its responsibility, etc. This info can be retrievedObjectModel.getProperties(). This parameter may benull- Throws:
ResourcePublicationException- if resource can't be published because to:- @javax.ws.rs.Path annotation is missing
- resource has not any method with JAX-RS annotations
- JAX-RS annotations are ambiguous or invalid
- resource with the sane
UriPatternalready registered
- See Also:
-
addResource
Register supplied Object as singleton root resource if it has valid JAX-RS annotations and no one resource with the same UriPattern already registered.- Parameters:
resource- candidate to be root resourceproperties- optional resource properties. It may contains additional info about resource, e.g. description of resource, its responsibility, etc. This info can be retrievedObjectModel.getProperties(). This parameter may benull- Throws:
ResourcePublicationException- if resource can't be published because to:- @javax.ws.rs.Path annotation is missing
- resource has not any method with JAX-RS annotations
- JAX-RS annotations are ambiguous or invalid
- resource with the sane
UriPatternalready registered
- See Also:
-
addResource
Register supplied root resource if no one resource with the same UriPattern already registered.- Parameters:
resourceFactory- root resource- Throws:
ResourcePublicationException- if resource can't be published because resource with the saneUriPatternalready registered
-
addResourceListener
Register new resource listener.- Parameters:
listener- listener- See Also:
-
bind
Deprecated.useaddResource(Class, MultivaluedMap)insteadRegister root resource.- Parameters:
resourceClass- class of candidate to be root resource- Returns:
- true if resource was bound and false if resource was not bound cause it is not root resource
-
bind
Deprecated.useaddResource(Object, MultivaluedMap)insteadRegister supplied Object as singleton root resource if it has valid JAX-RS annotations and no one resource with the same UriPattern already registered.- Parameters:
resource- candidate to be root resource- Returns:
- true if resource was bound and false if resource was not bound cause it is not root resource
-
clear
public void clear()Clear the list of ResourceContainer description. -
getMatchedResource
public ObjectFactory<AbstractResourceDescriptor> getMatchedResource(String requestPath, List<String> parameterValues) Get root resource matched torequestPath.- Parameters:
requestPath- request pathparameterValues- seeApplicationContext.getParameterValues()- Returns:
- root resource matched to
requestPathornull
-
getResources
- Returns:
- all registered root resources
-
getRootResources
Deprecated.- Returns:
- all registered root resources
-
getSize
public int getSize()- Returns:
- number of bound resources
-
removeResource
Remove root resource of supplied class from root resource collection.- Parameters:
clazz- root resource class- Returns:
- removed resource or
nullif resource of specified class not found
-
removeResource
Remove root resource with specified UriTemplate from root resource collection.- Parameters:
path- root resource path- Returns:
- removed resource or
nullif resource for specified template not found
-
unbind
Deprecated.Remove root resource of supplied class from root resource collection.- Parameters:
clazz- root resource class- Returns:
- true if resource was unbound false otherwise
-
unbind
Deprecated.useremoveResource(String)insteadRemove root resource with specified UriTemplate from root resource collection.- Parameters:
path- root resource path- Returns:
- true if resource was unbound false otherwise
-
start
public void start()- Specified by:
startin interfaceorg.picocontainer.Startable
-
stop
public void stop()- Specified by:
stopin interfaceorg.picocontainer.Startable
-
startResourceCleaner
protected void startResourceCleaner()Start resource cleaner which periodically check all available resources and remove expired. Expired date may be specified by adding special property (seeRESOURCE_EXPIRED) when resource added. In example below resource will be expired in one minute. By default resources check one time per minute so live time less than one minute is not guaranteed.ResourceBinder binder = ... Class<?> resource = ... MultivaluedMap<String, String> properties = new MultivaluedMapImpl(); properties.putSingle("resource.expiration.date", Long.toString(System.currentTimeMillis() + 60000L)); binder.addResource(resource, properties);
-