You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by pa...@apache.org on 2002/06/14 17:12:06 UTC
cvs commit: xml-xalan/test/java/src/org/apache/qetest/dtm TimeDTMTraverserDeep.java
pauldick 2002/06/14 08:12:05
Modified: test/java/src/org/apache/qetest/dtm
TimeDTMTraverserDeep.java
Log:
Major cleanup and integration with QeDtmUtils
Revision Changes Path
1.4 +7 -133 xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMTraverserDeep.java
Index: TimeDTMTraverserDeep.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TimeDTMTraverserDeep.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TimeDTMTraverserDeep.java 10 Jun 2002 19:00:15 -0000 1.3
+++ TimeDTMTraverserDeep.java 14 Jun 2002 15:12:05 -0000 1.4
@@ -67,6 +67,7 @@
import org.apache.xml.dtm.*;
import org.apache.xml.dtm.ref.*;
+import org.apache.qetest.dtm.*;
import org.apache.qetest.dtm.dtmWSStripper;
@@ -84,80 +85,18 @@
* */
public class TimeDTMTraverserDeep {
-static final String[] TYPENAME=
- { "NULL",
- "ELEMENT",
- "ATTRIBUTE",
- "TEXT",
- "CDATA_SECTION",
- "ENTITY_REFERENCE",
- "ENTITY",
- "PROCESSING_INSTRUCTION",
- "COMMENT",
- "DOCUMENT",
- "DOCUMENT_TYPE",
- "DOCUMENT_FRAGMENT",
- "NOTATION",
- "NAMESPACE"
- };
-
public static void main(String argv[])
{
long dtmStart = 0; // Time the creation of dtmManager, and dtm initialization.
System.out.println("\n#### Testing Traversal of DEEP documents. ####");
- try
- {
- // Pick our input source
- Source source=null;
- if(argv.length<1)
- {
- String defaultSource=
- "<?xml version=\"1.0\"?>\n"+
- "<Document>"+
- "<Aa><Ab><Ac><Ad><Ae><Af><Ag><Ah><Ai><Aj><Ak>"+
- "<Al><Am><An><Ao><Ap><Aq><Ar><As><At><Au><Av>"+
- "<Aw><Ax><Ay><Az/>"+
- "</Ay></Ax></Aw>"+
- "</Av></Au></At></As></Ar></Aq></Ap></Ao></An></Am></Al>"+
- "</Ak></Aj></Ai></Ah></Ag></Af></Ae></Ad></Ac></Ab></Aa>"+
- "</Document>";
-
- source=new StreamSource(new StringReader(defaultSource));
- }
- else if (argv.length>1 && "X".equalsIgnoreCase(argv[1]))
- {
- // XNI stream startup goes here
- // Remember to perform Schema validation, to obtain PSVI annotations
- }
- else
- {
- // Read from a URI via whatever mechanism the DTMManager prefers
- source=new StreamSource(argv[0]);
- }
-
- // Get a DTM manager, and ask it to load the DTM "uniquely",
- // with no whitespace filtering, nonincremental, but _with_
- // indexing (a fairly common case, and avoids the special
- // mode used for RTF DTMs).
- // For testing with some of David Marston's files I do want to strip whitespace.
- dtmWSStripper stripper = new dtmWSStripper();
+ StringBuffer buf = new StringBuffer();
+ DTM dtm = QeDtmUtils.createDTM(0, QeDtmUtils.deepFile, buf);
// Time the creation of the dtm
-
- dtmStart = System.currentTimeMillis();
- DTMManager manager= new DTMManagerDefault().newInstance(new XMLStringFactoryImpl());
- DTM dtm=manager.getDTM(source, true, stripper, false, true);
- System.out.println("DTM initialization took: "+ (System.currentTimeMillis() - dtmStart)+ "\n");
-
- System.out.println("Pre-DTM free memory:" + Runtime.getRuntime().freeMemory());
- System.out.println("Post-DTM free memory:" + Runtime.getRuntime().freeMemory());
- Runtime.getRuntime().gc();
- System.out.println("Post-GC free memory:" + Runtime.getRuntime().freeMemory());
-
// Get various nodes to use as context nodes.
int dtmRoot = dtm.getDocument(); // #document
String dtmRootName = dtm.getNodeName(dtmRoot); // Used for output
@@ -170,12 +109,12 @@
// Get a traverser for Descendant:: axis.
System.out.println("\n* DESCENDANT from "+"<"+DNodeName+">");
- timeAxis(dtm, Axis.DESCENDANT, DNode, rtData);
+ QeDtmUtils.timeAxisTraverser(dtm, Axis.DESCENDANT, DNode, rtData);
System.out.println("Time="+rtData[0] + " : " + "LastNode="+rtData[1]+" nodes="+rtData[2]);
// Get a traverser for Descendant:: axis.
System.out.println("\n* DESCENDANT-OR-SELF from "+"<"+DNodeName+">");
- timeAxis(dtm, Axis.DESCENDANTORSELF, DNode, rtData);
+ QeDtmUtils.timeAxisTraverser(dtm, Axis.DESCENDANTORSELF, DNode, rtData);
System.out.println("Time="+rtData[0] + " : " + "LastNode="+rtData[1]+" nodes="+rtData[2]);
// Use last node from Child traverse as Context node for subsequent traversals
@@ -184,79 +123,14 @@
// Get a traverser for Ancestor:: axis.
System.out.println("\n* ANCESTOR from "+"<"+lastNodeName+">");
- timeAxis(dtm, Axis.ANCESTOR, lastNode, rtData);
+ QeDtmUtils.timeAxisTraverser(dtm, Axis.ANCESTOR, lastNode, rtData);
System.out.println("Time="+rtData[0] + " : " + "LastNode="+rtData[1]+" nodes="+rtData[2]);
// Get a traverser for Ancestor:: axis.
System.out.println("\n* ANCESTOR-OR-SELF from "+"<"+lastNodeName+">");
- timeAxis(dtm, Axis.ANCESTORORSELF, lastNode, rtData);
+ QeDtmUtils.timeAxisTraverser(dtm, Axis.ANCESTORORSELF, lastNode, rtData);
System.out.println("Time="+rtData[0] + " : " + "LastNode="+rtData[1]+" nodes="+rtData[2]);
}
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
-
- static void timeAxis(DTM dtm, int axis, int context, int[] rtdata)
- {
- long startTime = 0;
- long endTime = 0;
- long travTime = 0;
- int atNode = 0;
- int lastNode = 0;
- int numOfNodes =0;
-
- DTMAxisTraverser at = dtm.getAxisTraverser(axis);
-
- // Time the traversal.
- startTime = System.currentTimeMillis();
-
- for (atNode = at.first(context); DTM.NULL != atNode;
- atNode = at.next(context, atNode))
- { //printNode(dtm, atNode, " ");
- lastNode = atNode;
- numOfNodes = numOfNodes + 1;
- }
-
- travTime = System.currentTimeMillis() - startTime;
-
- //System.out.println("Time was: " + travTime );
- //System.out.println("lastNode was: " + lastNode );
-
- printNode(dtm, lastNode, " ");
- rtdata[0] = (int)travTime;
- rtdata[1] = lastNode;
- rtdata[2] = numOfNodes;
-
-
- }
-
-
- static void printNode(DTM dtm,int nodeHandle,String indent)
- {
- // Briefly display this node
- // Don't bother displaying namespaces or attrs; we do that at the
- // next level up.
- // %REVIEW% Add namespace info, type info, ...
-
- // Formatting hack -- suppress quotes when value is null, to distinguish
- // it from "null".
- String value=dtm.getNodeValue(nodeHandle);
- String vq=(value==null) ? "" : "\"";
-
- // Skip outputing of text nodes. In most cases they clutter the output,
- // besides I'm only interested in the elemental structure of the dtm.
- if( TYPENAME[dtm.getNodeType(nodeHandle)] != "TEXT" )
- {
- System.out.println(indent+
- +nodeHandle+": "+
- TYPENAME[dtm.getNodeType(nodeHandle)]+" "+
- dtm.getNodeName(nodeHandle)+" "+
- " Level=" + dtm.getLevel(nodeHandle)
- );
- }
}
-}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org