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