2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.shale.clay.component.chain;
22
23 import java.util.Iterator;
24
25 import javax.faces.component.ActionSource;
26 import javax.faces.component.UIComponent;
27
28 import org.apache.commons.chain.Catalog;
29 import org.apache.commons.chain.Command;
30 import org.apache.commons.chain.Context;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.apache.shale.clay.config.Globals;
34 import org.apache.shale.clay.config.beans.ActionListenerBean;
35 import org.apache.shale.clay.config.beans.ComponentBean;
36
37 /***
38 * <p>
39 * Iterates over the action listeners defined in the {@link ComponentBean}
40 * invoking {@link CreateActionListenerCommand}.
41 * </p>
42 */
43 public class AssignActionListenersCommand extends AbstractCommand {
44
45 /***
46 * <p>
47 * Common logger utility.
48 * </p>
49 */
50 private static Log log;
51 static {
52 log = LogFactory.getLog(AssignActionListenersCommand.class);
53 }
54
55 /***
56 * <p>
57 * This {@link Command} will use the {@link ClayContext} to invoke the
58 * <code>Globals.ADD_ACTION_LISTENER_COMMAND_NAME</code>.</p>
59 *
60 * @param context commons chains
61 * @return <code>true</code> if the chain is done
62 * @exception Exception propagated up to the top of the chain
63 */
64 public boolean execute(Context context) throws Exception {
65
66 boolean isFinal = false;
67
68 ClayContext clayContext = (ClayContext) context;
69 if (clayContext == null) {
70 throw new NullPointerException(getMessages()
71 .getMessage("clay.null.clayContext"));
72 }
73
74 UIComponent child = (UIComponent) clayContext.getChild();
75 if (child == null) {
76 throw new NullPointerException(getMessages()
77 .getMessage("clay.null.childComponent"));
78 }
79
80 ComponentBean displayElement = clayContext.getDisplayElement();
81 if (displayElement == null) {
82 throw new NullPointerException(getMessages()
83 .getMessage("clay.null.componentBean"));
84 }
85
86 if (displayElement.getActionListeners().size() > 0) {
87 if (child instanceof ActionSource) {
88
89 Iterator vi = displayElement.getActionListenerIterator();
90 while (vi.hasNext()) {
91 ActionListenerBean actionListener = (ActionListenerBean) vi
92 .next();
93
94 ClayContext subContext = (ClayContext) clayContext.clone();
95 subContext.setDisplayElement(actionListener);
96 subContext.setParent(child);
97
98 Catalog catalog = getCatalog();
99 Command command = catalog
100 .getCommand(Globals.ADD_ACTION_LISTENER_COMMAND_NAME);
101 command.execute(subContext);
102
103 }
104 } else {
105 log.error(getMessages().getMessage("assign.action.listener.error",
106 new Object[] { displayElement }));
107 }
108 }
109
110 return isFinal;
111 }
112
113 }
114