Framework Professional Edition Package


org.mbs.services.metatype
Class Convertor

java.lang.Object
  extended by org.mbs.services.metatype.Convertor

public class Convertor
extends java.lang.Object

The purpose of the class is to facilitate applications in dealing with configuration objects. The class can be used in order to represent configuration properties values as String objects. In order to get the real object as is, one have to use the decoding methods this class includes in conjunction with the Util class. As coded values are type loose the corresponding MetaTypeProvider must also be available.

Objects this class operates on could be of type 'containers' (Vector, Dictionary or array of String or any primitive type) or 'single' (String, Character, Long, Integer, Short, Byte, Boolean). They are converted ot String as follows:
1) array of Strings or primitive classes: ',' separated values of the converted to String elements enclosed by the '{' and '}' chars. Example: {value_1,value_2,...,valueN}
2) Vector instance: ',' separated values of the converted to String elements, enclosed by the '[' and ']' chars. Elements must be 'single' objects and of the same class. Example: [value_1,value_2,...,valueN]
3) Dictionary instance: ';' separated values of the converted to String keys and elements, enclosed by the '<' and '>' chars. Keys must be of type String. A value has to be of 'single' type. Example:
4) Boolean, String, Character or any subclass of the Numeric class: the value returned by its toString() method where the ',', '\\', '<', '{' and '[' characters are escaped by the '\\' char.

Notes:
- Once converted to String an object loses its type information. When converted back to Object it is actually a String, which must further be processed by methods of the Util class. Exception of this rule are only 'containers'. In the latter case the contained objects must be proccessed.
- No other object classes are supported.

See Also:
Util

Field Summary
static char BEGIN_ARRAY
          Constant char, used as flag for the begining of an array 'container'.
static char BEGIN_DICTIONARY
          Constant char, used as flag for the begining of a Dictionary 'container'.
static char BEGIN_VECTOR
          Constant char, used as flag for the begining of a Vector 'container'.
static char END_ARRAY
          Constant char, used as flag for the end of an array 'container'.
static char END_DICTIONARY
          Constant char, used as flag for the end of a Dictionary 'container'.
static char END_VECTOR
          Constant char, used as flag for the end of a Vector 'container'.
static char ESCAPE_CHARACTER
          Constant char, used as an escape symbol.
static char VALUE_DELIMITER
          Constant char used to separate the elements of a 'container' whet it is being converted to String.
 
Constructor Summary
Convertor()
           
 
Method Summary
protected static java.lang.String code(java.lang.String string)
          Returns a String where the 'reserved' characters from the original String are escaped.
static java.lang.String coreObjectToString(java.lang.Object object)
          Use this method in order to code an object of 'single' type as a String.
protected static java.lang.String decode(java.lang.String string)
          This method is the reverse of the code(String) method.
static java.lang.String dictionaryToString(java.util.Dictionary dictionary)
          Use this method in order to code a Dictionary as a String.
static java.lang.String objectToString(java.lang.Object object)
          General method for Object conversion to String.
static java.lang.String primitiveArrayToString(java.lang.Object array)
          Method facilitating conversion of an array of primitive values to String.
static java.lang.String stringArrayToString(java.lang.String[] array)
          Method facilitating the conversion of a String array to String.
static java.lang.String[] stringToArray(java.lang.String string)
          Method for decoding a String back to an array.
static java.util.Dictionary stringToDictionary(java.lang.String string)
          Method for decoding a String back to Dictionary.
static java.lang.Object stringToObject(java.lang.String string)
          General method for back convertion of a String to Object.
static java.util.Vector stringToVector(java.lang.String string)
          Method for decoding a String back to Vector.
static java.lang.String[] toArray(java.lang.String string, char beginChar)
          Method for decoding a String.
static java.lang.Object toStringOrArray(java.lang.String string)
          Method for decoding a String.
static java.lang.String vectorToString(java.util.Vector vector)
          Use this method in order to code a Vector as a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_DELIMITER

public static final char VALUE_DELIMITER
Constant char used to separate the elements of a 'container' whet it is being converted to String.

See Also:
Constant Field Values

BEGIN_ARRAY

public static final char BEGIN_ARRAY
Constant char, used as flag for the begining of an array 'container'.

See Also:
Constant Field Values

END_ARRAY

public static final char END_ARRAY
Constant char, used as flag for the end of an array 'container'.

See Also:
Constant Field Values

BEGIN_VECTOR

public static final char BEGIN_VECTOR
Constant char, used as flag for the begining of a Vector 'container'.

See Also:
Constant Field Values

END_VECTOR

public static final char END_VECTOR
Constant char, used as flag for the end of a Vector 'container'.

See Also:
Constant Field Values

BEGIN_DICTIONARY

public static final char BEGIN_DICTIONARY
Constant char, used as flag for the begining of a Dictionary 'container'.

See Also:
Constant Field Values

END_DICTIONARY

public static final char END_DICTIONARY
Constant char, used as flag for the end of a Dictionary 'container'.

See Also:
Constant Field Values

ESCAPE_CHARACTER

public static final char ESCAPE_CHARACTER
Constant char, used as an escape symbol.

See Also:
Constant Field Values
Constructor Detail

