1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.define;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.TagSupport;
20 import org.apache.commons.jelly.XMLOutput;
21 import org.apache.commons.jelly.expression.Expression;
22 import org.apache.commons.jelly.impl.Attribute;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /***
28 * This tag is bound onto a Java Bean class. When the tag is invoked a bean will be created
29 * using the tags attributes.
30 * The bean may also have an invoke method called invoke(), run(), execute() or some such method
31 * which will be invoked after the bean has been configured.</p>
32 *
33 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
34 * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
35 * @version $Revision: 155420 $
36 */
37 public class AttributeTag extends TagSupport {
38
39 /*** The Log to which logging calls will be made. */
40 private static final Log log = LogFactory.getLog(AttributeTag.class);
41
42 /*** the attribute definition */
43 private Attribute attribute;
44
45 public AttributeTag() {
46 attribute = new Attribute();
47 }
48
49 public AttributeTag(Attribute attribute) {
50 this.attribute = attribute;
51 }
52
53
54
55 public void doTag(XMLOutput output) throws JellyTagException {
56 BeanTag tag = (BeanTag) findAncestorWithClass( BeanTag.class );
57 if ( tag == null ) {
58 throw new JellyTagException( "This tag should be nested inside a <define:bean> or <define:jellybean> tag" );
59 }
60
61 tag.addAttribute( attribute );
62 }
63
64
65
66
67 /***
68 * Sets the name of the attribute
69 */
70 public void setName(String name) {
71 attribute.setName(name);
72 }
73
74 /***
75 * Sets whether this attribute is mandatory or not
76 */
77 public void setRequired(boolean required) {
78 attribute.setRequired(required);
79 }
80
81 /***
82 * Sets the default value of this attribute
83 */
84 public void setDefaultValue(Expression defaultValue) {
85 attribute.setDefaultValue(defaultValue);
86 }
87 }