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...@apache.org on 2001/06/04 23:25:54 UTC
cvs commit: xml-xalan/java/src/org/apache/xpath/patterns FunctionPattern.java
sboag 01/06/04 14:25:54
Modified: java/src/org/apache/xalan/templates Tag: DTM_EXP
ElemVariable.java FuncDocument.java
java/src/org/apache/xml/dtm Tag: DTM_EXP DTMIterator.java
java/src/org/apache/xpath Tag: DTM_EXP NodeSet.java
java/src/org/apache/xpath/axes Tag: DTM_EXP
LocPathIterator.java UnionPathIterator.java
java/src/org/apache/xpath/functions Tag: DTM_EXP
FuncCount.java FuncSum.java
java/src/org/apache/xpath/objects Tag: DTM_EXP XNodeSet.java
java/src/org/apache/xpath/patterns Tag: DTM_EXP
FunctionPattern.java
Log:
Enabled detach() in a few more places, and fixed bug where
detach() was being used with a variable: when owned by a variable
you don't want to have the iterator detached, so I had to add a
allowDetachToRelease(boolean allowRelease) method on
DTMIterator, so that detach() can be called harmlessly by other
callers. (Perhaps detach() should be renamed to release() or some
such()?).
Also discovered that the isNodesetExpr on Expression is
pretty dangerous, since we'll not be able to predict this for
extension functions. Yuck, I wish we had static typing. Since
this is being used in a few places, I suspect there are still some
holes left.
Revision Changes Path
No revision
No revision
1.10.2.4 +2 -0 xml-xalan/java/src/org/apache/xalan/templates/ElemVariable.java
Index: ElemVariable.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemVariable.java,v
retrieving revision 1.10.2.3
retrieving revision 1.10.2.4
diff -u -r1.10.2.3 -r1.10.2.4
--- ElemVariable.java 2001/05/10 20:48:14 1.10.2.3
+++ ElemVariable.java 2001/06/04 21:25:49 1.10.2.4
@@ -282,6 +282,8 @@
if (null != m_selectPattern)
{
var = m_selectPattern.execute(xctxt, sourceNode, this);
+ if(var.getType() == XObject.CLASS_NODESET)
+ ((org.apache.xpath.objects.XNodeSet)var).allowDetachToRelease(false);
if(TransformerImpl.S_DEBUG)
transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
"select", m_selectPattern, var);
1.19.2.9 +11 -0 xml-xalan/java/src/org/apache/xalan/templates/FuncDocument.java
Index: FuncDocument.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/FuncDocument.java,v
retrieving revision 1.19.2.8
retrieving revision 1.19.2.9
diff -u -r1.19.2.8 -r1.19.2.9
--- FuncDocument.java 2001/06/04 13:48:37 1.19.2.8
+++ FuncDocument.java 2001/06/04 21:25:49 1.19.2.9
@@ -467,4 +467,15 @@
if ((argNum < 1) || (argNum > 2))
throw new WrongNumberArgsException("1 or 2");
}
+
+ /**
+ * Tell if the expression is a nodeset expression. In other words, tell
+ * if you can execute {@link asNode() asNode} without an exception.
+ * @return true if the expression can be represented as a nodeset.
+ */
+ public boolean isNodesetExpr()
+ {
+ return true;
+ }
+
}
No revision
No revision
1.1.2.9 +8 -0 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMIterator.java
Index: DTMIterator.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMIterator.java,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -r1.1.2.8 -r1.1.2.9
--- DTMIterator.java 2001/06/03 03:00:36 1.1.2.8
+++ DTMIterator.java 2001/06/04 21:25:50 1.1.2.9
@@ -226,6 +226,14 @@
* raise a runtime exception.
*/
public void detach();
+
+ /**
+ * Specify if it's OK for detach to release the iterator for reuse.
+ *
+ * @param allowRelease true if it is OK for detach to release this iterator
+ * for pooling.
+ */
+ public void allowDetachToRelease(boolean allowRelease);
/**
* Get the current node in the iterator. Note that this differs from
No revision
No revision
1.10.2.7 +13 -1 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.10.2.6
retrieving revision 1.10.2.7
diff -u -r1.10.2.6 -r1.10.2.7
--- NodeSet.java 2001/06/03 03:24:23 1.10.2.6
+++ NodeSet.java 2001/06/04 21:25:51 1.10.2.7
@@ -413,6 +413,18 @@
* </p>
*/
public void detach(){}
+
+ /**
+ * Specify if it's OK for detach to release the iterator for reuse.
+ *
+ * @param allowRelease true if it is OK for detach to release this iterator
+ * for pooling.
+ */
+ public void allowDetachToRelease(boolean allowRelease)
+ {
+ // no action for right now.
+ }
+
/**
* Tells if this NodeSet is "fresh", in other words, if
@@ -1015,7 +1027,7 @@
return super.elementAt(i);
}
-
+
/**
* Tell if the table contains the given node.
*
No revision
No revision
1.24.2.12 +27 -20 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.24.2.11
retrieving revision 1.24.2.12
diff -u -r1.24.2.11 -r1.24.2.12
--- LocPathIterator.java 2001/06/04 07:52:58 1.24.2.11
+++ LocPathIterator.java 2001/06/04 21:25:51 1.24.2.12
@@ -214,22 +214,12 @@
throws javax.xml.transform.TransformerException
{
- try
- {
-
- // LocPathIterator clone = (LocPathIterator) m_pool.getInstanceIfFree();
- // if (null == clone)
- LocPathIterator clone = (LocPathIterator) this.clone();
+ LocPathIterator clone = (LocPathIterator)m_clones.getInstance();
- int current = xctxt.getCurrentNode();
- clone.setRoot(current, xctxt);
+ int current = xctxt.getCurrentNode();
+ clone.setRoot(current, xctxt);
- return new XNodeSet(clone);
- }
- catch (CloneNotSupportedException ncse)
- {
- throw new javax.xml.transform.TransformerException(ncse);
- }
+ return new XNodeSet(clone);
}
/**
@@ -622,6 +612,20 @@
{
return true;
}
+
+ /** Control over whether it is OK for detach to reset the iterator. */
+ private boolean m_allowDetach = true;
+
+ /**
+ * Specify if it's OK for detach to release the iterator for reuse.
+ *
+ * @param allowRelease true if it is OK for detach to release this iterator
+ * for pooling.
+ */
+ public void allowDetachToRelease(boolean allowRelease)
+ {
+ m_allowDetach = allowRelease;
+ }
/**
* Detaches the iterator from the set which it iterated over, releasing
@@ -632,12 +636,15 @@
*/
public void detach()
{
- m_cachedNodes = null;
- m_execContext = null;
- m_prefixResolver = null;
- m_cdtm = null;
-
- m_clones.freeInstance(this);
+ if(m_allowDetach)
+ {
+ m_cachedNodes = null;
+ m_execContext = null;
+ m_prefixResolver = null;
+ m_cdtm = null;
+
+ m_clones.freeInstance(this);
+ }
}
/**
1.15.2.9 +32 -25 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.15.2.8
retrieving revision 1.15.2.9
diff -u -r1.15.2.8 -r1.15.2.9
--- UnionPathIterator.java 2001/06/03 03:09:23 1.15.2.8
+++ UnionPathIterator.java 2001/06/04 21:25:51 1.15.2.9
@@ -128,6 +128,20 @@
}
}
}
+
+ /** Control over whether it is OK for detach to reset the iterator. */
+ private boolean m_allowDetach = true;
+
+ /**
+ * Specify if it's OK for detach to release the iterator for reuse.
+ *
+ * @param allowRelease true if it is OK for detach to release this iterator
+ * for pooling.
+ */
+ public void allowDetachToRelease(boolean allowRelease)
+ {
+ m_allowDetach = allowRelease;
+ }
/**
* Detaches the iterator from the set which it iterated over, releasing
@@ -138,23 +152,25 @@
*/
public void detach()
{
-
- this.m_context = DTM.NULL;
- this.m_execContext = null;
- this.m_context = DTM.NULL;
-
- int n = m_iterators.length;
- for (int i = 0; i < n; i++)
+ if(m_allowDetach)
{
- m_iterators[i].detach();
+ this.m_execContext = null;
+ this.m_context = DTM.NULL;
+
+ // int n = m_iterators.length;
+ //
+ // for (int i = 0; i < n; i++)
+ // {
+ // m_iterators[i].detach();
+ // }
+
+ m_clones.freeInstance(this);
}
-
- m_pool.freeInstance(this);
}
/** Pool of UnionPathIterators. (The need for this has to be re-evaluated. -sb) */
- transient ObjectPool m_pool = new ObjectPool(this.getClass());
+ protected IteratorPool m_clones = new IteratorPool(this);
/**
* Execute this iterator, meaning create a clone that can
@@ -170,23 +186,14 @@
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
-
- try
- {
- UnionPathIterator clone =
- (UnionPathIterator) m_pool.getInstanceIfFree();
- if (null == clone)
- clone = (UnionPathIterator) this.clone();
+ UnionPathIterator clone =
+ (UnionPathIterator) m_clones.getInstance();
- int current = xctxt.getCurrentNode();
- clone.setRoot(current, xctxt);
-
- return new XNodeSet(clone);
- }
- catch (CloneNotSupportedException ncse){}
+ int current = xctxt.getCurrentNode();
+ clone.setRoot(current, xctxt);
- return null;
+ return new XNodeSet(clone);
}
/** If this iterator needs to cache nodes that are fetched, they
No revision
No revision
1.4.2.2 +2 -2 xml-xalan/java/src/org/apache/xpath/functions/FuncCount.java
Index: FuncCount.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncCount.java,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -r1.4.2.1 -r1.4.2.2
--- FuncCount.java 2001/04/10 18:45:28 1.4.2.1
+++ FuncCount.java 2001/06/04 21:25:52 1.4.2.2
@@ -89,7 +89,7 @@
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
- DTMIterator nl = m_arg0.execute(xctxt).nodeset();
+ DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
// We should probably make a function on the iterator for this,
// as a given implementation could optimize.
@@ -99,7 +99,7 @@
{
i++;
}
- // nl.detach();
+ nl.detach();
return new XNumber((double) i);
}
1.4.2.4 +2 -2 xml-xalan/java/src/org/apache/xpath/functions/FuncSum.java
Index: FuncSum.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncSum.java,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -r1.4.2.3 -r1.4.2.4
--- FuncSum.java 2001/05/19 07:05:54 1.4.2.3
+++ FuncSum.java 2001/06/04 21:25:52 1.4.2.4
@@ -88,7 +88,7 @@
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{
- DTMIterator nodes = m_arg0.execute(xctxt).nodeset();
+ DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
double sum = 0.0;
int pos;
@@ -100,7 +100,7 @@
if (null != s)
sum += s.toDouble();
}
- // nodes.detach();
+ nodes.detach();
return new XNumber(sum);
}
No revision
No revision
1.10.2.6 +23 -0 xml-xalan/java/src/org/apache/xpath/objects/XNodeSet.java
Index: XNodeSet.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XNodeSet.java,v
retrieving revision 1.10.2.5
retrieving revision 1.10.2.6
diff -u -r1.10.2.5 -r1.10.2.6
--- XNodeSet.java 2001/05/19 07:05:57 1.10.2.5
+++ XNodeSet.java 2001/06/04 21:25:53 1.10.2.6
@@ -226,6 +226,29 @@
XString xstring = (XString)xstr();
xstring.appendToFsb(fsb);
}
+
+ /**
+ * Specify if it's OK for detach to release the iterator for reuse.
+ *
+ * @param allowRelease true if it is OK for detach to release this iterator
+ * for pooling.
+ */
+ public void allowDetachToRelease(boolean allowRelease)
+ {
+ ((DTMIterator) m_obj).allowDetachToRelease(allowRelease);
+ }
+
+ /**
+ * Detaches the <code>DTMIterator</code> from the set which it iterated
+ * over, releasing any computational resources and placing the iterator
+ * in the INVALID state. After <code>detach</code> has been invoked,
+ * calls to <code>nextNode</code> or <code>previousNode</code> will
+ * raise a runtime exception.
+ */
+ public void detach()
+ {
+ ((DTMIterator) m_obj).detach();
+ }
/**
No revision
No revision
1.7.2.8 +6 -8 xml-xalan/java/src/org/apache/xpath/patterns/FunctionPattern.java
Index: FunctionPattern.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/FunctionPattern.java,v
retrieving revision 1.7.2.7
retrieving revision 1.7.2.8
diff -u -r1.7.2.7 -r1.7.2.8
--- FunctionPattern.java 2001/06/04 07:53:00 1.7.2.7
+++ FunctionPattern.java 2001/06/04 21:25:53 1.7.2.8
@@ -124,8 +124,7 @@
throws javax.xml.transform.TransformerException
{
- XObject obj = m_functionExpr.execute(xctxt);
- DTMIterator nl = obj.nodeset();
+ DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl)
@@ -146,6 +145,7 @@
// nl.detach();
}
+ nl.detach();
return score;
}
@@ -168,8 +168,7 @@
throws javax.xml.transform.TransformerException
{
- XObject obj = m_functionExpr.execute(xctxt);
- DTMIterator nl = obj.nodeset();
+ DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl)
@@ -188,7 +187,7 @@
}
}
- // nl.detach();
+ nl.detach();
}
return score;
@@ -212,8 +211,7 @@
{
int context = xctxt.getCurrentNode();
- XObject obj = m_functionExpr.execute(xctxt);
- DTMIterator nl = obj.nodeset();
+ DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl)
@@ -232,7 +230,7 @@
}
}
- // nl.detach();
+ nl.detach();
}
return score;
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org