Convertor

public Convertor()
Method Detail

objectToString

public static java.lang.String objectToString(java.lang.Object object)
General method for Object conversion to String. The argument MUST be of a type as explained above.

Parameters:
object - The object to be converted.
Returns:
String representation of the passed object argument.
Throws:
java.lang.IllegalArgumentException - is thrown if the argument passed is not a 'container' or a 'single' type as explained above.

stringArrayToString

public static java.lang.String stringArrayToString(java.lang.String[] array)
Method facilitating the conversion of a String array to String.

Parameters:
array - The array to be converted.
Returns:
String representaton of the passed array argument.

primitiveArrayToString

public static java.lang.String primitiveArrayToString(java.lang.Object array)
Method facilitating conversion of an array of primitive values to String.

Parameters:
array - The primitive array to be converted.
Returns:
String representaton of the passed array argument.

dictionaryToString

public static java.lang.String dictionaryToString(java.util.Dictionary dictionary)
Use this method in order to code a Dictionary as a String. This method is called by objectToString(java.lang.Object) if the passed object is a Dictionary instance. This object should be a configuration property value.

Parameters:
dictionary - The dictionary for which String representation will be returned.
Returns:
String representation of the passed Dictionary argument.
Throws:
java.lang.IllegalArgumentException - is thrown if the dictionary contains a non String key or if a value is not of 'single' type.

vectorToString

public static java.lang.String vectorToString(java.util.Vector vector)
Use this method in order to code a Vector as a String. This method is called objectToString(java.lang.Object) when the passed object is a Vector instance. This object should be a configuration property value.

Parameters:
vector - The vector to be represented as String.
Returns:
String representation of the passed Vector argument.
Throws:
java.lang.IllegalArgumentException - if the argument contains objects of non 'single' type, or if the objects are not of the same type.

coreObjectToString

public static java.lang.String coreObjectToString(java.lang.Object object)
Use this method in order to code an object of 'single' type as a String. This method is called by objectToString(java.lang.Object) if the passed object is such an instance. This object should be a configuration property value.

Parameters:
object - The object to be represented as String.
Returns:
String representation of the passed argument.
Throws:
java.lang.IllegalArgumentException - thrown if the object is not of 'single' type.

stringToObject

public static java.lang.Object stringToObject(java.lang.String string)
General method for back convertion of a String to Object. The returned object is a String or container of Strings rather than the real object, but the values are no longer escaped. For full convertion Util class must be further used.

Parameters:
string - The String to be converted.
Returns:
a String or a 'container' object of Strings.

toStringOrArray

public static java.lang.Object toStringOrArray(java.lang.String string)
Method for decoding a String. This method acts as stringToObject(String) method but rather than container object a String array is returned.

Parameters:
string - The String to be converted.
Returns:
String or array of Strings.
Throws:
java.lang.IllegalArgumentException - if the format of the passed String is not of valid.

toArray

public static java.lang.String[] toArray(java.lang.String string,
                                         char beginChar)
Method for decoding a String. It is considered that the String argument corresponds to a container as specified by the beginChar argument.

Parameters:
string - The string to decode.
beginChar - Character pointing the type of the container. Currently BEGIN_ARRAY, BEGIN_VECTOR and BEGIN_DICTIONARY are legal argument values.
Returns:
array of Strings
Throws:
java.lang.IllegalArgumentException - if the format of the passed String is not of valid.

stringToVector

public static java.util.Vector stringToVector(java.lang.String string)
Method for decoding a String back to Vector. The returned object will contain all of its originally contained values as Strings. Further every single value must be passed through Util.makeObject(java.lang.String, int) in order to get back the real configuration property value.

Parameters:
string - The String to be decoded.
Returns:
Vector of Strings
Throws:
java.lang.IllegalArgumentException - if the original object was not a Vector instance.

stringToArray

public static java.lang.String[] stringToArray(java.lang.String string)
Method for decoding a String back to an array. The returned object will contain all of its originally contained values as Strings. Further the array must be passed through Util.makeArr(String[], int) in order to get back the real configuration property value.

Parameters:
string - The String to be decoded.
Returns:
An array of Strings.
Throws:
java.lang.IllegalArgumentException - if the original object was not an array.

stringToDictionary

public static java.util.Dictionary stringToDictionary(java.lang.String string)
Method for decoding a String back to Dictionary. The returned object will contain all of its originally contained values as Strings. Further every dictionary value must be passed through Util.makeObject(java.lang.String, int) in order to get back the real object contained by the dictionary property value.

Parameters:
string - The String to be decoded.
Returns:
name-value pairs of Strings.
Throws:
java.lang.IllegalArgumentException - if the original object was not a Dictionary instance.

code

protected static java.lang.String code(java.lang.String string)
Returns a String where the 'reserved' characters from the original String are escaped.

Parameters:
string - The string to code.
Returns:
String with escaped 'reserved' characters.

decode

protected static java.lang.String decode(java.lang.String string)
This method is the reverse of the code(String) method. It returns a string where the escaped 'reserved' characters from the given String are converted back to their original values.

Parameters:
string - String to decode.
Returns:
String with un-escaped 'reserved' characters.

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved