|
|
|
|
|
|
|
*/ |
|
/* |
|
* Licensed to the Apache Software Foundation (ASF) under one or more |
|
* contributor license agreements. See the NOTICE file distributed with |
|
* this work for additional information regarding copyright ownership. |
|
* The ASF licenses this file to You 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. |
|
*/ |
|
|
|
package com.sun.org.apache.xpath.internal.axes; |
|
|
|
import com.sun.org.apache.xml.internal.dtm.DTM; |
|
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; |
|
import com.sun.org.apache.xpath.internal.XPathContext; |
|
|
|
|
|
|
|
|
|
*/ |
|
public class ReverseAxesWalker extends AxesWalker |
|
{ |
|
static final long serialVersionUID = 2847007647832768941L; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
ReverseAxesWalker(LocPathIterator locPathIterator, int axis) |
|
{ |
|
super(locPathIterator, axis); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void setRoot(int root) |
|
{ |
|
super.setRoot(root); |
|
m_iterator = getDTM(root).getAxisIterator(m_axis); |
|
m_iterator.setStartNode(root); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void detach() |
|
{ |
|
m_iterator = null; |
|
super.detach(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected int getNextNode() |
|
{ |
|
if (m_foundLast) |
|
return DTM.NULL; |
|
|
|
int next = m_iterator.next(); |
|
|
|
if (m_isFresh) |
|
m_isFresh = false; |
|
|
|
if (DTM.NULL == next) |
|
this.m_foundLast = true; |
|
|
|
return next; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean isReverseAxes() |
|
{ |
|
return true; |
|
} |
|
|
|
// /** |
|
// * Set the root node of the TreeWalker. |
|
// * |
|
// * @param root The context node of this step. |
|
// */ |
|
// public void setRoot(int root) |
|
// { |
|
// super.setRoot(root); |
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected int getProximityPosition(int predicateIndex) |
|
{ |
|
// A negative predicate index seems to occur with |
|
// (preceding-sibling::*|following-sibling::*)/ancestor::*[position()]/*[position()] |
|
|
|
if(predicateIndex < 0) |
|
return -1; |
|
|
|
int count = m_proximityPositions[predicateIndex]; |
|
|
|
if (count <= 0) |
|
{ |
|
AxesWalker savedWalker = wi().getLastUsedWalker(); |
|
|
|
try |
|
{ |
|
ReverseAxesWalker clone = (ReverseAxesWalker) this.clone(); |
|
|
|
clone.setRoot(this.getRoot()); |
|
|
|
clone.setPredicateCount(predicateIndex); |
|
|
|
clone.setPrevWalker(null); |
|
clone.setNextWalker(null); |
|
wi().setLastUsedWalker(clone); |
|
|
|
|
|
count++; |
|
int next; |
|
|
|
while (DTM.NULL != (next = clone.nextNode())) |
|
{ |
|
count++; |
|
} |
|
|
|
m_proximityPositions[predicateIndex] = count; |
|
} |
|
catch (CloneNotSupportedException cnse) |
|
{ |
|
|
|
// can't happen |
|
} |
|
finally |
|
{ |
|
wi().setLastUsedWalker(savedWalker); |
|
} |
|
} |
|
|
|
return count; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected void countProximityPosition(int i) |
|
{ |
|
if (i < m_proximityPositions.length) |
|
m_proximityPositions[i]--; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public int getLastPos(XPathContext xctxt) |
|
{ |
|
|
|
int count = 0; |
|
AxesWalker savedWalker = wi().getLastUsedWalker(); |
|
|
|
try |
|
{ |
|
ReverseAxesWalker clone = (ReverseAxesWalker) this.clone(); |
|
|
|
clone.setRoot(this.getRoot()); |
|
|
|
clone.setPredicateCount(this.getPredicateCount() - 1); |
|
|
|
clone.setPrevWalker(null); |
|
clone.setNextWalker(null); |
|
wi().setLastUsedWalker(clone); |
|
|
|
// Count 'em all |
|
|
|
int next; |
|
|
|
while (DTM.NULL != (next = clone.nextNode())) |
|
{ |
|
count++; |
|
} |
|
} |
|
catch (CloneNotSupportedException cnse) |
|
{ |
|
|
|
// can't happen |
|
} |
|
finally |
|
{ |
|
wi().setLastUsedWalker(savedWalker); |
|
} |
|
|
|
return count; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean isDocOrdered() |
|
{ |
|
return false; |
|
} |
|
|
|
|
|
protected DTMAxisIterator m_iterator; |
|
} |