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 org.apache.commons.chain.Catalog;
26 import org.apache.commons.chain.Command;
27 import org.apache.commons.chain.Context;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.shale.clay.config.Globals;
31 import org.apache.shale.clay.config.beans.AttributeBean;
32 import org.apache.shale.clay.config.beans.ComponentBean;
33
34 /***
35 * <p>
36 * Sets the <code>UIComponent</code> properties using the attributes collection of
37 * {@link org.apache.shale.clay.config.beans.AttributeBean} by invoking the
38 * <code>Globals.SET_ATTRIBUTE_COMMAND_NAME</code> <code>Chain</code>.
39 * </p>
40 */
41 public class AssignPropertiesCommand extends AbstractCommand {
42
43 /***
44 * <p>
45 * Common logger utility.
46 * </p>
47 */
48 private static Log log;
49 static {
50 log = LogFactory.getLog(AssignPropertiesCommand.class);
51 }
52
53 /***
54 * <p>
55 * Invokes a chain that fires several Commands.
56 * <dl>
57 * <dt>Associated Property Commands
58 * <dd>{@link org.apache.shale.clay.component.chain.PropertyActionCommand}
59 * <dd>{@link org.apache.shale.clay.component.chain.PropertyActionListenerCommand}
60 * <dd>{@link org.apache.shale.clay.component.chain.PropertyValidatorCommand}
61 * <dd>{@link org.apache.shale.clay.component.chain.PropertyValueChangeListenerCommand}
62 * <dd>{@link org.apache.shale.clay.component.chain.PropertyValueCommand}
63 * </dl>
64 * </p>
65 *
66 * @param context common chains
67 * @return <code>true</code> if the chain is complete
68 * @exception Exception propagated up to the top of the chain
69 */
70 public boolean execute(Context context) throws Exception {
71
72 boolean isFinal = false;
73
74 ClayContext clayContext = (ClayContext) context;
75 if (clayContext == null) {
76 throw new NullPointerException(getMessages()
77 .getMessage("clay.null.clayContext"));
78 }
79
80 ComponentBean displayElement = clayContext.getDisplayElement();
81 if (displayElement == null) {
82 throw new NullPointerException(getMessages()
83 .getMessage("clay.null.componentBean"));
84 }
85
86 Iterator ai = displayElement.getAttributeIterator();
87 Catalog defaultCatalog = getCatalog();
88 Catalog customizationCatalog = getCustomizationCatalog();
89
90 Command defaultCommand = defaultCatalog.getCommand(Globals.SET_ATTRIBUTE_COMMAND_NAME);
91 next: while (ai.hasNext()) {
92 AttributeBean a = (AttributeBean) ai.next();
93 if (a.getValue() == null) {
94 continue next;
95 }
96
97 Command command = null;
98
99 if (customizationCatalog != null) {
100 command = customizationCatalog.getCommand(a.getName());
101 }
102
103 if (command == null) {
104 command = defaultCatalog.getCommand(a.getName());
105 }
106
107 if (command == null) {
108 command = defaultCommand;
109 }
110
111 clayContext.setAttribute(a);
112
113 try {
114 command.execute(clayContext);
115 } catch (Exception e) {
116 log.error(getMessages().getMessage("assign.property.error",
117 new Object[] { a }), e);
118 throw e;
119
120 }
121
122 }
123 ai = null;
124
125 return isFinal;
126 }
127
128 }