Class ResourceBinder

java.lang.Object
org.exoplatform.services.rest.impl.ResourceBinder
All Implemented Interfaces:
org.picocontainer.Startable

public class ResourceBinder extends Object implements 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:
  • Field Details

    • RESOURCE_EXPIRED

      public static final String 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

      protected static final Comparator<ObjectFactory<AbstractResourceDescriptor>> RESOURCE_COMPARATOR
      Resource's comparator.
    • cleanerStop

      protected boolean cleanerStop
    • rdv

      protected final ResourceDescriptorVisitor rdv
      Validator.
    • rd

      @Deprecated protected final javax.ws.rs.ext.RuntimeDelegate rd
      Deprecated.
      See Also:
      • RuntimeDelegate
    • invokerFactory

      protected final MethodInvokerFactory invokerFactory
      Producer of methods invokers. If not specified then DefaultMethodInvoker will be in use.
    • rootResources

      protected final List<ObjectFactory<AbstractResourceDescriptor>> rootResources
      List of all available root resources.
    • resourceListeners

      protected final List<ResourceListener> resourceListeners
      Resource listeners.
    • container

      protected final org.exoplatform.container.ExoContainer container
      Deprecated.
      Do not need container here any more.
    • containerName

      protected final String 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 context
      invokerFactory - method invoker producer
      Throws:
      Exception - if can't set instance of RuntimeDelegate
      See Also:
  • Method Details

    • addApplication

      public void addApplication(javax.ws.rs.core.Application application)
      Deprecated.
      Use ApplicationRegistry.addApplication(Application) instead of using this method .
      Parameters:
      application - Application
      See Also:
      • Application
    • 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 resource
      properties - optional resource properties. It may contains additional info about resource, e.g. description of resource, its responsibility, etc. This info can be retrieved ObjectModel.getProperties(). This parameter may be null
      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 UriPattern already registered
      See Also:
    • addResource

      public void addResource(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.
      Parameters:
      resource - candidate to be root resource
      properties - optional resource properties. It may contains additional info about resource, e.g. description of resource, its responsibility, etc. This info can be retrieved ObjectModel.getProperties(). This parameter may be null
      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 UriPattern already registered
      See Also:
    • addResource

      public void addResource(ObjectFactory<AbstractResourceDescriptor> resourceFactory)
      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 sane UriPattern already registered
    • addResourceListener

      public void addResourceListener(ResourceListener listener)
      Register new resource listener.
      Parameters:
      listener - listener
      See Also:
    • bind

      public boolean bind(Class<?> resourceClass)
      Deprecated.
      Register 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

      public boolean bind(Object resource)
      Deprecated.
      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 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 to requestPath.
      Parameters:
      requestPath - request path
      parameterValues - see ApplicationContext.getParameterValues()
      Returns:
      root resource matched to requestPath or null
    • getResources

      Returns:
      all registered root resources
    • getRootResources

      @Deprecated public List<AbstractResourceDescriptor> getRootResources()
      Deprecated.
      Returns:
      all registered root resources
    • getSize

      public int getSize()
      Returns:
      number of bound resources
    • removeResource

      public ObjectFactory<AbstractResourceDescriptor> removeResource(Class clazz)
      Remove root resource of supplied class from root resource collection.
      Parameters:
      clazz - root resource class
      Returns:
      removed resource or null if resource of specified class not found
    • removeResource

      public ObjectFactory<AbstractResourceDescriptor> removeResource(String path)
      Remove root resource with specified UriTemplate from root resource collection.
      Parameters:
      path - root resource path
      Returns:
      removed resource or null if resource for specified template not found
    • unbind

      public boolean unbind(Class clazz)
      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

      public boolean unbind(String path)
      Deprecated.
      Remove 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:
      start in interface org.picocontainer.Startable
    • stop

      public void stop()
      Specified by:
      stop in interface org.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 (see RESOURCE_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);