You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/08/12 17:23:08 UTC
svn commit: r232310 [66/92] - in /beehive/trunk/controls/test: common/
infra/gtlf/ infra/gtlf/xsl/ infra/mantis/ infra/tch/ infra/tch/messages/
infra/tch/runtime/ infra/tch/schema/ perf/ perf/bin/ perf/cases/
perf/ctlsrc/org/apache/beehive/controls/per...
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestRunner.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestRunner.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestRunner.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestRunner.java Fri Aug 12 08:12:28 2005
@@ -1,415 +1,415 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.MalformedURLException;
-import java.rmi.Naming;
-import java.rmi.NotBoundException;
-import java.rmi.RemoteException;
-import java.text.SimpleDateFormat;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.beehive.test.tools.tch.common.util.NestedRuntimeException;
-import org.apache.beehive.test.tools.tch.compose.internal.TestNode;
-import org.apache.beehive.test.tools.tch.compose.internal.context.AtomicTestContext;
-import org.apache.beehive.test.tools.tch.core.process.ProcessEngine;
-import org.apache.beehive.test.tools.tch.core.remote.RemoteProcessEngineWrapper;
-import org.apache.beehive.test.tools.tch.core.test.BasicInternalParameters;
-import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
-import org.apache.beehive.test.tools.tch.core.test.UsedParameterAdderResultHandler;
-import org.apache.beehive.test.tools.tch.logger.CompositeLogger;
-import org.apache.beehive.test.tools.tch.logger.Logger;
-import org.apache.beehive.test.tools.tch.logger.PrintWriterLoggerAdapter;
-import org.apache.beehive.test.tools.tch.util.TestResult;
-import org.apache.beehive.test.tools.tch.util.TestResultBean;
-
-/**
- * Instantiates and runs a test class.
- * Two modes: When used through a browser (interactive) and
- * when called from the javatest client (!interactive)
- *
- */
-public class TestRunner extends HttpServlet
-{
-
- // ============================================================
- // Constants
-
- public final static String DEBUG_PARAM = ServletTestVehicle.DEBUG_PARAM;
-
- private final static String HELP_MESSAGE =
- "<html><head><title>JavatestServlet</title></head>"
- + "<body bgcolor='#FFFFFF'><p>"
- + "<center>Welcome to JavatestServlet</center><hr>"
- + "<b>Arguments:</b></p><blockquote>"
- + "<p>"
- + ServletTestVehicle.CLASS_PARAM
- + " : a Javatest test class</p>"
- + "<p>"
- + ServletTestVehicle.METHOD_PARAM
- + " : comma-separated list of "
- + "test methods to run</p>"
- + "<p>"
- + ServletTestVehicle.SERVER_SIDE_LOGGING_PARAM
- + " : write standard log to stdout."
- + "</p>"
- + "<p>"
- + DEBUG_PARAM
- + " : enable debugging mode (verbose stdout)</p>"
- + "</blockquote><p><b>Example:</b></p><blockquote>"
- + "<p>http://localhost:9001/javatesthelpers/JavatestServlet?</p>"
- + "<blockquote><p>"
- + ServletTestVehicle.CLASS_PARAM
- + "=org.apache.beehive.test.tools.tch.tests.mytests.waiting3"
- + "</p>"
- + "</blockquote><p>or:</p><blockquote>"
- + "<p>"
- + ServletTestVehicle.CLASS_PARAM
- + "=org.apache.beehive.test.tools.tch.test.RandomTest&<br>"
- + ServletTestVehicle.METHOD_PARAM
- + "=testGG&serverSideLogging=true&"
- + DEBUG_PARAM
- + "=false</p></blockquote></blockquote></body></html>";
-
- // ============================================================
- // Variables
-
- private boolean debug = true, interactive = true;
- private HttpServletResponse myServletResponse = null;
- private PrintWriter pw = null;
- private Properties mProperties;
-
- public void init()
- {
- System.out.println("FOOO");
- if (debug)
- System.out.println("JavatestServlet-->JavatestServlet in init()");
- }
-
- public void service(HttpServletRequest rq, HttpServletResponse rp)
- throws IOException
- {
- // init some things every time we hit the servlet
- System.out.println("FOOO in service");
- myServletResponse = rp;
- if (debug)
- System.out.println("JavatestServlet-->Begin Service Method");
- interactive = true;
- // get params
- mProperties = initProperties();
- collectParams(rq);
-
- if (debug)
- System.out.println("JavatestServlet-->interactive is: " + interactive);
-
- if (interactive)
- {
- myServletResponse.setContentType("text/html");
- pw = myServletResponse.getWriter();
- }
- else
- {
- myServletResponse.setContentType("text/plain");
- pw = new PrintWriter(myServletResponse.getOutputStream());
- }
-
- // getting test class name
- String className =
- (String)mProperties.remove(ServletTestVehicle.CLASS_PARAM);
- // getting test method name
- String methodName =
- (String)mProperties.remove(ServletTestVehicle.METHOD_PARAM);
- // AtomicTestContext wants a Vector for passing in specific methods to
- // run
- Vector testMethods = new Vector();
- if (methodName != null)
- {
- StringTokenizer st = new StringTokenizer(methodName, ",");
- while (st.hasMoreTokens())
- {
- testMethods.addElement(st.nextToken());
- }
- }
- // getting roster url
- String processEngineLookupUrl =
- (String)mProperties.remove(
- ServletTestVehicle.PROCESS_ENGINE_WRAPPER_LOOKUP_URL_PARAM);
-
- if (debug)
- {
- System.out.println("JavatestServlet-->Class is: " + className);
- System.out.println("JavatestServlet-->Method is: " + methodName);
- System.out.println(
- "JavatestServlet-->Roster url is: " + processEngineLookupUrl);
- }
-
- if (className == null)
- {
- if (interactive)
- {
- pw.print(HELP_MESSAGE);
- return;
- }
- }
- else
- {
- if (interactive)
- {
- pw.println("Attempting to load: " + className + "<br>");
- }
-
- // put a parameter to indicate it is a server-side test
- }
-
- BasicInternalParameters mBasicInternalParameters =
- new BasicInternalParameters(mProperties);
-
- TestNode localTestNode = null;
- try
- {
- localTestNode =
- new AtomicTestContext(className, mBasicInternalParameters, testMethods);
- }
- catch (Throwable t)
- {
- if (interactive)
- {
- pw.println("<b>Could not find class " + className + "</b></br>");
- }
- if (debug)
- t.printStackTrace();
- System.out.println(
- "\n[JavatestServlet] Could not find class: " + className);
- System.out.println(
- "[JavatestServlet] Is it in the server " + "classpath?");
- //closeStreams();
- return;
- }
-
- // get process engine from rmi reg
- // only if not interactive
- if (!interactive && processEngineLookupUrl != null)
- {
- ProcessEngine processEngine = null;
- try
- {
- RemoteProcessEngineWrapper wrapper =
- (RemoteProcessEngineWrapper)Naming.lookup(processEngineLookupUrl);
- localTestNode.setProcessEngine(wrapper.getProcessEngine());
- }
- catch (Exception ex)
- {
- // TODO: what is best to throw out here?
- throw new NestedRuntimeException(ex);
- }
- }
-
- Logger logger = initLogger();
- ResultHandler handler =
- new UsedParameterAdderResultHandler(
- new LocalResultHandler(logger),
- mBasicInternalParameters);
-
- //ResultHandler handler = new LocalResultHandler(logger);
- localTestNode.setResultHandler(handler);
- try
- {
- if (!interactive)
- inform("Test " + className + " starting on server", handler);
- localTestNode.run();
- if (!interactive)
- inform("Test " + className + " finishing on server ", handler);
- }
- catch (Throwable t)
- {
- if (interactive)
- {
- pw.println("<b>Unable to run tests:</b><br> " + t.toString());
- }
- t.printStackTrace();
- }
- finally
- {
- logger.close();
- if (interactive)
- {
- pw.println("Done running test class " + className + "<br>");
- }
- //closeStreams();
- }
- }
-
- private Logger initLogger()
- {
- CompositeLogger myLogger = new CompositeLogger();
- String logToServer =
- (String)mProperties.remove(ServletTestVehicle.SERVER_SIDE_LOGGING_PARAM);
- if (logToServer != null && logToServer.equalsIgnoreCase("true"))
- {
-
- }
- if (interactive)
- {
- myLogger.add(new LocalLogger());
- }
- else
- {
- // log to client
- ResultXMLLogger xmlLogger = new ResultXMLLogger(pw);
- myLogger.add(xmlLogger);
- }
- myLogger.open();
- return myLogger;
- }
-
- private void collectParams(HttpServletRequest rq)
- {
- String paramName = null;
- String[] paramValues = null;
- Enumeration params = rq.getParameterNames();
- while (params.hasMoreElements())
- {
- paramName = (String)params.nextElement();
- paramValues = rq.getParameterValues(paramName);
- for (int i = 0; i < paramValues.length; i++)
- {
- mProperties.put(paramName, paramValues[i].toString());
- // FIXME? override if array
- if (debug)
- {
- System.out.println(
- "JavatestServlet: " + paramName + "-->" + paramValues[i]);
- }
- }
- }
- // checking debug setting -
- // kind of stupid: have to run twice to see all debug info
- if (mProperties.get(DEBUG_PARAM) != null)
- {
- debug =
- (new Boolean((String)mProperties.remove(DEBUG_PARAM))).booleanValue();
- }
- if (debug)
- System.out.println("JavatestServlet-->Got params: " + mProperties);
- // check if called from javatest - if yes, set interactive to false
- if (mProperties.get(ServletTestVehicle.JAVATEST_PARAM) != null
- && mProperties.get(ServletTestVehicle.JAVATEST_PARAM).equals("false"))
- {
- interactive = false;
- mProperties.remove(ServletTestVehicle.JAVATEST_PARAM);
- }
- }
-
- private Properties initProperties()
- {
- Properties p = new Properties();
- p.setProperty(ServletTestVehicle.SERVER_SIDE_LOGGING_PARAM, "false");
- return p;
- }
-
- private void inform(String message, ResultHandler handler)
- {
- System.out.println(message);
- }
-
- private class LocalResultHandler implements ResultHandler
- {
- private Logger logger = null;
- public LocalResultHandler(Logger in)
- {
- logger = in;
- }
-
- public void submitResult(TestResultBean tr)
- {
- logger.log(tr);
- }
-
- public void submitResult(TestResultBean tr, String resultName)
- {
- tr.setName(resultName);
- logger.log(tr);
- }
-
- }
-
- private class LocalLogger extends PrintWriterLoggerAdapter
- {
- private final String tw = "width='200'";
- private SimpleDateFormat mDateFormat = new SimpleDateFormat();
- private Vector results = null;
-
- public void init(Map m)
- {
- }
- public void logInit()
- {
- }
-
- public void open()
- {
- pw.print("<hr>Servlet Logger Opened<br>");
- pw.print(
- "<table><tr><td "
- + tw
- + "><b>Time</b></td>"
- + "<td "
- + tw
- + "><b>Test</b></td>"
- + "<td "
- + tw
- + "><b>Result</b></td>"
- + "<td "
- + tw
- + "><b>Message<b></td></tr></b>"
- + "</table>");
- }
-
- public void close()
- {
- pw.print("<br>Servlet Logger Closed<hr>");
- }
-
- public void logIndividualRes(TestResult inResult)
- {
- String resultType = inResult.getTypeAsString();
- String date = (mDateFormat.format(inResult.getTimeStamp()) + " ");
- String message =
- (inResult.getOutputMessage() == null
- ? ""
- : inResult.getOutputMessage());
- String name = inResult.getName();
-
- pw.print(
- "<table><tr><td "
- + tw
- + ">"
- + date
- + "</td>"
- + "<td "
- + tw
- + ">"
- + name
- + "</td>"
- + "<td "
- + tw
- + ">"
- + resultType
- + "</td>"
- + "<td "
- + tw
- + ">"
- + message
- + "</td></tr>"
- + "</table>");
- }
- }
-}
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
+import java.text.SimpleDateFormat;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.beehive.test.tools.tch.common.util.NestedRuntimeException;
+import org.apache.beehive.test.tools.tch.compose.internal.TestNode;
+import org.apache.beehive.test.tools.tch.compose.internal.context.AtomicTestContext;
+import org.apache.beehive.test.tools.tch.core.process.ProcessEngine;
+import org.apache.beehive.test.tools.tch.core.remote.RemoteProcessEngineWrapper;
+import org.apache.beehive.test.tools.tch.core.test.BasicInternalParameters;
+import org.apache.beehive.test.tools.tch.core.test.ResultHandler;
+import org.apache.beehive.test.tools.tch.core.test.UsedParameterAdderResultHandler;
+import org.apache.beehive.test.tools.tch.logger.CompositeLogger;
+import org.apache.beehive.test.tools.tch.logger.Logger;
+import org.apache.beehive.test.tools.tch.logger.PrintWriterLoggerAdapter;
+import org.apache.beehive.test.tools.tch.util.TestResult;
+import org.apache.beehive.test.tools.tch.util.TestResultBean;
+
+/**
+ * Instantiates and runs a test class.
+ * Two modes: When used through a browser (interactive) and
+ * when called from the javatest client (!interactive)
+ *
+ */
+public class TestRunner extends HttpServlet
+{
+
+ // ============================================================
+ // Constants
+
+ public final static String DEBUG_PARAM = ServletTestVehicle.DEBUG_PARAM;
+
+ private final static String HELP_MESSAGE =
+ "<html><head><title>JavatestServlet</title></head>"
+ + "<body bgcolor='#FFFFFF'><p>"
+ + "<center>Welcome to JavatestServlet</center><hr>"
+ + "<b>Arguments:</b></p><blockquote>"
+ + "<p>"
+ + ServletTestVehicle.CLASS_PARAM
+ + " : a Javatest test class</p>"
+ + "<p>"
+ + ServletTestVehicle.METHOD_PARAM
+ + " : comma-separated list of "
+ + "test methods to run</p>"
+ + "<p>"
+ + ServletTestVehicle.SERVER_SIDE_LOGGING_PARAM
+ + " : write standard log to stdout."
+ + "</p>"
+ + "<p>"
+ + DEBUG_PARAM
+ + " : enable debugging mode (verbose stdout)</p>"
+ + "</blockquote><p><b>Example:</b></p><blockquote>"
+ + "<p>http://localhost:9001/javatesthelpers/JavatestServlet?</p>"
+ + "<blockquote><p>"
+ + ServletTestVehicle.CLASS_PARAM
+ + "=org.apache.beehive.test.tools.tch.tests.mytests.waiting3"
+ + "</p>"
+ + "</blockquote><p>or:</p><blockquote>"
+ + "<p>"
+ + ServletTestVehicle.CLASS_PARAM
+ + "=org.apache.beehive.test.tools.tch.test.RandomTest&<br>"
+ + ServletTestVehicle.METHOD_PARAM
+ + "=testGG&serverSideLogging=true&"
+ + DEBUG_PARAM
+ + "=false</p></blockquote></blockquote></body></html>";
+
+ // ============================================================
+ // Variables
+
+ private boolean debug = true, interactive = true;
+ private HttpServletResponse myServletResponse = null;
+ private PrintWriter pw = null;
+ private Properties mProperties;
+
+ public void init()
+ {
+ System.out.println("FOOO");
+ if (debug)
+ System.out.println("JavatestServlet-->JavatestServlet in init()");
+ }
+
+ public void service(HttpServletRequest rq, HttpServletResponse rp)
+ throws IOException
+ {
+ // init some things every time we hit the servlet
+ System.out.println("FOOO in service");
+ myServletResponse = rp;
+ if (debug)
+ System.out.println("JavatestServlet-->Begin Service Method");
+ interactive = true;
+ // get params
+ mProperties = initProperties();
+ collectParams(rq);
+
+ if (debug)
+ System.out.println("JavatestServlet-->interactive is: " + interactive);
+
+ if (interactive)
+ {
+ myServletResponse.setContentType("text/html");
+ pw = myServletResponse.getWriter();
+ }
+ else
+ {
+ myServletResponse.setContentType("text/plain");
+ pw = new PrintWriter(myServletResponse.getOutputStream());
+ }
+
+ // getting test class name
+ String className =
+ (String)mProperties.remove(ServletTestVehicle.CLASS_PARAM);
+ // getting test method name
+ String methodName =
+ (String)mProperties.remove(ServletTestVehicle.METHOD_PARAM);
+ // AtomicTestContext wants a Vector for passing in specific methods to
+ // run
+ Vector testMethods = new Vector();
+ if (methodName != null)
+ {
+ StringTokenizer st = new StringTokenizer(methodName, ",");
+ while (st.hasMoreTokens())
+ {
+ testMethods.addElement(st.nextToken());
+ }
+ }
+ // getting roster url
+ String processEngineLookupUrl =
+ (String)mProperties.remove(
+ ServletTestVehicle.PROCESS_ENGINE_WRAPPER_LOOKUP_URL_PARAM);
+
+ if (debug)
+ {
+ System.out.println("JavatestServlet-->Class is: " + className);
+ System.out.println("JavatestServlet-->Method is: " + methodName);
+ System.out.println(
+ "JavatestServlet-->Roster url is: " + processEngineLookupUrl);
+ }
+
+ if (className == null)
+ {
+ if (interactive)
+ {
+ pw.print(HELP_MESSAGE);
+ return;
+ }
+ }
+ else
+ {
+ if (interactive)
+ {
+ pw.println("Attempting to load: " + className + "<br>");
+ }
+
+ // put a parameter to indicate it is a server-side test
+ }
+
+ BasicInternalParameters mBasicInternalParameters =
+ new BasicInternalParameters(mProperties);
+
+ TestNode localTestNode = null;
+ try
+ {
+ localTestNode =
+ new AtomicTestContext(className, mBasicInternalParameters, testMethods);
+ }
+ catch (Throwable t)
+ {
+ if (interactive)
+ {
+ pw.println("<b>Could not find class " + className + "</b></br>");
+ }
+ if (debug)
+ t.printStackTrace();
+ System.out.println(
+ "\n[JavatestServlet] Could not find class: " + className);
+ System.out.println(
+ "[JavatestServlet] Is it in the server " + "classpath?");
+ //closeStreams();
+ return;
+ }
+
+ // get process engine from rmi reg
+ // only if not interactive
+ if (!interactive && processEngineLookupUrl != null)
+ {
+ ProcessEngine processEngine = null;
+ try
+ {
+ RemoteProcessEngineWrapper wrapper =
+ (RemoteProcessEngineWrapper)Naming.lookup(processEngineLookupUrl);
+ localTestNode.setProcessEngine(wrapper.getProcessEngine());
+ }
+ catch (Exception ex)
+ {
+ // TODO: what is best to throw out here?
+ throw new NestedRuntimeException(ex);
+ }
+ }
+
+ Logger logger = initLogger();
+ ResultHandler handler =
+ new UsedParameterAdderResultHandler(
+ new LocalResultHandler(logger),
+ mBasicInternalParameters);
+
+ //ResultHandler handler = new LocalResultHandler(logger);
+ localTestNode.setResultHandler(handler);
+ try
+ {
+ if (!interactive)
+ inform("Test " + className + " starting on server", handler);
+ localTestNode.run();
+ if (!interactive)
+ inform("Test " + className + " finishing on server ", handler);
+ }
+ catch (Throwable t)
+ {
+ if (interactive)
+ {
+ pw.println("<b>Unable to run tests:</b><br> " + t.toString());
+ }
+ t.printStackTrace();
+ }
+ finally
+ {
+ logger.close();
+ if (interactive)
+ {
+ pw.println("Done running test class " + className + "<br>");
+ }
+ //closeStreams();
+ }
+ }
+
+ private Logger initLogger()
+ {
+ CompositeLogger myLogger = new CompositeLogger();
+ String logToServer =
+ (String)mProperties.remove(ServletTestVehicle.SERVER_SIDE_LOGGING_PARAM);
+ if (logToServer != null && logToServer.equalsIgnoreCase("true"))
+ {
+
+ }
+ if (interactive)
+ {
+ myLogger.add(new LocalLogger());
+ }
+ else
+ {
+ // log to client
+ ResultXMLLogger xmlLogger = new ResultXMLLogger(pw);
+ myLogger.add(xmlLogger);
+ }
+ myLogger.open();
+ return myLogger;
+ }
+
+ private void collectParams(HttpServletRequest rq)
+ {
+ String paramName = null;
+ String[] paramValues = null;
+ Enumeration params = rq.getParameterNames();
+ while (params.hasMoreElements())
+ {
+ paramName = (String)params.nextElement();
+ paramValues = rq.getParameterValues(paramName);
+ for (int i = 0; i < paramValues.length; i++)
+ {
+ mProperties.put(paramName, paramValues[i].toString());
+ // FIXME? override if array
+ if (debug)
+ {
+ System.out.println(
+ "JavatestServlet: " + paramName + "-->" + paramValues[i]);
+ }
+ }
+ }
+ // checking debug setting -
+ // kind of stupid: have to run twice to see all debug info
+ if (mProperties.get(DEBUG_PARAM) != null)
+ {
+ debug =
+ (new Boolean((String)mProperties.remove(DEBUG_PARAM))).booleanValue();
+ }
+ if (debug)
+ System.out.println("JavatestServlet-->Got params: " + mProperties);
+ // check if called from javatest - if yes, set interactive to false
+ if (mProperties.get(ServletTestVehicle.JAVATEST_PARAM) != null
+ && mProperties.get(ServletTestVehicle.JAVATEST_PARAM).equals("false"))
+ {
+ interactive = false;
+ mProperties.remove(ServletTestVehicle.JAVATEST_PARAM);
+ }
+ }
+
+ private Properties initProperties()
+ {
+ Properties p = new Properties();
+ p.setProperty(ServletTestVehicle.SERVER_SIDE_LOGGING_PARAM, "false");
+ return p;
+ }
+
+ private void inform(String message, ResultHandler handler)
+ {
+ System.out.println(message);
+ }
+
+ private class LocalResultHandler implements ResultHandler
+ {
+ private Logger logger = null;
+ public LocalResultHandler(Logger in)
+ {
+ logger = in;
+ }
+
+ public void submitResult(TestResultBean tr)
+ {
+ logger.log(tr);
+ }
+
+ public void submitResult(TestResultBean tr, String resultName)
+ {
+ tr.setName(resultName);
+ logger.log(tr);
+ }
+
+ }
+
+ private class LocalLogger extends PrintWriterLoggerAdapter
+ {
+ private final String tw = "width='200'";
+ private SimpleDateFormat mDateFormat = new SimpleDateFormat();
+ private Vector results = null;
+
+ public void init(Map m)
+ {
+ }
+ public void logInit()
+ {
+ }
+
+ public void open()
+ {
+ pw.print("<hr>Servlet Logger Opened<br>");
+ pw.print(
+ "<table><tr><td "
+ + tw
+ + "><b>Time</b></td>"
+ + "<td "
+ + tw
+ + "><b>Test</b></td>"
+ + "<td "
+ + tw
+ + "><b>Result</b></td>"
+ + "<td "
+ + tw
+ + "><b>Message<b></td></tr></b>"
+ + "</table>");
+ }
+
+ public void close()
+ {
+ pw.print("<br>Servlet Logger Closed<hr>");
+ }
+
+ public void logIndividualRes(TestResult inResult)
+ {
+ String resultType = inResult.getTypeAsString();
+ String date = (mDateFormat.format(inResult.getTimeStamp()) + " ");
+ String message =
+ (inResult.getOutputMessage() == null
+ ? ""
+ : inResult.getOutputMessage());
+ String name = inResult.getName();
+
+ pw.print(
+ "<table><tr><td "
+ + tw
+ + ">"
+ + date
+ + "</td>"
+ + "<td "
+ + tw
+ + ">"
+ + name
+ + "</td>"
+ + "<td "
+ + tw
+ + ">"
+ + resultType
+ + "</td>"
+ + "<td "
+ + tw
+ + ">"
+ + message
+ + "</td></tr>"
+ + "</table>");
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestRunner.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicle.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicle.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicle.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicle.java Fri Aug 12 08:12:28 2005
@@ -1,28 +1,28 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
-import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
-import org.apache.beehive.test.tools.tch.task.TaskException;
-import org.apache.beehive.test.tools.tch.task.TaskTransportException;
-
-public interface TestVehicle
-{
- //Note to self: No state in TestVehicle, as they are shared by all tests!!!
-
- public String getType();
- public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
- throws TaskTransportException, TaskException;
-
- /**
- * True if this test-vehicle is the default, local test vehicle.
- * The local test-vehicle runs tests in-process.
- */
- public boolean isLocal();
-
- /**
- * Called by the framework if this test-vehicle has been running a
- * TestLogicTask for too long, without returning.
- */
- public void notifyTimeout(TestLogicTask task);
-}
-
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import org.apache.beehive.test.tools.tch.core.process.ProcessHandler;
+import org.apache.beehive.test.tools.tch.core.test.TestLogicTask;
+import org.apache.beehive.test.tools.tch.task.TaskException;
+import org.apache.beehive.test.tools.tch.task.TaskTransportException;
+
+public interface TestVehicle
+{
+ //Note to self: No state in TestVehicle, as they are shared by all tests!!!
+
+ public String getType();
+ public void run(ProcessHandler inProcessHandler, TestLogicTask inTask)
+ throws TaskTransportException, TaskException;
+
+ /**
+ * True if this test-vehicle is the default, local test vehicle.
+ * The local test-vehicle runs tests in-process.
+ */
+ public boolean isLocal();
+
+ /**
+ * Called by the framework if this test-vehicle has been running a
+ * TestLogicTask for too long, without returning.
+ */
+ public void notifyTimeout(TestLogicTask task);
+}
+
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicle.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicleRegistry.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicleRegistry.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicleRegistry.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicleRegistry.java Fri Aug 12 08:12:28 2005
@@ -1,119 +1,119 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.beehive.test.tools.tch.core.configuration.UnitConfigurationInfo;
-
-public class TestVehicleRegistry {
-
- private static TestVehicleRegistry reg = null;
-
- private Map testVehicles = new HashMap(); //String (type) -> Entry
-
- private TestVehicleRegistry() {}
-
- public synchronized static TestVehicleRegistry getRegistry()
- {
- if (reg == null)
- reg = new TestVehicleRegistry();
- return reg;
- }
-
- public static boolean isLocalTestVehicle(String testVehicleType)
- {
- Entry entry = getRegistry().getTestVehicleEntry(testVehicleType);
- if (entry == null)
- return false;
- else
- return entry.getTestVehicle().isLocal();
- }
-
- /**
- * Takes Collection of UnitConfigurationInfo objects
- */
-
- public synchronized void setTestVehicleEntry(String type,
- TestVehicle tv)
- {
- testVehicles.put(type, new TestVehicleRegistry.Entry(tv));
- }
-
- public TestVehicleRegistry.Entry getTestVehicleEntry(String type)
- {
- return (TestVehicleRegistry.Entry)testVehicles.get(type);
- }
-
- public void addUnitConfigurationInfo(String type,
- String processType,
- UnitConfigurationInfo info)
- {
- ((Entry)testVehicles.get(type))
- .addUnitConfigurationInfo(processType, info);
- }
-
- /**
- * Returns Collection of UnitConfigurationInfo
- */
-
- public Collection getAllUnitConfigurationInfo(String type)
- {
- return ((Entry)testVehicles.get(type)).getAllUnitConfigurationInfo();
- }
-
- public String toString()
- {
- return testVehicles.toString();
- }
-
- public static class Entry
- {
- private TestVehicle testVehicle = null;
-
- //currently this map will only have one item since we never
- //use a test vehicle for more than one process-type.
-
- // ProcessType (String) --> UnitConfigurationInfo
- private Map unitConfigurationInfoMap = new HashMap();
-
-
- public Entry(TestVehicle in)
- {
- testVehicle = in;
- }
-
- public TestVehicle getTestVehicle()
- {
- return testVehicle;
- }
-
- /**
- * Returns Collection of UnitConfigurationInfo
- */
-
- public Collection getAllUnitConfigurationInfo()
- {
- return unitConfigurationInfoMap.values();
- }
-
- public synchronized void addUnitConfigurationInfo(String inProcessType,
- UnitConfigurationInfo inUnitConfig)
- {
- unitConfigurationInfoMap.put(inProcessType, inUnitConfig);
- }
-
- public UnitConfigurationInfo getUnitConfigurationInfo(String inProcessType)
- {
- return (UnitConfigurationInfo)unitConfigurationInfoMap.get(inProcessType);
- }
-
- public String toString()
- {
- return "TestVehicle: "+testVehicle+"\n"
- + "UnitConfigurationInfoMap: " + unitConfigurationInfoMap;
- }
- }
-}
-
-
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.beehive.test.tools.tch.core.configuration.UnitConfigurationInfo;
+
+public class TestVehicleRegistry {
+
+ private static TestVehicleRegistry reg = null;
+
+ private Map testVehicles = new HashMap(); //String (type) -> Entry
+
+ private TestVehicleRegistry() {}
+
+ public synchronized static TestVehicleRegistry getRegistry()
+ {
+ if (reg == null)
+ reg = new TestVehicleRegistry();
+ return reg;
+ }
+
+ public static boolean isLocalTestVehicle(String testVehicleType)
+ {
+ Entry entry = getRegistry().getTestVehicleEntry(testVehicleType);
+ if (entry == null)
+ return false;
+ else
+ return entry.getTestVehicle().isLocal();
+ }
+
+ /**
+ * Takes Collection of UnitConfigurationInfo objects
+ */
+
+ public synchronized void setTestVehicleEntry(String type,
+ TestVehicle tv)
+ {
+ testVehicles.put(type, new TestVehicleRegistry.Entry(tv));
+ }
+
+ public TestVehicleRegistry.Entry getTestVehicleEntry(String type)
+ {
+ return (TestVehicleRegistry.Entry)testVehicles.get(type);
+ }
+
+ public void addUnitConfigurationInfo(String type,
+ String processType,
+ UnitConfigurationInfo info)
+ {
+ ((Entry)testVehicles.get(type))
+ .addUnitConfigurationInfo(processType, info);
+ }
+
+ /**
+ * Returns Collection of UnitConfigurationInfo
+ */
+
+ public Collection getAllUnitConfigurationInfo(String type)
+ {
+ return ((Entry)testVehicles.get(type)).getAllUnitConfigurationInfo();
+ }
+
+ public String toString()
+ {
+ return testVehicles.toString();
+ }
+
+ public static class Entry
+ {
+ private TestVehicle testVehicle = null;
+
+ //currently this map will only have one item since we never
+ //use a test vehicle for more than one process-type.
+
+ // ProcessType (String) --> UnitConfigurationInfo
+ private Map unitConfigurationInfoMap = new HashMap();
+
+
+ public Entry(TestVehicle in)
+ {
+ testVehicle = in;
+ }
+
+ public TestVehicle getTestVehicle()
+ {
+ return testVehicle;
+ }
+
+ /**
+ * Returns Collection of UnitConfigurationInfo
+ */
+
+ public Collection getAllUnitConfigurationInfo()
+ {
+ return unitConfigurationInfoMap.values();
+ }
+
+ public synchronized void addUnitConfigurationInfo(String inProcessType,
+ UnitConfigurationInfo inUnitConfig)
+ {
+ unitConfigurationInfoMap.put(inProcessType, inUnitConfig);
+ }
+
+ public UnitConfigurationInfo getUnitConfigurationInfo(String inProcessType)
+ {
+ return (UnitConfigurationInfo)unitConfigurationInfoMap.get(inProcessType);
+ }
+
+ public String toString()
+ {
+ return "TestVehicle: "+testVehicle+"\n"
+ + "UnitConfigurationInfoMap: " + unitConfigurationInfoMap;
+ }
+ }
+}
+
+
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/TestVehicleRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLLogParser.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLLogParser.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLLogParser.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLLogParser.java Fri Aug 12 08:12:28 2005
@@ -1,114 +1,114 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Properties;
-import java.util.TreeMap;
-
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- */
-
-class XMLLogParser extends XMLReader
-{
-
- // ============================================================
- // Constants
-
- public static final String TEST_RESULT_ELEMENT = "result";
- public static final String RESULT_TYPE = "result-type";
- public static final String SUBTEST_NAME = "subtest-name";
- public static final String TIME = "time";
- public static final String MESSAGE_ELEMENT = "message";
- public static final String EXCEPTION_ELEMENT = "throwable";
- public static final String USED_PARAMS = "params";
- public static final String USED_PARAMNAME = "paramname";
- public static final String USED_PARAMVALUE = "paramvalue";
- public static final String ROOT_ELEMENT = "servlet-log";
-
- // ============================================================
- // Variables
-
- private boolean debug = false;
-
- // ============================================================
- // Constructors
-
- public XMLLogParser(InputSource is)
- throws ParserConfigurationException, IOException, SAXException
- {
- super(is);
- }
-
- /*
- * Return a collection of Maps. Each Map represents the
- * data (output message, exception) for a single test result.
- */
- public Collection getResults()
- {
- // get all test results out of file
- Collection testResults = new ArrayList();
- // FIXME: should not hard-code element names
- NodeList XmlResults = getAllNodes(TEST_RESULT_ELEMENT);
- if (XmlResults != null)
- {
- int numResults = XmlResults.getLength();
- for (int resultIndex = 0; resultIndex < numResults; resultIndex++)
- {
- Node resultNode = XmlResults.item(resultIndex);
- // get all attributes
- Properties testResultInfo = getNodeAttributes(resultNode);
-
- // convert to a HashMap
- HashMap testResultMap = new HashMap(testResultInfo);
-
- // now get some CDATA child elements...
- String[] childrenNames =
- new String[] { MESSAGE_ELEMENT, EXCEPTION_ELEMENT };
- for (int i = 0; i < childrenNames.length; i++)
- {
- Node n = getChildByName(resultNode, childrenNames[i]);
- testResultMap.put(childrenNames[i], getCDATA(n));
- }
- // Parse out the used parameters
- TreeMap tm = new TreeMap();
- NodeList childnodes = resultNode.getChildNodes();
- for (int i=0; i<childnodes.getLength(); ++i) {
- Node paramnode = childnodes.item(i);
- // get the name and value of the parameter
- if (paramnode.getNodeName().equals(USED_PARAMS)) {
- Node namenode = getChildByName(paramnode, USED_PARAMNAME);
- Node valuenode = getChildByName(paramnode, USED_PARAMVALUE);
- tm.put( getCDATA(namenode), getCDATA(valuenode) );
- }
- }
- testResultMap.put(USED_PARAMS, tm);
-
- testResults.add(testResultMap);
- }
- }
- return testResults;
- }
-
- private String getCDATA(Node n)
- {
- String cdata = "";
- if (n != null)
- {
- NodeList list = n.getChildNodes();
- if (list != null && list.getLength() > 0)
- {
- cdata = list.item(0).getNodeValue().trim();
- }
- }
- return cdata;
- }
-}
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.TreeMap;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ */
+
+class XMLLogParser extends XMLReader
+{
+
+ // ============================================================
+ // Constants
+
+ public static final String TEST_RESULT_ELEMENT = "result";
+ public static final String RESULT_TYPE = "result-type";
+ public static final String SUBTEST_NAME = "subtest-name";
+ public static final String TIME = "time";
+ public static final String MESSAGE_ELEMENT = "message";
+ public static final String EXCEPTION_ELEMENT = "throwable";
+ public static final String USED_PARAMS = "params";
+ public static final String USED_PARAMNAME = "paramname";
+ public static final String USED_PARAMVALUE = "paramvalue";
+ public static final String ROOT_ELEMENT = "servlet-log";
+
+ // ============================================================
+ // Variables
+
+ private boolean debug = false;
+
+ // ============================================================
+ // Constructors
+
+ public XMLLogParser(InputSource is)
+ throws ParserConfigurationException, IOException, SAXException
+ {
+ super(is);
+ }
+
+ /*
+ * Return a collection of Maps. Each Map represents the
+ * data (output message, exception) for a single test result.
+ */
+ public Collection getResults()
+ {
+ // get all test results out of file
+ Collection testResults = new ArrayList();
+ // FIXME: should not hard-code element names
+ NodeList XmlResults = getAllNodes(TEST_RESULT_ELEMENT);
+ if (XmlResults != null)
+ {
+ int numResults = XmlResults.getLength();
+ for (int resultIndex = 0; resultIndex < numResults; resultIndex++)
+ {
+ Node resultNode = XmlResults.item(resultIndex);
+ // get all attributes
+ Properties testResultInfo = getNodeAttributes(resultNode);
+
+ // convert to a HashMap
+ HashMap testResultMap = new HashMap(testResultInfo);
+
+ // now get some CDATA child elements...
+ String[] childrenNames =
+ new String[] { MESSAGE_ELEMENT, EXCEPTION_ELEMENT };
+ for (int i = 0; i < childrenNames.length; i++)
+ {
+ Node n = getChildByName(resultNode, childrenNames[i]);
+ testResultMap.put(childrenNames[i], getCDATA(n));
+ }
+ // Parse out the used parameters
+ TreeMap tm = new TreeMap();
+ NodeList childnodes = resultNode.getChildNodes();
+ for (int i=0; i<childnodes.getLength(); ++i) {
+ Node paramnode = childnodes.item(i);
+ // get the name and value of the parameter
+ if (paramnode.getNodeName().equals(USED_PARAMS)) {
+ Node namenode = getChildByName(paramnode, USED_PARAMNAME);
+ Node valuenode = getChildByName(paramnode, USED_PARAMVALUE);
+ tm.put( getCDATA(namenode), getCDATA(valuenode) );
+ }
+ }
+ testResultMap.put(USED_PARAMS, tm);
+
+ testResults.add(testResultMap);
+ }
+ }
+ return testResults;
+ }
+
+ private String getCDATA(Node n)
+ {
+ String cdata = "";
+ if (n != null)
+ {
+ NodeList list = n.getChildNodes();
+ if (list != null && list.getLength() > 0)
+ {
+ cdata = list.item(0).getNodeValue().trim();
+ }
+ }
+ return cdata;
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLLogParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLReader.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLReader.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLReader.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLReader.java Fri Aug 12 08:12:28 2005
@@ -1,680 +1,680 @@
-package org.apache.beehive.test.tools.tch.core.test.vehicle;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Properties;
-import java.util.Vector;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/*
- * For comments/questions, send mail to stoens@bea.com
- *
-*/
-class XMLReader
-{
-
- // ============================================================
- // Constants
-
- public static final String XML_VERSION = "<?xml version=\"1.0\"?>";
- public static final String DTD_VALIDATING_PARAM = "tch.DtdValidating";
- public static final boolean DEFAULT_DTD_VALIDATING = false;
- public static final String BEGIN_CDATA = "![CDATA[";
- public static final String END_CDATA = "]]";
-
- public static boolean checkedDtdValidating = false;
-
- public final static String DEBUG_PARAM = "debugQuetzal";
-
- //=========================================================================
- // Private variables
-
- private Document root = null;
- private String dtd = null;
-
- //=========================================================================
- // Protected variables
-
- protected boolean debug = false;
-
- //=========================================================================
- // Constructors
-
- public XMLReader(InputStream is)
- throws ParserConfigurationException, IOException, SAXException
- {
- // do not validate against .dtd when reading from stream
- this(new InputSource(is), false);
- }
-
- public XMLReader(String s)
- throws ParserConfigurationException, IOException, SAXException
- {
- this(new InputSource(s));
- }
-
- public XMLReader(String s, boolean doValidating)
- throws ParserConfigurationException, IOException, SAXException
- {
- this(new InputSource(s), doValidating);
- }
-
- public XMLReader(InputSource is)
- throws ParserConfigurationException, IOException, SAXException
- {
- this(is, getDtdValidating());
- }
-
- public XMLReader(InputSource is, boolean doValidating)
- throws ParserConfigurationException, IOException, SAXException
- {
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setValidating(doValidating);
- factory.setNamespaceAware(false);
- DocumentBuilder parser = null;
- parser = factory.newDocumentBuilder();
- parser.setErrorHandler(new MyErrorHandler());
- root = parser.parse(is);
- //debug = getDebug();
- }
-
- public XMLReader() throws ParserConfigurationException
- {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setValidating(false);
- dbf.setNamespaceAware(false);
- DocumentBuilder db = null;
- db = dbf.newDocumentBuilder();
- root = db.newDocument();
- //debug = getDebug();
- }
-
- public XMLReader(XMLReader in) throws ParserConfigurationException
- {
- this();
- root = in.getDocument();
-
- }
-
- //=========================================================================
- // Static methods
-
- /**
- * Dtd validating is enabled by default
- */
- private static boolean getDtdValidating()
- {
- boolean response = DEFAULT_DTD_VALIDATING;
- String validating = System.getProperty(DTD_VALIDATING_PARAM);
- if (validating != null)
- {
- response = new Boolean(validating).booleanValue();
- }
- // only print this message once
- if (!checkedDtdValidating && response == false)
- {
- checkedDtdValidating = true;
- }
- return response;
- }
-
- //=========================================================================
- // Public methods
-
- /*
- * Returns an XMLReader consisting only
- * of the specified element.
- * Null if elementName' does not exist in this XMLReader.
- */
- public XMLReader elementAsXMLReader(String elementName)
- throws ParserConfigurationException
- {
- XMLReader response = null;
- // check if specified element exists in this XMLRoster
- NodeList elements = root.getElementsByTagName(elementName);
- if (elements != null && elements.getLength() != 0)
- {
- // only take first in list
- Node match = elements.item(0);
- // create a new XMLRoster object
- response = new XMLReader();
- response.setFirstNode(elementName);
- // make a copy
- Node clone = match.cloneNode(true);
- // append the Node to the new XMLRoster
- response.appendNode(clone);
- // remove the element from this XMLRoster
- removeElement(match);
- if (debug)
- {
- System.out.println(
- "XMLReader --> getElementAsXMLReader --> after removing element:");
- printTree();
- }
- if (debug)
- {
- System.out.println(
- "XMLReader --> getElementAsXMLReader --> response is:");
- response.printTree();
- }
-
- }
- return response;
- }
-
- /**
- * Appends passed in Node to this XMLReader's root
- */
- public void appendNode(Node firstForeignNode)
- {
- // if attributes are set, get them over
- NamedNodeMap atts = firstForeignNode.getAttributes();
- if (atts != null && atts.getLength() != 0)
- {
- for (int i = 0, iL = atts.getLength(); i < iL; i++)
- {
- Node att = atts.item(i);
- Attr newAtt = (Attr)root.importNode(att, true);
- ((Element)getFirstNode()).setAttributeNode(newAtt);
- }
- }
- // now deal with children
- NodeList children = firstForeignNode.getChildNodes();
- int length = children.getLength();
- for (int i = 0; i < length; i++)
- {
- Node n = children.item(i);
- Node newNode = root.importNode(n, true);
- getFirstNode().appendChild(newNode);
-
- }
- }
-
- /**
- * Create .DTD reference for this XMLReader
- */
- public void setDTDReference(String inDTD)
- {
- dtd = inDTD;
- }
-
- /*
- * Appends passed in XMLReader to this XMLReader's root
- */
- public void appendXMLReader(XMLReader appendMe)
- {
- // get first element out of passed in XMLReader
- Node firstForeignNode = appendMe.getFirstNode();
- appendNode(firstForeignNode);
- }
-
- public void removeElement(Node deleteMe)
- {
- if (deleteMe != root.getDocumentElement())
- {
- // get the parent of "deleteMe"
- Node parent = deleteMe.getParentNode();
- // remove "deleteMe"
- parent.removeChild(deleteMe);
- }
- }
-
- public void addComment(String elementType, String commentString)
- {
- addComment(elementType, "", commentString);
- }
-
- public void addComment(
- String elementType,
- String parentElementName,
- String commentString)
- {
- Node insertAtThisElement = null;
- Comment xmlComment = root.createComment(commentString);
- if (parentElementName.equals(""))
- {
- NodeList elements = root.getElementsByTagName(elementType);
- if (elements != null && elements.getLength() != 0)
- {
- insertAtThisElement = elements.item(0);
- }
- }
- if (insertAtThisElement != null)
- {
- insertAtThisElement.appendChild(xmlComment);
- }
- }
-
- public boolean hasElement(String elementName)
- {
- NodeList nList = root.getElementsByTagName(elementName);
- if (nList != null && nList.getLength() != 0)
- return true;
-
- return false;
- }
-
- /**
- * Searches through child nodes for
- * specified child (only one level deep)
- */
- public Node getChildByName(Node parent, String childName)
- {
- Node result = null;
- NodeList children = parent.getChildNodes();
- if (children != null)
- {
- int numChildren = children.getLength();
- for (int i = 0; i < numChildren; i++)
- {
- Node child = children.item(i);
- if (child.getNodeName().equals(childName))
- {
- result = child;
- break;
- }
- }
- }
- return result;
- }
-
- /**
- * Returns attributes of Node specified in a
- * Properties Object. Returns after one Node
- * with 'NodeName' has been found.
- */
- public Properties getAttributes(String nodeName)
- {
- Vector v = getAttributes(nodeName, 1);
- return (Properties)v.firstElement();
- }
-
- /**
- * Returns attributes of all Nodes with
- * 'nodeName' that have a parent with
- * name 'parentName'
- */
- public Vector getAttributes(String nodeName, String parentName)
- {
- Vector results = new Vector();
- Hashtable attToNodeMappings = getAttributeToNodeMappings(nodeName, -1);
- Enumeration e = attToNodeMappings.keys();
- while (e.hasMoreElements())
- {
- Properties p = (Properties)e.nextElement();
- Node n = (Node)attToNodeMappings.get(p);
- Node parent = n.getParentNode();
- if (parent.getNodeName().equals(parentName))
- {
- results.addElement(p);
- }
- }
- return results;
- }
-
- public Vector getAttributes(String nodeName, int matchNum)
- {
- Vector results = new Vector();
- Hashtable mappings = getAttributeToNodeMappings(nodeName, matchNum);
- // only need the keys
- addEnumerationToVector(mappings.keys(), results);
- return results;
- }
-
- public void writeToFile(File fileName) throws IOException
- {
- OutputStream out = null;
- out = new FileOutputStream(fileName);
- printTree(root, "", true, out);
- out.close();
- }
-
- public void printTree()
- {
- try
- {
- printTree(root, "", false, null);
- }
- catch (IOException ioe)
- {
- // because this call to printTree does not do any file IO.
- System.err.println("XMLRoster -> printTree: You should never see this:");
- ioe.printStackTrace();
- }
- }
-
- //=========================================================================
- // Protected methods
-
- protected Node getFirstNode()
- {
- return root.getDocumentElement();
- }
-
- protected void setFirstNode(String inElementName)
- {
- Element firstElement = root.createElement(inElementName);
- root.appendChild(firstElement);
- }
-
- /**
- * Returns the first occurence of node name
- * specified. Returns null if node does not exists
- * in this XMLReader.
- */
- protected Node getFirstNode(String nodeName)
- {
- Node node = null;
- NodeList nodes = root.getElementsByTagName(nodeName);
- if (nodes != null && nodes.getLength() != 0)
- {
- node = nodes.item(0);
- }
- return node;
- }
-
- /**
- * Returns a Properties Object with all attributes
- * of the node specified
- */
- protected Properties getNodeAttributes(Node n)
- {
- Properties result = new Properties();
- NamedNodeMap attributes = n.getAttributes();
- int attributesLength = attributes.getLength();
- for (int i = 0; i < attributesLength; i++)
- {
- Node current = attributes.item(i);
- result.setProperty(current.getNodeName(), current.getNodeValue());
- }
- return result;
- }
-
- /**
- * Returns occurences of node name
- * specified. Returns null if node does not exists
- * in this XMLReader.
- */
- protected NodeList getAllNodes(String nodeName)
- {
- return root.getElementsByTagName(nodeName);
- }
-
- /**
- * Returns the Element that has all attributes(name-value combinations)
- * specified in the Properties object
- */
- protected List getElementThatHasAttributes(
- String elementName,
- Properties props)
- {
- List results = new ArrayList();
- Hashtable mappings = getAttributeToNodeMappings(elementName, -1);
- Enumeration e = mappings.keys();
- // loop over all attributes of nodes with elementName
- while (e.hasMoreElements())
- {
- Enumeration p = props.propertyNames();
- Properties attributes = (Properties)e.nextElement();
- boolean matched = true;
- // loop over the properties passed in
- while (p.hasMoreElements())
- {
- String wantToMatchName = (String)p.nextElement();
- String wantToMatchValue = props.getProperty(wantToMatchName);
- // these are the name=value pair we want to match
- String attributeValue =
- String.valueOf(attributes.getProperty(wantToMatchName));
- if (!wantToMatchValue.equals(attributeValue))
- {
- matched = false;
- break;
- }
- } // end inner while
- if (matched)
- {
- results.add(mappings.get(attributes));
- }
- }
- return results;
- }
-
- /**
- * Returns the Element that has an attribute matching
- * 'attributeName and 'attributeValue'
- * by invoking getElementThatHasAttributes() method.
- */
- protected Node getElementThatHasAttribute(
- String elementName,
- String attributeName,
- String attributeValue)
- {
- Node result = null;
- Properties myprops = new Properties();
- myprops.setProperty(attributeName, attributeValue);
- List results = getElementThatHasAttributes(elementName, myprops);
- if (!results.isEmpty())
- {
- result = (Node)results.toArray()[0];
- }
- return result;
- }
-
- /**
- * Returns attributes of Nodes that match 'nodeName'.
- *
- * Returns a Hashtable with Properties Objects as keys.
- * Each Properties Object maps to its Node.
- *
- * 'matchNum' specifies how many Nodes with
- * specified Name should be matched.
- * A negative number indicates to collect attributes
- * of all Nodes with 'NodeName'.
- */
-
- protected Hashtable getAttributeToNodeMappings(String nodeName, int matchNum)
- {
- Hashtable results = new Hashtable();
- NodeList elements = getAllNodes(nodeName);
- if (elements != null)
- {
- int totalElements = elements.getLength();
- for (int elementCounter = 0;
- elementCounter < totalElements;
- elementCounter++)
- {
- if (results.size() == matchNum)
- {
- break;
- }
- Node n = elements.item(elementCounter);
- Properties attributesP = getNodeAttributes(n);
- results.put(attributesP, n);
- }
- }
- return results;
- }
-
- protected Element createElement(String name)
- {
- return createElement(name, new Properties());
- }
-
- protected Element createElement(String name, Properties attributes)
- {
- Element newElement = root.createElement(name);
- Enumeration keys = attributes.keys();
- while (keys.hasMoreElements())
- {
- String key = (String)keys.nextElement();
- String value = (String)attributes.get(key);
- newElement.setAttribute(key, value);
- }
- return newElement;
- }
-
- //=========================================================================
- // Private methods
-
- private Document getDocument()
- {
- return root;
- }
-
- private static Vector addEnumerationToVector(
- Enumeration inEnum,
- Vector inVector)
- {
- while (inEnum.hasMoreElements())
- {
- inVector.addElement(inEnum.nextElement());
- }
- return inVector;
- }
-
- private void printTree(
- Node node,
- String indentation,
- boolean useStream,
- OutputStream out)
- throws IOException
- {
- switch (node.getNodeType())
- {
- case Node.DOCUMENT_NODE :
- myPrint(XML_VERSION + "\n", useStream, out);
- if (dtd != null && !dtd.equals(""))
- {
- myPrint(dtd + "\n", useStream, out);
- }
- Document doc = (Document)node;
- printTree(doc.getDocumentElement(), indentation, useStream, out);
- break;
-
- case Node.ELEMENT_NODE :
- String name = node.getNodeName();
- myPrint("\n" + indentation + "<" + name, useStream, out);
- NamedNodeMap attributes = node.getAttributes();
- int attributesLength = attributes.getLength();
- if (attributesLength > 0)
- {
- for (int i = 0; i < attributesLength; i++)
- {
- Node current = attributes.item(i);
- String mess =
- "\n"
- + indentation
- + " "
- + current.getNodeName()
- + "=\""
- + current.getNodeValue()
- + "\"";
- myPrint(mess, useStream, out);
- }
- myPrint(">" + "\n", useStream, out);
- }
- else
- {
- myPrint(">" + "\n", useStream, out);
- }
-
- NodeList children = node.getChildNodes();
- int childrenLength = children.getLength();
- if (children != null)
- {
- for (int i = 0; i < childrenLength; i++)
- {
- printTree(children.item(i), indentation + " ", useStream, out);
- }
- }
-
- myPrint("\n" + indentation + "</" + name + ">" + "\n", useStream, out);
-
- break;
-
- case Node.COMMENT_NODE :
- myPrint("\n <!--" + node.getNodeValue() + "-->\n", useStream, out);
- break;
- case Node.CDATA_SECTION_NODE :
- StringBuffer sb = new StringBuffer(500);
- sb.append("\n");
- sb.append(indentation);
- sb.append("<");
- sb.append(BEGIN_CDATA);
- sb.append(node.getNodeValue());
- sb.append(END_CDATA);
- sb.append(">");
- myPrint(sb.toString(), useStream, out);
- break;
- case Node.PROCESSING_INSTRUCTION_NODE :
- case Node.ENTITY_REFERENCE_NODE :
- case Node.TEXT_NODE :
- case Node.DOCUMENT_TYPE_NODE :
- break;
- }
- }
-
- /**
- * Write to screen or OutputStream.
- */
- private void myPrint(String text, boolean useOutputStream, OutputStream out)
- throws IOException
- {
- if (useOutputStream)
- {
- byte buf[] = text.toString().getBytes();
- out.write(buf);
- }
- else
- {
- System.out.print(text);
- }
- }
-
- private boolean getDebug()
- {
- String debug = System.getProperty(DEBUG_PARAM);
- if (debug != null && debug.equals("true"))
- return true;
- return false;
- }
-
- class MyErrorHandler implements ErrorHandler
- {
- public void warning(SAXParseException e) throws SAXParseException
- {
- throw e;
- }
- public void error(SAXParseException e) throws SAXParseException
- {
- throw e;
- }
- public void fatalError(SAXParseException e) throws SAXParseException
- {
- throw e;
- }
- }
-}
+package org.apache.beehive.test.tools.tch.core.test.vehicle;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/*
+ * For comments/questions, send mail to stoens@bea.com
+ *
+*/
+class XMLReader
+{
+
+ // ============================================================
+ // Constants
+
+ public static final String XML_VERSION = "<?xml version=\"1.0\"?>";
+ public static final String DTD_VALIDATING_PARAM = "tch.DtdValidating";
+ public static final boolean DEFAULT_DTD_VALIDATING = false;
+ public static final String BEGIN_CDATA = "![CDATA[";
+ public static final String END_CDATA = "]]";
+
+ public static boolean checkedDtdValidating = false;
+
+ public final static String DEBUG_PARAM = "debugQuetzal";
+
+ //=========================================================================
+ // Private variables
+
+ private Document root = null;
+ private String dtd = null;
+
+ //=========================================================================
+ // Protected variables
+
+ protected boolean debug = false;
+
+ //=========================================================================
+ // Constructors
+
+ public XMLReader(InputStream is)
+ throws ParserConfigurationException, IOException, SAXException
+ {
+ // do not validate against .dtd when reading from stream
+ this(new InputSource(is), false);
+ }
+
+ public XMLReader(String s)
+ throws ParserConfigurationException, IOException, SAXException
+ {
+ this(new InputSource(s));
+ }
+
+ public XMLReader(String s, boolean doValidating)
+ throws ParserConfigurationException, IOException, SAXException
+ {
+ this(new InputSource(s), doValidating);
+ }
+
+ public XMLReader(InputSource is)
+ throws ParserConfigurationException, IOException, SAXException
+ {
+ this(is, getDtdValidating());
+ }
+
+ public XMLReader(InputSource is, boolean doValidating)
+ throws ParserConfigurationException, IOException, SAXException
+ {
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(doValidating);
+ factory.setNamespaceAware(false);
+ DocumentBuilder parser = null;
+ parser = factory.newDocumentBuilder();
+ parser.setErrorHandler(new MyErrorHandler());
+ root = parser.parse(is);
+ //debug = getDebug();
+ }
+
+ public XMLReader() throws ParserConfigurationException
+ {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setValidating(false);
+ dbf.setNamespaceAware(false);
+ DocumentBuilder db = null;
+ db = dbf.newDocumentBuilder();
+ root = db.newDocument();
+ //debug = getDebug();
+ }
+
+ public XMLReader(XMLReader in) throws ParserConfigurationException
+ {
+ this();
+ root = in.getDocument();
+
+ }
+
+ //=========================================================================
+ // Static methods
+
+ /**
+ * Dtd validating is enabled by default
+ */
+ private static boolean getDtdValidating()
+ {
+ boolean response = DEFAULT_DTD_VALIDATING;
+ String validating = System.getProperty(DTD_VALIDATING_PARAM);
+ if (validating != null)
+ {
+ response = new Boolean(validating).booleanValue();
+ }
+ // only print this message once
+ if (!checkedDtdValidating && response == false)
+ {
+ checkedDtdValidating = true;
+ }
+ return response;
+ }
+
+ //=========================================================================
+ // Public methods
+
+ /*
+ * Returns an XMLReader consisting only
+ * of the specified element.
+ * Null if elementName' does not exist in this XMLReader.
+ */
+ public XMLReader elementAsXMLReader(String elementName)
+ throws ParserConfigurationException
+ {
+ XMLReader response = null;
+ // check if specified element exists in this XMLRoster
+ NodeList elements = root.getElementsByTagName(elementName);
+ if (elements != null && elements.getLength() != 0)
+ {
+ // only take first in list
+ Node match = elements.item(0);
+ // create a new XMLRoster object
+ response = new XMLReader();
+ response.setFirstNode(elementName);
+ // make a copy
+ Node clone = match.cloneNode(true);
+ // append the Node to the new XMLRoster
+ response.appendNode(clone);
+ // remove the element from this XMLRoster
+ removeElement(match);
+ if (debug)
+ {
+ System.out.println(
+ "XMLReader --> getElementAsXMLReader --> after removing element:");
+ printTree();
+ }
+ if (debug)
+ {
+ System.out.println(
+ "XMLReader --> getElementAsXMLReader --> response is:");
+ response.printTree();
+ }
+
+ }
+ return response;
+ }
+
+ /**
+ * Appends passed in Node to this XMLReader's root
+ */
+ public void appendNode(Node firstForeignNode)
+ {
+ // if attributes are set, get them over
+ NamedNodeMap atts = firstForeignNode.getAttributes();
+ if (atts != null && atts.getLength() != 0)
+ {
+ for (int i = 0, iL = atts.getLength(); i < iL; i++)
+ {
+ Node att = atts.item(i);
+ Attr newAtt = (Attr)root.importNode(att, true);
+ ((Element)getFirstNode()).setAttributeNode(newAtt);
+ }
+ }
+ // now deal with children
+ NodeList children = firstForeignNode.getChildNodes();
+ int length = children.getLength();
+ for (int i = 0; i < length; i++)
+ {
+ Node n = children.item(i);
+ Node newNode = root.importNode(n, true);
+ getFirstNode().appendChild(newNode);
+
+ }
+ }
+
+ /**
+ * Create .DTD reference for this XMLReader
+ */
+ public void setDTDReference(String inDTD)
+ {
+ dtd = inDTD;
+ }
+
+ /*
+ * Appends passed in XMLReader to this XMLReader's root
+ */
+ public void appendXMLReader(XMLReader appendMe)
+ {
+ // get first element out of passed in XMLReader
+ Node firstForeignNode = appendMe.getFirstNode();
+ appendNode(firstForeignNode);
+ }
+
+ public void removeElement(Node deleteMe)
+ {
+ if (deleteMe != root.getDocumentElement())
+ {
+ // get the parent of "deleteMe"
+ Node parent = deleteMe.getParentNode();
+ // remove "deleteMe"
+ parent.removeChild(deleteMe);
+ }
+ }
+
+ public void addComment(String elementType, String commentString)
+ {
+ addComment(elementType, "", commentString);
+ }
+
+ public void addComment(
+ String elementType,
+ String parentElementName,
+ String commentString)
+ {
+ Node insertAtThisElement = null;
+ Comment xmlComment = root.createComment(commentString);
+ if (parentElementName.equals(""))
+ {
+ NodeList elements = root.getElementsByTagName(elementType);
+ if (elements != null && elements.getLength() != 0)
+ {
+ insertAtThisElement = elements.item(0);
+ }
+ }
+ if (insertAtThisElement != null)
+ {
+ insertAtThisElement.appendChild(xmlComment);
+ }
+ }
+
+ public boolean hasElement(String elementName)
+ {
+ NodeList nList = root.getElementsByTagName(elementName);
+ if (nList != null && nList.getLength() != 0)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Searches through child nodes for
+ * specified child (only one level deep)
+ */
+ public Node getChildByName(Node parent, String childName)
+ {
+ Node result = null;
+ NodeList children = parent.getChildNodes();
+ if (children != null)
+ {
+ int numChildren = children.getLength();
+ for (int i = 0; i < numChildren; i++)
+ {
+ Node child = children.item(i);
+ if (child.getNodeName().equals(childName))
+ {
+ result = child;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns attributes of Node specified in a
+ * Properties Object. Returns after one Node
+ * with 'NodeName' has been found.
+ */
+ public Properties getAttributes(String nodeName)
+ {
+ Vector v = getAttributes(nodeName, 1);
+ return (Properties)v.firstElement();
+ }
+
+ /**
+ * Returns attributes of all Nodes with
+ * 'nodeName' that have a parent with
+ * name 'parentName'
+ */
+ public Vector getAttributes(String nodeName, String parentName)
+ {
+ Vector results = new Vector();
+ Hashtable attToNodeMappings = getAttributeToNodeMappings(nodeName, -1);
+ Enumeration e = attToNodeMappings.keys();
+ while (e.hasMoreElements())
+ {
+ Properties p = (Properties)e.nextElement();
+ Node n = (Node)attToNodeMappings.get(p);
+ Node parent = n.getParentNode();
+ if (parent.getNodeName().equals(parentName))
+ {
+ results.addElement(p);
+ }
+ }
+ return results;
+ }
+
+ public Vector getAttributes(String nodeName, int matchNum)
+ {
+ Vector results = new Vector();
+ Hashtable mappings = getAttributeToNodeMappings(nodeName, matchNum);
+ // only need the keys
+ addEnumerationToVector(mappings.keys(), results);
+ return results;
+ }
+
+ public void writeToFile(File fileName) throws IOException
+ {
+ OutputStream out = null;
+ out = new FileOutputStream(fileName);
+ printTree(root, "", true, out);
+ out.close();
+ }
+
+ public void printTree()
+ {
+ try
+ {
+ printTree(root, "", false, null);
+ }
+ catch (IOException ioe)
+ {
+ // because this call to printTree does not do any file IO.
+ System.err.println("XMLRoster -> printTree: You should never see this:");
+ ioe.printStackTrace();
+ }
+ }
+
+ //=========================================================================
+ // Protected methods
+
+ protected Node getFirstNode()
+ {
+ return root.getDocumentElement();
+ }
+
+ protected void setFirstNode(String inElementName)
+ {
+ Element firstElement = root.createElement(inElementName);
+ root.appendChild(firstElement);
+ }
+
+ /**
+ * Returns the first occurence of node name
+ * specified. Returns null if node does not exists
+ * in this XMLReader.
+ */
+ protected Node getFirstNode(String nodeName)
+ {
+ Node node = null;
+ NodeList nodes = root.getElementsByTagName(nodeName);
+ if (nodes != null && nodes.getLength() != 0)
+ {
+ node = nodes.item(0);
+ }
+ return node;
+ }
+
+ /**
+ * Returns a Properties Object with all attributes
+ * of the node specified
+ */
+ protected Properties getNodeAttributes(Node n)
+ {
+ Properties result = new Properties();
+ NamedNodeMap attributes = n.getAttributes();
+ int attributesLength = attributes.getLength();
+ for (int i = 0; i < attributesLength; i++)
+ {
+ Node current = attributes.item(i);
+ result.setProperty(current.getNodeName(), current.getNodeValue());
+ }
+ return result;
+ }
+
+ /**
+ * Returns occurences of node name
+ * specified. Returns null if node does not exists
+ * in this XMLReader.
+ */
+ protected NodeList getAllNodes(String nodeName)
+ {
+ return root.getElementsByTagName(nodeName);
+ }
+
+ /**
+ * Returns the Element that has all attributes(name-value combinations)
+ * specified in the Properties object
+ */
+ protected List getElementThatHasAttributes(
+ String elementName,
+ Properties props)
+ {
+ List results = new ArrayList();
+ Hashtable mappings = getAttributeToNodeMappings(elementName, -1);
+ Enumeration e = mappings.keys();
+ // loop over all attributes of nodes with elementName
+ while (e.hasMoreElements())
+ {
+ Enumeration p = props.propertyNames();
+ Properties attributes = (Properties)e.nextElement();
+ boolean matched = true;
+ // loop over the properties passed in
+ while (p.hasMoreElements())
+ {
+ String wantToMatchName = (String)p.nextElement();
+ String wantToMatchValue = props.getProperty(wantToMatchName);
+ // these are the name=value pair we want to match
+ String attributeValue =
+ String.valueOf(attributes.getProperty(wantToMatchName));
+ if (!wantToMatchValue.equals(attributeValue))
+ {
+ matched = false;
+ break;
+ }
+ } // end inner while
+ if (matched)
+ {
+ results.add(mappings.get(attributes));
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Returns the Element that has an attribute matching
+ * 'attributeName and 'attributeValue'
+ * by invoking getElementThatHasAttributes() method.
+ */
+ protected Node getElementThatHasAttribute(
+ String elementName,
+ String attributeName,
+ String attributeValue)
+ {
+ Node result = null;
+ Properties myprops = new Properties();
+ myprops.setProperty(attributeName, attributeValue);
+ List results = getElementThatHasAttributes(elementName, myprops);
+ if (!results.isEmpty())
+ {
+ result = (Node)results.toArray()[0];
+ }
+ return result;
+ }
+
+ /**
+ * Returns attributes of Nodes that match 'nodeName'.
+ *
+ * Returns a Hashtable with Properties Objects as keys.
+ * Each Properties Object maps to its Node.
+ *
+ * 'matchNum' specifies how many Nodes with
+ * specified Name should be matched.
+ * A negative number indicates to collect attributes
+ * of all Nodes with 'NodeName'.
+ */
+
+ protected Hashtable getAttributeToNodeMappings(String nodeName, int matchNum)
+ {
+ Hashtable results = new Hashtable();
+ NodeList elements = getAllNodes(nodeName);
+ if (elements != null)
+ {
+ int totalElements = elements.getLength();
+ for (int elementCounter = 0;
+ elementCounter < totalElements;
+ elementCounter++)
+ {
+ if (results.size() == matchNum)
+ {
+ break;
+ }
+ Node n = elements.item(elementCounter);
+ Properties attributesP = getNodeAttributes(n);
+ results.put(attributesP, n);
+ }
+ }
+ return results;
+ }
+
+ protected Element createElement(String name)
+ {
+ return createElement(name, new Properties());
+ }
+
+ protected Element createElement(String name, Properties attributes)
+ {
+ Element newElement = root.createElement(name);
+ Enumeration keys = attributes.keys();
+ while (keys.hasMoreElements())
+ {
+ String key = (String)keys.nextElement();
+ String value = (String)attributes.get(key);
+ newElement.setAttribute(key, value);
+ }
+ return newElement;
+ }
+
+ //=========================================================================
+ // Private methods
+
+ private Document getDocument()
+ {
+ return root;
+ }
+
+ private static Vector addEnumerationToVector(
+ Enumeration inEnum,
+ Vector inVector)
+ {
+ while (inEnum.hasMoreElements())
+ {
+ inVector.addElement(inEnum.nextElement());
+ }
+ return inVector;
+ }
+
+ private void printTree(
+ Node node,
+ String indentation,
+ boolean useStream,
+ OutputStream out)
+ throws IOException
+ {
+ switch (node.getNodeType())
+ {
+ case Node.DOCUMENT_NODE :
+ myPrint(XML_VERSION + "\n", useStream, out);
+ if (dtd != null && !dtd.equals(""))
+ {
+ myPrint(dtd + "\n", useStream, out);
+ }
+ Document doc = (Document)node;
+ printTree(doc.getDocumentElement(), indentation, useStream, out);
+ break;
+
+ case Node.ELEMENT_NODE :
+ String name = node.getNodeName();
+ myPrint("\n" + indentation + "<" + name, useStream, out);
+ NamedNodeMap attributes = node.getAttributes();
+ int attributesLength = attributes.getLength();
+ if (attributesLength > 0)
+ {
+ for (int i = 0; i < attributesLength; i++)
+ {
+ Node current = attributes.item(i);
+ String mess =
+ "\n"
+ + indentation
+ + " "
+ + current.getNodeName()
+ + "=\""
+ + current.getNodeValue()
+ + "\"";
+ myPrint(mess, useStream, out);
+ }
+ myPrint(">" + "\n", useStream, out);
+ }
+ else
+ {
+ myPrint(">" + "\n", useStream, out);
+ }
+
+ NodeList children = node.getChildNodes();
+ int childrenLength = children.getLength();
+ if (children != null)
+ {
+ for (int i = 0; i < childrenLength; i++)
+ {
+ printTree(children.item(i), indentation + " ", useStream, out);
+ }
+ }
+
+ myPrint("\n" + indentation + "</" + name + ">" + "\n", useStream, out);
+
+ break;
+
+ case Node.COMMENT_NODE :
+ myPrint("\n <!--" + node.getNodeValue() + "-->\n", useStream, out);
+ break;
+ case Node.CDATA_SECTION_NODE :
+ StringBuffer sb = new StringBuffer(500);
+ sb.append("\n");
+ sb.append(indentation);
+ sb.append("<");
+ sb.append(BEGIN_CDATA);
+ sb.append(node.getNodeValue());
+ sb.append(END_CDATA);
+ sb.append(">");
+ myPrint(sb.toString(), useStream, out);
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE :
+ case Node.ENTITY_REFERENCE_NODE :
+ case Node.TEXT_NODE :
+ case Node.DOCUMENT_TYPE_NODE :
+ break;
+ }
+ }
+
+ /**
+ * Write to screen or OutputStream.
+ */
+ private void myPrint(String text, boolean useOutputStream, OutputStream out)
+ throws IOException
+ {
+ if (useOutputStream)
+ {
+ byte buf[] = text.toString().getBytes();
+ out.write(buf);
+ }
+ else
+ {
+ System.out.print(text);
+ }
+ }
+
+ private boolean getDebug()
+ {
+ String debug = System.getProperty(DEBUG_PARAM);
+ if (debug != null && debug.equals("true"))
+ return true;
+ return false;
+ }
+
+ class MyErrorHandler implements ErrorHandler
+ {
+ public void warning(SAXParseException e) throws SAXParseException
+ {
+ throw e;
+ }
+ public void error(SAXParseException e) throws SAXParseException
+ {
+ throw e;
+ }
+ public void fatalError(SAXParseException e) throws SAXParseException
+ {
+ throw e;
+ }
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/core/test/vehicle/XMLReader.java
------------------------------------------------------------------------------
svn:eol-style = native