org.apache.struts2.dispatcher.mapper
public class: CompositeActionMapper [javadoc |
source]
java.lang.Object
org.apache.struts2.dispatcher.mapper.CompositeActionMapper
All Implemented Interfaces:
ActionMapper
A composite action mapper that is capable of delegating to a series of
ActionMapper if the former
failed to obtained a valid
ActionMapping or uri.
It is configured through struts.properties.
For example, with the following entries in struts.properties
<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts"
class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />
<constant name="struts.mapper.composite"
value="org.apache.struts2.dispatcher.mapper.DefaultActionMapper,org.apache.struts2.dispatcher.mapper.RestfulActionMapper,org.apache.struts2.dispatcher.mapper.Restful2ActionMapper" />
When
CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager) or
CompositeActionMapper#getUriFromActionMapping(ActionMapping) is invoked,
CompositeActionMapper would go through these
ActionMapper s in sequence
starting from
ActionMapper identified by 'struts.mapper.composite.1', followed by
'struts.mapper.composite.2' and finally 'struts.mapper.composite.3' (in this case) until either
one of the
ActionMapper return a valid result (not null) or it runs out of
ActionMapper
in which case it will just return null for both
CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager) and
CompositeActionMapper#getUriFromActionMapping(ActionMapping) methods.
For example with the following in struts-*.xml :-
<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts"
class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />
<constant name="struts.mapper.composite"
value="org.apache.struts2.dispatcher.mapper.DefaultActionMapper,foo.bar.MyActionMapper,foo.bar.MyAnotherActionMapper" />
CompositeActionMapper will be configured with 3 ActionMapper, namely
"DefaultActionMapper", "MyActionMapper" and "MyAnotherActionMapper".
CompositeActionMapper would consult each of them in order described above.
Also see:
- ActionMapper
- ActionMapping
- version:
$ - Date: 2009-07-07 13:47:34 -0400 (Tue, 07 Jul 2009) $ $Id: CompositeActionMapper.java 791919 2009-07-07 17:47:34Z musachy $
| Field Summary |
|---|
| protected Container | container | |
| protected List<ActionMapper> | actionMappers | |
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.apache.struts2.dispatcher.mapper.CompositeActionMapper Detail: |
public ActionMapping getMapping(HttpServletRequest request,
ConfigurationManager configManager) {
for (ActionMapper actionMapper : actionMappers) {
ActionMapping actionMapping = actionMapper.getMapping(request, configManager);
if (LOG.isDebugEnabled()) {
LOG.debug("Using ActionMapper "+actionMapper);
}
if (actionMapping == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("ActionMapper "+actionMapper+" failed to return an ActionMapping (null)");
}
}
else {
return actionMapping;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("exhausted from ActionMapper that could return an ActionMapping");
}
return null;
}
|
public ActionMapping getMappingFromActionName(String actionName) {
for (ActionMapper actionMapper : actionMappers) {
ActionMapping actionMapping = actionMapper.getMappingFromActionName(actionName);
if (LOG.isDebugEnabled()) {
LOG.debug("Using ActionMapper "+actionMapper);
}
if (actionMapping == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("ActionMapper "+actionMapper+" failed to return an ActionMapping (null)");
}
}
else {
return actionMapping;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("exhausted from ActionMapper that could return an ActionMapping");
}
return null;
}
|
public String getUriFromActionMapping(ActionMapping mapping) {
for (ActionMapper actionMapper : actionMappers) {
String uri = actionMapper.getUriFromActionMapping(mapping);
if (LOG.isDebugEnabled()) {
LOG.debug("Using ActionMapper "+actionMapper);
}
if (uri == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("ActionMapper "+actionMapper+" failed to return an ActionMapping (null)");
}
}
else {
return uri;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("exhausted from ActionMapper that could return a uri");
}
return null;
}
|
public void setActionMappers(String list) {
if (list != null) {
String[] arr = list.split(",");
for (String name : arr) {
Object obj = container.getInstance(ActionMapper.class, name);
if (obj != null) {
actionMappers.add((ActionMapper) obj);
}
}
}
}
|
public void setContainer(Container container) {
this.container = container;
}
|