KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > Arg


1 /*
2  * Copyright 1999-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 /*
17  * $Id: Arg.java,v 1.15 2004/02/17 04:30:02 minchau Exp $
18  */

19 package org.apache.xpath;
20
21 import org.apache.xml.utils.QName;
22 import org.apache.xpath.objects.XObject;
23
24 /**
25  * This class holds an instance of an argument on
26  * the stack. The value of the argument can be either an
27  * XObject or a String containing an expression.
28  * @xsl.usage internal
29  */

30 public class Arg
31 {
32
33   /** Field m_qname: The name of this argument, expressed as a QName
34    * (Qualified Name) object.
35    * @see getQName
36    * @see setQName
37    * */

38   private QName m_qname;
39
40   /**
41    * Get the qualified name for this argument.
42    *
43    * @return QName object containing the qualified name
44    */

45   public final QName getQName()
46   {
47     return m_qname;
48   }
49
50   /**
51    * Set the qualified name for this argument.
52    *
53    * @param name QName object representing the new Qualified Name.
54    */

55   public final void setQName(QName name)
56   {
57     m_qname = name;
58   }
59
60   /** Field m_val: Stored XObject value of this argument
61    * @see #getVal()
62    * @see #setVal()
63    */

64   private XObject m_val;
65
66   /**
67    * Get the value for this argument.
68    *
69    * @return the argument's stored XObject value.
70    * @see #setVal(XObject)
71    */

72   public final XObject getVal()
73   {
74     return m_val;
75   }
76
77   /**
78    * Set the value of this argument.
79    *
80    * @param val an XObject representing the arguments's value.
81    * @see #getVal()
82    */

83   public final void setVal(XObject val)
84   {
85     m_val = val;
86   }
87   
88   /**
89    * Have the object release it's resources.
90    * Call only when the variable or argument is going out of scope.
91    */

92   public void detach()
93   {
94     if(null != m_val)
95     {
96       m_val.allowDetachToRelease(true);
97       m_val.detach();
98     }
99   }
100
101
102   /** Field m_expression: Stored expression value of this argument.
103    * @see #setExpression
104    * @see #getExpression
105    * */

106   private String JavaDoc m_expression;
107
108   /**
109    * Get the value expression for this argument.
110    *
111    * @return String containing the expression previously stored into this
112    * argument
113    * @see #setExpression
114    */

115   public String JavaDoc getExpression()
116   {
117     return m_expression;
118   }
119
120   /**
121    * Set the value expression for this argument.
122    *
123    * @param expr String containing the expression to be stored as this
124    * argument's value.
125    * @see #getExpression
126    */

127   public void setExpression(String JavaDoc expr)
128   {
129     m_expression = expr;
130   }
131
132   /**
133    * True if this variable was added with an xsl:with-param or
134    * is added via setParameter.
135    */

136   private boolean m_isFromWithParam;
137
138   /**
139    * Tell if this variable is a parameter passed with a with-param or as
140    * a top-level parameter.
141    */

142    public boolean isFromWithParam()
143    {
144     return m_isFromWithParam;
145    }
146
147   /**
148    * True if this variable is currently visible. To be visible,
149    * a variable needs to come either from xsl:variable or be
150    * a "received" parameter, ie one for which an xsl:param has
151    * been encountered.
152    * Set at the time the object is constructed and updated as needed.
153    */

154   private boolean m_isVisible;
155
156   /**
157    * Tell if this variable is currently visible.
158    */

159    public boolean isVisible()
160    {
161     return m_isVisible;
162    }
163    
164   /**
165    * Update visibility status of this variable.
166    */

167    public void setIsVisible(boolean b)
168    {
169     m_isVisible = b;
170    }
171
172   /**
173    * Construct a dummy parameter argument, with no QName and no
174    * value (either expression string or value XObject). isVisible
175    * defaults to true.
176    */

177   public Arg()
178   {
179
180     m_qname = new QName("");
181     ; // so that string compares can be done.
182
m_val = null;
183     m_expression = null;
184     m_isVisible = true;
185     m_isFromWithParam = false;
186   }
187
188   /**
189    * Construct a parameter argument that contains an expression.
190    *
191    * @param qname Name of the argument, expressed as a QName object.
192    * @param expression String to be stored as this argument's value expression.
193    * @param isFromWithParam True if this is a parameter variable.
194    */

195   public Arg(QName qname, String JavaDoc expression, boolean isFromWithParam)
196   {
197
198     m_qname = qname;
199     m_val = null;
200     m_expression = expression;
201     m_isFromWithParam = isFromWithParam;
202     m_isVisible = !isFromWithParam;
203   }
204
205   /**
206    * Construct a parameter argument which has an XObject value.
207    * isVisible defaults to true.
208    *
209    * @param qname Name of the argument, expressed as a QName object.
210    * @param val Value of the argument, expressed as an XObject
211    */

212   public Arg(QName qname, XObject val)
213   {
214
215     m_qname = qname;
216     m_val = val;
217     m_isVisible = true;
218     m_isFromWithParam = false;
219     m_expression = null;
220   }
221   
222   /**
223    * Equality function specialized for the variable name. If the argument
224    * is not a qname, it will deligate to the super class.
225    *
226    * @param obj the reference object with which to compare.
227    * @return <code>true</code> if this object is the same as the obj
228    * argument; <code>false</code> otherwise.
229    */

230   public boolean equals(Object JavaDoc obj)
231   {
232     if(obj instanceof QName)
233     {
234       return m_qname.equals(obj);
235     }
236     else
237       return super.equals(obj);
238   }
239
240   /**
241    * Construct a parameter argument.
242    *
243    * @param qname Name of the argument, expressed as a QName object.
244    * @param val Value of the argument, expressed as an XObject
245    * @param isFromWithParam True if this is a parameter variable.
246    */

247   public Arg(QName qname, XObject val, boolean isFromWithParam)
248   {
249
250     m_qname = qname;
251     m_val = val;
252     m_isFromWithParam = isFromWithParam;
253     m_isVisible = !isFromWithParam;
254     m_expression = null;
255   }
256 }
257
Popular Tags