| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 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 | 18 | private static final Log log = LogFactory.getLog(AttributeTag.class); |
| 41 | ||
| 42 | /** the attribute definition */ |
|
| 43 | private Attribute attribute; |
|
| 44 | ||
| 45 | 0 | public AttributeTag() { |
| 46 | 0 | attribute = new Attribute(); |
| 47 | 0 | } |
| 48 | ||
| 49 | 0 | public AttributeTag(Attribute attribute) { |
| 50 | 0 | this.attribute = attribute; |
| 51 | 0 | } |
| 52 | ||
| 53 | // Tag interface |
|
| 54 | //------------------------------------------------------------------------- |
|
| 55 | public void doTag(XMLOutput output) throws JellyTagException { |
|
| 56 | 0 | BeanTag tag = (BeanTag) findAncestorWithClass( BeanTag.class ); |
| 57 | 0 | if ( tag == null ) { |
| 58 | 0 | throw new JellyTagException( "This tag should be nested inside a <define:bean> or <define:jellybean> tag" ); |
| 59 | } |
|
| 60 | ||
| 61 | 0 | tag.addAttribute( attribute ); |
| 62 | 0 | } |
| 63 | ||
| 64 | // Properties |
|
| 65 | //------------------------------------------------------------------------- |
|
| 66 | ||
| 67 | /** |
|
| 68 | * Sets the name of the attribute |
|
| 69 | */ |
|
| 70 | public void setName(String name) { |
|
| 71 | 0 | attribute.setName(name); |
| 72 | 0 | } |
| 73 | ||
| 74 | /** |
|
| 75 | * Sets whether this attribute is mandatory or not |
|
| 76 | */ |
|
| 77 | public void setRequired(boolean required) { |
|
| 78 | 0 | attribute.setRequired(required); |
| 79 | 0 | } |
| 80 | ||
| 81 | /** |
|
| 82 | * Sets the default value of this attribute |
|
| 83 | */ |
|
| 84 | public void setDefaultValue(Expression defaultValue) { |
|
| 85 | 0 | attribute.setDefaultValue(defaultValue); |
| 86 | 0 | } |
| 87 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |