org.inria.ns.reflex.processor.xcl
Class ForEachAction

java.lang.Object
  extended by org.inria.ns.reflex.processor.core.AbstractAction
      extended by org.inria.ns.reflex.processor.core.AbstractSetAction
          extended by org.inria.ns.reflex.processor.xcl.ForEachAction
All Implemented Interfaces:
Computable, Executable, Presentable, NamespaceContextFactory

public class ForEachAction
extends AbstractSetAction

At runtime, the <xcl:for-each> element processes the execution of dependant actions for each item of the collection given by the select attribute.

A property named with the name attribute is successively bind to each item of the collection while running the subactions. When exiting, the property is discarded from the dataset.

Usage

<xcl:for-each name="foo" select="{expression}">
     <!-- do something -->
 </xcl:for-each>
 

Sequences

Basically, if the result of the selection is a single item, this instruction will enter the loop with it, except for sequences that are marked explicitely with the LoopOnChildren interface.

This facility was introduced because single items of sequences are automatically extracted by Jaxen.

Author:
Philippe Poulard
See Also:
BreakAction, ContinueAction, LoopOnChildren

Nested Class Summary
 
Nested classes/interfaces inherited from class org.inria.ns.reflex.processor.core.AbstractAction
AbstractAction.ParameterAdapter, AbstractAction.UselessAction
 
Field Summary
 
Fields inherited from class org.inria.ns.reflex.processor.core.AbstractSetAction
NO_VALUE
 
Fields inherited from class org.inria.ns.reflex.processor.core.AbstractAction
actions, parent, processorInstance
 
Constructor Summary
ForEachAction(QExpression name, Expression selection, Element element, AbstractAction parent)
          Creates a new instance of ForEachAction.
 
Method Summary
 Object getComputedValue(DataSet dataSet)
          Return an exception : this method is irrelevant for this object.
 void runAction(DataSet dataSet)
          Execute the action by evaluating the collection and executing the dependent actions for each item.
static AbstractAction unmarshal(AbstractAction parent, Element element)
          XML unmarshaller for ForEachAction.
 
Methods inherited from class org.inria.ns.reflex.processor.core.AbstractSetAction
addProperty, getComputedName, getName, getValue, scope, unmarshalScope
 
Methods inherited from class org.inria.ns.reflex.processor.core.AbstractAction
addAction, addFallbackAction, createContext, getCanonicalPath, getFallbackAction, getLocalFallbackAction, getLogger, getNamespaceContext, getNode, getParent, recover, recover, removeFallbackAction, reorganize, run, runActions, toPrettyString, toPrettyString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ForEachAction

public ForEachAction(QExpression name,
                     Expression selection,
                     Element element,
                     AbstractAction parent)
              throws XMLException
Creates a new instance of ForEachAction.

Parameters:
name - The name of the property used for each item, as a QExpression .
selection - The expression used to get the collection.
element - The element from which the action has been unmarshalled. Used for namespace prefix resolution when performing XPath expressions.
parent - The action depending from.
Throws:
XMLException
Method Detail

unmarshal

public static AbstractAction unmarshal(AbstractAction parent,
                                       Element element)
                                throws XMLException
XML unmarshaller for ForEachAction.

Parameters:
parent - The action depending from.
element - The XML element to unmarshall.
Returns:
The ForEachAction created.
Throws:
UnmarshalException - When the element and its content is not those expected.
XMLException

getComputedValue

public Object getComputedValue(DataSet dataSet)
                        throws ExecutionException
Return an exception : this method is irrelevant for this object.

Specified by:
getComputedValue in interface Computable
Specified by:
getComputedValue in class AbstractSetAction
Parameters:
dataSet - The set of datas used when the name is computed.
Returns:
Nothing : an exception is thrown.
Throws:
ExecutionException - Always thrown.

runAction

public void runAction(DataSet dataSet)
               throws ExecutionException,
                      XPathException
Execute the action by evaluating the collection and executing the dependent actions for each item.

Overrides:
runAction in class AbstractSetAction
Parameters:
dataSet - The set of datas used when the action is running.
Throws:
ExecutionException - If the action can't be performed.
XPathException
See Also:
LoopOnChildren