com.ximpleware.FilterExpr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vtd-xml Show documentation
Show all versions of vtd-xml Show documentation
XimpleWare's VTD-XML is, far and away, the industry's most advanced and powerful XML processing model for SOA and Cloud Computing
/*
* Copyright (C) 2002-2015 XimpleWare, [email protected]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*VTD-XML is protected by US patent 7133857, 7260652, an 7761459*/
/*All licenses to any parties in litigation with XimpleWare have been expressly terminated. No new license, and no renewal of any revoked license,
* is granted to those parties as a result of re-downloading software from this or any other website*/
package com.ximpleware;
import com.ximpleware.xpath.Predicate;
/**
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class FilterExpr extends Expr {
public Expr e;
public Predicate p;
//FastIntBuffer fib;
//int stackSize;
boolean first_time;
public boolean out_of_range;
//public int position;
public FilterExpr(Expr l, Predicate pr){
e = l;
p = pr;
//cacheable =false;
//stackSize = 0;
//position = 1;
//fib = new FastIntBuffer(8);
first_time = true;
out_of_range=false;
pr.fe=this;
//needReordering =false;
}
/*public int getPositon(){
return fib.size();
}*/
final public boolean evalBoolean(VTDNav vn) {
//if (e.isBoolean())
// return e.evalBoolean(vn);
boolean a = false;
vn.push2();
//record stack size
int size = vn.contextStack2.size;
try{
a = (evalNodeSet(vn) != -1);
}catch (Exception e){
}
//rewind stack
vn.contextStack2.size = size;
reset(vn);
vn.pop2();
return a;
}
final public double evalNumber(VTDNav vn) {
//String s = "";
double d = Double.NaN;
int a = 0x7fffffff,k=-1;
vn.push2();
int size = vn.contextStack2.size;
try {
if (needReordering) {
while ((k = evalNodeSet(vn)) != -1) {
// a = evalNodeSet(vn);
if (k < a)
a = k;
}
if (a == 0x7fffffff)
a = -1;
}else{
a =evalNodeSet(vn);
}
if (a != -1) {
int t = vn.getTokenType(a);
if (t == VTDNav.TOKEN_ATTR_NAME) {
d = vn.parseDouble(a+1);
} else if (t == VTDNav.TOKEN_STARTING_TAG || t ==VTDNav.TOKEN_DOCUMENT) {
//String s = vn.getXPathStringVal();
d = vn.XPathStringVal2Double(a);// Double.parseDouble(s);
}else if (t == VTDNav.TOKEN_PI_NAME) {
if (a+1 < vn.vtdSize || vn.getTokenType(a+1)==VTDNav.TOKEN_PI_VAL)
//s = vn.toString(a+1);
d = vn.parseDouble(a+1);
}else
d = vn.parseDouble(a);
}
} catch (Exception e) {
}
vn.contextStack2.size = size;
reset(vn);
vn.pop2();
//return s;
return d;
}
final public int evalNodeSet(VTDNav vn)
throws XPathEvalException, NavException {
// if tne predicate require context size
// needs to precompute the context size
// vn.push2();
// computerContext();
// set contxt();
// vn.pop2()
// if the context size is zero
// get immediately set teh state to end
// or backward
if (first_time && p.requireContext){
first_time = false;
int i = 0;
//vn.push2();
e.adjust(vn.getTokenCount());
while(e.evalNodeSet(vn)!=-1)
i++;
//vn.pop2();
p.setContextSize(i);
reset2(vn);
}
if(out_of_range)
return -1;
int a = e.evalNodeSet(vn);
while (a!=-1){
if (p.eval(vn)==true){
//p.reset();
return a;
}else {
//p.reset();
a = e.evalNodeSet(vn);
}
}
return -1;
}
final public String evalString(VTDNav vn) {
String s = "";
int a=0x7fffffff, k=-1;
vn.push2();
int size = vn.contextStack2.size;
try {
if (needReordering) {
while ((k = evalNodeSet(vn)) != -1) {
// a = evalNodeSet(vn);
if (k < a)
a = k;
}
if (a == 0x7fffffff)
a = -1;
} else {
a = evalNodeSet(vn);
}
if (a != -1) {
int t = vn.getTokenType(a);
switch(t){
case VTDNav.TOKEN_STARTING_TAG:
case VTDNav.TOKEN_DOCUMENT:
s = vn.getXPathStringVal();
break;
case VTDNav.TOKEN_ATTR_NAME:
s = vn.toString(a + 1);
break;
case VTDNav.TOKEN_PI_NAME:
//if (a + 1 < vn.vtdSize
// || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL)
s = vn.toString(a + 1);
break;
default:
s = vn.toString(a);
break;
}
}
} catch (Exception e) {
}
vn.contextStack2.size = size;
reset(vn);
vn.pop2();
return s;
}
final public void reset(VTDNav vn) {
reset2(vn);
//vn.contextStack2.size = stackSize;
//position = 1;
first_time = true;
/*cached = false;
if (cachedNodeSet != null){
cachedNodeSet.clear();
}*/
}
final public void reset2(VTDNav vn){
out_of_range=false;
e.reset(vn);
p.reset(vn);
//fib.clear();
}
final public String toString() {
return "("+e+") "+p;
}
final public boolean isNumerical() {
return false;
}
final public boolean isNodeSet() {
return true;
}
/*public boolean isUnique(int i){
int size = fib.size();
for (int j=0; j