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 javax.faces.component.UIComponent;
24 import javax.faces.component.ValueHolder;
25
26 import org.apache.commons.chain.Catalog;
27 import org.apache.commons.chain.Command;
28 import org.apache.commons.chain.Context;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.shale.clay.config.Globals;
32 import org.apache.shale.clay.config.beans.ComponentBean;
33
34 /***
35 * <p>
36 * Determines if the {@link ComponentBean} has a {@link org.apache.shale.clay.config.beans.ConverterBean} assigned.
37 * A <code>Converter</code> is created by invoking the
38 * {@link org.apache.shale.clay.component.chain.CreateConverterCommand}.
39 * </p>
40 */
41 public class AssignConverterCommand extends AbstractCommand {
42
43 /***
44 * <p>
45 * Common Logging utility.
46 * </p>
47 */
48 private static Log log;
49 static {
50 log = LogFactory.getLog(AssignConverterCommand.class);
51 }
52
53 /***
54 * <p>
55 * Checks to see if the {@link org.apache.shale.clay.config.beans.ComponentBean}
56 * has a {@link org.apache.shale.clay.config.beans.ConverterBean}
57 * assigned. The <code>Globals.ADD_CONVERTER_COMMAND_NAME</code> is
58 * invoked to create a <code>Converter</code>.
59 *
60 * @param context common chains
61 * @return <code>true</code> if the chain is complete
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.getConverter() != null) {
87 if (child instanceof ValueHolder) {
88
89 ClayContext subContext = (ClayContext) clayContext.clone();
90 subContext.setDisplayElement(displayElement.getConverter());
91 subContext.setParent(child);
92
93 Catalog catalog = getCatalog();
94 Command command = catalog
95 .getCommand(Globals.ADD_CONVERTER_COMMAND_NAME);
96 command.execute(subContext);
97
98 } else {
99 log.error(getMessages().getMessage("assign.converter.error",
100 new Object[] { displayElement }));
101 }
102 }
103
104 return isFinal;
105 }
106
107 }