it.negro.jajb.utility
Class Utility

java.lang.Object
  extended by it.negro.jajb.utility.Utility

public class Utility
extends java.lang.Object

This Class provides some utilities used by JAJB and can be reused as you want.

Author:
Gabriele Negro

Constructor Summary
Utility()
           
 
Method Summary
static java.lang.Class<?> getArrayClass(java.lang.Class<?> componentType)
          This method return an array Class for the componentType Class passed.
static java.lang.Class<?> getClass(java.lang.String typeName)
          Return correct primitive type class for typeName passed like, "int", "short", "float", etc.
static java.lang.Class<?> getCollectionClass(java.lang.String collectionType, java.lang.Class<?> componentType)
          Returns the correct collection class type for the passed collectionType and componentType passed parameters.
static it.dangelo.domjson.JSONBuilder getJSONBuilder()
          Returns a JSONBuilder instance.
static boolean isComplexType(java.lang.Class<?> clazz)
          Return true is passed parameter clazz is not primitive, is not an array, is not a Wrapper Class (Integer, Long, String, etc.), is not the Class of Object and is not a java.util.Date.
static boolean isWrapper(java.lang.Class<?> clazz)
          This method says if passed parameter Class is one of Byte, Short, Integer, Long, String, Character, Boolean, Float, Double or not.
static it.dangelo.domjson.JSONArray marshallSimpleArrayToJSONArray(java.lang.Object array)
          Converts an array into a JSONArray.
static it.dangelo.domjson.JSONArray marshallSimpleCollectionToJSONArray(java.util.Collection<?> collection, java.lang.Class<?> componentType)
          Converts a collection into a JSONArray.
static java.lang.String resolveRefId(java.lang.Class<?> clazz)
          Returns the refId of passed clazz.
static java.lang.Object unmarshallSimpleArray(it.dangelo.domjson.JSONArray jsonArray, java.lang.Class<?> arrayClass)
          Converts a JSONArray into Java Array.
static java.util.Collection<?> unmarshallSimpleCollection(it.dangelo.domjson.JSONArray jsonArray, java.lang.Class<?> collectionClass, java.lang.Class<?> componentType)
          Does the same work of unmarshallSimpleArray method, but using collections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

getJSONBuilder

public static it.dangelo.domjson.JSONBuilder getJSONBuilder()
Returns a JSONBuilder instance.

Returns:
- JSONBuilder

isWrapper

public static boolean isWrapper(java.lang.Class<?> clazz)
This method says if passed parameter Class is one of Byte, Short, Integer, Long, String, Character, Boolean, Float, Double or not.

Parameters:
clazz -
Returns:

getArrayClass

public static java.lang.Class<?> getArrayClass(java.lang.Class<?> componentType)
This method return an array Class for the componentType Class passed. For example, if componentType is Integer.TYPE, it return int[].class. In particular, returns all possible primitive array Class, otherwise returns Object[].class.

Parameters:
componentType -
Returns:

isComplexType

public static boolean isComplexType(java.lang.Class<?> clazz)
Return true is passed parameter clazz is not primitive, is not an array, is not a Wrapper Class (Integer, Long, String, etc.), is not the Class of Object and is not a java.util.Date. It says if passed clazz parameter may be one of your own defined Java Beans.

Parameters:
clazz -
Returns:

getClass

public static java.lang.Class<?> getClass(java.lang.String typeName)
                                   throws java.lang.ClassNotFoundException
Return correct primitive type class for typeName passed like, "int", "short", "float", etc. It you pass "", return Class of Object, Otherwise returns the Class object for the passed class name.

Parameters:
typeName -
Returns:
Throws:
java.lang.ClassNotFoundException

getCollectionClass

public static java.lang.Class<?> getCollectionClass(java.lang.String collectionType,
                                                    java.lang.Class<?> componentType)
                                             throws java.lang.ClassNotFoundException
Returns the correct collection class type for the passed collectionType and componentType passed parameters. If collectionType is "array", returns an Array Class for componentType Class; if collectionType is "vector" returns Vector Class; if collectionType is "list" returns ArrayList Class; if collectionType is "set" return HashSet Class; otherwise tries to take the Class treating collectionType like a Collection Class name.

Parameters:
collectionType -
componentType -
Returns:
Throws:
java.lang.ClassNotFoundException

resolveRefId

public static java.lang.String resolveRefId(java.lang.Class<?> clazz)
Returns the refId of passed clazz. If clazz has an EntityAnnotation returns '@className', otherwise '#className'.

Parameters:
clazz -
Returns:
refId

unmarshallSimpleArray

public static java.lang.Object unmarshallSimpleArray(it.dangelo.domjson.JSONArray jsonArray,
                                                     java.lang.Class<?> arrayClass)
                                              throws JAJBUnMarshallException
Converts a JSONArray into Java Array. Use it only for simple component type (wrapper, primitive or Date

Parameters:
jsonArray - the JSONArray to convert
arrayClass - the array class for result (for example 'int[].class', 'String[].class', etc.
Returns:
- an array like specified in arrayClass parameter
Throws:
JAJBUnMarshallException

unmarshallSimpleCollection

public static java.util.Collection<?> unmarshallSimpleCollection(it.dangelo.domjson.JSONArray jsonArray,
                                                                 java.lang.Class<?> collectionClass,
                                                                 java.lang.Class<?> componentType)
                                                          throws JAJBUnMarshallException
Does the same work of unmarshallSimpleArray method, but using collections. In add o you must pass the class of component of the expected collection.

Parameters:
jsonArray - the JSONArray to convert
collectionClass - the collection class for result (for example 'ArrayList.class', 'Vector.class', etc.
componentType - the class of collection component
Returns:
- a collection like specified in collectionClass parameter
Throws:
JAJBUnMarshallException

marshallSimpleArrayToJSONArray

public static it.dangelo.domjson.JSONArray marshallSimpleArrayToJSONArray(java.lang.Object array)
                                                                   throws JAJBMarshallException
Converts an array into a JSONArray. Converts only Date[] or primitive array (int[], char[], etc) or wrapper array (String[], Boolean[], etc.)

Parameters:
array - the array to convert
Returns:
- passed array parameter converted into JSONArray
Throws:
JAJBMarshallException

marshallSimpleCollectionToJSONArray

public static it.dangelo.domjson.JSONArray marshallSimpleCollectionToJSONArray(java.util.Collection<?> collection,
                                                                               java.lang.Class<?> componentType)
                                                                        throws JAJBMarshallException
Converts a collection into a JSONArray. Component type must be a wrapper type (String, Long, etc.9 or a Date

Parameters:
collection -
componentType -
Returns:
JSONArray
Throws:
JAJBMarshallException


Copyright © 2008. All Rights Reserved.