KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > magnet > domain > Param


1 package org.sapia.magnet.domain;
2
3 // Import of Sapia's Corus classes
4
// --------------------------------
5
import org.sapia.magnet.render.AbstractRenderable;
6 import org.sapia.magnet.render.MagnetContext;
7 import org.sapia.magnet.render.RenderingException;
8
9
10 /**
11  *
12  *
13  * @author Jean-Cedric Desrochers
14  *
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class Param extends AbstractRenderable {
22
23   /////////////////////////////////////////////////////////////////////////////////////////
24
////////////////////////////////// CLASS ATTRIBUTES ///////////////////////////////////
25
/////////////////////////////////////////////////////////////////////////////////////////
26

27   /** Defines the SYSTEM paramter scope. */
28   public static final String JavaDoc SCOPE_SYSTEM = "system";
29
30   /** Defines the MAGNET paramter scope. */
31   public static final String JavaDoc SCOPE_MAGNET = "magnet";
32
33   /////////////////////////////////////////////////////////////////////////////////////////
34
///////////////////////////////// INSTANCE ATTRIBUTES /////////////////////////////////
35
/////////////////////////////////////////////////////////////////////////////////////////
36

37   /** The name of this parameter. */
38   private String JavaDoc _theName;
39
40   /** The value of this parameter. */
41   private String JavaDoc _theValue;
42
43   /** The scope of this parameter. */
44   private String JavaDoc _theScope;
45   
46   /** The required param name to use this parameter. */
47   private String JavaDoc _theIfDefine;
48   
49   /** The inexistant param name to use this parameter. */
50   private String JavaDoc _theUnlessDefine;
51
52   /////////////////////////////////////////////////////////////////////////////////////////
53
//////////////////////////////////// CONSTRUCTORS /////////////////////////////////////
54
/////////////////////////////////////////////////////////////////////////////////////////
55

56   /**
57    * Creates a new Param instance.
58    */

59   public Param() {
60     _theScope = SCOPE_MAGNET;
61   }
62
63   /**
64    * Creates a new Parameter instance with the arguments passed in.
65    *
66    * @param aName The name of this parameter.
67    * @param aValue The value of this parameter.
68    */

69   public Param(String JavaDoc aName, String JavaDoc aValue) {
70     this(aName, aValue, SCOPE_MAGNET);
71   }
72
73   /**
74    * Creates a new Parameter instance with the arguments passed in.
75    *
76    * @param aName The name of this parameter.
77    * @param aValue The value of this parameter.
78    * @param aScope The scope of this parameter.
79    */

80   public Param(String JavaDoc aName, String JavaDoc aValue, String JavaDoc aScope) {
81     _theName = aName;
82     _theValue = aValue;
83     _theScope = aScope;
84   }
85
86   /////////////////////////////////////////////////////////////////////////////////////////
87
////////////////////////////////// ACCESSOR METHODS ///////////////////////////////////
88
/////////////////////////////////////////////////////////////////////////////////////////
89

90   /**
91    * Returns the name of this parameter.
92    *
93    * @return The name of this parameter.
94    */

95   public String JavaDoc getName() {
96     return _theName;
97   }
98
99   /**
100    * Returns the value of this parameter.
101    *
102    * @return The value of this parameter.
103    */

104   public String JavaDoc getValue() {
105     return _theValue;
106   }
107
108   /**
109    * Returns the scope of this parameter.
110    *
111    * @return The scope of this parameter.
112    */

113   public String JavaDoc getScope() {
114     return _theScope;
115   }
116   
117   /**
118    * Returns the name of the variable that MUST exist to
119    * use this parameter.
120    *
121    * @return The name of the variable that MUST exist to
122    * use this parameter.
123    */

124   public String JavaDoc getIfDefine() {
125     return _theIfDefine;
126   }
127   
128   /**
129    * Returns the name of the variable that must NOT exist to
130    * use this parameter.
131    *
132    * @return The name of the variable that must NOT exist to
133    * use this parameter.
134    */

135   public String JavaDoc getUnlessDefine() {
136     return _theUnlessDefine;
137   }
138   
139   
140
141   /////////////////////////////////////////////////////////////////////////////////////////
142
/////////////////////////////////// MUTATOR METHODS ///////////////////////////////////
143
/////////////////////////////////////////////////////////////////////////////////////////
144

145   /**
146    * Changes the name of this parameter.
147    *
148    * @param aName The new name of this parameter.
149    */

150   public void setName(String JavaDoc aName) {
151     _theName = aName;
152   }
153
154   /**
155    * Changes the value of this parameter.
156    *
157    * @param aValue The new value of this parameter.
158    */

159   public void setValue(String JavaDoc aValue) {
160     _theValue = aValue;
161   }
162
163   /**
164    * Changes the scope of this parameter.
165    *
166    * @param aScope The scope of this parameter.
167    */

168   public void setScope(String JavaDoc aScope) {
169     _theScope = aScope;
170   }
171   
172   /**
173    * Changes the name of the parameters that MUST exist to use
174    * this parameter
175    *
176    * @param aParamName The name of the parameter that need to exist.
177    */

178   public void setIfDefine(String JavaDoc aParamName) {
179     _theIfDefine = aParamName;
180   }
181   
182   /**
183    * Changes the name of the parameters that must NOT exist to use
184    * this parameter
185    *
186    * @param aParamName The name of the parameter that need to be inexistant.
187    */

188   public void setUnlessDefine(String JavaDoc aParamName) {
189     _theUnlessDefine = aParamName;
190   }
191
192   /////////////////////////////////////////////////////////////////////////////////////////
193
////////////////////////////////// OVERRIDEN METHODS //////////////////////////////////
194
/////////////////////////////////////////////////////////////////////////////////////////
195

196   /**
197    * Renders this objects to the magnet context passed in.
198    *
199    * @param aContext The magnet context to use.
200    * @exception RenderingException If an error occurs while rendering this object.
201    */

202   public void render(MagnetContext aContext) throws RenderingException {
203     try {
204       _theValue = resolveValue(aContext, _theValue);
205       _theScope = resolveValue(aContext, _theScope);
206     } catch (RenderingException re) {
207       StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc();
208       aBuffer.append("Unable to resolve an attribute of the param '").
209               append(_theName).append("'");
210       
211       throw new RenderingException(aBuffer.toString(), re);
212     }
213   }
214
215   /**
216    * Returns a string representation of this parameter.
217    *
218    * @return A string representation of this parameter.
219    */

220   public String JavaDoc toString() {
221     StringBuffer JavaDoc aBuffer = new StringBuffer JavaDoc(super.toString());
222     aBuffer.append("[name=").append(_theName).
223             append(" value=").append(_theValue).
224             append(" scope=").append(_theScope).
225             append(" ifDefine=").append(_theIfDefine).
226             append(" unlessDefine=").append(_theUnlessDefine).
227             append("]");
228
229     return aBuffer.toString();
230   }
231 }
232
Popular Tags