|
Java example source code file (MatchPatternIterator.java)
The MatchPatternIterator.java Java example source code/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: MatchPatternIterator.java,v 1.2.4.2 2005/09/14 19:45:22 jeffsuttor Exp $
*/
package com.sun.org.apache.xpath.internal.axes;
import com.sun.org.apache.xml.internal.dtm.Axis;
import com.sun.org.apache.xml.internal.dtm.DTM;
import com.sun.org.apache.xml.internal.dtm.DTMAxisTraverser;
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
import com.sun.org.apache.xpath.internal.XPathContext;
import com.sun.org.apache.xpath.internal.compiler.Compiler;
import com.sun.org.apache.xpath.internal.compiler.OpMap;
import com.sun.org.apache.xpath.internal.objects.XObject;
import com.sun.org.apache.xpath.internal.patterns.NodeTest;
import com.sun.org.apache.xpath.internal.patterns.StepPattern;
/**
* This class treats a
* <a href="http://www.w3.org/TR/xpath#location-paths">LocationPath as a
* filtered iteration over the tree, evaluating each node in a super axis
* traversal against the LocationPath interpreted as a match pattern. This
* class is useful to find nodes in document order that are complex paths
* whose steps probably criss-cross each other.
*/
public class MatchPatternIterator extends LocPathIterator
{
static final long serialVersionUID = -5201153767396296474L;
/** This is the select pattern, translated into a match pattern. */
protected StepPattern m_pattern;
/** The traversal axis from where the nodes will be filtered. */
protected int m_superAxis = -1;
/** The DTM inner traversal class, that corresponds to the super axis. */
protected DTMAxisTraverser m_traverser;
/** DEBUG flag for diagnostic dumps. */
private static final boolean DEBUG = false;
// protected int m_nsElemBase = DTM.NULL;
/**
* Create a LocPathIterator object, including creation
* of step walkers from the opcode list, and call back
* into the Compiler to create predicate expressions.
*
* @param compiler The Compiler which is creating
* this expression.
* @param opPos The position of this iterator in the
* opcode list from the compiler.
* @param analysis Analysis bits that give general information about the
* LocationPath.
*
* @throws javax.xml.transform.TransformerException
*/
MatchPatternIterator(Compiler compiler, int opPos, int analysis)
throws javax.xml.transform.TransformerException
{
super(compiler, opPos, analysis, false);
int firstStepPos = OpMap.getFirstChildPos(opPos);
m_pattern = WalkerFactory.loadSteps(this, compiler, firstStepPos, 0);
boolean fromRoot = false;
boolean walkBack = false;
boolean walkDescendants = false;
boolean walkAttributes = false;
if (0 != (analysis & (WalkerFactory.BIT_ROOT |
WalkerFactory.BIT_ANY_DESCENDANT_FROM_ROOT)))
fromRoot = true;
if (0 != (analysis
& (WalkerFactory.BIT_ANCESTOR
| WalkerFactory.BIT_ANCESTOR_OR_SELF
| WalkerFactory.BIT_PRECEDING
| WalkerFactory.BIT_PRECEDING_SIBLING
| WalkerFactory.BIT_FOLLOWING
| WalkerFactory.BIT_FOLLOWING_SIBLING
| WalkerFactory.BIT_PARENT | WalkerFactory.BIT_FILTER)))
walkBack = true;
if (0 != (analysis
& (WalkerFactory.BIT_DESCENDANT_OR_SELF
| WalkerFactory.BIT_DESCENDANT
| WalkerFactory.BIT_CHILD)))
walkDescendants = true;
if (0 != (analysis
& (WalkerFactory.BIT_ATTRIBUTE | WalkerFactory.BIT_NAMESPACE)))
walkAttributes = true;
if(false || DEBUG)
{
System.out.print("analysis: "+Integer.toBinaryString(analysis));
System.out.println(", "+WalkerFactory.getAnalysisString(analysis));
}
if(fromRoot || walkBack)
{
if(walkAttributes)
{
m_superAxis = Axis.ALL;
}
else
{
m_superAxis = Axis.DESCENDANTSFROMROOT;
}
}
else if(walkDescendants)
{
if(walkAttributes)
{
m_superAxis = Axis.ALLFROMNODE;
}
else
{
m_superAxis = Axis.DESCENDANTORSELF;
}
}
else
{
m_superAxis = Axis.ALL;
}
if(false || DEBUG)
{
System.out.println("axis: "+Axis.getNames(m_superAxis));
}
}
/**
* Initialize the context values for this expression
* after it is cloned.
*
* @param context The XPath runtime context for this
* transformation.
*/
public void setRoot(int context, Object environment)
{
super.setRoot(context, environment);
m_traverser = m_cdtm.getAxisTraverser(m_superAxis);
}
/**
* Detaches the iterator from the set which it iterated over, releasing
* any computational resources and placing the iterator in the INVALID
* state. After<code>detach has been invoked, calls to
* <code>nextNode or
Other Java examples (source code examples)Here is a short list of links related to this Java MatchPatternIterator.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.