286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: UnaryOperation.java,v 1.2.4.1 2005/09/14 21:31:44 jeffsuttor Exp $
286N/A */
286N/Apackage com.sun.org.apache.xpath.internal.operations;
286N/A
286N/Aimport com.sun.org.apache.xpath.internal.Expression;
286N/Aimport com.sun.org.apache.xpath.internal.ExpressionOwner;
286N/Aimport com.sun.org.apache.xpath.internal.XPathContext;
286N/Aimport com.sun.org.apache.xpath.internal.XPathVisitor;
286N/Aimport com.sun.org.apache.xpath.internal.objects.XObject;
286N/A
286N/A/**
286N/A * The unary operation base class.
286N/A */
286N/Apublic abstract class UnaryOperation extends Expression implements ExpressionOwner
286N/A{
286N/A static final long serialVersionUID = 6536083808424286166L;
286N/A
286N/A /** The operand for the operation.
286N/A * @serial */
286N/A protected Expression m_right;
286N/A
286N/A /**
286N/A * This function is used to fixup variables from QNames to stack frame
286N/A * indexes at stylesheet build time.
286N/A * @param vars List of QNames that correspond to variables. This list
286N/A * should be searched backwards for the first qualified name that
286N/A * corresponds to the variable reference qname. The position of the
286N/A * QName in the vector from the start of the vector will be its position
286N/A * in the stack frame (but variables above the globalsTop value will need
286N/A * to be offset to the current stack frame).
286N/A */
286N/A public void fixupVariables(java.util.Vector vars, int globalsSize)
286N/A {
286N/A m_right.fixupVariables(vars, globalsSize);
286N/A }
286N/A
286N/A /**
286N/A * Tell if this expression or it's subexpressions can traverse outside
286N/A * the current subtree.
286N/A *
286N/A * @return true if traversal outside the context node's subtree can occur.
286N/A */
286N/A public boolean canTraverseOutsideSubtree()
286N/A {
286N/A
286N/A if (null != m_right && m_right.canTraverseOutsideSubtree())
286N/A return true;
286N/A
286N/A return false;
286N/A }
286N/A
286N/A /**
286N/A * Set the expression operand for the operation.
286N/A *
286N/A *
286N/A * @param r The expression operand to which the unary operation will be
286N/A * applied.
286N/A */
286N/A public void setRight(Expression r)
286N/A {
286N/A m_right = r;
286N/A r.exprSetParent(this);
286N/A }
286N/A
286N/A /**
286N/A * Execute the operand and apply the unary operation to the result.
286N/A *
286N/A *
286N/A * @param xctxt The runtime execution context.
286N/A *
286N/A * @return An XObject that represents the result of applying the unary
286N/A * operation to the evaluated operand.
286N/A *
286N/A * @throws javax.xml.transform.TransformerException
286N/A */
286N/A public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
286N/A {
286N/A
286N/A return operate(m_right.execute(xctxt));
286N/A }
286N/A
286N/A /**
286N/A * Apply the operation to two operands, and return the result.
286N/A *
286N/A *
286N/A * @param right non-null reference to the evaluated right operand.
286N/A *
286N/A * @return non-null reference to the XObject that represents the result of the operation.
286N/A *
286N/A * @throws javax.xml.transform.TransformerException
286N/A */
286N/A public abstract XObject operate(XObject right)
286N/A throws javax.xml.transform.TransformerException;
286N/A
286N/A /** @return the operand of unary operation, as an Expression.
286N/A */
286N/A public Expression getOperand(){
286N/A return m_right;
286N/A }
286N/A
286N/A /**
286N/A * @see com.sun.org.apache.xpath.internal.XPathVisitable#callVisitors(ExpressionOwner, XPathVisitor)
286N/A */
286N/A public void callVisitors(ExpressionOwner owner, XPathVisitor visitor)
286N/A {
286N/A if(visitor.visitUnaryOperation(owner, this))
286N/A {
286N/A m_right.callVisitors(this, visitor);
286N/A }
286N/A }
286N/A
286N/A
286N/A /**
286N/A * @see ExpressionOwner#getExpression()
286N/A */
286N/A public Expression getExpression()
286N/A {
286N/A return m_right;
286N/A }
286N/A
286N/A /**
286N/A * @see ExpressionOwner#setExpression(Expression)
286N/A */
286N/A public void setExpression(Expression exp)
286N/A {
286N/A exp.exprSetParent(this);
286N/A m_right = exp;
286N/A }
286N/A
286N/A /**
286N/A * @see Expression#deepEquals(Expression)
286N/A */
286N/A public boolean deepEquals(Expression expr)
286N/A {
286N/A if(!isSameClass(expr))
286N/A return false;
286N/A
286N/A if(!m_right.deepEquals(((UnaryOperation)expr).m_right))
286N/A return false;
286N/A
286N/A return true;
286N/A }
286N/A
286N/A
286N/A}