|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.Restlet
org.restlet.routing.Router
org.restlet.ext.spring.SpringBeanRouter
public class SpringBeanRouter
Restlet Router
which behaves like Spring's
BeanNameUrlHandlerMapping
. It
takes every bean of type ServerResource
or
Restlet
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 URI.
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" /> <!-- Singleton bean for a restlet --> <bean name="/studies/{study-identifier}/files" id="filesResource" autowire="byName" class="edu.northwestern.myapp.MyDirectory" /> </beans>This will route two resources and one restlet:
"/studies"
,
"/studies/{study-identifier}/template"
, and
"/studies/{study-identifier}/files"
to the corresponding beans.
N.b.: Resources must be scoped prototype, since a new instance must be
created for each request. Restlets may be singletons (this class will only
ever load one instance for each).
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.
Field Summary |
---|
Fields inherited from class org.restlet.routing.Router |
---|
MODE_BEST_MATCH, MODE_CUSTOM, MODE_FIRST_MATCH, MODE_LAST_MATCH, MODE_NEXT_MATCH, MODE_RANDOM_MATCH |
Constructor Summary | |
---|---|
SpringBeanRouter()
Constructor. |
|
SpringBeanRouter(Context context)
Constructor with a parent context. |
|
SpringBeanRouter(Restlet parent)
Constructor with a parent Restlet. |
Method Summary | |
---|---|
protected void |
attachResource(String uri,
String beanName,
BeanFactory beanFactory)
Attaches the named resource bean at the given URI, creating a finder for it via createFinder(BeanFactory, String) . |
protected void |
attachRestlet(String uri,
String beanName,
BeanFactory beanFactory)
Attaches the named restlet bean directly at the given URI. |
protected Finder |
createFinder(BeanFactory beanFactory,
String beanName)
Creates an instance of SpringBeanFinder . |
protected Map<String,String> |
getAttachments()
Returns supplemental explicit mappings |
boolean |
isFindingInAncestors()
Returns true if bean names will be searched for higher up in the BeanFactory hierarchy. |
void |
postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
Attaches all ServerResource and Restlet beans found in
the surrounding bean factory for which resolveUri(java.lang.String, org.springframework.beans.factory.ListableBeanFactory) finds a usable
URI. |
protected String |
resolveUri(String beanName,
ListableBeanFactory beanFactory)
Uses this first alias for this bean that starts with '/' and is not mapped in the explicit attachments to another bean. |
void |
setApplicationContext(ApplicationContext applicationContext)
Sets the Spring application context. |
void |
setAttachments(Map<String,String> attachments)
Sets an explicit mapping of URI templates to bean IDs to use in addition to the usual bean name mapping behavior. |
void |
setFindingInAncestors(boolean findingInAncestors)
Sets if bean names will be searched for higher up in the BeanFactory hierarchy. |
Methods inherited from class org.restlet.routing.Router |
---|
attach, attach, attach, attach, attach, attach, attachDefault, attachDefault, createRoute, createRoute, detach, detach, doHandle, getCustom, getDefaultMatchingMode, getDefaultMatchingQuery, getDefaultRoute, getMatchingMode, getMaxAttempts, getNext, getRequiredScore, getRetryDelay, getRoutes, getRoutingMode, handle, logRoute, setDefaultMatchingMode, setDefaultMatchingQuery, setDefaultRoute, setMaxAttempts, setRequiredScore, setRetryDelay, setRoutes, setRoutingMode, start, stop |
Methods inherited from class org.restlet.Restlet |
---|
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SpringBeanRouter()
public SpringBeanRouter(Context context)
public SpringBeanRouter(Restlet parent)
Method Detail |
---|
protected void attachResource(String uri, String beanName, BeanFactory beanFactory)
createFinder(BeanFactory, String)
.
uri
- The attachment URI.beanName
- The bean name.beanFactory
- The Spring bean factory.protected void attachRestlet(String uri, String beanName, BeanFactory beanFactory)
uri
- The attachment URI.beanName
- The bean name.beanFactory
- The Spring bean factory.protected Finder createFinder(BeanFactory beanFactory, String beanName)
SpringBeanFinder
. This can be overridden
if necessary.
beanFactory
- The Spring bean factory.beanName
- The bean name.attachResource(java.lang.String, java.lang.String, org.springframework.beans.factory.BeanFactory)
protected Map<String,String> getAttachments()
public boolean isFindingInAncestors()
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
ServerResource
and Restlet
beans found in
the surrounding bean factory for which resolveUri(java.lang.String, org.springframework.beans.factory.ListableBeanFactory)
finds a usable
URI. Also attaches everything explicitly routed in the attachments
property.
postProcessBeanFactory
in interface BeanFactoryPostProcessor
beanFactory
- The Spring bean factory.
BeansException
setAttachments(java.util.Map)
protected String resolveUri(String beanName, ListableBeanFactory beanFactory)
BeanNameUrlHandlerMapping
.
beanName
- The bean name to lookup in the bean factory aliases.beanFactory
- The Spring bean factory.
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
applicationContext
- The context.
BeansException
public void setAttachments(Map<String,String> attachments)
attachments
- Supplemental explicit mappings.SpringRouter
public void setFindingInAncestors(boolean findingInAncestors)
findingInAncestors
- Search for beans higher up in the BeanFactory hierarchy.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |