KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xpath > internal > functions > FunctionOneArg


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: FunctionOneArg.java,v 1.13 2004/02/17 04:34:00 minchau Exp $
18  */

19 package com.sun.org.apache.xpath.internal.functions;
20
21 import com.sun.org.apache.xalan.internal.res.XSLMessages;
22 import com.sun.org.apache.xpath.internal.Expression;
23 import com.sun.org.apache.xpath.internal.ExpressionOwner;
24 import com.sun.org.apache.xpath.internal.XPathVisitor;
25
26 /**
27  * Base class for functions that accept one argument.
28  * @xsl.usage advanced
29  */

30 public class FunctionOneArg extends Function implements ExpressionOwner
31 {
32
33   /** The first argument passed to the function (at index 0).
34    * @serial */

35   Expression m_arg0;
36
37   /**
38    * Return the first argument passed to the function (at index 0).
39    *
40    * @return An expression that represents the first argument passed to the
41    * function.
42    */

43   public Expression getArg0()
44   {
45     return m_arg0;
46   }
47   
48   /**
49    * Set an argument expression for a function. This method is called by the
50    * XPath compiler.
51    *
52    * @param arg non-null expression that represents the argument.
53    * @param argNum The argument number index.
54    *
55    * @throws WrongNumberArgsException If the argNum parameter is greater than 0.
56    */

57   public void setArg(Expression arg, int argNum)
58           throws WrongNumberArgsException
59   {
60
61     if (0 == argNum)
62     {
63       m_arg0 = arg;
64       arg.exprSetParent(this);
65     }
66     else
67       reportWrongNumberArgs();
68   }
69
70   /**
71    * Check that the number of arguments passed to this function is correct.
72    *
73    *
74    * @param argNum The number of arguments that is being passed to the function.
75    *
76    * @throws WrongNumberArgsException
77    */

78   public void checkNumberArgs(int argNum) throws WrongNumberArgsException
79   {
80     if (argNum != 1)
81       reportWrongNumberArgs();
82   }
83
84   /**
85    * Constructs and throws a WrongNumberArgException with the appropriate
86    * message for this function object.
87    *
88    * @throws WrongNumberArgsException
89    */

90   protected void reportWrongNumberArgs() throws WrongNumberArgsException {
91       throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("one", null));
92   }
93   
94   /**
95    * Tell if this expression or it's subexpressions can traverse outside
96    * the current subtree.
97    *
98    * @return true if traversal outside the context node's subtree can occur.
99    */

100    public boolean canTraverseOutsideSubtree()
101    {
102     return m_arg0.canTraverseOutsideSubtree();
103    }
104    
105   /**
106    * This function is used to fixup variables from QNames to stack frame
107    * indexes at stylesheet build time.
108    * @param vars List of QNames that correspond to variables. This list
109    * should be searched backwards for the first qualified name that
110    * corresponds to the variable reference qname. The position of the
111    * QName in the vector from the start of the vector will be its position
112    * in the stack frame (but variables above the globalsTop value will need
113    * to be offset to the current stack frame).
114    */

115   public void fixupVariables(java.util.Vector JavaDoc vars, int globalsSize)
116   {
117     if(null != m_arg0)
118       m_arg0.fixupVariables(vars, globalsSize);
119   }
120   
121   /**
122    * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
123    */

124   public void callArgVisitors(XPathVisitor visitor)
125   {
126     if(null != m_arg0)
127         m_arg0.callVisitors(this, visitor);
128   }
129
130
131   /**
132    * @see ExpressionOwner#getExpression()
133    */

134   public Expression getExpression()
135   {
136     return m_arg0;
137   }
138
139   /**
140    * @see ExpressionOwner#setExpression(Expression)
141    */

142   public void setExpression(Expression exp)
143   {
144     exp.exprSetParent(this);
145     m_arg0 = exp;
146   }
147   
148   /**
149    * @see Expression#deepEquals(Expression)
150    */

151   public boolean deepEquals(Expression expr)
152   {
153     if(!super.deepEquals(expr))
154         return false;
155         
156     if(null != m_arg0)
157     {
158         if(null == ((FunctionOneArg)expr).m_arg0)
159             return false;
160             
161         if(!m_arg0.deepEquals(((FunctionOneArg)expr).m_arg0))
162             return false;
163     }
164     else if(null != ((FunctionOneArg)expr).m_arg0)
165         return false;
166
167     return true;
168   }
169
170
171 }
172
Popular Tags