org.apache.xpath.Expression Java Examples

The following examples show how to use org.apache.xpath.Expression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WalkingIterator.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
  if (!super.deepEquals(expr))
            return false;

  AxesWalker walker1 = m_firstWalker;
  AxesWalker walker2 = ((WalkingIterator)expr).m_firstWalker;
  while ((null != walker1) && (null != walker2))
  {
    if(!walker1.deepEquals(walker2))
    	return false;
    walker1 = walker1.getNextWalker();
    walker2 = walker2.getNextWalker();
  }
  
  if((null != walker1) || (null != walker2))
  	return false;

  return true;
}
 
Example #2
Source File: Compiler.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Compile a zero or more predicates for a given match pattern.
 * 
 * @param opPos The position of the first predicate the m_opMap array.
 *
 * @return reference to array of {@link org.apache.xpath.Expression} instances.
 *
 * @throws TransformerException if a error occurs creating the Expression.
 */
public Expression[] getCompiledPredicates(int opPos)
        throws TransformerException
{

  int count = countPredicates(opPos);

  if (count > 0)
  {
    Expression[] predicates = new Expression[count];

    compilePredicates(opPos, predicates);

    return predicates;
  }

  return null;
}
 
Example #3
Source File: RedundentExprEliminator.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Assert that the expression is a LocPathIterator, and, if 
 * not, try to give some diagnostic info.
 */
private final void assertIsLocPathIterator(Expression expr1, ExpressionOwner eo) 
  throws RuntimeException 
{
if(!(expr1 instanceof LocPathIterator))
{
	String errMsg;
	if(expr1 instanceof Variable)
	{
		errMsg = "Programmer's assertion: expr1 not an iterator: "+
		          ((Variable)expr1).getQName();
	}
	else
	{
		errMsg = "Programmer's assertion: expr1 not an iterator: "+
		          expr1.getClass().getName();
	}
	throw new RuntimeException(errMsg + ", "+
		          eo.getClass().getName()+" "+
		          expr1.exprGetParent());
}
}
 
Example #4
Source File: Function2Args.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Set an argument expression for a function.  This method is called by the 
 * XPath compiler.
 *
 * @param arg non-null expression that represents the argument.
 * @param argNum The argument number index.
 *
 * @throws WrongNumberArgsException If the argNum parameter is greater than 1.
 */
public void setArg(Expression arg, int argNum)
        throws WrongNumberArgsException
{

  // System.out.println("argNum: "+argNum);
  if (argNum == 0)
    super.setArg(arg, argNum);
  else if (1 == argNum)
  {
    m_arg1 = arg;
    arg.exprSetParent(this);
  }
  else
  reportWrongNumberArgs();
}
 
Example #5
Source File: UnionPattern.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
	if(!isSameClass(expr))
		return false;
		
	UnionPattern up = (UnionPattern)expr;
		
	if(null != m_patterns)
	{
		int n = m_patterns.length;
		if((null == up.m_patterns) || (up.m_patterns.length != n))
			return false;
			
		for(int i = 0; i < n; i++)
		{
			if(!m_patterns[i].deepEquals(up.m_patterns[i]))
				return false;
		}
	}
	else if(up.m_patterns != null)
		return false;
		
	return true;
	
}
 
Example #6
Source File: PredicatedNodeTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
  if (!super.deepEquals(expr))
        return false;

  PredicatedNodeTest pnt = (PredicatedNodeTest) expr;
  if (null != m_predicates)
  {

    int n = m_predicates.length;
    if ((null == pnt.m_predicates) || (pnt.m_predicates.length != n))
          return false;
    for (int i = 0; i < n; i++)
    {
      if (!m_predicates[i].deepEquals(pnt.m_predicates[i]))
      	return false; 
    }
  }
  else if (null != pnt.m_predicates)
          return false; 
          
  return true; 
}
 
Example #7
Source File: PredicatedNodeTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Set the number of predicates that this walker has.  This does more 
 * that one would think, as it creates a new predicate array of the 
 * size of the count argument, and copies count predicates into the new 
 * one from the old, and then reassigns the predicates value.  All this 
 * to keep from having to have a predicate count value.
 *
 * @param count The number of predicates, which must be equal or less 
 *               than the existing count.
 */
public void setPredicateCount(int count)
{
  if(count > 0)
  {
    Expression[] newPredicates = new Expression[count];
    for (int i = 0; i < count; i++) 
    {
      newPredicates[i] = m_predicates[i];
    }
    m_predicates = newPredicates;
  }
  else
    m_predicates = null;
  
}
 
Example #8
Source File: FunctionOneArg.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
	if(!super.deepEquals(expr))
		return false;
		
	if(null != m_arg0)
	{
		if(null == ((FunctionOneArg)expr).m_arg0)
			return false;
			
		if(!m_arg0.deepEquals(((FunctionOneArg)expr).m_arg0))
			return false;
	}
	else if(null != ((FunctionOneArg)expr).m_arg0)
		return false;

	return true;
}
 
