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.EditableValueHolder;
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.ComponentBean;
35 import org.apache.shale.clay.config.beans.ValueChangeListenerBean;
36
37 /***
38 * <p>
39 * For each {@link org.apache.shale.clay.config.beans.ValueChangeListenerBean}
40 * in the <code>valueChangeListeners</code> collection, the
41 * {@link org.apache.shale.clay.component.chain.CreateValueChangeListenerCommand}
42 * command will be invoked.
43 * </p>
44 */
45 public class AssignValueChangeListenersCommand extends AbstractCommand {
46
47 /***
48 * <p>
49 * Common Logging utility.
50 * </p>
51 */
52 private static Log log;
53 static {
54 log = LogFactory.getLog(AssignValueChangeListenersCommand.class);
55 }
56
57 /***
58 * <p>
59 * Uses the <code>Globals.ADD_VALUE_CHANGE_LISTENER_COMMAND_NAME</code>
60 * command to create a <code>ValueChangeListener</code>.</p>
61 *
62 * @param context common chains
63 * @return <code>true</code> if the chain is complete
64 * @exception Exception propagated up to the top of the chain
65 */
66 public boolean execute(Context context) throws Exception {
67
68 boolean isFinal = false;
69
70 ClayContext clayContext = (ClayContext) context;
71 if (clayContext == null) {
72 throw new NullPointerException(getMessages()
73 .getMessage("clay.null.clayContext"));
74 }
75
76 UIComponent child = (UIComponent) clayContext.getChild();
77 if (child == null) {
78 throw new NullPointerException(getMessages()
79 .getMessage("clay.null.childComponent"));
80 }
81
82 ComponentBean displayElement = clayContext.getDisplayElement();
83 if (displayElement == null) {
84 throw new NullPointerException(getMessages()
85 .getMessage("clay.null.componentBean"));
86 }
87
88 if (displayElement.getValueChangeListeners().size() > 0) {
89 if (child instanceof EditableValueHolder) {
90
91 Iterator vi = displayElement.getValueChangeListenerIterator();
92 while (vi.hasNext()) {
93 ValueChangeListenerBean valueChangeListener = (ValueChangeListenerBean) vi
94 .next();
95
96 ClayContext subContext = (ClayContext) clayContext.clone();
97 subContext.setDisplayElement(valueChangeListener);
98 subContext.setParent(child);
99
100 Catalog catalog = getCatalog();
101 Command command = catalog
102 .getCommand(Globals.ADD_VALUE_CHANGE_LISTENER_COMMAND_NAME);
103 command.execute(subContext);
104
105 }
106 } else {
107 log.error(getMessages().getMessage(
108 "assign.valueChangeListener.error",
109 new Object[] { displayElement }));
110 }
111 }
112
113 return isFinal;
114 }
115
116 }