KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jelly > tags > define > AttributeTag


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 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     // Tag interface
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     // Properties
65
//-------------------------------------------------------------------------
66

67     /**
68      * Sets the name of the attribute
69      */

70     public void setName(String JavaDoc 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 }
88
Popular Tags