Example #9
Source File: XObject.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
	if(!isSameClass(expr))
		return false;
		
	// If equals at the expression level calls deepEquals, I think we're 
	// still safe from infinite recursion since this object overrides 
	// equals.  I hope.
	if(!this.equals((XObject)expr))
		return false;
		
	return true;
}
 
Example #10
Source File: RedundentExprEliminator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * From an XPath expression component, get the ElemTemplateElement 
 * owner.
 * 
 * @param expr Should be static expression with proper parentage.
 * @return Valid ElemTemplateElement, or throw a runtime exception 
 * if it is not found.
 */
protected ElemTemplateElement getElemFromExpression(Expression expr)
{
	ExpressionNode parent = expr.exprGetParent();
	while(null != parent)
	{
		if(parent instanceof ElemTemplateElement)
			return (ElemTemplateElement)parent;
		parent = parent.exprGetParent();
	}
	throw new RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_ASSERT_NO_TEMPLATE_PARENT, null));
	// "Programmer's error! expr has no ElemTemplateElement parent!");
}
 
Example #11
Source File: RedundentExprEliminator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Visit a LocationPath.
 * @param owner The owner of the expression, to which the expression can 
 *              be reset if rewriting takes place.
 * @param path The LocationPath object.
 * @return true if the sub expressions should be traversed.
 */
public boolean visitLocationPath(ExpressionOwner owner, LocPathIterator path)
{
	// Don't optimize "." or single step variable paths.
	// Both of these cases could use some further optimization by themselves.
	if(path instanceof SelfIteratorNoPredicate)
	{
		return true;
	}
	else if(path instanceof WalkingIterator)
	{
		WalkingIterator wi = (WalkingIterator)path;
		AxesWalker aw = wi.getFirstWalker();
		if((aw instanceof FilterExprWalker) && (null == aw.getNextWalker()))
		{
			FilterExprWalker few = (FilterExprWalker)aw;
			Expression exp = few.getInnerExpression();
			if(exp instanceof Variable)
				return true;
		}
	}

  if (isAbsolute(path) && (null != m_absPaths))
  {
    if(DEBUG)
      validateNewAddition(m_absPaths, owner, path);
    m_absPaths.addElement(owner);
  }
  else if (m_isSameContext && (null != m_paths))
  {
    if(DEBUG)
      validateNewAddition(m_paths, owner, path);
    m_paths.addElement(owner);
  }

  return true;
}
 
Example #12
Source File: OneStepIterator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
	if(!super.deepEquals(expr))
		return false;
		
	if(m_axis != ((OneStepIterator)expr).m_axis)
		return false;
		
	return true;
}
 
Example #13
Source File: FunctionPattern.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a FunctionPattern from a
 * {@link org.apache.xpath.functions.Function expression}.
 *
 * NEEDSDOC @param expr
 */
public FunctionPattern(Expression expr, int axis, int predaxis)
{

  super(0, null, null, axis, predaxis);

  m_functionExpr = expr;
}
 
Example #14
Source File: NodeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
  * @see Expression#deepEquals(Expression)
  */
 public boolean deepEquals(Expression expr)
 {
 	if(!isSameClass(expr))
 		return false;
 		
 	NodeTest nt = (NodeTest)expr;

 	if(null != nt.m_name)
 	{
 		if(null == m_name)
 			return false;
 		else if(!nt.m_name.equals(m_name))
 			return false;
 	}
 	else if(null != m_name)
 		return false;

 	if(null != nt.m_namespace)
 	{
 		if(null == m_namespace)
 			return false;
 		else if(!nt.m_namespace.equals(m_namespace))
 			return false;
 	}
 	else if(null != m_namespace)
 		return false;
 		  		
 	if(m_whatToShow != nt.m_whatToShow)
 		return false;
 		
 	if(m_isTotallyWild != nt.m_isTotallyWild)
 		return false;

return true;
 }
 
Example #15
Source File: AxesWalker.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
  if (!super.deepEquals(expr))
            return false;

  AxesWalker walker = (AxesWalker)expr;
  if(this.m_axis != walker.m_axis)
  	return false;

  return true;
}
 
Example #16
Source File: FunctionMultiArgs.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
  if (!super.deepEquals(expr))
        return false;

  FunctionMultiArgs fma = (FunctionMultiArgs) expr;
  if (null != m_args)
  {
    int n = m_args.length;
    if ((null == fma) || (fma.m_args.length != n))
          return false;

    for (int i = 0; i < n; i++)
    {
      if (!m_args[i].deepEquals(fma.m_args[i]))
            return false;
    }

  }
  else if (null != fma.m_args)
  {
      return false;
  }

  return true;
}
 
