org.restlet.ext.spring
Class SpringBeanRouter

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.Router
              extended by org.restlet.ext.spring.SpringBeanRouter
All Implemented Interfaces:
BeanFactoryPostProcessor

public class SpringBeanRouter
extends Router
implements BeanFactoryPostProcessor

Restlet Router which behaves like Spring's BeanNameUrlHandlerMapping. It takes every bean of type Resource defined in a particular context and examines its aliases (generally speaking, its name and id). If one of the aliases begins with a forward slash, the resource will be attached to that URL.

Example:

 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" >
    <!-- Singleton instance of this class -->
    <bean name="router" class="org.restlet.ext.spring.SpringBeanRouter"/>
 
    <!-- Prototype beans for the resources -->
    <bean name="/studies" id="studiesResource" autowire="byName" scope="prototype" class="edu.northwestern.myapp.StudiesResource" >
       <property name="studyDao" ref="studyDao"/>
    </bean>
 
    <bean name="/studies/{study-identifier}/template" id="templateResource" autowire="byName" scope="prototype" class="edu.northwestern.myapp.TemplateResource" />
 </beans>
 
This will route two resources: "/studies" and "/studies/{study-identifier}/template" to the corresponding Resource subclass. Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.

Author:
Rhett Sutphin, James Maki

Field Summary
 
Fields inherited from class org.restlet.Router
BEST, CUSTOM, FIRST, LAST, NEXT, RANDOM
 
Constructor Summary
SpringBeanRouter()
           
 
Method Summary
protected  Finder createFinder(BeanFactory beanFactory, java.lang.String beanName)
          Creates an instance of SpringBeanFinder.
 boolean isFindInAncestors()
          Returns true if bean names will be searched for higher up in the BeanFactory hierarchy.
 void postProcessBeanFactory(ConfigurableListableBeanFactory factory)
          Modify the application context by looking up the name of all beans of type Resource, calling the resolveUri(String, ConfigurableListableBeanFactory) method for each of them.
protected  java.lang.String resolveUri(java.lang.String resourceName, ConfigurableListableBeanFactory factory)
          Uses this first alias for this bean that starts with '/'.
 void setFindInAncestors(boolean findInAncestors)
          Sets if bean names will be searched for higher up in the BeanFactory hierarchy.
 
Methods inherited from class org.restlet.Router
attach, attach, attach, attachDefault, attachDefault, createFinder, createRoute, detach, getCustom, getDefaultMatchingMode, getDefaultMatchQuery, getDefaultRoute, getFinderClass, getMaxAttempts, getNext, getRequiredScore, getRetryDelay, getRoutes, getRoutingMode, handle, setDefaultMatchingMode, setDefaultMatchQuery, setDefaultRoute, setFinderClass, setMaxAttempts, setRequiredScore, setRetryDelay, setRoutes, setRoutingMode
 
Methods inherited from class org.restlet.Restlet
getApplication, getContext, getLogger, init, isStarted, isStopped, setContext, start, stop
 
Methods inherited from class org.restlet.Uniform
delete, delete, get, get, handle, head, head, options, options, post, post, put, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpringBeanRouter

public SpringBeanRouter()
Method Detail

createFinder

protected Finder createFinder(BeanFactory beanFactory,
                              java.lang.String beanName)
Creates an instance of SpringBeanFinder. This can be overriden if necessary.

Parameters:
beanFactory - The Spring bean factory.
beanName - The bean name.

isFindInAncestors

public boolean isFindInAncestors()
Returns true if bean names will be searched for higher up in the BeanFactory hierarchy.

Default is true.

Returns:
true if bean names will be searched for higher up in the BeanFactory hierarchy

postProcessBeanFactory

public void postProcessBeanFactory(ConfigurableListableBeanFactory factory)
                            throws BeansException
Modify the application context by looking up the name of all beans of type Resource, calling the resolveUri(String, ConfigurableListableBeanFactory) method for each of them. If an URI is found, a finder is created for the bean name using the createFinder(BeanFactory, String) method.

Specified by:
postProcessBeanFactory in interface BeanFactoryPostProcessor
Throws:
BeansException

resolveUri

protected java.lang.String resolveUri(java.lang.String resourceName,
                                      ConfigurableListableBeanFactory factory)
Uses this first alias for this bean that starts with '/'. This mimics the behavior of BeanNameUrlHandlerMapping .


setFindInAncestors

public void setFindInAncestors(boolean findInAncestors)
Sets if bean names will be searched for higher up in the BeanFactory hierarchy.

Parameters:
findInAncestors - search for beans higher up in the BeanFactory hierarchy.


Copyright © 2005-2008 Noelios Technologies.