net.sf.crispy.util
Class Converter

java.lang.Object
  extended bynet.sf.crispy.util.Converter

public class Converter
extends java.lang.Object

Convert complex object in a simple form and back to the object.

Author:
Linke

Field Summary
protected static ClassPropertiesCache classPropertiesCacheGetter
           
protected static ClassPropertiesCache classPropertiesCacheSetter
           
static int GET_METHOD
           
static java.lang.String HASH_CODE_KEY
           
protected static java.util.Map isSimpleDataType
           
protected static org.apache.commons.logging.Log log
           
static int SET_METHOD
           
 
Constructor Summary
Converter()
           
Converter(int pvStartHashCode)
           
Converter(java.lang.String pvNullValue)
           
 
Method Summary
static java.lang.Object convertClassString2Object(java.lang.String pvClassName)
           
static java.lang.Object convertString2Value(java.lang.Object pvValue, java.lang.Class pvClass)
           
static java.lang.Object convertString2Value(java.lang.String pvStringValue, java.lang.Class pvClass)
          For example String to Integer or String to Date, ...
static java.lang.Object convertString2Value(java.lang.String pvStringValue, java.lang.String pvClassName)
          For example String to Integer or String to Date, ...
static java.lang.Object[] convertStringParams2MethodParams(java.lang.reflect.Method pvMethod, java.util.Vector pvParams)
          Convert String-Parameter (contains in the Vector) in Method-ParameterTypes.
static java.lang.Object createDefaultValueForPrimitiveClass(java.lang.Class pvClass)
           
static java.lang.Object createObjectWithParamConstructor(java.lang.Object pvParam, java.lang.Class pvParamType, java.lang.String pvClassName)
           
static java.lang.String extractHashCode(java.lang.Object pvObject)
          If pvObject.toString - method start with Converter.HASH_CODE_KEY, then extract the hash code.
 java.lang.String findNextFreeId(int pvHashCode)
           
static java.util.Map getAllGetterAndSetterMethod(java.lang.Class pvClass, int pvMethodType)
           
static java.util.Map getAllGetterMethod(java.lang.Class pvClass)
          Find all getter-method from a Class.
static java.util.Map getAllGetterMethodWithCache(java.lang.Class pvClass)
          Find all getter-method from a Class and remove all getter-method where no setter-method exist.
static java.lang.reflect.Method[] getAllMethodsByClass(java.lang.Class pvClass)
          Get all set/get methods from a Class.
static java.util.Map getAllNotEqualsGetterAndSetterAndRemoveThisProperties(java.util.Map pvGetterMap, java.util.Map pvSetterMap)
          Remove all getter-method where no setter-method exist.
static java.util.Map getAllSetterMethod(java.lang.Class pvClass)
          Find all setter-method from a Class.
static java.util.Map getAllSetterMethodWithCache(java.lang.Class pvClass)
          Find all setter-method from a Class.
static java.lang.Class getArrayType(java.lang.Object pvListObj)
          Analysed the objects in an Array/Collection.
static java.lang.String getClassWithoutPackage(java.lang.String pvClassWitchPackage, boolean pvToLowerCase)
          Extract from package + class name, the class name.
 java.lang.String getNullValue()
           
 boolean getWithSimpleKeyMapper()
           
static boolean isValideEdge(java.lang.Object pvObject)
           
static java.lang.Object makeAssignable(java.lang.Class pvSourceClass, java.lang.Object pvValue)
           
 java.lang.Object makeComplex(java.lang.Object pvObject)
           
 java.lang.Object makeComplex(java.lang.Object pvObject, java.lang.Class clazz)
           
 java.lang.Object makeComplex(java.lang.Object pvObject, java.lang.Class clazz, java.lang.Class clazzInArray)
           
 java.lang.Object makeSimple(java.lang.Object pvObject)
          Convert complex object in a Hashtable and relations in Vector.
 void setNullValue(java.lang.String pvNullValue)
           
 void setWithSimpleKeyMapper(boolean pvWithSimpleKeyMapper)
           
