1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.cocoon.components.treeprocessor.InvokeContext; 23 import org.apache.cocoon.components.treeprocessor.NamedProcessingNode; 24 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 25 import org.apache.cocoon.components.treeprocessor.SimpleSelectorProcessingNode; 26 import org.apache.cocoon.environment.Environment; 27 28 33 34 public class ActionSetNode extends SimpleSelectorProcessingNode 35 implements NamedProcessingNode { 36 37 public static final String CALLER_PARAMETERS = ActionSetNode.class.getName() + "/CallerParameters"; 38 public static final String ACTION_RESULTS = ActionSetNode.class.getName() + "/ActionResults"; 39 40 41 private ProcessingNode[] nodes; 42 43 44 private String [] actionNames; 45 46 public ActionSetNode( 47 String name, ProcessingNode[] nodes, String [] actionNames) { 48 super(name); 49 this.nodes = nodes; 50 this.actionNames = actionNames; 51 } 52 53 public final boolean invoke(Environment env, InvokeContext context) 54 throws Exception { 55 56 String msg = "An action-set cannot be invoked, at " + this.getLocation(); 59 throw new UnsupportedOperationException (msg); 60 } 61 62 66 public final Map call(Environment env, InvokeContext context, Parameters params) throws Exception { 67 68 String cocoonAction = env.getAction(); 69 70 73 74 Map result = null; 75 76 env.setAttribute(CALLER_PARAMETERS, params); 79 80 for (int i = 0; i < nodes.length; i++) { 81 82 83 String actionName = actionNames[i]; 84 if (actionName == null || actionName.equals(cocoonAction)) { 85 86 this.nodes[i].invoke(env, context); 87 88 Map actionResult = (Map )env.getAttribute(ACTION_RESULTS); 91 env.removeAttribute(ACTION_RESULTS); 93 94 if (actionResult != null) { 95 if (result == null) { 97 result = new HashMap (actionResult); 98 } else { 99 result.putAll(actionResult); 100 } 101 } 102 103 } } 106 return result; 107 } 108 109 112 113 public String getName() { 114 return this.componentName; 115 } 116 } 117 | Popular Tags |