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 [81/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/util/NoopCollection.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NoopCollection.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NoopCollection.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NoopCollection.java Fri Aug 12 08:12:28 2005
@@ -1,78 +1,78 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-/**
- * A Collection without state.
- *
- */
-public class NoopCollection implements Collection
-{
-
- public int size()
- {
- return 0;
- }
-
- public void clear()
- {
-
- }
-
- public boolean isEmpty()
- {
- return false;
- }
-
- public Object[] toArray()
- {
- return null;
- }
-
- public boolean add(Object o)
- {
- return false;
- }
-
- public boolean contains(Object o)
- {
- return false;
- }
-
- public boolean remove(Object o)
- {
- return false;
- }
-
- public boolean addAll(Collection c)
- {
- return false;
- }
-
- public boolean containsAll(Collection c)
- {
- return false;
- }
-
- public boolean removeAll(Collection c)
- {
- return false;
- }
-
- public boolean retainAll(Collection c)
- {
- return false;
- }
-
- public Iterator iterator()
- {
- return null;
- }
-
- public Object[] toArray(Object[] a)
- {
- return null;
- }
-
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * A Collection without state.
+ *
+ */
+public class NoopCollection implements Collection
+{
+
+ public int size()
+ {
+ return 0;
+ }
+
+ public void clear()
+ {
+
+ }
+
+ public boolean isEmpty()
+ {
+ return false;
+ }
+
+ public Object[] toArray()
+ {
+ return null;
+ }
+
+ public boolean add(Object o)
+ {
+ return false;
+ }
+
+ public boolean contains(Object o)
+ {
+ return false;
+ }
+
+ public boolean remove(Object o)
+ {
+ return false;
+ }
+
+ public boolean addAll(Collection c)
+ {
+ return false;
+ }
+
+ public boolean containsAll(Collection c)
+ {
+ return false;
+ }
+
+ public boolean removeAll(Collection c)
+ {
+ return false;
+ }
+
+ public boolean retainAll(Collection c)
+ {
+ return false;
+ }
+
+ public Iterator iterator()
+ {
+ return null;
+ }
+
+ public Object[] toArray(Object[] a)
+ {
+ return null;
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NoopCollection.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NullWriter.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NullWriter.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NullWriter.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NullWriter.java Fri Aug 12 08:12:28 2005
@@ -1,20 +1,20 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.io.Writer;
-
-/**
- * Provides no-op operations for a Writer object
- * @version 1.0, Nov 3, 2001
- */
-public class NullWriter extends Writer {
- public static final NullWriter SINGLETON = new NullWriter ();
-
- public void close() {}
- public void flush() {}
- public void write(char[] cbuf) {}
- public void write(char[] cbuf, int off, int len) {}
- public void write(int c) {}
- public void write(String str) {}
- public void write(String str, int off, int len) {}
-}
-
+package org.apache.beehive.test.tools.tch.util;
+
+import java.io.Writer;
+
+/**
+ * Provides no-op operations for a Writer object
+ * @version 1.0, Nov 3, 2001
+ */
+public class NullWriter extends Writer {
+ public static final NullWriter SINGLETON = new NullWriter ();
+
+ public void close() {}
+ public void flush() {}
+ public void write(char[] cbuf) {}
+ public void write(char[] cbuf, int off, int len) {}
+ public void write(int c) {}
+ public void write(String str) {}
+ public void write(String str, int off, int len) {}
+}
+
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/NullWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedMap.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedMap.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedMap.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedMap.java Fri Aug 12 08:12:28 2005
@@ -1,130 +1,130 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A simple extension to HashMap that iterates its
- * keys and values in the order in which they were added.
- */
-public class OrderedMap extends HashMap
-{
- private Set keysInOrder = new OrderedSet();
-
- /**
- * Default constructor.
- */
- public OrderedMap()
- {
- super();
- }
-
- /**
- * @param initial capacity
- */
- public OrderedMap(int in)
- {
- super(in);
- }
-
- /**
- * @param arg0
- */
- public OrderedMap(Map in)
- {
- super();
- for (Iterator iter = in.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry entry = (Map.Entry)iter.next();
- put(entry.getKey(), entry.getValue());
- }
- }
-
- public Object put(Object inKey, Object inVal)
- {
- if (!keysInOrder.contains(inKey)) //only once in list, first always wins
- keysInOrder.add(inKey);
- return super.put(inKey, inVal);
- }
-
- public Object remove(Object inKey)
- {
- keysInOrder.remove(inKey);
- return super.remove(inKey);
- }
-
- public Set keySet()
- {
- return keysInOrder;
- }
-
- public Set entrySet()
- {
- OrderedSet entrySet = new OrderedSet();
- for (Iterator iter = keysInOrder.iterator(); iter.hasNext();)
- {
- entrySet.add(new Entry(this, iter.next()));
- }
- return entrySet;
- }
-
- public Collection values()
- {
- List valuesInOrder = new ArrayList();
- for (Iterator iter = keysInOrder.iterator(); iter.hasNext();)
- {
- valuesInOrder.add(get(iter.next()));
- }
- return valuesInOrder;
- }
-
- public class Entry implements Map.Entry
- {
- private Object key = null;
- private Map underlyingMap = null;
-
- public Entry(Map inUnderlyingMap, Object inKey)
- {
- underlyingMap = inUnderlyingMap;
- key = inKey;
- }
-
- public Object getKey()
- {
- return key;
- }
-
- public Object getValue()
- {
- return underlyingMap.get(key);
- }
-
- public Object setValue(Object inValue)
- {
- Object rtn = underlyingMap.get(key);
- underlyingMap.put(key, inValue);
- return rtn;
- }
- }
-
- public static void main(String args[])
- {
- Map om = new OrderedMap();
- //Map om = new HashMap();
- om.put("10", "11");
- om.put("4", "5");
- om.put("2", "3");
- om.put("5", "6");
- om.put("6", "7");
- om.put("7", "8");
- om.put("1", "2");
- System.out.println("toString(): " + om.toString());
- System.out.println("keySet(): " + om.keySet());
- System.out.println("values(): " + om.values());
- }
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A simple extension to HashMap that iterates its
+ * keys and values in the order in which they were added.
+ */
+public class OrderedMap extends HashMap
+{
+ private Set keysInOrder = new OrderedSet();
+
+ /**
+ * Default constructor.
+ */
+ public OrderedMap()
+ {
+ super();
+ }
+
+ /**
+ * @param initial capacity
+ */
+ public OrderedMap(int in)
+ {
+ super(in);
+ }
+
+ /**
+ * @param arg0
+ */
+ public OrderedMap(Map in)
+ {
+ super();
+ for (Iterator iter = in.entrySet().iterator(); iter.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)iter.next();
+ put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ public Object put(Object inKey, Object inVal)
+ {
+ if (!keysInOrder.contains(inKey)) //only once in list, first always wins
+ keysInOrder.add(inKey);
+ return super.put(inKey, inVal);
+ }
+
+ public Object remove(Object inKey)
+ {
+ keysInOrder.remove(inKey);
+ return super.remove(inKey);
+ }
+
+ public Set keySet()
+ {
+ return keysInOrder;
+ }
+
+ public Set entrySet()
+ {
+ OrderedSet entrySet = new OrderedSet();
+ for (Iterator iter = keysInOrder.iterator(); iter.hasNext();)
+ {
+ entrySet.add(new Entry(this, iter.next()));
+ }
+ return entrySet;
+ }
+
+ public Collection values()
+ {
+ List valuesInOrder = new ArrayList();
+ for (Iterator iter = keysInOrder.iterator(); iter.hasNext();)
+ {
+ valuesInOrder.add(get(iter.next()));
+ }
+ return valuesInOrder;
+ }
+
+ public class Entry implements Map.Entry
+ {
+ private Object key = null;
+ private Map underlyingMap = null;
+
+ public Entry(Map inUnderlyingMap, Object inKey)
+ {
+ underlyingMap = inUnderlyingMap;
+ key = inKey;
+ }
+
+ public Object getKey()
+ {
+ return key;
+ }
+
+ public Object getValue()
+ {
+ return underlyingMap.get(key);
+ }
+
+ public Object setValue(Object inValue)
+ {
+ Object rtn = underlyingMap.get(key);
+ underlyingMap.put(key, inValue);
+ return rtn;
+ }
+ }
+
+ public static void main(String args[])
+ {
+ Map om = new OrderedMap();
+ //Map om = new HashMap();
+ om.put("10", "11");
+ om.put("4", "5");
+ om.put("2", "3");
+ om.put("5", "6");
+ om.put("6", "7");
+ om.put("7", "8");
+ om.put("1", "2");
+ System.out.println("toString(): " + om.toString());
+ System.out.println("keySet(): " + om.keySet());
+ System.out.println("values(): " + om.values());
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedSet.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedSet.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedSet.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedSet.java Fri Aug 12 08:12:28 2005
@@ -1,109 +1,109 @@
-package org.apache.beehive.test.tools.tch.util;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * A set that remembers and traverses its elements in the order they were added.
- */
-public class OrderedSet extends HashSet
-{
- private List objectsInOrder = new ArrayList();
-
- public OrderedSet()
- {
- super();
- }
-
- public OrderedSet(Collection in)
- {
- super();
- for (Iterator iter = in.iterator(); iter.hasNext();)
- add(iter.next());
- }
-
- public OrderedSet(int capacity)
- {
- super(capacity);
- }
-
- public boolean add(Object o)
- {
- boolean newEntry = super.add(o);
- if (newEntry)
- objectsInOrder.add(o);
-
- return newEntry;
- }
-
- public void clear()
- {
- super.clear();
- objectsInOrder.clear();
- }
-
- public boolean remove(Object o)
- {
- boolean exists = super.remove(o);
- if (exists)
- objectsInOrder.remove(o);
- return exists;
- }
-
- public Iterator iterator()
- {
- return new OrderedSetIterator(this);
- }
-
- private List getObjectsInOrder()
- {
- return objectsInOrder;
- }
-
- public class OrderedSetIterator implements Iterator
- {
- private int position = 0;
- private boolean legalToCallRemove = false;
- private OrderedSet underlyingSet = null;
- public OrderedSetIterator(OrderedSet in)
- {
- underlyingSet = in;
- }
- public Object next()
- {
- Object rtn = underlyingSet.getObjectsInOrder().get(position);
- position++;
- legalToCallRemove = true;
- return rtn;
- }
- public boolean hasNext()
- {
- return (position < (underlyingSet.getObjectsInOrder().size()));
- }
- public void remove()
- {
- if (!legalToCallRemove)
- throw new IllegalStateException();
- else
- underlyingSet.remove(
- underlyingSet.getObjectsInOrder().get(position - 1));
- legalToCallRemove = false;
- }
- }
- public static void main(String args[])
- {
- Set os = new OrderedSet();
- //Set os = new HashSet();
- os.add("10");
- os.add("4");
- os.add("2");
- os.add("5");
- os.add("6");
- os.add("7");
- os.add("1");
- System.out.println(os.toString());
- }
-}
+package org.apache.beehive.test.tools.tch.util;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A set that remembers and traverses its elements in the order they were added.
+ */
+public class OrderedSet extends HashSet
+{
+ private List objectsInOrder = new ArrayList();
+
+ public OrderedSet()
+ {
+ super();
+ }
+
+ public OrderedSet(Collection in)
+ {
+ super();
+ for (Iterator iter = in.iterator(); iter.hasNext();)
+ add(iter.next());
+ }
+
+ public OrderedSet(int capacity)
+ {
+ super(capacity);
+ }
+
+ public boolean add(Object o)
+ {
+ boolean newEntry = super.add(o);
+ if (newEntry)
+ objectsInOrder.add(o);
+
+ return newEntry;
+ }
+
+ public void clear()
+ {
+ super.clear();
+ objectsInOrder.clear();
+ }
+
+ public boolean remove(Object o)
+ {
+ boolean exists = super.remove(o);
+ if (exists)
+ objectsInOrder.remove(o);
+ return exists;
+ }
+
+ public Iterator iterator()
+ {
+ return new OrderedSetIterator(this);
+ }
+
+ private List getObjectsInOrder()
+ {
+ return objectsInOrder;
+ }
+
+ public class OrderedSetIterator implements Iterator
+ {
+ private int position = 0;
+ private boolean legalToCallRemove = false;
+ private OrderedSet underlyingSet = null;
+ public OrderedSetIterator(OrderedSet in)
+ {
+ underlyingSet = in;
+ }
+ public Object next()
+ {
+ Object rtn = underlyingSet.getObjectsInOrder().get(position);
+ position++;
+ legalToCallRemove = true;
+ return rtn;
+ }
+ public boolean hasNext()
+ {
+ return (position < (underlyingSet.getObjectsInOrder().size()));
+ }
+ public void remove()
+ {
+ if (!legalToCallRemove)
+ throw new IllegalStateException();
+ else
+ underlyingSet.remove(
+ underlyingSet.getObjectsInOrder().get(position - 1));
+ legalToCallRemove = false;
+ }
+ }
+ public static void main(String args[])
+ {
+ Set os = new OrderedSet();
+ //Set os = new HashSet();
+ os.add("10");
+ os.add("4");
+ os.add("2");
+ os.add("5");
+ os.add("6");
+ os.add("7");
+ os.add("1");
+ System.out.println(os.toString());
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/OrderedSet.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamValidator.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamValidator.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamValidator.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamValidator.java Fri Aug 12 08:12:28 2005
@@ -1,410 +1,410 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A simple parameter value validator
- *
- * Reads an xml file of the following format (see below)
- * and validates a Map of parameters against it.
- * If validation fails, retrieve an informative
- * message using 'getMessage'.
- *
- * <valid-params>
- *
- * <param name="release" required="true">
- * <option value="Acadia"/>
- * </param>
- * <param name="load" required="true">
- * <option value="13"/>
- * </param>
- * <param name="branch" required="true">
- * <option value="src"/>
- * <option value="src_stable"/>
- * </param>
- * <param name="hostname" required="true" type="string" />
- * <param name="toptestfile" required="true" type="string" />
- * <param name="exectime" type="date" format="yyyy-MM-dd hh:mm:ss.S"/>
- * <param name="resultcount" type="int" />
- * <param name="checksum" type="int" />
- * </valid-params>
- *
- * @version 1.0, Dec 19, 2001
- */
-public class ParamValidator {
-
- public static String sep = System.getProperty("line.separator");
- private static final String separator = "======================";
- private static final String separatorMinor = "----------------------";
-
-
- //=========================================================================
- // Private Variables
-
- private Map paramsToCheckAgainst;
- private Set warnings = new HashSet();
- private MessageHolder message = new MessageHolder ();
- private boolean verbose = false;
- private Object subject = null;
-
- //=========================================================================
- // Public Methods
-
- public void setMessageWriter(PrintWriter pw) {
- message = new MessageHolder(pw);
- }
-
- public void setMessageWriter(PrintStream ps) {
- message = new MessageHolder(ps);
- }
-
- public void setValidParams(Map inParamsToCheckAgainst) {
- paramsToCheckAgainst = inParamsToCheckAgainst;
- }
-
- /**
- * Validates 'paramsToValidate'.
- *
- * Assumes that setValidParams(...) has been called.
- *
- * Returns boolean to indicate whether validation succeeded or failed.
- * If it failed, a detailed error message can be retrieved by calling
- * getMessage().
- */
- public boolean validate(Map paramsToValidate) {
- return validate(paramsToValidate, false);
- }
-
- /**
- * Validates 'paramsToValidate', assumes setValidParams(...) has been called.
- * If 'checkAllParamsLegal', then all params in 'paramsToValidate' must
- * be listed in valid-params, else validation fails.
- *
- * Returns boolean to indicate whether validation succeeded or failed.
- * If it failed, a detailed error message can be retrieved by calling
- * getMessage().
- */
- public boolean validate(Map paramsToValidate, boolean checkAllParamsLegal) {
- if (paramsToCheckAgainst == null) {
- message.append("No valid params set, cannot validate.")
- .append(sep);
- return false;
- }
-
- boolean caseOk = checkForParamNameCaseMismatch(paramsToValidate);
- boolean paramValuesOk = checkParamValues(paramsToValidate);
- boolean requiredParamsOk = checkRequiredParams(paramsToValidate);
- boolean typeOk = checkParamType(paramsToValidate);
- boolean lengthOK = checkParamLength(paramsToValidate);
- boolean declaredOk = true;
- if (checkAllParamsLegal)
- declaredOk = checkAllParamsDeclared(paramsToValidate);
-
- boolean validateOk =
- caseOk &&
- paramValuesOk &&
- requiredParamsOk &&
- typeOk &&
- lengthOK &&
- declaredOk;
-
- if (!validateOk) {
- if (subject != null) {
- StringBuffer s = new StringBuffer();
- s.append("Validation failed for: ")
- .append(sep).append(separatorMinor)
- .append(sep).append(subject.toString())
- .append(separator).append(sep);
- message.append (s.toString());
- }
- message.append(sep);
- }
-
- return validateOk;
- }
-
- /**
- * FIXME: Better method name?
- * If validation fails, o.toString() will be included
- * in the message available through 'getMessage()'.
- * (inserted before the message)
- * The idea is that 'o' is the thing (represents the thing)
- * we are validating
- */
- public void setValidatingSubject(Object o) {
- subject = o;
- }
-
-
- /**
- * Returns the message that has been written while validating.
- */
- public String getMessage() {
- return message.toString();
- }
-
- /**
- * Clear the message that has been written while validating.
- */
- // public void clearMessage() {
- // message.delete(0, message.length() - 1);
- // }
-
- public String toString() {
- return paramsToCheckAgainst.toString();
- }
-
- //=========================================================================
- // Private Methods
-
- // checks that parameter has correct value
- // when checking, trim param value if 'trimToMaxLength' has been set
- private boolean checkParamValues(Map paramsToValidate) {
- boolean result = true;
- Iterator i = paramsToValidate.keySet().iterator();
- while (i.hasNext()) {
- String paramName = (String)i.next();
- String paramValue = (String)paramsToValidate.get(paramName);
- Set legalValuesSet = null;
- ParamWrapper pw = null;
- if (paramsToCheckAgainst.get(paramName) != null) {
- pw = (ParamWrapper)paramsToCheckAgainst.get(paramName);
- legalValuesSet = pw.legalValues;
- }
- if (legalValuesSet == null) {
- if (verbose) TchUtils.log("No entries found for: " + paramName);
- }
- else if (legalValuesSet.contains(paramValue)) {
- if (verbose) TchUtils.log(paramName + " is ok");
- }
- else if (pw.trimToMaxLength && pw.maxLength > 0 &&
- paramValue.length() > pw.maxLength &&
- legalValuesSet.contains(paramValue.substring(0, pw.maxLength))) {
- StringBuffer warning = new StringBuffer();
- warning.append("Warning: Will trim value of ").append(paramName)
- .append(" to ").append(paramValue.substring(0, pw.maxLength))
- .append(" (original value was: ").append(paramValue).append(")")
- .append(sep);
- logWarning(warning.toString());
- }
- else {
- message.append("Value ").append(paramValue).append(" for param ")
- .append(paramName).append(" is not valid").append(sep)
- .append("Legal values for ").append(paramName).append(" are ")
- .append(legalValuesSet.toString()).append(sep);
- result = false;
- }
- }
- return result;
- }
-
- // check that all required params have been passed
- private boolean checkRequiredParams(Map params) {
- boolean result = true;
- // put all required params in a set
- Set requiredSet = new HashSet();
- Iterator i = paramsToCheckAgainst.values().iterator();
- while (i.hasNext()) {
- ParamWrapper pw = (ParamWrapper)i.next();
- if (pw.required) requiredSet.add(pw.name);
- }
- // now check if we have all required params
- Iterator i2 = params.keySet().iterator();
- while (i2.hasNext()) {
- String paramKey = (String)i2.next();
- if (requiredSet.contains(paramKey)) {
- // this required param has been provided -
- // make sure its trimed value is not null or ""
- String paramValue = (String)params.get(paramKey);
- if (paramValue != null) {
- // Check if a required param allows empty value.
- // If it does, allow validation to pass.
- if (paramValue.trim().length() == 0) {
- ParamWrapper pw = (ParamWrapper)paramsToCheckAgainst.get(paramKey);
- Set legalVals = pw.legalValues;
- if (legalVals != null && legalVals.contains(""))
- requiredSet.remove(paramKey);
- } else
- requiredSet.remove(paramKey);
- }
- }
- }
- if (!requiredSet.isEmpty()) {
- result = false;
- message.append("The following required parameter(s) have not been ")
- .append("provided: ").append(requiredSet.toString()).append(sep);
- }
- return result;
- }
-
- // check param name has correct capitalization
- public boolean checkForParamNameCaseMismatch(Map params) {
- boolean result = true;
- Iterator paramKeysIt = params.keySet().iterator();
- while (paramKeysIt.hasNext()) {
- String paramKey = (String)paramKeysIt.next();
- Iterator validKeysIt = paramsToCheckAgainst.keySet().iterator();
- while (validKeysIt.hasNext()) {
- String validKey = (String)validKeysIt.next();
- if (paramKey.equalsIgnoreCase(validKey) &&
- !paramKey.equals(validKey)) {
- message.append("Case mismatch for: ").append(paramKey)
- .append(" - should be ").append(validKey).append(sep);
- result = false;
- }
- }
- }
- return result;
- }
-
- // check param value is correct type
- private boolean checkParamType(Map params) {
- boolean result = true;
- Iterator paramKeysIt = params.keySet().iterator();
- while (paramKeysIt.hasNext()) {
- String paramKey = (String)paramKeysIt.next();
- ParamWrapper pw = (ParamWrapper)paramsToCheckAgainst.get(paramKey);
- if (pw != null) {
- String expectedType = pw.type;
- String paramValue = (String)params.get(paramKey);
- if (paramValue != null && paramValue.length() > 0) {
- if (expectedType.equalsIgnoreCase("string")) {
- // it is a string!
- }
- else if (expectedType.equalsIgnoreCase("int")) {
- // try to convert to int
- try {
- Integer.parseInt(paramValue);
- } catch (NumberFormatException nfe) {
- result = false;
- message.append(paramKey).append(" has to be of type 'int'")
- .append(sep);
- }
- }
- else if (expectedType.equalsIgnoreCase("date") && pw.format != null)
- {
- if (pw.format.equalsIgnoreCase("sql.timestamp")) {
- try {
- Timestamp.valueOf(paramValue);
- } catch (IllegalArgumentException iae) {
- result = false;
- message.append(paramKey).append(" has to match the Timestamp")
- .append( ".toString() format (yyyy-mm-dd hh:mm:ss.ffffffff)")
- .append(sep);
- }
- }
- else {
- // try to format the date
- try {
- new SimpleDateFormat(pw.format).parse(paramValue);
- } catch (ParseException pe) {
- result = false;
- message.append(paramKey).append(" has to match date format: ")
- .append(pw.format)
- .append(sep);
- }
- }
- }
- }
- }
- }
- return result;
- }
-
- // check param value length
- private boolean checkParamLength(Map params) {
- boolean result = true;
- Iterator paramKeysIt = params.keySet().iterator();
- while (paramKeysIt.hasNext()) {
- String paramKey = (String)paramKeysIt.next();
- ParamWrapper pw = (ParamWrapper)paramsToCheckAgainst.get(paramKey);
- if (pw != null && pw.maxLength > -1) {
- int maxLength = pw.maxLength;
- String paramValue = (String)params.get(paramKey);
- if (paramValue != null) {
- if (paramValue.length() > maxLength && !pw.trimToMaxLength) {
- result = false;
- message.append(paramKey).append(" exceeds max length of ")
- .append(String.valueOf(maxLength)).append(" specified")
- .append(sep);
- }
- }
- }
- }
- return result;
- }
-
-
- // check that all params passed have been declared in
- // validparams file
- private boolean checkAllParamsDeclared(Map params) {
- boolean result = true;
- Set unknownParams = new HashSet();
- Iterator i = params.keySet().iterator();
- while (i.hasNext()) {
- String paramName = (String)i.next();
- if (!paramsToCheckAgainst.containsKey(paramName)) {
- unknownParams.add(paramName);
- result = false;
- }
- }
- if (!result) {
- message.append("The following parameter(s) is/are not recognized, ")
- .append("Please remove - ").append(unknownParams).append(sep);
- }
- return result;
- }
-
- private void logWarning(String warningStr) {
- // very simplistic for now
- // do not log any warning message twice
- if (!warnings.contains(warningStr)) {
- warnings.add(warningStr);
- message.append(warningStr);
- }
- }
-
- /**
- * Holds the Message, allowing us plug in a PrintWriter or StringBuffer
- * This class is private, as it is only used within this ParamValidator class
- */
- private static class MessageHolder {
- private PrintWriter pw = null;
- private StringWriter stw = null;
-
- private MessageHolder (PrintWriter pw) {
- this.pw = pw;
- }
-
- private MessageHolder (PrintStream ps) {
- this (new PrintWriter (ps));
- }
-
- private MessageHolder () {
- stw = new StringWriter ();
- pw = new PrintWriter (stw);
- }
-
- private MessageHolder append (Object obj) {
- pw.print (obj);
- pw.flush ();
- return this;
- }
-
- public String toString () {
- if (stw != null) return stw.toString ();
- return "report written to supplied writer object";
- }
- }
-
-}
-
+package org.apache.beehive.test.tools.tch.util;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A simple parameter value validator
+ *
+ * Reads an xml file of the following format (see below)
+ * and validates a Map of parameters against it.
+ * If validation fails, retrieve an informative
+ * message using 'getMessage'.
+ *
+ * <valid-params>
+ *
+ * <param name="release" required="true">
+ * <option value="Acadia"/>
+ * </param>
+ * <param name="load" required="true">
+ * <option value="13"/>
+ * </param>
+ * <param name="branch" required="true">
+ * <option value="src"/>
+ * <option value="src_stable"/>
+ * </param>
+ * <param name="hostname" required="true" type="string" />
+ * <param name="toptestfile" required="true" type="string" />
+ * <param name="exectime" type="date" format="yyyy-MM-dd hh:mm:ss.S"/>
+ * <param name="resultcount" type="int" />
+ * <param name="checksum" type="int" />
+ * </valid-params>
+ *
+ * @version 1.0, Dec 19, 2001
+ */
+public class ParamValidator {
+
+ public static String sep = System.getProperty("line.separator");
+ private static final String separator = "======================";
+ private static final String separatorMinor = "----------------------";
+
+
+ //=========================================================================
+ // Private Variables
+
+ private Map paramsToCheckAgainst;
+ private Set warnings = new HashSet();
+ private MessageHolder message = new MessageHolder ();
+ private boolean verbose = false;
+ private Object subject = null;
+
+ //=========================================================================
+ // Public Methods
+
+ public void setMessageWriter(PrintWriter pw) {
+ message = new MessageHolder(pw);
+ }
+
+ public void setMessageWriter(PrintStream ps) {
+ message = new MessageHolder(ps);
+ }
+
+ public void setValidParams(Map inParamsToCheckAgainst) {
+ paramsToCheckAgainst = inParamsToCheckAgainst;
+ }
+
+ /**
+ * Validates 'paramsToValidate'.
+ *
+ * Assumes that setValidParams(...) has been called.
+ *
+ * Returns boolean to indicate whether validation succeeded or failed.
+ * If it failed, a detailed error message can be retrieved by calling
+ * getMessage().
+ */
+ public boolean validate(Map paramsToValidate) {
+ return validate(paramsToValidate, false);
+ }
+
+ /**
+ * Validates 'paramsToValidate', assumes setValidParams(...) has been called.
+ * If 'checkAllParamsLegal', then all params in 'paramsToValidate' must
+ * be listed in valid-params, else validation fails.
+ *
+ * Returns boolean to indicate whether validation succeeded or failed.
+ * If it failed, a detailed error message can be retrieved by calling
+ * getMessage().
+ */
+ public boolean validate(Map paramsToValidate, boolean checkAllParamsLegal) {
+ if (paramsToCheckAgainst == null) {
+ message.append("No valid params set, cannot validate.")
+ .append(sep);
+ return false;
+ }
+
+ boolean caseOk = checkForParamNameCaseMismatch(paramsToValidate);
+ boolean paramValuesOk = checkParamValues(paramsToValidate);
+ boolean requiredParamsOk = checkRequiredParams(paramsToValidate);
+ boolean typeOk = checkParamType(paramsToValidate);
+ boolean lengthOK = checkParamLength(paramsToValidate);
+ boolean declaredOk = true;
+ if (checkAllParamsLegal)
+ declaredOk = checkAllParamsDeclared(paramsToValidate);
+
+ boolean validateOk =
+ caseOk &&
+ paramValuesOk &&
+ requiredParamsOk &&
+ typeOk &&
+ lengthOK &&
+ declaredOk;
+
+ if (!validateOk) {
+ if (subject != null) {
+ StringBuffer s = new StringBuffer();
+ s.append("Validation failed for: ")
+ .append(sep).append(separatorMinor)
+ .append(sep).append(subject.toString())
+ .append(separator).append(sep);
+ message.append (s.toString());
+ }
+ message.append(sep);
+ }
+
+ return validateOk;
+ }
+
+ /**
+ * FIXME: Better method name?
+ * If validation fails, o.toString() will be included
+ * in the message available through 'getMessage()'.
+ * (inserted before the message)
+ * The idea is that 'o' is the thing (represents the thing)
+ * we are validating
+ */
+ public void setValidatingSubject(Object o) {
+ subject = o;
+ }
+
+
+ /**
+ * Returns the message that has been written while validating.
+ */
+ public String getMessage() {
+ return message.toString();
+ }
+
+ /**
+ * Clear the message that has been written while validating.
+ */
+ // public void clearMessage() {
+ // message.delete(0, message.length() - 1);
+ // }
+
+ public String toString() {
+ return paramsToCheckAgainst.toString();
+ }
+
+ //=========================================================================
+ // Private Methods
+
+ // checks that parameter has correct value
+ // when checking, trim param value if 'trimToMaxLength' has been set
+ private boolean checkParamValues(Map paramsToValidate) {
+ boolean result = true;
+ Iterator i = paramsToValidate.keySet().iterator();
+ while (i.hasNext()) {
+ String paramName = (String)i.next();
+ String paramValue = (String)paramsToValidate.get(paramName);
+ Set legalValuesSet = null;
+ ParamWrapper pw = null;
+ if (paramsToCheckAgainst.get(paramName) != null) {
+ pw = (ParamWrapper)paramsToCheckAgainst.get(paramName);
+ legalValuesSet = pw.legalValues;
+ }
+ if (legalValuesSet == null) {
+ if (verbose) TchUtils.log("No entries found for: " + paramName);
+ }
+ else if (legalValuesSet.contains(paramValue)) {
+ if (verbose) TchUtils.log(paramName + " is ok");
+ }
+ else if (pw.trimToMaxLength && pw.maxLength > 0 &&
+ paramValue.length() > pw.maxLength &&
+ legalValuesSet.contains(paramValue.substring(0, pw.maxLength))) {
+ StringBuffer warning = new StringBuffer();
+ warning.append("Warning: Will trim value of ").append(paramName)
+ .append(" to ").append(paramValue.substring(0, pw.maxLength))
+ .append(" (original value was: ").append(paramValue).append(")")
+ .append(sep);
+ logWarning(warning.toString());
+ }
+ else {
+ message.append("Value ").append(paramValue).append(" for param ")
+ .append(paramName).append(" is not valid").append(sep)
+ .append("Legal values for ").append(paramName).append(" are ")
+ .append(legalValuesSet.toString()).append(sep);
+ result = false;
+ }
+ }
+ return result;
+ }
+
+ // check that all required params have been passed
+ private boolean checkRequiredParams(Map params) {
+ boolean result = true;
+ // put all required params in a set
+ Set requiredSet = new HashSet();
+ Iterator i = paramsToCheckAgainst.values().iterator();
+ while (i.hasNext()) {
+ ParamWrapper pw = (ParamWrapper)i.next();
+ if (pw.required) requiredSet.add(pw.name);
+ }
+ // now check if we have all required params
+ Iterator i2 = params.keySet().iterator();
+ while (i2.hasNext()) {
+ String paramKey = (String)i2.next();
+ if (requiredSet.contains(paramKey)) {
+ // this required param has been provided -
+ // make sure its trimed value is not null or ""
+ String paramValue = (String)params.get(paramKey);
+ if (paramValue != null) {
+ // Check if a required param allows empty value.
+ // If it does, allow validation to pass.
+ if (paramValue.trim().length() == 0) {
+ ParamWrapper pw = (ParamWrapper)paramsToCheckAgainst.get(paramKey);
+ Set legalVals = pw.legalValues;
+ if (legalVals != null && legalVals.contains(""))
+ requiredSet.remove(paramKey);
+ } else
+ requiredSet.remove(paramKey);
+ }
+ }
+ }
+ if (!requiredSet.isEmpty()) {
+ result = false;
+ message.append("The following required parameter(s) have not been ")
+ .append("provided: ").append(requiredSet.toString()).append(sep);
+ }
+ return result;
+ }
+
+ // check param name has correct capitalization
+ public boolean checkForParamNameCaseMismatch(Map params) {
+ boolean result = true;
+ Iterator paramKeysIt = params.keySet().iterator();
+ while (paramKeysIt.hasNext()) {
+ String paramKey = (String)paramKeysIt.next();
+ Iterator validKeysIt = paramsToCheckAgainst.keySet().iterator();
+ while (validKeysIt.hasNext()) {
+ String validKey = (String)validKeysIt.next();
+ if (paramKey.equalsIgnoreCase(validKey) &&
+ !paramKey.equals(validKey)) {
+ message.append("Case mismatch for: ").append(paramKey)
+ .append(" - should be ").append(validKey).append(sep);
+ result = false;
+ }
+ }
+ }
+ return result;
+ }
+
+ // check param value is correct type
+ private boolean checkParamType(Map params) {
+ boolean result = true;
+ Iterator paramKeysIt = params.keySet().iterator();
+ while (paramKeysIt.hasNext()) {
+ String paramKey = (String)paramKeysIt.next();
+ ParamWrapper pw = (ParamWrapper)paramsToCheckAgainst.get(paramKey);
+ if (pw != null) {
+ String expectedType = pw.type;
+ String paramValue = (String)params.get(paramKey);
+ if (paramValue != null && paramValue.length() > 0) {
+ if (expectedType.equalsIgnoreCase("string")) {
+ // it is a string!
+ }
+ else if (expectedType.equalsIgnoreCase("int")) {
+ // try to convert to int
+ try {
+ Integer.parseInt(paramValue);
+ } catch (NumberFormatException nfe) {
+ result = false;
+ message.append(paramKey).append(" has to be of type 'int'")
+ .append(sep);
+ }
+ }
+ else if (expectedType.equalsIgnoreCase("date") && pw.format != null)
+ {
+ if (pw.format.equalsIgnoreCase("sql.timestamp")) {
+ try {
+ Timestamp.valueOf(paramValue);
+ } catch (IllegalArgumentException iae) {
+ result = false;
+ message.append(paramKey).append(" has to match the Timestamp")
+ .append( ".toString() format (yyyy-mm-dd hh:mm:ss.ffffffff)")
+ .append(sep);
+ }
+ }
+ else {
+ // try to format the date
+ try {
+ new SimpleDateFormat(pw.format).parse(paramValue);
+ } catch (ParseException pe) {
+ result = false;
+ message.append(paramKey).append(" has to match date format: ")
+ .append(pw.format)
+ .append(sep);
+ }
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ // check param value length
+ private boolean checkParamLength(Map params) {
+ boolean result = true;
+ Iterator paramKeysIt = params.keySet().iterator();
+ while (paramKeysIt.hasNext()) {
+ String paramKey = (String)paramKeysIt.next();
+ ParamWrapper pw = (ParamWrapper)paramsToCheckAgainst.get(paramKey);
+ if (pw != null && pw.maxLength > -1) {
+ int maxLength = pw.maxLength;
+ String paramValue = (String)params.get(paramKey);
+ if (paramValue != null) {
+ if (paramValue.length() > maxLength && !pw.trimToMaxLength) {
+ result = false;
+ message.append(paramKey).append(" exceeds max length of ")
+ .append(String.valueOf(maxLength)).append(" specified")
+ .append(sep);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+
+ // check that all params passed have been declared in
+ // validparams file
+ private boolean checkAllParamsDeclared(Map params) {
+ boolean result = true;
+ Set unknownParams = new HashSet();
+ Iterator i = params.keySet().iterator();
+ while (i.hasNext()) {
+ String paramName = (String)i.next();
+ if (!paramsToCheckAgainst.containsKey(paramName)) {
+ unknownParams.add(paramName);
+ result = false;
+ }
+ }
+ if (!result) {
+ message.append("The following parameter(s) is/are not recognized, ")
+ .append("Please remove - ").append(unknownParams).append(sep);
+ }
+ return result;
+ }
+
+ private void logWarning(String warningStr) {
+ // very simplistic for now
+ // do not log any warning message twice
+ if (!warnings.contains(warningStr)) {
+ warnings.add(warningStr);
+ message.append(warningStr);
+ }
+ }
+
+ /**
+ * Holds the Message, allowing us plug in a PrintWriter or StringBuffer
+ * This class is private, as it is only used within this ParamValidator class
+ */
+ private static class MessageHolder {
+ private PrintWriter pw = null;
+ private StringWriter stw = null;
+
+ private MessageHolder (PrintWriter pw) {
+ this.pw = pw;
+ }
+
+ private MessageHolder (PrintStream ps) {
+ this (new PrintWriter (ps));
+ }
+
+ private MessageHolder () {
+ stw = new StringWriter ();
+ pw = new PrintWriter (stw);
+ }
+
+ private MessageHolder append (Object obj) {
+ pw.print (obj);
+ pw.flush ();
+ return this;
+ }
+
+ public String toString () {
+ if (stw != null) return stw.toString ();
+ return "report written to supplied writer object";
+ }
+ }
+
+}
+
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamWrapper.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamWrapper.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamWrapper.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamWrapper.java Fri Aug 12 08:12:28 2005
@@ -1,43 +1,43 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * A Wrapper that describes parameter properties.
- * Uses only by ParamValidator.
- *
- * @version 1.0, Dec 19, 2001
- */
-public class ParamWrapper
- implements Cloneable {
-
- public static String sep = System.getProperty("line.separator");
-
- public String name;
- public String type = "String";
- public String format;
- public Set legalValues;
- public boolean required = false;
- public boolean trimToMaxLength = false;
- public int maxLength = -1;
-
- public Object clone() throws CloneNotSupportedException {
- ParamWrapper copy = (ParamWrapper)super.clone();
- if (legalValues != null)
- copy.legalValues = new HashSet(legalValues);
- return copy;
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append("<ParamWrapper> ")
- .append("Param name: ").append(String.valueOf(name)).append(" ")
- .append("Legal Values: ").append(String.valueOf(legalValues)).append(" ")
- .append("Is required: ").append(String.valueOf(required)).append(" ")
- .append("Type: ").append(String.valueOf(type)).append(" ")
- .append("Format: ").append(String.valueOf(format)).append(" ")
- .append("</ParamWrapper>");
- return buf.toString();
- }
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A Wrapper that describes parameter properties.
+ * Uses only by ParamValidator.
+ *
+ * @version 1.0, Dec 19, 2001
+ */
+public class ParamWrapper
+ implements Cloneable {
+
+ public static String sep = System.getProperty("line.separator");
+
+ public String name;
+ public String type = "String";
+ public String format;
+ public Set legalValues;
+ public boolean required = false;
+ public boolean trimToMaxLength = false;
+ public int maxLength = -1;
+
+ public Object clone() throws CloneNotSupportedException {
+ ParamWrapper copy = (ParamWrapper)super.clone();
+ if (legalValues != null)
+ copy.legalValues = new HashSet(legalValues);
+ return copy;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<ParamWrapper> ")
+ .append("Param name: ").append(String.valueOf(name)).append(" ")
+ .append("Legal Values: ").append(String.valueOf(legalValues)).append(" ")
+ .append("Is required: ").append(String.valueOf(required)).append(" ")
+ .append("Type: ").append(String.valueOf(type)).append(" ")
+ .append("Format: ").append(String.valueOf(format)).append(" ")
+ .append("</ParamWrapper>");
+ return buf.toString();
+ }
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ParamWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PerThreadCache.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PerThreadCache.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PerThreadCache.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PerThreadCache.java Fri Aug 12 08:12:28 2005
@@ -1,222 +1,222 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-public class PerThreadCache {
-
- private static PerThreadCache reg = null;
-
- private Map threadMap = new HashMap(); // Thread -> Map
-
- private PerThreadCache() {}
-
- public synchronized static PerThreadCache getInstance()
- {
- if (reg == null)
- reg = new PerThreadCache();
- return reg;
- }
-
- public Object get(Object key)
- {
- return get(key,Thread.currentThread());
- }
-
- public Object get(Object key, Thread thread)
- {
- Map m = (Map)threadMap.get(thread);
- if(m != null)
- return m.get(key);
- else
- return null; //So we don't NPE
- }
-
- /**
- * This is to retrieve all cached items for the thread and
- * its parent threads, if it implements ChildThread
- * List is in child first order
- */
- public List getAll(Object key)
- {
- return getAll(key,Thread.currentThread());
- }
-
- public List getAll(Object key, Thread thread)
- {
- List rtn = new ArrayList();
- getAll(key,rtn,thread);
- return rtn;
- }
-
- public boolean containsKey(Object key)
- {
- return containsKey(key,Thread.currentThread());
- }
-
- public boolean containsKey(Object key, Thread thread)
- {
- if(threadMap.containsKey(thread))
- return ((Map)threadMap.get(thread)).containsKey(key);
- else
- return false;
- }
-
- public void set(Object key, Object value)
- {
- set(key,value,Thread.currentThread());
- }
-
- public synchronized void set(Object key, Object value, Thread thread)
- {
- Map innerMap = null;
- if(threadMap.containsKey(thread))
- innerMap = (Map)threadMap.get(thread);
- else
- {
- innerMap = new HashMap();
- threadMap.put(thread,innerMap);
- }
- innerMap.put(key,value);
- }
-
- public void remove(Object key)
- {
- remove(key,Thread.currentThread());
- }
-
- public synchronized void remove(Object key, Thread thread)
- {
- if(threadMap.containsKey(thread))
- {
- ((Map)threadMap.get(thread)).remove(key);
- }
- }
-
- //Some special stuff for the common case of having Lists as cache elements
-
- public Object getLast(Object key)
- {
- return getLast(key,Thread.currentThread());
- }
-
- public Object getLast(Object key, Thread thread)
- {
- Iterator iter = getAll(key,thread).iterator();
- if(iter.hasNext()) //might be none if top-level buildfile
- {
- List li = (List)iter.next(); //Child first returned, what is wanted
- return li.get(li.size()-1); //Want the last entry
- }
- return null;
- }
-
- public void addToList(Object key, Object value)
- {
- addToList(key,value,Thread.currentThread());
- }
-
- public void addToList(Object key, Object value, Thread thread)
- {
- List li = null;
- if(containsKey(key,thread))
- {
- li = (List)get(key,thread);
- }
- else
- {
- li = new ArrayList();
- set(key,li,thread);
- }
- li.add(value);
- }
-
- public void addToParentList(Object key, Object value)
- {
- addToParentList(key, value, Thread.currentThread());
- }
-
- public void addToParentList(Object key, Object value, Thread thread)
- {
- if (thread instanceof ChildThread)
- addToParentList(key, value, ((ChildThread)thread).getParentThread());
- else
- addToList(key, value, thread);
- }
-
- /**
- * Removes the last entry from the list coresponding to this entry
- * No-op if no list there
- */
-
- public void removeFromList(Object key)
- {
- removeFromList(key,Thread.currentThread());
- }
-
- public void removeFromList(Object key, Thread thread)
- {
- if(containsKey(key,thread))
- {
- List li = (List)get(key,thread);
- li.remove(li.size()-1); //remove last entry, must be one to remove
- if(li.size() == 0)
- {
- remove(key,thread);
- }
- }
- }
-
- public void removeFromParentList(Object key)
- {
- removeFromParentList(key, Thread.currentThread());
- }
-
- public void removeFromParentList(Object key, Thread thread)
- {
- if (thread instanceof ChildThread)
- removeFromParentList(key, ((ChildThread)thread).getParentThread());
- else
- removeFromList(key, thread);
- }
-
- public List getList(Object key)
- {
- return (List)get(key, Thread.currentThread());
- }
-
- public List getParentList(Object key)
- {
- return getParentList(key, Thread.currentThread());
- }
-
- public List getParentList(Object key, Thread thread)
- {
- if (thread instanceof ChildThread)
- return getParentList(key, ((ChildThread)thread).getParentThread());
- else
- return (List)get(key, thread);
- }
-
-
- //recursion up to parents
-
- private void getAll(Object key,
- List list,
- Thread thread)
- {
- Object value = get(key,thread);
- if(value != null)
- list.add(value);
- if(thread instanceof ChildThread)
- {
- getAll(key,list,((ChildThread)thread).getParentThread());
- }
- }
-}
-
-
-
+package org.apache.beehive.test.tools.tch.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class PerThreadCache {
+
+ private static PerThreadCache reg = null;
+
+ private Map threadMap = new HashMap(); // Thread -> Map
+
+ private PerThreadCache() {}
+
+ public synchronized static PerThreadCache getInstance()
+ {
+ if (reg == null)
+ reg = new PerThreadCache();
+ return reg;
+ }
+
+ public Object get(Object key)
+ {
+ return get(key,Thread.currentThread());
+ }
+
+ public Object get(Object key, Thread thread)
+ {
+ Map m = (Map)threadMap.get(thread);
+ if(m != null)
+ return m.get(key);
+ else
+ return null; //So we don't NPE
+ }
+
+ /**
+ * This is to retrieve all cached items for the thread and
+ * its parent threads, if it implements ChildThread
+ * List is in child first order
+ */
+ public List getAll(Object key)
+ {
+ return getAll(key,Thread.currentThread());
+ }
+
+ public List getAll(Object key, Thread thread)
+ {
+ List rtn = new ArrayList();
+ getAll(key,rtn,thread);
+ return rtn;
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return containsKey(key,Thread.currentThread());
+ }
+
+ public boolean containsKey(Object key, Thread thread)
+ {
+ if(threadMap.containsKey(thread))
+ return ((Map)threadMap.get(thread)).containsKey(key);
+ else
+ return false;
+ }
+
+ public void set(Object key, Object value)
+ {
+ set(key,value,Thread.currentThread());
+ }
+
+ public synchronized void set(Object key, Object value, Thread thread)
+ {
+ Map innerMap = null;
+ if(threadMap.containsKey(thread))
+ innerMap = (Map)threadMap.get(thread);
+ else
+ {
+ innerMap = new HashMap();
+ threadMap.put(thread,innerMap);
+ }
+ innerMap.put(key,value);
+ }
+
+ public void remove(Object key)
+ {
+ remove(key,Thread.currentThread());
+ }
+
+ public synchronized void remove(Object key, Thread thread)
+ {
+ if(threadMap.containsKey(thread))
+ {
+ ((Map)threadMap.get(thread)).remove(key);
+ }
+ }
+
+ //Some special stuff for the common case of having Lists as cache elements
+
+ public Object getLast(Object key)
+ {
+ return getLast(key,Thread.currentThread());
+ }
+
+ public Object getLast(Object key, Thread thread)
+ {
+ Iterator iter = getAll(key,thread).iterator();
+ if(iter.hasNext()) //might be none if top-level buildfile
+ {
+ List li = (List)iter.next(); //Child first returned, what is wanted
+ return li.get(li.size()-1); //Want the last entry
+ }
+ return null;
+ }
+
+ public void addToList(Object key, Object value)
+ {
+ addToList(key,value,Thread.currentThread());
+ }
+
+ public void addToList(Object key, Object value, Thread thread)
+ {
+ List li = null;
+ if(containsKey(key,thread))
+ {
+ li = (List)get(key,thread);
+ }
+ else
+ {
+ li = new ArrayList();
+ set(key,li,thread);
+ }
+ li.add(value);
+ }
+
+ public void addToParentList(Object key, Object value)
+ {
+ addToParentList(key, value, Thread.currentThread());
+ }
+
+ public void addToParentList(Object key, Object value, Thread thread)
+ {
+ if (thread instanceof ChildThread)
+ addToParentList(key, value, ((ChildThread)thread).getParentThread());
+ else
+ addToList(key, value, thread);
+ }
+
+ /**
+ * Removes the last entry from the list coresponding to this entry
+ * No-op if no list there
+ */
+
+ public void removeFromList(Object key)
+ {
+ removeFromList(key,Thread.currentThread());
+ }
+
+ public void removeFromList(Object key, Thread thread)
+ {
+ if(containsKey(key,thread))
+ {
+ List li = (List)get(key,thread);
+ li.remove(li.size()-1); //remove last entry, must be one to remove
+ if(li.size() == 0)
+ {
+ remove(key,thread);
+ }
+ }
+ }
+
+ public void removeFromParentList(Object key)
+ {
+ removeFromParentList(key, Thread.currentThread());
+ }
+
+ public void removeFromParentList(Object key, Thread thread)
+ {
+ if (thread instanceof ChildThread)
+ removeFromParentList(key, ((ChildThread)thread).getParentThread());
+ else
+ removeFromList(key, thread);
+ }
+
+ public List getList(Object key)
+ {
+ return (List)get(key, Thread.currentThread());
+ }
+
+ public List getParentList(Object key)
+ {
+ return getParentList(key, Thread.currentThread());
+ }
+
+ public List getParentList(Object key, Thread thread)
+ {
+ if (thread instanceof ChildThread)
+ return getParentList(key, ((ChildThread)thread).getParentThread());
+ else
+ return (List)get(key, thread);
+ }
+
+
+ //recursion up to parents
+
+ private void getAll(Object key,
+ List list,
+ Thread thread)
+ {
+ Object value = get(key,thread);
+ if(value != null)
+ list.add(value);
+ if(thread instanceof ChildThread)
+ {
+ getAll(key,list,((ChildThread)thread).getParentThread());
+ }
+ }
+}
+
+
+
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PerThreadCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ProcessHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ProcessHandler.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ProcessHandler.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ProcessHandler.java Fri Aug 12 08:12:28 2005
@@ -1,282 +1,282 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.io.FileWriter;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Handles Processes, giving us back the output and error strings
- * @version 1.0, Nov 3, 2001
- */
-public class ProcessHandler implements TchConstants
-{
- private boolean timedOut = false;
- private Process p;
- private long timeout = 10000;
- private String errstr = "";
- private String outstr = "";
- private String outerrstr = "";
- private int exitCode = -1;
- private Map params = null;
-
- /**
- * If no outfile, errfile, outerrfile specified,
- * assume we do not want to write to those.
- * Top level defaults are as below:
- * method: doGenericMethod
- * write-to-file: false
- * The other defaults are as below:
- * outfile: <null>
- * errfile: <null>
- * outerrfile: <null>
- * The following defaults only apply if above are not null
- * outfile-append: true
- * errfile-append: true
- * outerrfile-append: true
- *
- */
- public static Map getFixedMap(Map params)
- {
- Map map = new HashMap();
- if (params != null)
- map.putAll(params);
- if (map.get(PARAM_PREFIX + "method") == null)
- {
- map.put(PARAM_PREFIX + "method", "doGenericMethod");
- }
- if (map.get(PARAM_PREFIX + "write-to-file") == null)
- {
- map.put(PARAM_PREFIX + "write-to-file", "false");
- }
- if (map.get(PARAM_PREFIX + "outfile") == null)
- {
- // map.put (PARAM_PREFIX + "outfile", "outfile");
- }
- else
- if (map.get(PARAM_PREFIX + "outfile-append") == null)
- {
- map.put(PARAM_PREFIX + "outfile-append", "true");
- }
- if (map.get(PARAM_PREFIX + "errfile") == null)
- {
- // map.put (PARAM_PREFIX + "errfile", "errfile");
- }
- else
- if (map.get(PARAM_PREFIX + "errfile-append") == null)
- {
- map.put(PARAM_PREFIX + "errfile-append", "true");
- }
- if (map.get(PARAM_PREFIX + "outerrfile") == null)
- {
- // map.put (PARAM_PREFIX + "outerrfile", "outerrfile");
- }
- else
- if (map.get(PARAM_PREFIX + "outerrfile-append") == null)
- {
- map.put(PARAM_PREFIX + "outerrfile-append", "true");
- }
- if (map.get(PARAM_PREFIX + "wait-for-process-end") == null)
- {
- map.put(PARAM_PREFIX + "wait-for-process-end", "true");
- }
-
- return map;
- }
-
- /**
- * Takes a Process, and a Map of params (similar to what is expected
- * via the getFixedMap method.
- * @see getFixedMap ()
- */
- public ProcessHandler(Process p, long timeout, Map params)
- {
- this.p = p;
- if (timeout != -1)
- this.timeout = timeout;
- this.params = getFixedMap(params);
- }
-
- /**
- * Uses the params to determine what to do.
- * Basically, it connects the input stream and
- * output stream to the either files or strings,
- * waits for the process to end if desired,
- * and returns.
- * @see getFixedMap ()
- */
- public void run() throws Exception
- {
- InputStream pis = p.getInputStream();
- InputStream pes = p.getErrorStream();
-
- Writer nullWriter = NullWriter.SINGLETON;
-
- Writer stwrIs = nullWriter;
- Writer stwrEs = nullWriter;
- Writer stwrIEs = nullWriter;
-
- if ("true".equals(params.get(PARAM_PREFIX + "write-to-file")))
- {
- FileWriter fw = null;
- if (params.get(PARAM_PREFIX + "outfile") != null)
- {
- fw =
- new FileWriter(
- (String)params.get(PARAM_PREFIX + "outfile"),
- "true".equals(params.get(PARAM_PREFIX + "outfile-append")));
- stwrIs = new PrintWriter(fw);
- }
- if (params.get(PARAM_PREFIX + "errfile") != null)
- {
- fw =
- new FileWriter(
- (String)params.get(PARAM_PREFIX + "errfile"),
- "true".equals(params.get(PARAM_PREFIX + "errfile-append")));
- stwrEs = new PrintWriter(fw);
- }
- if (params.get(PARAM_PREFIX + "outerrfile") != null)
- {
- fw =
- new FileWriter(
- (String)params.get(PARAM_PREFIX + "outerrfile"),
- "true".equals(params.get(PARAM_PREFIX + "outerrfile-append")));
- stwrIEs = new PrintWriter(fw);
- }
- }
- else
- {
- stwrIs = new StringWriter();
- stwrEs = new StringWriter();
- stwrIEs = new StringWriter();
- }
- Thread[] thr = new Thread[2];
- HandlerHelper[] hh = new HandlerHelper[2];
-
- hh[0] = new HandlerHelper();
- hh[0].is = pis;
- hh[0].writers = new Writer[] { stwrIs, stwrIEs };
- thr[0] = new Thread(hh[0]);
- thr[0].setDaemon(true);
-
- hh[1] = new HandlerHelper();
- hh[1].is = pes;
- hh[1].writers = new Writer[] { stwrEs, stwrIEs };
- thr[1] = new Thread(hh[1]);
- thr[1].setDaemon(true);
-
- for (int i = 0; i < thr.length; i++)
- {
- thr[i].start();
- }
-
- if ("true".equals(params.get(PARAM_PREFIX + "wait-for-process-end")))
- {
- p.waitFor();
- // make sure all the output is read from the process
- for (int i = 0; i < thr.length; i++)
- {
- thr[i].join();
- }
- exitCode = p.exitValue();
- // p.destroy ();
- }
-
- if ("true".equals(params.get(PARAM_PREFIX + "write-to-file")))
- {
- outstr = (String)params.get(PARAM_PREFIX + "outfile");
- errstr = (String)params.get(PARAM_PREFIX + "errfile");
- outerrstr = (String)params.get(PARAM_PREFIX + "outerrfile");
- }
- else
- {
- stwrIs.flush();
- stwrEs.flush();
- stwrIEs.flush();
- outstr = stwrIs.toString();
- errstr = stwrEs.toString();
- outerrstr = stwrIEs.toString();
- }
-
- }
-
- /** Get the exit code, or -1 if we did not wait for the process to end. */
- public int getExitCode()
- {
- return exitCode;
- }
-
- /**
- * Get the StdErrString.
- * If writing to a file, this is just the file name
- */
- public String getStdErrString()
- {
- return errstr;
- }
-
- /**
- * Get the StdOutString.
- * If writing to a file, this is just the file name
- */
- public String getStdOutString()
- {
- return outstr;
- }
-
- /**
- * Get the StdOutErrString.
- * If writing to a file, this is just the file name
- */
- public String getStdOutErrString()
- {
- return outerrstr;
- }
-
- public boolean wasTimedOut()
- {
- return timedOut;
- }
-
- /**
- * Simple Runnable class which takes an Input Stream and an array of Writer objects,
- * and reads from the InputStream and writes to all the Writer objects
- * in synchronized fashion
- */
- public static class HandlerHelper implements Runnable
- {
- public InputStream is;
- public Writer[] writers;
- public boolean hasError = false;
- public void run()
- {
- try
- {
- int num = -1;
- InputStreamReader fr = new InputStreamReader(is);
- char[] fc = new char[1024];
- while ((num = fr.read(fc)) != -1)
- {
- for (int i = 0; i < writers.length; i++)
- {
- synchronized (writers[i])
- {
- writers[i].write(fc, 0, num);
- writers[i].flush();
- }
- }
- }
- }
- catch (Exception exc)
- {
- TchUtils.log(exc);
- hasError = true;
- }
- }
- }
-
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Handles Processes, giving us back the output and error strings
+ * @version 1.0, Nov 3, 2001
+ */
+public class ProcessHandler implements TchConstants
+{
+ private boolean timedOut = false;
+ private Process p;
+ private long timeout = 10000;
+ private String errstr = "";
+ private String outstr = "";
+ private String outerrstr = "";
+ private int exitCode = -1;
+ private Map params = null;
+
+ /**
+ * If no outfile, errfile, outerrfile specified,
+ * assume we do not want to write to those.
+ * Top level defaults are as below:
+ * method: doGenericMethod
+ * write-to-file: false
+ * The other defaults are as below:
+ * outfile: <null>
+ * errfile: <null>
+ * outerrfile: <null>
+ * The following defaults only apply if above are not null
+ * outfile-append: true
+ * errfile-append: true
+ * outerrfile-append: true
+ *
+ */
+ public static Map getFixedMap(Map params)
+ {
+ Map map = new HashMap();
+ if (params != null)
+ map.putAll(params);
+ if (map.get(PARAM_PREFIX + "method") == null)
+ {
+ map.put(PARAM_PREFIX + "method", "doGenericMethod");
+ }
+ if (map.get(PARAM_PREFIX + "write-to-file") == null)
+ {
+ map.put(PARAM_PREFIX + "write-to-file", "false");
+ }
+ if (map.get(PARAM_PREFIX + "outfile") == null)
+ {
+ // map.put (PARAM_PREFIX + "outfile", "outfile");
+ }
+ else
+ if (map.get(PARAM_PREFIX + "outfile-append") == null)
+ {
+ map.put(PARAM_PREFIX + "outfile-append", "true");
+ }
+ if (map.get(PARAM_PREFIX + "errfile") == null)
+ {
+ // map.put (PARAM_PREFIX + "errfile", "errfile");
+ }
+ else
+ if (map.get(PARAM_PREFIX + "errfile-append") == null)
+ {
+ map.put(PARAM_PREFIX + "errfile-append", "true");
+ }
+ if (map.get(PARAM_PREFIX + "outerrfile") == null)
+ {
+ // map.put (PARAM_PREFIX + "outerrfile", "outerrfile");
+ }
+ else
+ if (map.get(PARAM_PREFIX + "outerrfile-append") == null)
+ {
+ map.put(PARAM_PREFIX + "outerrfile-append", "true");
+ }
+ if (map.get(PARAM_PREFIX + "wait-for-process-end") == null)
+ {
+ map.put(PARAM_PREFIX + "wait-for-process-end", "true");
+ }
+
+ return map;
+ }
+
+ /**
+ * Takes a Process, and a Map of params (similar to what is expected
+ * via the getFixedMap method.
+ * @see getFixedMap ()
+ */
+ public ProcessHandler(Process p, long timeout, Map params)
+ {
+ this.p = p;
+ if (timeout != -1)
+ this.timeout = timeout;
+ this.params = getFixedMap(params);
+ }
+
+ /**
+ * Uses the params to determine what to do.
+ * Basically, it connects the input stream and
+ * output stream to the either files or strings,
+ * waits for the process to end if desired,
+ * and returns.
+ * @see getFixedMap ()
+ */
+ public void run() throws Exception
+ {
+ InputStream pis = p.getInputStream();
+ InputStream pes = p.getErrorStream();
+
+ Writer nullWriter = NullWriter.SINGLETON;
+
+ Writer stwrIs = nullWriter;
+ Writer stwrEs = nullWriter;
+ Writer stwrIEs = nullWriter;
+
+ if ("true".equals(params.get(PARAM_PREFIX + "write-to-file")))
+ {
+ FileWriter fw = null;
+ if (params.get(PARAM_PREFIX + "outfile") != null)
+ {
+ fw =
+ new FileWriter(
+ (String)params.get(PARAM_PREFIX + "outfile"),
+ "true".equals(params.get(PARAM_PREFIX + "outfile-append")));
+ stwrIs = new PrintWriter(fw);
+ }
+ if (params.get(PARAM_PREFIX + "errfile") != null)
+ {
+ fw =
+ new FileWriter(
+ (String)params.get(PARAM_PREFIX + "errfile"),
+ "true".equals(params.get(PARAM_PREFIX + "errfile-append")));
+ stwrEs = new PrintWriter(fw);
+ }
+ if (params.get(PARAM_PREFIX + "outerrfile") != null)
+ {
+ fw =
+ new FileWriter(
+ (String)params.get(PARAM_PREFIX + "outerrfile"),
+ "true".equals(params.get(PARAM_PREFIX + "outerrfile-append")));
+ stwrIEs = new PrintWriter(fw);
+ }
+ }
+ else
+ {
+ stwrIs = new StringWriter();
+ stwrEs = new StringWriter();
+ stwrIEs = new StringWriter();
+ }
+ Thread[] thr = new Thread[2];
+ HandlerHelper[] hh = new HandlerHelper[2];
+
+ hh[0] = new HandlerHelper();
+ hh[0].is = pis;
+ hh[0].writers = new Writer[] { stwrIs, stwrIEs };
+ thr[0] = new Thread(hh[0]);
+ thr[0].setDaemon(true);
+
+ hh[1] = new HandlerHelper();
+ hh[1].is = pes;
+ hh[1].writers = new Writer[] { stwrEs, stwrIEs };
+ thr[1] = new Thread(hh[1]);
+ thr[1].setDaemon(true);
+
+ for (int i = 0; i < thr.length; i++)
+ {
+ thr[i].start();
+ }
+
+ if ("true".equals(params.get(PARAM_PREFIX + "wait-for-process-end")))
+ {
+ p.waitFor();
+ // make sure all the output is read from the process
+ for (int i = 0; i < thr.length; i++)
+ {
+ thr[i].join();
+ }
+ exitCode = p.exitValue();
+ // p.destroy ();
+ }
+
+ if ("true".equals(params.get(PARAM_PREFIX + "write-to-file")))
+ {
+ outstr = (String)params.get(PARAM_PREFIX + "outfile");
+ errstr = (String)params.get(PARAM_PREFIX + "errfile");
+ outerrstr = (String)params.get(PARAM_PREFIX + "outerrfile");
+ }
+ else
+ {
+ stwrIs.flush();
+ stwrEs.flush();
+ stwrIEs.flush();
+ outstr = stwrIs.toString();
+ errstr = stwrEs.toString();
+ outerrstr = stwrIEs.toString();
+ }
+
+ }
+
+ /** Get the exit code, or -1 if we did not wait for the process to end. */
+ public int getExitCode()
+ {
+ return exitCode;
+ }
+
+ /**
+ * Get the StdErrString.
+ * If writing to a file, this is just the file name
+ */
+ public String getStdErrString()
+ {
+ return errstr;
+ }
+
+ /**
+ * Get the StdOutString.
+ * If writing to a file, this is just the file name
+ */
+ public String getStdOutString()
+ {
+ return outstr;
+ }
+
+ /**
+ * Get the StdOutErrString.
+ * If writing to a file, this is just the file name
+ */
+ public String getStdOutErrString()
+ {
+ return outerrstr;
+ }
+
+ public boolean wasTimedOut()
+ {
+ return timedOut;
+ }
+
+ /**
+ * Simple Runnable class which takes an Input Stream and an array of Writer objects,
+ * and reads from the InputStream and writes to all the Writer objects
+ * in synchronized fashion
+ */
+ public static class HandlerHelper implements Runnable
+ {
+ public InputStream is;
+ public Writer[] writers;
+ public boolean hasError = false;
+ public void run()
+ {
+ try
+ {
+ int num = -1;
+ InputStreamReader fr = new InputStreamReader(is);
+ char[] fc = new char[1024];
+ while ((num = fr.read(fc)) != -1)
+ {
+ for (int i = 0; i < writers.length; i++)
+ {
+ synchronized (writers[i])
+ {
+ writers[i].write(fc, 0, num);
+ writers[i].flush();
+ }
+ }
+ }
+ }
+ catch (Exception exc)
+ {
+ TchUtils.log(exc);
+ hasError = true;
+ }
+ }
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/ProcessHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyFileLoader.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyFileLoader.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyFileLoader.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyFileLoader.java Fri Aug 12 08:12:28 2005
@@ -1,42 +1,42 @@
-package org.apache.beehive.test.tools.tch.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Properties;
-
-/**
- * Intended to emulate the ant -propertyfile behavior
- */
-public class PropertyFileLoader
-{
- private static final String PROP_FILE_ARG = "-propertyfile";
-
- private PropertyFileLoader() {}
-
- /**
- * Searches 'args' for -propertyfile, if set, loads that file into
- * System props. if removeArg, removes the -propertyfile and filename
- * from the arg array.
- */
- public static String[] loadPropertyFile(String args[])
- throws IOException, FileNotFoundException
- {
- if (!GeneralUtil.isSet(args, PROP_FILE_ARG))
- {
- return args;
- }
- File propFile = new File(GeneralUtil.getValueFor(args, PROP_FILE_ARG));
- Properties propsFromFile = new Properties();
- propsFromFile.load(new FileInputStream(propFile));
- System.getProperties().putAll(propsFromFile);
-
- int index = GeneralUtil.getIndexOf(args, PROP_FILE_ARG);
- String newArgs[] = GeneralUtil.removeFromArray(args, index);
- newArgs = GeneralUtil.removeFromArray(newArgs, index);
-
- return newArgs;
- }
-
-}
+package org.apache.beehive.test.tools.tch.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Intended to emulate the ant -propertyfile behavior
+ */
+public class PropertyFileLoader
+{
+ private static final String PROP_FILE_ARG = "-propertyfile";
+
+ private PropertyFileLoader() {}
+
+ /**
+ * Searches 'args' for -propertyfile, if set, loads that file into
+ * System props. if removeArg, removes the -propertyfile and filename
+ * from the arg array.
+ */
+ public static String[] loadPropertyFile(String args[])
+ throws IOException, FileNotFoundException
+ {
+ if (!GeneralUtil.isSet(args, PROP_FILE_ARG))
+ {
+ return args;
+ }
+ File propFile = new File(GeneralUtil.getValueFor(args, PROP_FILE_ARG));
+ Properties propsFromFile = new Properties();
+ propsFromFile.load(new FileInputStream(propFile));
+ System.getProperties().putAll(propsFromFile);
+
+ int index = GeneralUtil.getIndexOf(args, PROP_FILE_ARG);
+ String newArgs[] = GeneralUtil.removeFromArray(args, index);
+ newArgs = GeneralUtil.removeFromArray(newArgs, index);
+
+ return newArgs;
+ }
+
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyFileLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyResolver.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyResolver.java?rev=232310&r1=232309&r2=232310&view=diff
==============================================================================
--- beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyResolver.java (original)
+++ beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyResolver.java Fri Aug 12 08:12:28 2005
@@ -1,10 +1,10 @@
-package org.apache.beehive.test.tools.tch.util;
-
-public interface PropertyResolver
-{
- /**
- * Must return the property value, or null to indicate that
- * this property could not be resolved.
- */
- public String getValue(String propertyName);
-}
+package org.apache.beehive.test.tools.tch.util;
+
+public interface PropertyResolver
+{
+ /**
+ * Must return the property value, or null to indicate that
+ * this property could not be resolved.
+ */
+ public String getValue(String propertyName);
+}
Propchange: beehive/trunk/controls/test/tools/tch/src/java/org/apache/beehive/test/tools/tch/util/PropertyResolver.java
------------------------------------------------------------------------------
svn:eol-style = native