1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly;
18
19 import org.apache.commons.beanutils.DynaBean;
20 import org.apache.commons.beanutils.DynaProperty;
21
22 /***
23 * <p><code>DynaBeanTag</code> is a DynaTag implementation which uses a DynaBean
24 * to store its attribute values in. Derived tags can then process this
25 * DynaBean in any way it wishes.
26 * </p>
27 *
28 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29 * @version $Revision: 155420 $
30 */
31
32 public abstract class DynaBeanTagSupport extends DynaTagSupport {
33
34 /*** the DynaBean which is used to store the attributes of this tag. */
35 private DynaBean dynaBean;
36
37 public DynaBeanTagSupport() {
38 }
39
40 public DynaBeanTagSupport(DynaBean dynaBean) {
41 this.dynaBean = dynaBean;
42 }
43
44 /*** Sets the context in which the tag will be run. */
45 public void setContext(JellyContext context) throws JellyTagException {
46 this.context = context;
47 beforeSetAttributes();
48 }
49
50 /*** Sets an attribute value of this tag before the tag is invoked
51 */
52 public void setAttribute(String name, Object value) throws JellyTagException {
53 getDynaBean().set(name, value);
54 }
55
56 /***
57 * @return the type of the given attribute. By default just return
58 * Object.class if this is not known.
59 */
60 public Class getAttributeType(String name) throws JellyTagException {
61 DynaProperty property = getDynaBean().getDynaClass().getDynaProperty(name);
62 if (property != null) {
63 return property.getType();
64 }
65 return Object.class;
66 }
67
68 /***
69 * @return the DynaBean which is used to store the
70 * attributes of this tag
71 */
72 public DynaBean getDynaBean() {
73 return dynaBean;
74 }
75
76 /***
77 * Sets the DynaBean which is used to store the
78 * attributes of this tag
79 */
80 public void setDynaBean(DynaBean dynaBean) {
81 this.dynaBean = dynaBean;
82 }
83
84 /***
85 * Callback to allow processing to occur before the attributes are about to be set
86 */
87 public void beforeSetAttributes() throws JellyTagException {
88 }
89
90 }