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.ActionSource;
24 import javax.faces.component.UIComponent;
25 import javax.faces.context.FacesContext;
26
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.beans.AttributeBean;
32 import org.apache.shale.clay.config.beans.ComponentBean;
33
34 /***
35 * <p>
36 * This <code>Command</code> will create an <code>action</code> method
37 * binding and assign it to the <code>UIComponent</code> implementing the
38 * <code>ActionSource</code> interface.
39 * </p>
40 */
41
42 public class PropertyActionCommand extends AbstractCommand implements Command {
43
44 /***
45 * <p>
46 * Common logger utility class.
47 * </p>
48 */
49 private static Log log;
50 static {
51 log = LogFactory.getLog(PropertyActionCommand.class);
52 }
53
54 /***
55 * <p>
56 * Looks to see if the {@link AttributeBean} on the {@link ClayContext} is a
57 * <code>action</code> attribute. If it is, create a
58 * <code>MethodBinding</code> and assign it to the component returning a
59 * <code>true</code> value. Otherwise, return a <code>false</code>
60 * value. This <code>Command</code> is invoked from the
61 * {@link AssignPropertiesCommand} chain.
62 * </p>
63 *
64 * @param context common chains
65 * @return <code>true</code> if the chain is complete
66 * @exception Exception propagated up to the top of the chain
67 */
68 public boolean execute(Context context) throws Exception {
69
70 boolean isFinal = false;
71
72 ClayContext clayContext = (ClayContext) context;
73 if (clayContext == null) {
74 throw new NullPointerException(getMessages().getMessage("clay.null.clayContext"));
75 }
76 AttributeBean attributeBean = clayContext.getAttribute();
77 if (attributeBean == null) {
78 throw new NullPointerException(getMessages().getMessage("clay.null.attributeBean"));
79 }
80 ComponentBean displayElement = clayContext.getDisplayElement();
81 if (displayElement == null) {
82 throw new NullPointerException(getMessages().getMessage("clay.null.componentBean"));
83 }
84 FacesContext facesContext = clayContext.getFacesContext();
85 if (facesContext == null) {
86 throw new NullPointerException(getMessages().getMessage("clay.null.facesContext"));
87 }
88
89 if (attributeBean.getName().equals("action") && attributeBean.getValue() != null) {
90 isFinal = true;
91
92 UIComponent child = (UIComponent) clayContext.getChild();
93 if (child == null) {
94 throw new NullPointerException(getMessages().getMessage("clay.null.childComponent"));
95 }
96
97 if (child instanceof ActionSource) {
98 String expr = null;
99 expr = replaceMnemonic(clayContext);
100 getTagUtils().setAction(child, expr);
101 } else {
102 log.error(getMessages().getMessage("property.action.error", new Object[] {attributeBean}));
103 }
104 }
105
106 return isFinal;
107 }
108 }