You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@locus.apache.org on 2000/11/15 00:15:11 UTC
cvs commit: xml-xalan/java/src/org/apache/xpath/functions FuncLast.java
sboag 00/11/14 15:15:10
Modified: java/src/org/apache/xalan/lib/sql XStatement.java
java/src/org/apache/xpath NodeSet.java
java/src/org/apache/xpath/axes ContextNodeList.java
LocPathIterator.java UnionPathIterator.java
java/src/org/apache/xpath/functions FuncLast.java
Log:
The last() function was trying to turn the context list into
a cached list on the fly, which causes nasty problems from inside
a predicate. So, I commented that code out (but left it there for
reference), and use a clone to get the count from the current
position. I then defined a set/getLast method on ContextNodeList,
and store the count there.
Revision Changes Path
1.5 +12 -0 xml-xalan/java/src/org/apache/xalan/lib/sql/XStatement.java
Index: XStatement.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/XStatement.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XStatement.java 2000/10/30 18:56:33 1.4
+++ XStatement.java 2000/11/14 23:15:09 1.5
@@ -566,4 +566,16 @@
return clone;
}
+
+ private int m_last = 0;
+
+ public int getLast()
+ {
+ return m_last;
+ }
+
+ public void setLast(int last)
+ {
+ m_last = last;
+ }
}
1.6 +14 -0 xml-xalan/java/src/org/apache/xpath/NodeSet.java
Index: NodeSet.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/NodeSet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NodeSet.java 2000/11/13 16:27:26 1.5
+++ NodeSet.java 2000/11/14 23:15:10 1.6
@@ -963,4 +963,18 @@
m_cacheNodes = b;
m_mutable = true;
}
+
+
+ private int m_last = 0;
+
+ public int getLast()
+ {
+ return m_last;
+ }
+
+ public void setLast(int last)
+ {
+ m_last = last;
+ }
+
}
1.4 +3 -0 xml-xalan/java/src/org/apache/xpath/axes/ContextNodeList.java
Index: ContextNodeList.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/ContextNodeList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContextNodeList.java 2000/11/13 16:27:29 1.3
+++ ContextNodeList.java 2000/11/14 23:15:10 1.4
@@ -147,4 +147,7 @@
* @throws CloneNotSupportedException
*/
public Object clone() throws CloneNotSupportedException;
+
+ public int getLast();
+ public void setLast(int last);
}
1.13 +14 -0 xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java
Index: LocPathIterator.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- LocPathIterator.java 2000/11/13 16:27:30 1.12
+++ LocPathIterator.java 2000/11/14 23:15:10 1.13
@@ -176,6 +176,8 @@
* a predicate.
*/
private boolean m_isTopLevel = false;
+
+ private int m_last = 0;
/**
* Create a LocPathIterator object.
@@ -628,6 +630,7 @@
m_foundLast = false;
m_lastFetched = null;
m_next = 0;
+ m_last = 0;
if (null != m_firstWalker)
{
@@ -912,4 +915,15 @@
{
return m_prefixResolver;
}
+
+ public int getLast()
+ {
+ return m_last;
+ }
+
+ public void setLast(int last)
+ {
+ m_last = last;
+ }
+
}
1.8 +12 -0 xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java
Index: UnionPathIterator.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- UnionPathIterator.java 2000/11/13 16:27:30 1.7
+++ UnionPathIterator.java 2000/11/14 23:15:10 1.8
@@ -658,4 +658,16 @@
* path</a> contained in the union expression.
*/
protected LocPathIterator[] m_iterators;
+
+ private int m_last = 0;
+
+ public int getLast()
+ {
+ return m_last;
+ }
+
+ public void setLast(int last)
+ {
+ m_last = last;
+ }
}
1.4 +20 -1 xml-xalan/java/src/org/apache/xpath/functions/FuncLast.java
Index: FuncLast.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncLast.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FuncLast.java 2000/11/13 16:27:33 1.3
+++ FuncLast.java 2000/11/14 23:15:10 1.4
@@ -102,19 +102,38 @@
if (cnl.size() == 0)
{
+ try
+ {
+ NodeIterator ni = (NodeIterator)cnl.clone();
+ int count = cnl.getCurrentPos();
+ while(null != ni.nextNode())
+ count++;
+ cnl.setLast(count);
+ return count;
+ }
+ catch(CloneNotSupportedException cnse){}
+ }
+ return cnl.size();
+
+ /*
+ // The code below has massive problem if inside of a predicate. -sb
+ if (cnl.size() == 0)
+ {
int currentPos = cnl.getCurrentPos();
- // System.out.println("getCountOfContextNodeList - currentPos: "+currentPos);
+ // This has problems if inside a predicate. For now, just clone.
if (!cnl.isFresh())
cnl.reset();
cnl.setShouldCacheNodes(true);
cnl.runTo(-1);
cnl.setCurrentPos(currentPos);
+ System.out.println("cnl.getCurrentPos() after: "+cnl.getCurrentPos());
}
// System.out.println("cnl.size(): "+cnl.size());
return cnl.size();
+ */
}
/**