001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: Arg.java,v 1.15 2004/02/17 04:30:02 minchau Exp $
018: */
019: package org.apache.xpath;
020:
021: import org.apache.xml.utils.QName;
022: import org.apache.xpath.objects.XObject;
023:
024: /**
025: * This class holds an instance of an argument on
026: * the stack. The value of the argument can be either an
027: * XObject or a String containing an expression.
028: * @xsl.usage internal
029: */
030: public class Arg {
031:
032: /** Field m_qname: The name of this argument, expressed as a QName
033: * (Qualified Name) object.
034: * @see getQName
035: * @see setQName
036: * */
037: private QName m_qname;
038:
039: /**
040: * Get the qualified name for this argument.
041: *
042: * @return QName object containing the qualified name
043: */
044: public final QName getQName() {
045: return m_qname;
046: }
047:
048: /**
049: * Set the qualified name for this argument.
050: *
051: * @param name QName object representing the new Qualified Name.
052: */
053: public final void setQName(QName name) {
054: m_qname = name;
055: }
056:
057: /** Field m_val: Stored XObject value of this argument
058: * @see #getVal()
059: * @see #setVal()
060: */
061: private XObject m_val;
062:
063: /**
064: * Get the value for this argument.
065: *
066: * @return the argument's stored XObject value.
067: * @see #setVal(XObject)
068: */
069: public final XObject getVal() {
070: return m_val;
071: }
072:
073: /**
074: * Set the value of this argument.
075: *
076: * @param val an XObject representing the arguments's value.
077: * @see #getVal()
078: */
079: public final void setVal(XObject val) {
080: m_val = val;
081: }
082:
083: /**
084: * Have the object release it's resources.
085: * Call only when the variable or argument is going out of scope.
086: */
087: public void detach() {
088: if (null != m_val) {
089: m_val.allowDetachToRelease(true);
090: m_val.detach();
091: }
092: }
093:
094: /** Field m_expression: Stored expression value of this argument.
095: * @see #setExpression
096: * @see #getExpression
097: * */
098: private String m_expression;
099:
100: /**
101: * Get the value expression for this argument.
102: *
103: * @return String containing the expression previously stored into this
104: * argument
105: * @see #setExpression
106: */
107: public String getExpression() {
108: return m_expression;
109: }
110:
111: /**
112: * Set the value expression for this argument.
113: *
114: * @param expr String containing the expression to be stored as this
115: * argument's value.
116: * @see #getExpression
117: */
118: public void setExpression(String expr) {
119: m_expression = expr;
120: }
121:
122: /**
123: * True if this variable was added with an xsl:with-param or
124: * is added via setParameter.
125: */
126: private boolean m_isFromWithParam;
127:
128: /**
129: * Tell if this variable is a parameter passed with a with-param or as
130: * a top-level parameter.
131: */
132: public boolean isFromWithParam() {
133: return m_isFromWithParam;
134: }
135:
136: /**
137: * True if this variable is currently visible. To be visible,
138: * a variable needs to come either from xsl:variable or be
139: * a "received" parameter, ie one for which an xsl:param has
140: * been encountered.
141: * Set at the time the object is constructed and updated as needed.
142: */
143: private boolean m_isVisible;
144:
145: /**
146: * Tell if this variable is currently visible.
147: */
148: public boolean isVisible() {
149: return m_isVisible;
150: }
151:
152: /**
153: * Update visibility status of this variable.
154: */
155: public void setIsVisible(boolean b) {
156: m_isVisible = b;
157: }
158:
159: /**
160: * Construct a dummy parameter argument, with no QName and no
161: * value (either expression string or value XObject). isVisible
162: * defaults to true.
163: */
164: public Arg() {
165:
166: m_qname = new QName("");
167: ; // so that string compares can be done.
168: m_val = null;
169: m_expression = null;
170: m_isVisible = true;
171: m_isFromWithParam = false;
172: }
173:
174: /**
175: * Construct a parameter argument that contains an expression.
176: *
177: * @param qname Name of the argument, expressed as a QName object.
178: * @param expression String to be stored as this argument's value expression.
179: * @param isFromWithParam True if this is a parameter variable.
180: */
181: public Arg(QName qname, String expression, boolean isFromWithParam) {
182:
183: m_qname = qname;
184: m_val = null;
185: m_expression = expression;
186: m_isFromWithParam = isFromWithParam;
187: m_isVisible = !isFromWithParam;
188: }
189:
190: /**
191: * Construct a parameter argument which has an XObject value.
192: * isVisible defaults to true.
193: *
194: * @param qname Name of the argument, expressed as a QName object.
195: * @param val Value of the argument, expressed as an XObject
196: */
197: public Arg(QName qname, XObject val) {
198:
199: m_qname = qname;
200: m_val = val;
201: m_isVisible = true;
202: m_isFromWithParam = false;
203: m_expression = null;
204: }
205:
206: /**
207: * Equality function specialized for the variable name. If the argument
208: * is not a qname, it will deligate to the super class.
209: *
210: * @param obj the reference object with which to compare.
211: * @return <code>true</code> if this object is the same as the obj
212: * argument; <code>false</code> otherwise.
213: */
214: public boolean equals(Object obj) {
215: if (obj instanceof QName) {
216: return m_qname.equals(obj);
217: } else
218: return super .equals(obj);
219: }
220:
221: /**
222: * Construct a parameter argument.
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: * @param isFromWithParam True if this is a parameter variable.
227: */
228: public Arg(QName qname, XObject val, boolean isFromWithParam) {
229:
230: m_qname = qname;
231: m_val = val;
232: m_isFromWithParam = isFromWithParam;
233: m_isVisible = !isFromWithParam;
234: m_expression = null;
235: }
236: }
|