KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > operations > UnaryOperation


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: UnaryOperation.java,v 1.12 2004/02/17 04:35:12 minchau Exp $
18  */

19 package org.apache.xpath.operations;
20
21 import org.apache.xpath.Expression;
22 import org.apache.xpath.ExpressionOwner;
23 import org.apache.xpath.XPathContext;
24 import org.apache.xpath.XPathVisitor;
25 import org.apache.xpath.objects.XObject;
26
27 /**
28  * The unary operation base class.
29  */

30 public abstract class UnaryOperation extends Expression implements ExpressionOwner
31 {
32
33   /** The operand for the operation.
34    * @serial */

35   protected Expression m_right;
36   
37   /**
38    * This function is used to fixup variables from QNames to stack frame
39    * indexes at stylesheet build time.
40    * @param vars List of QNames that correspond to variables. This list
41    * should be searched backwards for the first qualified name that
42    * corresponds to the variable reference qname. The position of the
43    * QName in the vector from the start of the vector will be its position
44    * in the stack frame (but variables above the globalsTop value will need
45    * to be offset to the current stack frame).
46    */

47   public void fixupVariables(java.util.Vector JavaDoc vars, int globalsSize)
48   {
49     m_right.fixupVariables(vars, globalsSize);
50   }
51   
52   /**
53    * Tell if this expression or it's subexpressions can traverse outside
54    * the current subtree.
55    *
56    * @return true if traversal outside the context node's subtree can occur.
57    */

58   public boolean canTraverseOutsideSubtree()
59   {
60
61     if (null != m_right && m_right.canTraverseOutsideSubtree())
62       return true;
63
64     return false;
65   }
66
67   /**
68    * Set the expression operand for the operation.
69    *
70    *
71    * @param r The expression operand to which the unary operation will be
72    * applied.
73    */

74   public void setRight(Expression r)
75   {
76     m_right = r;
77     r.exprSetParent(this);
78   }
79
80   /**
81    * Execute the operand and apply the unary operation to the result.
82    *
83    *
84    * @param xctxt The runtime execution context.
85    *
86    * @return An XObject that represents the result of applying the unary
87    * operation to the evaluated operand.
88    *
89    * @throws javax.xml.transform.TransformerException
90    */

91   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException JavaDoc
92   {
93
94     return operate(m_right.execute(xctxt));
95   }
96
97   /**
98    * Apply the operation to two operands, and return the result.
99    *
100    *
101    * @param right non-null reference to the evaluated right operand.
102    *
103    * @return non-null reference to the XObject that represents the result of the operation.
104    *
105    * @throws javax.xml.transform.TransformerException
106    */

107   public abstract XObject operate(XObject right)
108     throws javax.xml.transform.TransformerException JavaDoc;
109
110   /** @return the operand of unary operation, as an Expression.
111    */

112   public Expression getOperand(){
113     return m_right;
114   }
115   
116   /**
117    * @see XPathVisitable#callVisitors(XPathVisitor)
118    */

119   public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
120   {
121     if(visitor.visitUnaryOperation(owner, this))
122     {
123         m_right.callVisitors(this, visitor);
124     }
125   }
126
127
128   /**
129    * @see ExpressionOwner#getExpression()
130    */

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

139   public void setExpression(Expression exp)
140   {
141     exp.exprSetParent(this);
142     m_right = exp;
143   }
144   
145   /**
146    * @see Expression#deepEquals(Expression)
147    */

148   public boolean deepEquals(Expression expr)
149   {
150     if(!isSameClass(expr))
151         return false;
152         
153     if(!m_right.deepEquals(((UnaryOperation)expr).m_right))
154         return false;
155         
156     return true;
157   }
158
159
160 }
161
Popular Tags