[jboss-svn-commits] JBL Code SVN: r6789 - in labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta: src/org/jboss/soa/esb/helpers tests/src/org/jboss/soa/esb/helpers
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 13 09:46:13 EDT 2006
Author: estebanschifman
Date: 2006-10-13 09:46:08 -0400 (Fri, 13 Oct 2006)
New Revision: 6789
Modified:
labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java
Log:
Minor changes, add some missing methods, add javadoc
Modified: labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
===================================================================
--- labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java 2006-10-13 09:41:24 UTC (rev 6788)
+++ labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java 2006-10-13 13:46:08 UTC (rev 6789)
@@ -12,8 +12,8 @@
import org.w3c.dom.*;
import org.xml.sax.SAXException;
/**
- * Standard object intended to be used for run time configuration of ESB components
- * <p/> This class should gradually replace the DomElement class
+ * Objects of this class are to be used for run time configuration of ESB components
+ * <p/> This should gradually replace the DomElement class
* <br/> It is a subset of Tree that accepts a Map of attributes, and a List of children
* <br/> children can only be String values, or objects of this class
* <p/> fromXml() and toXml() methods allow 'visible' representations of objects of this class
@@ -26,7 +26,7 @@
{
private static final long serialVersionUID = 1L;
/**
- * Constructor of a root node
+ * Constructor of a root node (an uppermost ConfigTree)
* @param name String - the element name of 'this'
*/
public ConfigTree(String name) { this(name,null); }
@@ -43,7 +43,7 @@
/**
*
- * @return String - the name of this object
+ * @return String - the name of this tree (element name for XML representation)
*/
public String getName() { return _name; }
/**
@@ -71,7 +71,7 @@
_dad.addChild(this);
}
/**
- * assign a value to a name
+ * assign a value to a named attribute
* @param name String - the name (key) for the new attribute
* @param value String - the value assigned to the key (if null - old value will be deleted)
* @return String - old value assigned to the name (null if there was none)
@@ -105,7 +105,7 @@
return (null==_attributes) ? null : _attributes.get(name);
} // _______________________________
/**
- * obtain the list of attribute names
+ * obtain the list of all attribute names
* @return Set<String> - the set of keys that have been assigned a non null value
*/
public Set<String>getAttributeNames()
@@ -118,7 +118,7 @@
* <br/>"" (zero length String) if no String child nodes
* @return String - concatenation of all String segments (equivalent to xml text nodes)
*/
- public String getAllText()
+ public String getWholeText()
{
if (null==_childs)
return "";
@@ -135,6 +135,25 @@
} // _______________________________
/**
+ * <b>first</b> child containing only text, with name=arg0
+ * @param name String - the name to filter
+ * @return full text content of first 'pure text' child element under that name - <null> if none
+ */
+ public String getFirstTextChild(String name)
+ {
+ if (null==name)
+ throw new IllegalArgumentException();
+ if (null!=_childs)
+ for (Child oCurr : _childs)
+ {
+ ConfigTree tree = oCurr.getTree();
+ if (null != tree && tree.isPureText() && name.equals(tree.getName()))
+ return tree.getWholeText();
+ }
+ return null;
+ } // _______________________________
+
+ /**
* Obtain all String values with the same name
* @param name String - filter for child String nodes
* @return String[]
@@ -150,7 +169,7 @@
{
ConfigTree tree = oCurr.getTree();
if (null != tree && tree.isPureText() && name.equals(tree.getName()))
- oRet.add(tree.getAllText());
+ oRet.add(tree.getWholeText());
}
return oRet.toArray(new String[oRet.size()]);
} // _______________________________
@@ -216,7 +235,7 @@
} // _______________________________
/**
- * remove by name
+ * remove children by name
* @param name String - only children by that name will be removed
*/
public void removeChildrenByName(String name)
@@ -229,6 +248,10 @@
II.remove();
} // __________________________________
+ /**
+ *
+ * @return the number of child nodes (of any type)
+ */
public int childCount()
{
return (null==_childs) ? 0 : _childs.size();
@@ -238,6 +261,8 @@
public Object clone() { return cloneObj(); }
/**
+ * instantiate a new ConfigTree with the same topology and contents of 'this'
+ * <br/>Contained ConfigTree child elements will also be cloned
* @return ConfigTree - Deep copy of 'this'
*/
public ConfigTree cloneObj() {return cloneSubtree(null); }
@@ -264,7 +289,7 @@
} // __________________________________
/**
* obtain an instance of this class, from a 'normalized' xml format, with the default encoding
- * <p/> the 'normalized' xml format is the output of the instance method toXml()
+ * <p/> the 'normalized' xml format is the output of the toXml() instance method
* @param xml String - what to parse
* @return ConfigTree - an object of this class
* @throws SAXException - if xml format is invalid
@@ -282,7 +307,7 @@
/**
* obtain an instance of this class, from a 'normalized' xml format, with the encoding defined in arg1
- * <p/> the 'normalized' xml format is the output of the instance method toXml()
+ * <p/> the 'normalized' xml format is the output of the toXml() instance method
* @param xml String - what to parse
* @param encoding String - The encoding of arg 0
* @return ConfigTree - an object of this class
@@ -302,8 +327,8 @@
} // __________________________________
/**
- * obtain an instance of this class, from a 'normalized' xml format, from an input stream
- * <p/> the 'normalized' xml format is the output of the instance method toXml()
+ * obtain an instance of this class, from a 'normalized' xml format contained in an input stream
+ * <p/> the 'normalized' xml format is the output of the toXml() instance method
* @param input InputStream - where to parse from
* @return ConfigTree - an object of this class
* @throws SAXException - if xml format is invalid
@@ -322,7 +347,7 @@
}
Document oDoc = builder.parse(input);
oDoc.normalize();
- return fromElement(oDoc.getDocumentElement(),null);
+ return fromDomElement(oDoc.getDocumentElement(),null);
} // __________________________________
/**
* Obtain a ConfigTree from a org.w3c.dom.Element
@@ -330,14 +355,14 @@
* @param dad - where should the resulting object be added as a child
* @return a valid ConfigTree
*/
- public static ConfigTree fromElement(Element elem, ConfigTree dad)
+ public static ConfigTree fromDomElement(Element elem, ConfigTree dad)
{
ConfigTree oRet = new ConfigTree(elem.getNodeName(),dad);
for (Node nCurr = elem.getFirstChild();null!=nCurr;nCurr = nCurr.getNextSibling())
switch (nCurr.getNodeType())
{
case Node.ELEMENT_NODE:
- fromElement((Element)nCurr,oRet);
+ fromDomElement((Element)nCurr,oRet);
break;
case Node.TEXT_NODE:
oRet.addTextChild(nCurr.getNodeValue());
@@ -370,12 +395,21 @@
return elem;
} // __________________________________
/**
+ * Equivalent to a call to toXml()
* @return String - a String with the 'standard' xml representation of 'this',
* using the default encoding
*/
public String toString() { return toXml(); }
/**
+ * Equivalent to a call to toXml(encoding)
+ * @param encoding String -
* @return String - a String with the 'standard' xml representation of 'this',
+ * using the encoding specified in arg 0
+ */
+
+ public String toString(String encoding) { return toXml(encoding); }
+ /**
+ * @return String - a String with the 'standard' xml representation of 'this',
* using the default encoding
*/
public String toXml()
@@ -424,7 +458,7 @@
} // __________________________________
/**
*
- * @return boolean - indicating if 'this' element has ONLY text children (and no ConfigTree children)
+ * @return boolean - indicating if 'this' element has ONLY text children (and consequently no ConfigTree children)
*/
public boolean isPureText() { return _pureText; }
Modified: labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java
===================================================================
--- labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java 2006-10-13 09:41:24 UTC (rev 6788)
+++ labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java 2006-10-13 13:46:08 UTC (rev 6789)
@@ -159,7 +159,7 @@
// I think perhaps this method should not be depending on getTextValue because getTextValue
// concatentates the child text nodes.
assertTrue("invalid Text Children list",
- "Some root text... and some more root text...".equals(confTree.getAllText()));
+ "Some root text... and some more root text...".equals(confTree.getWholeText()));
assertTrue("invalid Text Children list",
Arrays.equals(new String[] {"", "Some nested text..."}, confTree.getTextChildren("el")));
}
More information about the jboss-svn-commits
mailing list