Author: natalia
Date: Wed Oct 17 18:04:25 2007
New Revision: 585768
URL: http://svn.apache.org/viewvc?rev=585768&view=rev
Log:
Fixes for calculations of the context node name in the location path.
Fixed couple of NullPointerExceptions.
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java?rev=585768&r1=585767&r2=585768&view=diff
==============================================================================
---
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
(original)
+++
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
Wed Oct 17 18:04:25 2007
@@ -202,7 +202,7 @@
public XPath xp;
public Key[] keys;
- public XPathQuery(Collection context, String query,
NamespaceMap nsMap, Key[] keys)
+ public XPathQuery(Collection context, String query, NamespaceMap
nsMap, Key[] keys)
throws QueryException {
this.context = context;
this.query = query;
@@ -210,7 +210,7 @@
this.keys = keys;
Expression ex;
- try {
+ try {
if (nsMap != null) {
Node n = nsMap.getContextNode();
pr = new PrefixResolverDefault(n);
@@ -404,7 +404,7 @@
case OpCodes.NODETYPE_TEXT:
case OpCodes.NODETYPE_NODE:
- return owner;
+ return WILDCARD;
case OpCodes.NODETYPE_ANYELEMENT:
case OpCodes.ELEMWILDCARD:
@@ -427,10 +427,11 @@
private Object evalLocationPath(String owner, int pos) throws
Exception {
int lp = Compiler.getFirstChildPos(pos);
List ks = new ArrayList();
- String name = null;
+
+ String name = owner;
boolean attr = false;
while (cmp.getOp(lp) != -1) {
- Object obj = evaluate(owner, lp);
+ Object obj = evaluate(name, lp);
if (obj instanceof NamedKeys) {
NamedKeys nk = (NamedKeys) obj;
if (nk.name != null) {
@@ -733,7 +734,7 @@
private Object evalAxis(int op, String owner, int pos) throws
Exception {
String nsURI = cmp.getStepNS(pos);
- owner = (String) evaluate(owner,
Compiler.getFirstChildPosOfStep(pos));
+ String name = (String) evaluate(owner,
Compiler.getFirstChildPosOfStep(pos));
// owner = cmp.getStepLocalName(pos);
if (nsURI != null && nsMap != null) {
@@ -753,10 +754,18 @@
sb.append(pfx);
sb.append(':');
sb.append(owner);
- owner = sb.toString();
+ name = sb.toString();
}
}
+ if (op == OpCodes.FROM_ATTRIBUTES) {
+ owner = owner + '@' + name;
+ } else if (op == OpCodes.FROM_SELF && WILDCARD.equals(name)) {
+ name = owner;
+ } else {
+ owner = name;
+ }
+
int rp = cmp.getFirstPredicateOpPos(pos);
List ks = new ArrayList();
@@ -770,7 +779,7 @@
}
rp = cmp.getNextOpPos(rp);
}
- return new NamedKeys(owner, (op == OpCodes.FROM_ATTRIBUTES),
andKeys(ks));
+ return new NamedKeys(name, (op == OpCodes.FROM_ATTRIBUTES),
andKeys(ks));
}
private Object evalLiteral(String owner, int pos) {
@@ -932,20 +941,22 @@
}
} else if (o instanceof NamedKeys && s instanceof XObject) {
NamedKeys nk = (NamedKeys) o;
- String ps;
- if (nk.attribute && nk.name.indexOf('@') == -1) {
- ps = owner + "@" + nk.name;
- } else {
- ps = nk.name;
- }
+ if (nk.name != null) {
+ String ps;
+ if (nk.attribute && nk.name.indexOf('@') == -1) {
+ ps = owner + "@" + nk.name;
+ } else {
+ ps = nk.name;
+ }
- IndexPattern pattern = new IndexPattern(symbols, ps,
nsMap);
+ IndexPattern pattern = new IndexPattern(symbols, ps,
nsMap);
- XObject obj = (XObject) s;
- Value val1 = new Value(obj.str());
+ XObject obj = (XObject) s;
+ Value val1 = new Value(obj.str());
- IndexQuery iq = new IndexQuerySW(pattern, val1);
- return queryIndexes(nk, iq, ps, obj.getType());
+ IndexQuery iq = new IndexQuerySW(pattern, val1);
+ return queryIndexes(nk, iq, ps, obj.getType());
+ }
}
}
return null;
@@ -1136,41 +1147,45 @@
NamedKeys nk = (NamedKeys) left;
XObject obj = (XObject) right;
- String ps;
- if (nk.attribute && nk.name.indexOf('@') == -1) {
- ps = owner + "@" + nk.name;
- } else {
- ps = nk.name;
- }
+ if (nk.name != null) {
+ String ps;
+ if (nk.attribute && nk.name.indexOf('@') == -1) {
+ ps = owner + "@" + nk.name;
+ } else {
+ ps = nk.name;
+ }
- IndexQuery iq;
- IndexPattern pattern = new IndexPattern(symbols, ps, nsMap);
- String value = obj.str();
+ IndexQuery iq;
+ IndexPattern pattern = new IndexPattern(symbols, ps, nsMap);
+ String value = obj.str();
- switch (op) {
- case IndexQuery.NEQ:
- iq = new IndexQueryNEQ(pattern, value);
- break;
- case IndexQuery.EQ:
- iq = new IndexQueryEQ(pattern, value);
- break;
- case IndexQuery.LEQ:
- iq = new IndexQueryLEQ(pattern, value);
- break;
- case IndexQuery.LT:
- iq = new IndexQueryLT(pattern, value);
- break;
- case IndexQuery.GEQ:
- iq = new IndexQueryGEQ(pattern, value);
- break;
- case IndexQuery.GT:
- iq = new IndexQueryGT(pattern, value);
- break;
- default :
- iq = null; // Won't happen
- }
+ switch (op) {
+ case IndexQuery.NEQ:
+ iq = new IndexQueryNEQ(pattern, value);
+ break;
+ case IndexQuery.EQ:
+ iq = new IndexQueryEQ(pattern, value);
+ break;
+ case IndexQuery.LEQ:
+ iq = new IndexQueryLEQ(pattern, value);
+ break;
+ case IndexQuery.LT:
+ iq = new IndexQueryLT(pattern, value);
+ break;
+ case IndexQuery.GEQ:
+ iq = new IndexQueryGEQ(pattern, value);
+ break;
+ case IndexQuery.GT:
+ iq = new IndexQueryGT(pattern, value);
+ break;
+ default :
+ iq = null; // Won't happen
+ }
- return queryIndexes(nk, iq, ps, obj.getType());
+ return queryIndexes(nk, iq, ps, obj.getType());
+ } else {
+ return null;
+ }
}
}