Example #17
Source File: StepPattern.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Set the predicates for this match pattern step.
 *
 *
 * @param predicates An array of expressions that define predicates
 *                   for this step.
 */
public void setPredicates(Expression[] predicates)
{

  m_predicates = predicates;
  if(null != predicates)
  {
  	for(int i = 0; i < predicates.length; i++)
  	{
  		predicates[i].exprSetParent(this);
  	}
  }

  calcScore();
}
 
Example #18
Source File: FuncExtFunction.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Set the parent node.
 * For an extension function, we also need to set the parent
 * node for all argument expressions.
 * 
 * @param n The parent node
 */
public void exprSetParent(ExpressionNode n) 
{
	
  super.exprSetParent(n);
    
  int nArgs = m_argVec.size();

  for (int i = 0; i < nArgs; i++)
  {
    Expression arg = (Expression) m_argVec.elementAt(i);

    arg.exprSetParent(n);
  }		
}
 
Example #19
Source File: FunctionOneArg.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Set an argument expression for a function.  This method is called by the 
 * XPath compiler.
 *
 * @param arg non-null expression that represents the argument.
 * @param argNum The argument number index.
 *
 * @throws WrongNumberArgsException If the argNum parameter is greater than 0.
 */
public void setArg(Expression arg, int argNum)
        throws WrongNumberArgsException
{

  if (0 == argNum)
  {
    m_arg0 = arg;
    arg.exprSetParent(this);
  }
  else
    reportWrongNumberArgs();
}
 
Example #20
Source File: Function.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
	if(!isSameClass(expr))
		return false;
		
	return true;
}
 
Example #21
Source File: StepPattern.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
	if(!super.deepEquals(expr))
		return false;
		
	StepPattern sp = (StepPattern)expr;
	
  if (null != m_predicates)
  {
      int n = m_predicates.length;
      if ((null == sp.m_predicates) || (sp.m_predicates.length != n))
            return false;
      for (int i = 0; i < n; i++)
      {
        if (!m_predicates[i].deepEquals(sp.m_predicates[i]))
        	return false; 
      }
  }
  else if (null != sp.m_predicates)
  	return false;
		
	if(null != m_relativePathPattern)
	{
		if(!m_relativePathPattern.deepEquals(sp.m_relativePathPattern))
			return false;
	}
	else if(sp.m_relativePathPattern != null)
		return false;
		
	return true;
}
 
Example #22
Source File: Operation.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @see Expression#deepEquals(Expression)
 */
public boolean deepEquals(Expression expr)
{
	if(!isSameClass(expr))
		return false;
		
	if(!m_left.deepEquals(((Operation)expr).m_left))
		return false;
		
	if(!m_right.deepEquals(((Operation)expr).m_right))
		return false;
		
	return true;
}
 
Example #23
Source File: Compiler.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Bottle-neck compilation of a unary operation.
 *
 * @param unary The parent unary operation.
 * @param opPos The position in the op map of the parent operation.
 *
 * @return The unary argument.
 *
 * @throws TransformerException if syntax or other error occurs.
 */
private Expression compileUnary(UnaryOperation unary, int opPos)
        throws TransformerException
{

  int rightPos = getFirstChildPos(opPos);

  unary.setRight(compile(rightPos));

  return unary;
}
 
Example #24
Source File: Compiler.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Compiles predicates in the step.
 *
 * @param opPos The position of the first predicate the m_opMap array.
 * @param predicates An empty pre-determined array of 
 *            {@link org.apache.xpath.Expression}s, that will be filled in.
 *
 * @throws TransformerException
 */
private void compilePredicates(int opPos, Expression[] predicates)
        throws TransformerException
{

  for (int i = 0; OpCodes.OP_PREDICATE == getOp(opPos); i++)
  {
    predicates[i] = predicate(opPos);
    opPos = getNextOpPos(opPos);
  }
}
 
Example #25
Source File: Operation.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @see ExpressionOwner#getExpression()
 */
public Expression getExpression()
{
  return m_right;
}
 
Example #26
Source File: FilterExprWalker.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Set the inner contained expression of this filter.
 */
public void setInnerExpression(Expression expr)
{
	expr.exprSetParent(this);
	m_expr = expr;
}
 
Example #27
Source File: FuncExtFunction.java    From j2objc with Apache License 2.0 4 votes vote down vote up
ArgExtOwner(Expression exp)
{
	m_exp = exp;
}
 
Example #28
Source File: WalkingIterator.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @see ExpressionOwner#getExpression()
 */
public Expression getExpression()
{
  return m_firstWalker;
}
 
Example #29
Source File: Operation.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/** @return the right operand of binary operation, as an Expression.
 */
public Expression getRightOperand(){
  return m_right;
}
 
Example #30
Source File: AxesWalker.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @see ExpressionOwner#getExpression()
 */
public Expression getExpression()
{
  return m_nextWalker;
}