Framework Professional Edition Package


org.mbs.services.metatype
Class Util

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

public class Util
extends java.lang.Object

Utility class for dealing with metatype and configuration information. Applications working with String data may use this class to convert Strings to Objects which are actually used by the ConfigurationAdmin. (see OSGi ConfigurationAdmin specification). The Util class provides conversion methods, which receive metatype definition and String representation of an object and return its real value.

See Also:
Convertor, AttributeDefinition

Constructor Summary
Util()
           
 
Method Summary
static int compareObjects(java.lang.Object first, java.lang.Object second, int syntax)
          Comapres two object numerically.
static java.lang.Object getRealObject(java.lang.String[] object, int cardinality, int syntax)
          Based on an AttributeDefinition's default value, cardinality, and syntax an object is created.
static java.lang.Object getRealObject(java.lang.String[] object, int cardinality, int syntax, int[] syntaxes)
          Based on an AttributeDefinition's default value, cardinality, and syntax an object is created.
static java.lang.Object makeArr(java.lang.String[] array, int syntax)
          Makes an array from the string array value and the syntax.
static java.util.Dictionary makeDictionary(java.lang.String[] array, int[] syntaxes)
          Makes an Dictionary from its presentation as String array and the syntaxes of its values.
static java.lang.Object makeObject(java.lang.String string, int syntax)
          Creates an object from a String value and a type, as returned by the corresponding AttributeDefinition.getType() method.
static java.lang.String[] stringToArray(java.lang.String str, java.lang.String separators)
          Converts a delimited string into an array of string tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

compareObjects

public static int compareObjects(java.lang.Object first,
                                 java.lang.Object second,
                                 int syntax)
Comapres two object numerically. The objects can be of Integer, Long, Float, Double, Byte, Short or Character class.

Parameters:
first - The first of the objects to be compared.
second - The second of the objects to be compared.
syntax - A syntax, valid in the terms of an AttributeDefinition.
Returns:
-1, 0, 1 if first object is respectively numerically less than, equal to, or greater than second.

makeObject

public static java.lang.Object makeObject(java.lang.String string,
                                          int syntax)
                                   throws java.lang.IllegalArgumentException
Creates an object from a String value and a type, as returned by the corresponding AttributeDefinition.getType() method.

Parameters:
string - The String value representation of the object.
syntax - The object's type as defined by AttributeDefinition.
Returns:
an Object, which is of a type, corresponding to the given, and value - got from the string parameter. E.g. if syntax is equal to AttributeDefinition.INTEGER and string is "1", then the value returned should be Integer("1").
Throws:
java.lang.IllegalArgumentException - if a proper object can not be created due to incompatibility of syntax and value or if the parameters are not correct (e.g. syntax is not a valid AttributeDefinition constant).

getRealObject

public static java.lang.Object getRealObject(java.lang.String[] object,
                                             int cardinality,
                                             int syntax,
                                             int[] syntaxes)
                                      throws java.lang.IllegalArgumentException
Based on an AttributeDefinition's default value, cardinality, and syntax an object is created.

Parameters:
object - The String array representation of the object.
cardinality - The cardinality of the object as defined by AttributeDefinition.
syntax - The object's type as defined by AttributeDefinition.
syntaxes - Used only when syntax is DICITONARY. Defines the types, as defined by AttributeDefinition, of the dictionary's values. In this case the object argument's length must be the doubled value of the syntaxes length.
Returns:
an object, of type corresponding to syntax and value, build from the given string array. Depending on the cardinality, this can be either a single object, or an array of objects or primitives, a Vector of objects or a Dictionary.
Throws:
java.lang.IllegalArgumentException - if any of the arguments is not compatible with the others.

getRealObject

public static java.lang.Object getRealObject(java.lang.String[] object,
                                             int cardinality,
                                             int syntax)
                                      throws java.lang.IllegalArgumentException
Based on an AttributeDefinition's default value, cardinality, and syntax an object is created.

Parameters:
object - The String array representation of the object.
cardinality - The cardinality of the object as defined by AttributeDefinition.
syntax - The object's type as defined by AttributeDefinition.
Returns:
an object, of type corresponding to syntax and value, build from the given string array. Depending on the cardinality, this can be either a single object, or an array of objects or primitives or a Vector of objects.
Throws:
java.lang.IllegalArgumentException - if any of the arguments is not compatible with the others.

makeDictionary

public static java.util.Dictionary makeDictionary(java.lang.String[] array,
                                                  int[] syntaxes)
Makes an Dictionary from its presentation as String array and the syntaxes of its values.

Parameters:
array - String array which hold in its odd position the keys of the dictionary and the String representations of the corresponding values on the even positions. Its lenght must be even and exaclty twice the length of the syntaxes array. The type of the value of the element which key is at position i * 2 is specified with the ith element in the syntaxes array.
syntaxes - The types of the dictionary's valus, as defined by AttributeDefinition.
Returns:
a Dictionary
Throws:
java.lang.IllegalArgumentException - if any of the elements in the string array can not be converted to a proper object or primitive, the array is not of event lenght of if any of the syntaxes is not a valid AttributeDefinition type constant.

makeArr

public static java.lang.Object makeArr(java.lang.String[] array,
                                       int syntax)
                                throws java.lang.IllegalArgumentException
Makes an array from the string array value and the syntax.

Parameters:
array - String array representation of an array, which follows the rules defined by AttributeDefinition.
syntax - The array's type as defined by AttributeDefinition.
Returns:
an arary of primitives or objects, whose component type corresponds to syntax, and value build from the string array passed.
Throws:
java.lang.IllegalArgumentException - if any of the elements in the string array can not be converted to a proper object or primitive, or if the syntax is not a valid AttributeDefinition type constant.

stringToArray

public static final java.lang.String[] stringToArray(java.lang.String str,
                                                     java.lang.String separators)
Converts a delimited string into an array of string tokens.

Parameters:
String[] - The 'separator' separated string.
String - The string separator.
Returns:
String A string array of the original tokens.

Framework Professional Edition Package


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