KickJava   Java API By Example, From Geeks To Geeks.

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


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: Function3Args.java,v 1.14 2004/02/17 04:34:01 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 three arguments.
28  * @xsl.usage advanced
29  */

30 public class Function3Args extends Function2Args
31 {
32
33   /** The third argument passed to the function (at index 2).
34    * @serial */

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

43   public Expression getArg2()
44   {
45     return m_arg2;
46   }
47   
48   /**
49    * This function is used to fixup variables from QNames to stack frame
50    * indexes at stylesheet build time.
51    * @param vars List of QNames that correspond to variables. This list
52    * should be searched backwards for the first qualified name that
53    * corresponds to the variable reference qname. The position of the
54    * QName in the vector from the start of the vector will be its position
55    * in the stack frame (but variables above the globalsTop value will need
56    * to be offset to the current stack frame).
57    */

58   public void fixupVariables(java.util.Vector JavaDoc vars, int globalsSize)
59   {
60     super.fixupVariables(vars, globalsSize);
61     if(null != m_arg2)
62       m_arg2.fixupVariables(vars, globalsSize);
63   }
64
65   /**
66    * Set an argument expression for a function. This method is called by the
67    * XPath compiler.
68    *
69    * @param arg non-null expression that represents the argument.
70    * @param argNum The argument number index.
71    *
72    * @throws WrongNumberArgsException If the argNum parameter is greater than 2.
73    */

74   public void setArg(Expression arg, int argNum)
75           throws WrongNumberArgsException
76   {
77
78     if (argNum < 2)
79       super.setArg(arg, argNum);
80     else if (2 == argNum)
81     {
82       m_arg2 = arg;
83       arg.exprSetParent(this);
84     }
85     else
86           reportWrongNumberArgs();
87   }
88
89   /**
90    * Check that the number of arguments passed to this function is correct.
91    *
92    *
93    * @param argNum The number of arguments that is being passed to the function.
94    *
95    * @throws WrongNumberArgsException
96    */

97   public void checkNumberArgs(int argNum) throws WrongNumberArgsException
98   {
99     if (argNum != 3)
100       reportWrongNumberArgs();
101   }
102
103   /**
104    * Constructs and throws a WrongNumberArgException with the appropriate
105    * message for this function object.
106    *
107    * @throws WrongNumberArgsException
108    */

109   protected void reportWrongNumberArgs() throws WrongNumberArgsException {
110       throw new WrongNumberArgsException(XSLMessages.createXPATHMessage("three", null));
111   }
112   
113   /**
114    * Tell if this expression or it's subexpressions can traverse outside
115    * the current subtree.
116    *
117    * @return true if traversal outside the context node's subtree can occur.
118    */

119    public boolean canTraverseOutsideSubtree()
120    {
121     return super.canTraverseOutsideSubtree()
122     ? true : m_arg2.canTraverseOutsideSubtree();
123    }
124    
125   class Arg2Owner implements ExpressionOwner
126   {
127     /**
128      * @see ExpressionOwner#getExpression()
129      */

130     public Expression getExpression()
131     {
132       return m_arg2;
133     }
134
135
136     /**
137      * @see ExpressionOwner#setExpression(Expression)
138      */

139     public void setExpression(Expression exp)
140     {
141         exp.exprSetParent(Function3Args.this);
142         m_arg2 = exp;
143     }
144   }
145
146    
147   /**
148    * @see XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
149    */

150   public void callArgVisitors(XPathVisitor visitor)
151   {
152     super.callArgVisitors(visitor);
153     if(null != m_arg2)
154         m_arg2.callVisitors(new Arg2Owner(), visitor);
155   }
156
157   /**
158    * @see Expression#deepEquals(Expression)
159    */

160   public boolean deepEquals(Expression expr)
161   {
162     if(!super.deepEquals(expr))
163         return false;
164         
165     if(null != m_arg2)
166     {
167         if(null == ((Function3Args)expr).m_arg2)
168             return false;
169
170         if(!m_arg2.deepEquals(((Function3Args)expr).m_arg2))
171             return false;
172     }
173     else if (null != ((Function3Args)expr).m_arg2)
174         return false;
175         
176     return true;
177   }
178
179
180 }
181
Popular Tags