com.opensymphony.xwork2.interceptor
public class: ChainingInterceptor [javadoc |
source]
java.lang.Object
com.opensymphony.xwork2.interceptor.AbstractInterceptor
com.opensymphony.xwork2.interceptor.ChainingInterceptor
All Implemented Interfaces:
Interceptor
An interceptor that copies all the properties of every object in the value stack to the currently executing object,
except for any object that implements
Unchainable . A collection of optional
includes and
excludes may be provided to control how and which parameters are copied. Only includes or excludes may be
specified. Specifying both results in undefined behavior. See the javadocs for
ReflectionProvider#copy(Object, Object,
java.util.Map, java.util.Collection, java.util.Collection) for more information.
Note: It is important to remember that this interceptor does nothing if there are no objects already on the stack.
This means two things:
One, you can safely apply it to all your actions without any worry of adverse affects.
Two, it is up to you to ensure an object exists in the stack prior to invoking this action. The most typical way this is done
is through the use of the
chain result type, which combines with this interceptor to make up the action
chaining feature.
Interceptor parameters:
- excludes (optional) - the list of parameter names to exclude from copying (all others will be included).
- includes (optional) - the list of parameter names to include when copying (all others will be excluded).
Extending the interceptor:
There are no known extension points to this interceptor.
Example code:
<action name="someAction" class="com.examples.SomeAction">
<interceptor-ref name="basicStack"/>
<result name="success" type="chain">otherAction</result>
</action>
<action name="otherAction" class="com.examples.OtherAction">
<interceptor-ref name="chain"/>
<interceptor-ref name="basicStack"/>
<result name="success">good_result.ftl</result>
</action>
Field Summary |
---|
protected Collection<String> | excludes | |
protected Collection<String> | includes | |
protected ReflectionProvider | reflectionProvider | |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from com.opensymphony.xwork2.interceptor.ChainingInterceptor Detail: |
public Collection<String> getExcludes() {
return excludes;
}
Gets list of parameter names to exclude |
public Collection<String> getIncludes() {
return includes;
}
Gets list of parameter names to include |
public String intercept(ActionInvocation invocation) throws Exception {
ValueStack stack = invocation.getStack();
CompoundRoot root = stack.getRoot();
if (root.size() > 1) {
List< CompoundRoot > list = new ArrayList< CompoundRoot >(root);
list.remove(0);
Collections.reverse(list);
Map< String, Object > ctxMap = invocation.getInvocationContext().getContextMap();
Iterator< CompoundRoot > iterator = list.iterator();
int index = 1; // starts with 1, 0 has been removed
while (iterator.hasNext()) {
index = index + 1;
Object o = iterator.next();
if (o != null) {
if (!(o instanceof Unchainable)) {
reflectionProvider.copy(o, invocation.getAction(), ctxMap, excludes, includes);
}
}
else {
LOG.warn("compound root element at index "+index+" is null");
}
}
}
return invocation.invoke();
}
|
public void setExcludes(Collection<String> excludes) {
this.excludes = excludes;
}
Sets the list of parameter names to exclude from copying (all others will be included). |
public void setIncludes(Collection<String> includes) {
this.includes = includes;
}
Sets the list of parameter names to include when copying (all others will be excluded). |
public void setReflectionProvider(ReflectionProvider prov) {
this.reflectionProvider = prov;
}
|