|
|
|
|
|
*/ |
|
/* |
|
* 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.DTMIterator; |
|
import com.sun.org.apache.xml.internal.utils.QName; |
|
import com.sun.org.apache.xpath.internal.XPathContext; |
|
import com.sun.org.apache.xpath.internal.objects.XObject; |
|
import com.sun.org.apache.xpath.internal.patterns.NodeTest; |
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public class UnionChildIterator extends ChildTestIterator |
|
{ |
|
static final long serialVersionUID = 3500298482193003495L; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private PredicatedNodeTest[] m_nodeTests = null; |
|
|
|
|
|
|
|
*/ |
|
public UnionChildIterator() |
|
{ |
|
super(null); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void addNodeTest(PredicatedNodeTest test) |
|
{ |
|
|
|
// Increase array size by only 1 at a time. Fix this |
|
|
|
if (null == m_nodeTests) |
|
{ |
|
m_nodeTests = new PredicatedNodeTest[1]; |
|
m_nodeTests[0] = test; |
|
} |
|
else |
|
{ |
|
PredicatedNodeTest[] tests = m_nodeTests; |
|
int len = m_nodeTests.length; |
|
|
|
m_nodeTests = new PredicatedNodeTest[len + 1]; |
|
|
|
System.arraycopy(tests, 0, m_nodeTests, 0, len); |
|
|
|
m_nodeTests[len] = test; |
|
} |
|
test.exprSetParent(this); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public void fixupVariables(List<QName> vars, int globalsSize) |
|
{ |
|
super.fixupVariables(vars, globalsSize); |
|
if (m_nodeTests != null) { |
|
for (int i = 0; i < m_nodeTests.length; i++) { |
|
m_nodeTests[i].fixupVariables(vars, globalsSize); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public short acceptNode(int n) |
|
{ |
|
XPathContext xctxt = getXPathContext(); |
|
try |
|
{ |
|
xctxt.pushCurrentNode(n); |
|
for (int i = 0; i < m_nodeTests.length; i++) |
|
{ |
|
PredicatedNodeTest pnt = m_nodeTests[i]; |
|
XObject score = pnt.execute(xctxt, n); |
|
if (score != NodeTest.SCORE_NONE) |
|
{ |
|
|
|
if (pnt.getPredicateCount() > 0) |
|
{ |
|
if (pnt.executePredicates(n, xctxt)) |
|
return DTMIterator.FILTER_ACCEPT; |
|
} |
|
else |
|
return DTMIterator.FILTER_ACCEPT; |
|
|
|
} |
|
} |
|
} |
|
catch (javax.xml.transform.TransformerException se) |
|
{ |
|
|
|
|
|
throw new RuntimeException(se.getMessage()); |
|
} |
|
finally |
|
{ |
|
xctxt.popCurrentNode(); |
|
} |
|
return DTMIterator.FILTER_SKIP; |
|
} |
|
|
|
} |