FileDocCategorySizeDatePackage
CompositeActionMapper.javaAPI DocExample6613Mon Jul 23 13:26:36 BST 2007org.apache.struts2.dispatcher.mapper

CompositeActionMapper

public class CompositeActionMapper extends Object implements ActionMapper
A composite action mapper that is capable of delegating to a series of {@link ActionMapper} if the former failed to obtained a valid {@link 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.RestfulActionMapperorg.apache.struts2.dispatcher.mapper.Restful2ActionMapper" />

When {@link CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager)} or {@link CompositeActionMapper#getUriFromActionMapping(ActionMapping)} is invoked, {@link CompositeActionMapper} would go through these {@link ActionMapper}s in sequence starting from {@link 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 {@link ActionMapper} return a valid result (not null) or it runs out of {@link ActionMapper} in which case it will just return null for both {@link CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager)} and {@link 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.

see
ActionMapper
see
ActionMapperFactory
see
ActionMapping
see
IndividualActionMapperEntry
version
$Date: 2006-11-23 12:31:52 -0500 (Thu, 23 Nov 2006) $ $Id: CompositeActionMapper.java 478625 2006-11-23 17:31:52Z wsmoak $

Fields Summary
private static final Log
LOG
protected com.opensymphony.xwork2.inject.Container
container
protected List
actionMappers
Constructors Summary
Methods Summary
public ActionMappinggetMapping(javax.servlet.http.HttpServletRequest request, com.opensymphony.xwork2.config.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 java.lang.StringgetUriFromActionMapping(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 voidsetActionMappers(java.lang.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 voidsetContainer(com.opensymphony.xwork2.inject.Container container)

    
    
        
        this.container = container;