Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.jbossmx.cluster.watchdog.util.xml
Class XMLObjectCreator  view XMLObjectCreator download XMLObjectCreator.java

java.lang.Object
  extended byorg.jbossmx.cluster.watchdog.util.xml.XMLObjectCreator

public class XMLObjectCreator
extends java.lang.Object

XMLObjectCreator is a utility class for creating Java objects from XML

Examples of XML:

   Example 1:
   <param class="java.lang.String">Hello</param>

   Example 2:
   <param class="java.lang.Boolean">true</param>

   Example 3:
   <param class="com.company.Rational">
     <param class="java.lang.Integer">3</param>
     <param class="java.lang.Integer">4</param>
   </param>

   Example 4:
   <param class="com.company.Thing[]">
     <param class="com.company.Thing">
       <param class="java.lang.Integer">1</param>
       <param class="java.lang.Integer">2</param>
       <param class="java.lang.Integer">3</param>
     </param>
   </param>

 Note that the following fragment

   <param class="java.lang.Thing">
     <param class="java.lang.String">Value</param
   </param>

 can be simplified to:
   <param class="java.lang.Thing">Value</param>


Constructor Summary
private XMLObjectCreator()
          XMLObjectCreator doesn't need to be created.
 
Method Summary
private static java.lang.String concatenateNodes(org.w3c.dom.NodeList nodeList)
          Concatenates the values of all the nodes in nodeList
static java.lang.Object createObject(org.w3c.dom.Node node)
          Creates a Java object represented by node
static java.lang.Object[] createObjects(org.w3c.dom.NodeList nodeList)
          Creates an array of Objects from the list of XML Nodes
private static java.lang.Class getClassFromNode(org.w3c.dom.Node node)
          Creates a Class object from the 'class' attribute of node
private static java.lang.Class[] getConstructorClasses(org.w3c.dom.NodeList nodeList)
          Gets an array of Classes from the node List, if nodeList is empty of only contains #text node types that a String.class is returned
private static java.lang.Class[] getConstructorClasses(java.lang.Object[] objects)
           
private static java.lang.reflect.Constructor getMatchingConstructor(java.lang.Class classInstance, java.lang.Class[] constructorClasses)
           
private static int getMatchingNodeCount(org.w3c.dom.NodeList nodeList, java.lang.String nodeName)
          Returns the number of nodes in nodeList that have a node name equal to nodeName
private static int howManyOccurences(java.lang.String searchIn, java.lang.String searchFor)
          Returns the number of times searchIn occurs in searchIn
private static boolean isAssignableFrom(java.lang.Class[] left, java.lang.Class[] right)
           
private static void printObjectArray(java.lang.Object[] array)
          Prints out the class type and string representation of all the Objects in the array
private static java.lang.String repeatString(java.lang.String repeatWhat, int howMany)
          Returns repeatWhat repeated howMany times
private static java.lang.String translateArrayClassString(java.lang.String from)
          Converts from to a Class.forName(java.lang.String)>Class.forName(java.lang.String) 55 compliant String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLObjectCreator

private XMLObjectCreator()
XMLObjectCreator doesn't need to be created.

Method Detail

createObjects

public static java.lang.Object[] createObjects(org.w3c.dom.NodeList nodeList)
                                        throws java.lang.Exception
Creates an array of Objects from the list of XML Nodes


printObjectArray

private static void printObjectArray(java.lang.Object[] array)
Prints out the class type and string representation of all the Objects in the array


createObject

public static java.lang.Object createObject(org.w3c.dom.Node node)
                                     throws java.lang.Exception
Creates a Java object represented by node


getMatchingConstructor

private static java.lang.reflect.Constructor getMatchingConstructor(java.lang.Class classInstance,
                                                                    java.lang.Class[] constructorClasses)

isAssignableFrom

private static boolean isAssignableFrom(java.lang.Class[] left,
                                        java.lang.Class[] right)

getConstructorClasses

private static java.lang.Class[] getConstructorClasses(java.lang.Object[] objects)

getConstructorClasses

private static java.lang.Class[] getConstructorClasses(org.w3c.dom.NodeList nodeList)
                                                throws java.lang.ClassNotFoundException
Gets an array of Classes from the node List, if nodeList is empty of only contains #text node types that a String.class is returned


getMatchingNodeCount

private static int getMatchingNodeCount(org.w3c.dom.NodeList nodeList,
                                        java.lang.String nodeName)
Returns the number of nodes in nodeList that have a node name equal to nodeName


concatenateNodes

private static java.lang.String concatenateNodes(org.w3c.dom.NodeList nodeList)
Concatenates the values of all the nodes in nodeList


getClassFromNode

private static java.lang.Class getClassFromNode(org.w3c.dom.Node node)
                                         throws java.lang.ClassNotFoundException
Creates a Class object from the 'class' attribute of node


translateArrayClassString

private static java.lang.String translateArrayClassString(java.lang.String from)
Converts from to a Class.forName(java.lang.String)>Class.forName(java.lang.String) 55 compliant String

Class.forName requires strings that represent arrays to specified in a form like [Ljava.lang.String; or [[Lcom.company.MyClass; This function translates from a nicer form java.lang.String[], com.company.MyClass[][], etc. to form required by Class.forName


howManyOccurences

private static int howManyOccurences(java.lang.String searchIn,
                                     java.lang.String searchFor)
Returns the number of times searchIn occurs in searchIn


repeatString

private static java.lang.String repeatString(java.lang.String repeatWhat,
                                             int howMany)
Returns repeatWhat repeated howMany times