1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xpath;
  58. import org.apache.xml.utils.QName;
  59. import org.apache.xpath.objects.XObject;
  60. /**
  61. * <meta name="usage" content="internal"/>
  62. * This class holds an instance of an argument on
  63. * the stack. The value of the argument can be either an
  64. * XObject or a String containing an expression.
  65. */
  66. public class Arg
  67. {
  68. /** Field m_qname: The name of this argument, expressed as a QName
  69. * (Qualified Name) object.
  70. * @see getQName
  71. * @see setQName
  72. * */
  73. private QName m_qname;
  74. /**
  75. * Get the qualified name for this argument.
  76. *
  77. * @return QName object containing the qualified name
  78. */
  79. public final QName getQName()
  80. {
  81. return m_qname;
  82. }
  83. /**
  84. * Set the qualified name for this argument.
  85. *
  86. * @param name QName object representing the new Qualified Name.
  87. */
  88. public final void setQName(QName name)
  89. {
  90. m_qname = name;
  91. }
  92. /** Field m_val: Stored XObject value of this argument
  93. * @see #getVal()
  94. * @see #setVal()
  95. */
  96. private XObject m_val;
  97. /**
  98. * Get the value for this argument.
  99. *
  100. * @return the argument's stored XObject value.
  101. * @see #setVal(XObject)
  102. */
  103. public final XObject getVal()
  104. {
  105. return m_val;
  106. }
  107. /**
  108. * Set the value of this argument.
  109. *
  110. * @param val an XObject representing the arguments's value.
  111. * @see #getVal()
  112. */
  113. public final void setVal(XObject val)
  114. {
  115. m_val = val;
  116. }
  117. /**
  118. * Have the object release it's resources.
  119. * Call only when the variable or argument is going out of scope.
  120. */
  121. public void detach()
  122. {
  123. if(null != m_val)
  124. {
  125. m_val.allowDetachToRelease(true);
  126. m_val.detach();
  127. }
  128. }
  129. /** Field m_expression: Stored expression value of this argument.
  130. * @see #setExpression
  131. * @see #getExpression
  132. * */
  133. private String m_expression;
  134. /**
  135. * Get the value expression for this argument.
  136. *
  137. * @return String containing the expression previously stored into this
  138. * argument
  139. * @see #setExpression
  140. */
  141. public String getExpression()
  142. {
  143. return m_expression;
  144. }
  145. /**
  146. * Set the value expression for this argument.
  147. *
  148. * @param expr String containing the expression to be stored as this
  149. * argument's value.
  150. * @see #getExpression
  151. */
  152. public void setExpression(String expr)
  153. {
  154. m_expression = expr;
  155. }
  156. /**
  157. * True if this variable was added with an xsl:with-param or
  158. * is added via setParameter.
  159. */
  160. private boolean m_isFromWithParam;
  161. /**
  162. * Tell if this variable is a parameter passed with a with-param or as
  163. * a top-level parameter.
  164. */
  165. public boolean isFromWithParam()
  166. {
  167. return m_isFromWithParam;
  168. }
  169. /**
  170. * True if this variable is currently visible. To be visible,
  171. * a variable needs to come either from xsl:variable or be
  172. * a "received" parameter, ie one for which an xsl:param has
  173. * been encountered.
  174. * Set at the time the object is constructed and updated as needed.
  175. */
  176. private boolean m_isVisible;
  177. /**
  178. * Tell if this variable is currently visible.
  179. */
  180. public boolean isVisible()
  181. {
  182. return m_isVisible;
  183. }
  184. /**
  185. * Update visibility status of this variable.
  186. */
  187. public void setIsVisible(boolean b)
  188. {
  189. m_isVisible = b;
  190. }
  191. /**
  192. * Construct a dummy parameter argument, with no QName and no
  193. * value (either expression string or value XObject). isVisible
  194. * defaults to true.
  195. */
  196. public Arg()
  197. {
  198. m_qname = new QName("");
  199. ; // so that string compares can be done.
  200. m_val = null;
  201. m_expression = null;
  202. m_isVisible = true;
  203. m_isFromWithParam = false;
  204. }
  205. /**
  206. * Construct a parameter argument that contains an expression.
  207. *
  208. * @param qname Name of the argument, expressed as a QName object.
  209. * @param expression String to be stored as this argument's value expression.
  210. * @param isFromWithParam True if this is a parameter variable.
  211. */
  212. public Arg(QName qname, String expression, boolean isFromWithParam)
  213. {
  214. m_qname = qname;
  215. m_val = null;
  216. m_expression = expression;
  217. m_isFromWithParam = isFromWithParam;
  218. m_isVisible = !isFromWithParam;
  219. }
  220. /**
  221. * Construct a parameter argument which has an XObject value.
  222. * isVisible defaults to true.
  223. *
  224. * @param qname Name of the argument, expressed as a QName object.
  225. * @param val Value of the argument, expressed as an XObject
  226. */
  227. public Arg(QName qname, XObject val)
  228. {
  229. m_qname = qname;
  230. m_val = val;
  231. m_isVisible = true;
  232. m_isFromWithParam = false;
  233. m_expression = null;
  234. }
  235. /**
  236. * Equality function specialized for the variable name. If the argument
  237. * is not a qname, it will deligate to the super class.
  238. *
  239. * @param obj the reference object with which to compare.
  240. * @return <code>true</code> if this object is the same as the obj
  241. * argument; <code>false</code> otherwise.
  242. */
  243. public boolean equals(Object obj)
  244. {
  245. if(obj instanceof QName)
  246. {
  247. return m_qname.equals(obj);
  248. }
  249. else
  250. return super.equals(obj);
  251. }
  252. /**
  253. * Construct a parameter argument.
  254. *
  255. * @param qname Name of the argument, expressed as a QName object.
  256. * @param val Value of the argument, expressed as an XObject
  257. * @param isFromWithParam True if this is a parameter variable.
  258. */
  259. public Arg(QName qname, XObject val, boolean isFromWithParam)
  260. {
  261. m_qname = qname;
  262. m_val = val;
  263. m_isFromWithParam = isFromWithParam;
  264. m_isVisible = !isFromWithParam;
  265. m_expression = null;
  266. }
  267. }