static java.util.Date string2Date(java.lang.String pvDateString)
          Convert a Date-String to a Date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HASH_CODE_KEY

public static final java.lang.String HASH_CODE_KEY
See Also:
Constant Field Values

GET_METHOD

public static final int GET_METHOD
See Also:
Constant Field Values

SET_METHOD

public static final int SET_METHOD
See Also:
Constant Field Values

log

protected static final org.apache.commons.logging.Log log

isSimpleDataType

protected static final java.util.Map isSimpleDataType

classPropertiesCacheGetter

protected static final ClassPropertiesCache classPropertiesCacheGetter

classPropertiesCacheSetter

protected static final ClassPropertiesCache classPropertiesCacheSetter
Constructor Detail

Converter

public Converter()

Converter

public Converter(java.lang.String pvNullValue)

Converter

public Converter(int pvStartHashCode)
Method Detail

setWithSimpleKeyMapper

public void setWithSimpleKeyMapper(boolean pvWithSimpleKeyMapper)

getWithSimpleKeyMapper

public boolean getWithSimpleKeyMapper()

isValideEdge

public static boolean isValideEdge(java.lang.Object pvObject)

getNullValue

public java.lang.String getNullValue()

setNullValue

public void setNullValue(java.lang.String pvNullValue)

findNextFreeId

public java.lang.String findNextFreeId(int pvHashCode)

makeSimple

public java.lang.Object makeSimple(java.lang.Object pvObject)
                            throws java.lang.Exception
Convert complex object in a Hashtable and relations in Vector. Cycles are finded and removed.

Parameters:
pvObject - Complex or simple object.
Returns:
Simple object structure.
Throws:
java.lang.Exception

makeComplex

public java.lang.Object makeComplex(java.lang.Object pvObject)
                             throws java.lang.Exception
Throws:
java.lang.Exception

makeComplex

public java.lang.Object makeComplex(java.lang.Object pvObject,
                                    java.lang.Class clazz)
                             throws java.lang.Exception
Throws:
java.lang.Exception

makeComplex

public java.lang.Object makeComplex(java.lang.Object pvObject,
                                    java.lang.Class clazz,
                                    java.lang.Class clazzInArray)
                             throws java.lang.Exception
Throws:
java.lang.Exception

makeAssignable

public static java.lang.Object makeAssignable(java.lang.Class pvSourceClass,
                                              java.lang.Object pvValue)

getArrayType

public static java.lang.Class getArrayType(java.lang.Object pvListObj)
Analysed the objects in an Array/Collection. If all Object from the same class type, then is the return value this class. If are several class types in the Array, then ist the return class from type Object.

Parameters:
pvListObj -
Returns:
Class, that are in the Array or Collection

convertClassString2Object

public static java.lang.Object convertClassString2Object(java.lang.String pvClassName)
                                                  throws java.lang.Exception
Throws:
java.lang.Exception

createObjectWithParamConstructor

public static java.lang.Object createObjectWithParamConstructor(java.lang.Object pvParam,
                                                                java.lang.Class pvParamType,
                                                                java.lang.String pvClassName)

convertString2Value

public static java.lang.Object convertString2Value(java.lang.String pvStringValue,
                                                   java.lang.String pvClassName)
                                            throws java.lang.Exception
For example String to Integer or String to Date, ...

Parameters:
pvStringValue - Value in String class.
pvClassName - Class name to convert the String value.
Returns:
The converted String value.
Throws:
java.lang.Exception

convertString2Value

public static java.lang.Object convertString2Value(java.lang.Object pvValue,
                                                   java.lang.Class pvClass)

convertString2Value

public static java.lang.Object convertString2Value(java.lang.String pvStringValue,
                                                   java.lang.Class pvClass)
For example String to Integer or String to Date, ...

Parameters:
pvStringValue - Value in String class.
pvClass - Type to convert the String value.
Returns:
The converted String value.

convertStringParams2MethodParams

public static java.lang.Object[] convertStringParams2MethodParams(java.lang.reflect.Method pvMethod,
                                                                  java.util.Vector pvParams)
