public OutletResult execute(ControllerState controllerState)
throws GeneratorException
{
TokenReplacer tokenReplacer = new TokenReplacer(controllerState);
Outlet outlet;
{
OutletConfiguration outletConfiguration
= controllerState.getUnitConfiguration()
.getOutletConfiguration();
String detokenizedOutletName
= tokenReplacer.process(outletName);
QualifiedName outletQName = new QualifiedName(
detokenizedOutletName,
Namespace.ROOT_NAMESPACE);
outlet = outletConfiguration.getOutlet(outletQName);
if (outlet == null)
{
throw new GeneratorException("TraverseAllAction : The outlet "
+ outletName
+ " does not exist");
}
}
SourceElement currentElement = controllerState.getSourceElement();
String detokenizedElementToTraverseName
= tokenReplacer.process(elementsToTraverseName);
List<SourceElement> selectedElements
= SourcePath.getElements(
currentElement,
detokenizedElementToTraverseName);
if (!acceptEmpty && selectedElements.isEmpty())
{
throw new GeneratorException(
"TraverseAllAction : selected element "
+ elementsToTraverseName
+ " does not exist and acceptEmpty was set to false");
}
List<OutletResult> resultList
= new ArrayList<OutletResult>(selectedElements.size());
for (SourceElement sourceElement : selectedElements)
{
controllerState.setSourceElement(sourceElement);
outlet.beforeExecute(controllerState);
resultList.add(outlet.execute(controllerState));
outlet.afterExecute(controllerState);
}
controllerState.setSourceElement(currentElement);
if (resultList.isEmpty())
{
return new OutletResult("");