|
From: <pm_...@us...> - 2012-02-07 08:57:41
|
Revision: 4523
http://mxquery.svn.sourceforge.net/mxquery/?rev=4523&view=rev
Author: pm_fischer
Date: 2012-02-07 08:57:31 +0000 (Tue, 07 Feb 2012)
Log Message:
-----------
more merging
Modified Paths:
--------------
trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonValidatingStaxAdapterProjection.java
Modified: trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonValidatingStaxAdapterProjection.java
===================================================================
--- trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonValidatingStaxAdapterProjection.java 2012-02-07 08:56:21 UTC (rev 4522)
+++ trunk/MXQuery/src/ch/ethz/mxquery/xdmio/xmlAdapters/NonValidatingStaxAdapterProjection.java 2012-02-07 08:57:31 UTC (rev 4523)
@@ -171,9 +171,10 @@
return new TextToken(Type.TEXT_NODE_UNTYPED_ATOMIC, createNextTokenId(Type.TEXT_NODE_UNTYPED_ATOMIC, null), mergedText.toString(),curNsScope);
}
case XMLStreamConstants.COMMENT:
- if (curProjMode == PROJ_MODE_SKIP || curProjMode == PROJ_MODE_MOVE)
+ if (curProjMode == PROJ_MODE_SKIP || curProjMode == PROJ_MODE_MOVE) {
+ reader.next();
continue;
-
+ }
tok = new CommentToken(createNextTokenId(Type.COMMENT, null), reader.getText(),curNsScope);
break;
case XMLStreamConstants.END_DOCUMENT:
@@ -181,16 +182,23 @@
break;
case XMLStreamConstants.END_ELEMENT: {
boolean emitTag = false;
- javax.xml.namespace.QName name_debug = reader.getName();
+ tok = null;
+ javax.xml.namespace.QName name = reader.getName();
switch (curProjMode) {
case PROJ_MODE_KEEP_SUB:
//KEEP_SUB->MOVE: reached skipKeepLevel
//KEEP_SUB->KEEP_SUB: any closing tag greater than skipKeepLevel
if (skipKeepLevel == level) {
+ restoreDroppedPaths();
curProjMode = PROJ_MODE_MOVE;
skipKeepLevel = -1;
bufferedPathName.pop();
pathProducedLevel--;
+// java.util.Iterator pathIt = activePaths.iterator();
+// while (pathIt.hasNext()) {
+// int pathPos = ((Integer)pathIt.next()).intValue();
+// projPathPos[pathPos]--;
+// }
}
emitTag = true;
break;
@@ -198,8 +206,10 @@
// go to "KEEP", check later if we keep or move
if (skipKeepLevel == level+1) {
+ //javax.xml.namespace.QName name = reader.getName();
+ curProjMode = PROJ_MODE_MOVE;
restoreDroppedPaths();
- curProjMode = PROJ_MODE_MOVE;
+
if (pathProducedLevel >= level) {
emitTag = true;
pathProducedLevel--;
@@ -208,7 +218,8 @@
}
else
if (skipKeepLevel == level) {
- javax.xml.namespace.QName name = reader.getName();
+ //javax.xml.namespace.QName name = reader.getName();
+ boolean foundMove = false;
boolean foundKeep = false;
for (int pathPos=0;pathPos<projectionPaths.size();pathPos++) {
// check those paths that we active before we started skipping
@@ -216,25 +227,24 @@
if (lastActiveStep[pathPos]==level) {
// they will become active again
activePaths.add(new Integer(pathPos));
+ foundMove =true;
}
- // last step was KEEP
- if (lastActiveStep[pathPos]+1==level) {
- // they will become active again
- activePaths.add(new Integer(pathPos));
- // decide if we go to KEEP
- Vector path = (Vector)projectionPaths.get(pathPos);
- XQName curPathCheck = ((AbstractStep) (path).elementAt(projPathPos[pathPos])).getNodeTest().getXQName();
- if (equalsQNames(curPathCheck,name) || /*FIXME*/ level != projPathPos[pathPos]) {
- foundKeep = true;
- }
+
+ Vector path = (Vector)projectionPaths.get(pathPos);
+ if (path.size()==level && lastActiveStep[pathPos]==level-1) {
+// activePaths.add(new Integer(pathPos));
+ foundKeep = true;
}
+
}
- if (foundKeep)
+ if (foundMove) {
+ curProjMode = PROJ_MODE_MOVE;
+ skipKeepLevel = -1;
+ } else
+ if (foundKeep) {
curProjMode = PROJ_MODE_KEEP;
- else
- curProjMode = PROJ_MODE_MOVE;
-
- skipKeepLevel = -1;
+ skipKeepLevel = -1;
+ }
}
else {
reader.next();
@@ -243,25 +253,33 @@
}
break;
case PROJ_MODE_MOVE: {
- restoreDroppedPaths();
- javax.xml.namespace.QName name = reader.getName();
+
+ //javax.xml.namespace.QName name = reader.getName();
//TODO: remove this consistency check - only trivially possible for a single path
- XQName curPathCheck = ((AbstractStep) ((Vector)projectionPaths.get(0)).elementAt(projPathPos[0]-1)).getNodeTest().getXQName();
- if (!equalsQNames(curPathCheck,name))
- throw new MXQueryException(ErrorCodes.A0007_EC_IO, "Inconsistency in projecting, expected "+curPathCheck+" saw "+name, loc);
+// XQName curPathCheck = ((AbstractStep) ((Vector)projectionPaths.get(0)).elementAt(projPathPos[0]-1)).getNodeTest().getXQName();
+// if (!equalsQNames(curPathCheck,name))
+// throw new MXQueryException(ErrorCodes.A0007_EC_IO, "Inconsistency in projecting, expected "+curPathCheck+" saw "+name, loc);
// if kept nodes are on the path, i.e. we had "KEEP" for them but did not produce any lower
// output them
if (!keptNodes.empty()&&((Integer)keptNodes.peek()).intValue() == level ) {
tok = extractPendingElements();
- // TODO: extract+emit!
- }
+ XQName tName = transformQName((javax.xml.namespace.QName)bufferedPathName.elementAt(level-1));
+ tokensList.add(new ElementToken(Type.END_TAG, createNextTokenId(Type.END_TAG, tName.toString()), tName, curNsScope));
+ pathProducedLevel--;
+ } else
if (pathProducedLevel >= level) {
emitTag = true;
pathProducedLevel--;
}
- projPathPos[0]--;
+ java.util.Iterator pathIt = activePaths.iterator();
+ while (pathIt.hasNext()) {
+ int pathPos = ((Integer)pathIt.next()).intValue();
+
+ projPathPos[pathPos]--;
+ }
+ restoreDroppedPaths();
bufferedPathName.pop();
} break;
case PROJ_MODE_KEEP: {
@@ -269,8 +287,18 @@
//decide if keep or move directly, when we came from SKIP
//SKIP->KEEP: reached skipKeepLevel, level above matched
// SKIP->MOVE: reached skipKeepLevel, level above did not match
- javax.xml.namespace.QName name = reader.getName();
-
+ //javax.xml.namespace.QName name = reader.getName();
+ for (int pathPos=0;pathPos<projectionPaths.size();pathPos++) {
+ Vector path = (Vector)projectionPaths.get(pathPos);
+
+ if (path.size()==level+1) {
+ XQName curPathCheck = ((AbstractStep) (path).elementAt(projPathPos[pathPos])).getNodeTest().getXQName();
+ if (equalsQNames(curPathCheck, name))
+ activePaths.add(new Integer(pathPos));
+ }
+
+ }
+
// Vector path = (Vector)projectionPaths.get(0);
// if (path.size() == projPathPos[0]+1) {// last element in path, and not a "KEEP"
@@ -303,15 +331,14 @@
//
+ level--;
if (emitTag) {
- javax.xml.namespace.QName name = reader.getName();
+ //javax.xml.namespace.QName name = reader.getName();
XQName tName = transformQName(name);
tok = new ElementToken(Type.END_TAG, null, tName, curNsScope);
checkCloseNsScope();
- level--;
- } else {
- reader.next();
- level--;
+ } else if (tok==null){
+ reader.next();
continue;
}
@@ -324,13 +351,17 @@
case XMLStreamConstants.NAMESPACE:
break;
case XMLStreamConstants.NOTATION_DECLARATION:
- if (curProjMode == PROJ_MODE_SKIP || curProjMode == PROJ_MODE_MOVE)
+ if (curProjMode == PROJ_MODE_SKIP || curProjMode == PROJ_MODE_MOVE) {
+ reader.next();
continue;
+ }
tok = new TextToken(createNextTokenId(Type.NOTATION, null), reader.getText());
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
- if (curProjMode == PROJ_MODE_SKIP || curProjMode == PROJ_MODE_MOVE)
+ if (curProjMode == PROJ_MODE_SKIP || curProjMode == PROJ_MODE_MOVE) {
+ reader.next();
continue;
+ }
tok = new ProcessingInstrToken(createNextTokenId(Type.PROCESSING_INSTRUCTION, null), reader.getPIData(), reader.getPITarget(),curNsScope);
break;
case XMLStreamConstants.START_DOCUMENT:
@@ -402,7 +433,12 @@
// else stay in MOVE
} else { // otherwise remove from set of active paths
- lastActiveStep[pathPos] = level;
+ // only assign new last active
+// if (lastActiveStep[pathPos]<0)
+ lastActiveStep[pathPos] = level;
+// else {
+// lastActiveStep[pathPos] = lastActiveStep[pathPos]; // dummy for debugging
+// }
activePaths.remove(new Integer(pathPos));
//curProjMode = PROJ_MODE_SKIP;
}
@@ -560,6 +596,7 @@
reader.next();
else {
endOfSeq = true;
+ tok = Token.END_SEQUENCE_TOKEN;
}
return tok;
} catch (XMLStreamException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|