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 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 22 | public class AssignValueChangeListenersCommand extends AbstractCommand { |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
private static Log log; |
53 | |
static { |
54 | 2 | log = LogFactory.getLog(AssignValueChangeListenersCommand.class); |
55 | 1 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public boolean execute(Context context) throws Exception { |
67 | |
|
68 | 398 | boolean isFinal = false; |
69 | |
|
70 | 398 | ClayContext clayContext = (ClayContext) context; |
71 | 398 | if (clayContext == null) { |
72 | |
throw new NullPointerException(getMessages() |
73 | |
.getMessage("clay.null.clayContext")); |
74 | |
} |
75 | |
|
76 | 398 | UIComponent child = (UIComponent) clayContext.getChild(); |
77 | 398 | if (child == null) { |
78 | |
throw new NullPointerException(getMessages() |
79 | |
.getMessage("clay.null.childComponent")); |
80 | |
} |
81 | |
|
82 | 398 | ComponentBean displayElement = clayContext.getDisplayElement(); |
83 | 398 | if (displayElement == null) { |
84 | |
throw new NullPointerException(getMessages() |
85 | |
.getMessage("clay.null.componentBean")); |
86 | |
} |
87 | |
|
88 | 398 | if (displayElement.getValueChangeListeners().size() > 0) { |
89 | 2 | if (child instanceof EditableValueHolder) { |
90 | |
|
91 | 2 | Iterator vi = displayElement.getValueChangeListenerIterator(); |
92 | 4 | while (vi.hasNext()) { |
93 | 2 | ValueChangeListenerBean valueChangeListener = (ValueChangeListenerBean) vi |
94 | |
.next(); |
95 | |
|
96 | 2 | ClayContext subContext = (ClayContext) clayContext.clone(); |
97 | 2 | subContext.setDisplayElement(valueChangeListener); |
98 | 2 | subContext.setParent(child); |
99 | |
|
100 | 2 | Catalog catalog = getCatalog(); |
101 | 2 | Command command = catalog |
102 | |
.getCommand(Globals.ADD_VALUE_CHANGE_LISTENER_COMMAND_NAME); |
103 | 2 | command.execute(subContext); |
104 | |
|
105 | 2 | } |
106 | 2 | } else { |
107 | |
log.error(getMessages().getMessage( |
108 | |
"assign.valueChangeListener.error", |
109 | |
new Object[] { displayElement })); |
110 | |
} |
111 | |
} |
112 | |
|
113 | 398 | return isFinal; |
114 | |
} |
115 | |
|
116 | |
} |