01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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)
46: throws JellyTagException {
47: this .context = context;
48: beforeSetAttributes();
49: }
50:
51: /** Sets an attribute value of this tag before the tag is invoked
52: */
53: public void setAttribute(String name, Object value)
54: throws JellyTagException {
55: getDynaBean().set(name, value);
56: }
57:
58: /**
59: * @return the type of the given attribute. By default just return
60: * Object.class if this is not known.
61: */
62: public Class getAttributeType(String name) throws JellyTagException {
63: DynaProperty property = getDynaBean().getDynaClass()
64: .getDynaProperty(name);
65: if (property != null) {
66: return property.getType();
67: }
68: return Object.class;
69: }
70:
71: /**
72: * @return the DynaBean which is used to store the
73: * attributes of this tag
74: */
75: public DynaBean getDynaBean() {
76: return dynaBean;
77: }
78:
79: /**
80: * Sets the DynaBean which is used to store the
81: * attributes of this tag
82: */
83: public void setDynaBean(DynaBean dynaBean) {
84: this .dynaBean = dynaBean;
85: }
86:
87: /**
88: * Callback to allow processing to occur before the attributes are about to be set
89: */
90: public void beforeSetAttributes() throws JellyTagException {
91: }
92:
93: }
|