Convert String-Parameter (contains in the Vector) in Method-ParameterTypes. For example: Vector ["5", "8"] convert to new Integer [] { new Integer(5), new Integer (8) }

Parameters:
pvMethod - Method with ParameterTypes.
pvParams - Vector with Strings.
Returns:
Array with ParameterTypes and ParameterValues.

string2Date

public static java.util.Date string2Date(java.lang.String pvDateString)
Convert a Date-String to a Date. The Converter neglected the Millisecond. Example: Thu Aug 11 19:30:57 CEST 2005

Parameters:
pvDateString - The Date-String (unequal null).
Returns:
Valid java.util.Date.

getClassWithoutPackage

public static java.lang.String getClassWithoutPackage(java.lang.String pvClassWitchPackage,
                                                      boolean pvToLowerCase)
Extract from package + class name, the class name. Example (pvToLowerCase = false)): Input: net.sf.crispy.ServiceManager -> Output: ServiceManger. Example (pvToLowerCase = true)): Input: net.sf.crispy.ServiceManager -> Output: servicemanger.

Parameters:
pvClassWitchPackage -
pvToLowerCase -
Returns:
The class without package.

extractHashCode

public static java.lang.String extractHashCode(java.lang.Object pvObject)
If pvObject.toString - method start with Converter.HASH_CODE_KEY, then extract the hash code. Example: make from ~hashCode~24306761 to 24306761.

Parameters:
pvObject -
Returns:
The hash code.

getAllNotEqualsGetterAndSetterAndRemoveThisProperties

public static java.util.Map getAllNotEqualsGetterAndSetterAndRemoveThisProperties(java.util.Map pvGetterMap,
                                                                                  java.util.Map pvSetterMap)
Remove all getter-method where no setter-method exist.


getAllGetterMethodWithCache

public static java.util.Map getAllGetterMethodWithCache(java.lang.Class pvClass)
                                                 throws java.beans.IntrospectionException
Find all getter-method from a Class and remove all getter-method where no setter-method exist.

Parameters:
pvClass - Class to anaylse.
Returns:
Map from getter-method (key=property name, value=method).
Throws:
java.beans.IntrospectionException

getAllSetterMethodWithCache

public static java.util.Map getAllSetterMethodWithCache(java.lang.Class pvClass)
                                                 throws java.beans.IntrospectionException
Find all setter-method from a Class.

Parameters:
pvClass - Class to analyse.
Returns:
Map all setter-Method (key=property name, value=method).
Throws:
java.beans.IntrospectionException

getAllGetterMethod

public static java.util.Map getAllGetterMethod(java.lang.Class pvClass)
                                        throws java.beans.IntrospectionException
Find all getter-method from a Class.

Parameters:
pvClass - Class to analyse.
Returns:
Map all getter-Method (key=property name, value=method).
Throws:
java.beans.IntrospectionException

getAllSetterMethod

public static java.util.Map getAllSetterMethod(java.lang.Class pvClass)
                                        throws java.beans.IntrospectionException
Find all setter-method from a Class.

Parameters:
pvClass - Class to analyse.
Returns:
Map all setter-Method (key=property name, value=method).
Throws:
java.beans.IntrospectionException

getAllMethodsByClass

public static java.lang.reflect.Method[] getAllMethodsByClass(java.lang.Class pvClass)
Get all set/get methods from a Class. With methods from all super classes.

Parameters:
pvClass - Analyse Class.
Returns:
All finded methods.

getAllGetterAndSetterMethod

public static java.util.Map getAllGetterAndSetterMethod(java.lang.Class pvClass,
                                                        int pvMethodType)
                                                 throws java.beans.IntrospectionException
Parameters:
pvClass - Find all get or set method from a Class.
pvMethodType - get or set
Returns:
Method map (key=property name, value=method).
Throws:
java.beans.IntrospectionException

createDefaultValueForPrimitiveClass

public static java.lang.Object createDefaultValueForPrimitiveClass(java.lang.Class pvClass)


Copyright © 2005-2006 Crispy. All Rights Reserved.