View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2003-2006 Christian W. Hargraves (engrean@hotmail.com)
4       
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  package net.sf.jameleon;
20  
21  import net.sf.jameleon.function.FunctionTag;
22  import java.util.ArrayList;
23  
24  import org.apache.commons.jelly.MissingAttributeException;
25  import org.apache.commons.jelly.JellyTagException;
26  import org.apache.commons.jelly.TagSupport;
27  import org.apache.commons.jelly.XMLOutput;
28  
29  /***
30   * Used to give a function tag a parameter or a list of parameters.
31   * 
32   * For example:
33   * <pre>
34   *      &lt;param&gt;
35   *          &lt;param-name&gt;someName&lt;/param-name&gt;
36   *          &lt;param-value&gt;foo&lt;/param-value&gt;
37   *          &lt;param-type&gt;text&lt;/param-type&gt;
38   *      &lt;/param&gt;
39   * </pre>
40   * This tag adds itself to a list of param tags to the parent FunctionTag.
41   * It's up to the FunctionTag to use the parameters. They can be accessed via
42   * the {@link net.sf.jameleon.function.FunctionTag#getParams()} method.
43   * 
44   * @jameleon.function name="param"
45   */
46  public class ParamTag extends TagSupport {
47      
48      /***
49       * The value of the param.
50       */
51      protected ArrayList values;
52      /***
53       * The name of param.
54       */
55      protected String name;
56      /***
57       * The input type of the param (text, checkbox, listbox...)
58       */
59      protected String paramType;
60  
61      protected String fromVariable;
62  
63      public ParamTag(){
64          super();
65          values = new ArrayList();
66      }
67  
68      public void doTag(XMLOutput out) throws MissingAttributeException, JellyTagException{
69          values = new ArrayList();
70          //To support child elements
71          invokeBody(out);
72          validate();
73  
74          FunctionTag tag = (FunctionTag) findAncestorWithClass(FunctionTag.class);
75          tag.addParam(this);        
76      }
77  
78      /***
79       * Used to validate everything is set up correctly.
80       * @throws MissingAttributeException - When a required attribute isn't set.
81       * @throws JellyTagException - When this tag is used out of context.
82       */
83      protected void validate()throws MissingAttributeException, JellyTagException{
84          if (name == null){
85              throw new MissingAttributeException("name is a required tag!");
86          }
87      }
88  
89      /***
90       * @return The param type
91       */
92      public String getParamType(){
93          return this.paramType;
94      }
95  
96      /***
97       * @return The first param value from the list of values
98       */
99      public String getValue(){
100         return (String)values.get(0);
101     }
102 
103     /***
104      * @return The param values
105      */
106     public ArrayList getParamValues(){
107         return values;
108     }
109 
110     /***
111      * Adds a value to the list of values supplied for this parameter.
112      * @param value The param value
113      */
114     public void addParamValue(String value){
115         values.add(value);
116     }
117 
118     /***
119      * @return The param name
120      */
121     public String getName(){
122         return this.name;
123     }
124 
125     /***
126      * @return The param name
127      */
128     public String getParamName(){
129         return this.name;
130     }
131 
132     public void setParamName(String paramName){
133         name = paramName;
134     }
135 
136     public void setParamValue(String value){
137         values = new ArrayList();
138         values.add(value);
139     }
140 
141     public void setParamType(String paramType){
142         this.paramType = paramType;
143     }
144 
145     public String getFromVariable(){
146         return fromVariable;
147     }
148 
149     public void setFromVariable(String fromVar){
150         fromVariable = fromVar;
151     }
152 
153 }