xml2class
XML data structures

xml2class
Class X2cTools

java.lang.Object
  |
  +--xml2class.X2cTools

public class X2cTools
extends java.lang.Object

This class provides some utility methods for the whole xml2class package. Most important: an entity encoder, a method invoker and a token-string to array converter.

Author:
Simon Bünzli, zeniko@gmx.ch
See Also:
XML2ClassParser, XMLFile

Constructor Summary
X2cTools()
           
 
Method Summary
static java.lang.Object invokeMethod(java.lang.Object element, java.lang.String methodName)
          Allows to invoke any (parameterless) method for any object.
static java.lang.String stripClassPath(java.lang.String fullTagName)
          Removes any path information from a class name.
static java.lang.String toEntityString(java.lang.String s)
          Returns the same string, but with any entity character encoded as XML entity (e.g.
static java.lang.String[] tokensToArray(java.lang.String tokenString)
          Transforms a token-string into a string array.
static java.lang.String[] tokensToArray(java.lang.String tokenString, java.lang.String separators)
          Transforms a token-string into a string array.
static java.lang.String toXMLString(java.lang.Object element)
          Converts any element into an XML string, at the condition that it provides a toXMLString() method.
static java.lang.String upperCaseFirstLetter(java.lang.String string)
          Capitalizes the first character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

X2cTools

public X2cTools()
Method Detail

stripClassPath

public static java.lang.String stripClassPath(java.lang.String fullTagName)
Removes any path information from a class name.
Returns:
the class name only (without classpath).

upperCaseFirstLetter

public static java.lang.String upperCaseFirstLetter(java.lang.String string)
Capitalizes the first character.
Returns:
the same string with a capitalized initial letter.

tokensToArray

public static java.lang.String[] tokensToArray(java.lang.String tokenString)
Transforms a token-string into a string array.
Parameters:
tokenString - any string, asuming that whitespace serves as token separator.
Returns:
a string array containing all the string's tokens.

tokensToArray

public static java.lang.String[] tokensToArray(java.lang.String tokenString,
                                               java.lang.String separators)
Transforms a token-string into a string array.
Parameters:
tokenString - any string.
separators - a string including any token separator characters.
Returns:
a string array containing all the string's tokens.

toEntityString

public static java.lang.String toEntityString(java.lang.String s)
Returns the same string, but with any entity character encoded as XML entity (e.g. < results in &lt;).
Parameters:
s - String whose entities should be encoded.
Returns:
an entity encoded string.

invokeMethod

public static java.lang.Object invokeMethod(java.lang.Object element,
                                            java.lang.String methodName)
                                     throws X2cClassBuildingException
Allows to invoke any (parameterless) method for any object.
Parameters:
element - the object whose method should be invoked.
methodName - the method's name.
Returns:
any object returned by the invoked method.
Throws:
X2cClassBuildingException - is thrown if the indicated method could not be found or invoked for any reasons.

toXMLString

public static java.lang.String toXMLString(java.lang.Object element)
                                    throws X2cOutputException
Converts any element into an XML string, at the condition that it provides a toXMLString() method.
Parameters:
any - object (not necessarily XMLSaveable).
Returns:
the object's XML representation.
Throws:
X2cOutputException - is thrown if the element does not support toXMLString().

xml2class
XML data structures

Copyleft 2001 by Simon Bünzli, zeniko@gmx.ch