atg.rest.util
Class BeanUtils

java.lang.Object
  extended by atg.rest.util.BeanUtils

public class BeanUtils
extends java.lang.Object

A class which provides common utility methods.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
BeanUtils()
           
 
Method Summary
protected static java.util.Collection<?> convertCollectionType(java.lang.Class<?> pClass, java.lang.Class<?> pComponentClass, java.lang.String pValue, boolean pUseStandardJSON, JSONObject pControlParamsForJSON, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Converts the given string into an object of the specified Collection type.
protected static java.util.Collection<?> convertCollectionType(java.lang.Class<?> pClass, java.lang.String pValue, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Converts the given string into an object of the specified Collection type.
static java.lang.Object convertDataToType(java.lang.Class<?> pClass, java.lang.Class<?> pKeyClass, java.lang.Class<?> pComponentClass, java.lang.String pValue, boolean pUseStandardJSON, JSONObject pControlParamsForJSON, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method converts the given value to an object of the given Class type.
static java.lang.Object convertDataToType(java.lang.Class<?> pClass, java.lang.String pValue, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method converts the given value to an object of the given Class type.
protected static java.util.Date convertDateTimeType(java.lang.Class<?> pClass, java.lang.String pValue)
          Converts the given string into an object of the specified "date" or "time" type.
protected static java.util.Map<?,?> convertMapType(java.lang.Class<?> pClass, java.lang.Class<?> pKeyClass, java.lang.Class<?> pValueClass, java.lang.String pValue, boolean pUseStandardJSON, JSONObject pControlParamsForJSON, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Converts the given string into an object of the specified Map type.
protected static java.util.Map<?,?> convertMapType(java.lang.Class<?> pClass, java.lang.String pValue, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Converts the given string into an object of the specified Map type.
protected static java.lang.Object convertObjectArrayType(java.lang.Class<?> pClass, java.lang.String pValue, boolean pUseStandardJSON, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method converts the given value to an object of the given object array Class type.
protected static java.lang.Object convertObjectArrayType(java.lang.Class<?> pClass, java.lang.String pValue, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method converts the given value to an object of the given object array Class type.
static java.lang.Integer convertObjectToInteger(java.lang.Object pObj)
           
protected static java.lang.Object convertPrimitiveArrayType(java.lang.Class<?> pClass, java.lang.String pValue)
          This method converts the given value to an object of the given primitive array Class type.
protected static java.lang.Object convertPrimitiveType(java.lang.Class<?> pClass, java.lang.String pValue)
          This method converts the given value to an object of the given primitive Class type.
static java.lang.String formatStringForDate(java.util.Date pDate, java.lang.String pTimeZoneId)
          get the string format for a date object
static java.lang.Object getFilteredPropertyValue(PropertyConfiguration pPropertyConfig, java.lang.Object pResContainer, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method a filtered property value.
protected static java.lang.Object getMultivaluedElement(java.lang.Object pContainer, java.lang.String pProperty)
          Returns the element in a List or array which is located in the slot specified by pProperty
static NameValuePair getPropertyNameAndValue(java.lang.String[] pPropertyNames, java.lang.Object pResContainer)
          This method returns the property value for a property that is a child or grandchild of the resource container.
static NameValuePair getPropertyNameAndValue(java.lang.String[] pPropertyNames, java.lang.Object pResContainer, ComponentConfiguration pCFC, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This method returns the property value for a property that is a child or grandchild of the resource container.
static NameValuePair getPropertyNameAndValue(java.lang.String pPropertyName, java.lang.Object pResContainer)
          Convenience method for getting the property name from the given property descriptor and the value from the given resource container.
static NameValuePair getPropertyNameAndValue(java.lang.String pPropertyName, java.lang.Object pResContainer, ComponentConfiguration pCFC, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Convenience method for getting the property name from the given property descriptor and the value from the given resource container.
static boolean isIntegerString(java.lang.String pString)
          Returns true if pString is a string version of an integer, false otherwise
static java.lang.String removeBrackets(java.lang.String pValue)
          Convenience method for removing brackets [ and ] from a String if it contains them.
static java.lang.String removeQuotes(java.lang.String pValue)
          Convenience method for removing quotes " or ' from a String if it contains them.
static void setArrayEntryValue(java.lang.Object pArray, java.lang.String pIndex, java.lang.String pValue, DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          Sets the given value into an array element
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

isIntegerString

public static boolean isIntegerString(java.lang.String pString)
Returns true if pString is a string version of an integer, false otherwise

Parameters:
pString - the string to test
Returns:
true if pString is a string version of an integer, false otherwise

getPropertyNameAndValue

public static NameValuePair getPropertyNameAndValue(java.lang.String[] pPropertyNames,
                                                    java.lang.Object pResContainer)
                                             throws PropertyNotFoundException
This method returns the property value for a property that is a child or grandchild of the resource container.

Parameters:
pPropertyNames - a String array containing the sub-properties
pResContainer - the object containing the resource
Returns:
the property value for a property that is a child or grandchild of the resource container
Throws:
PropertyNotFoundException - if the requested property cannot be found

getPropertyNameAndValue

public static NameValuePair getPropertyNameAndValue(java.lang.String pPropertyName,
                                                    java.lang.Object pResContainer)
                                             throws PropertyNotFoundException
Convenience method for getting the property name from the given property descriptor and the value from the given resource container.

Parameters:
pPropertyName - the property name of the property to retrieve
pResContainer - the object to get the value from
Returns:
a NameValuePair object containing the property name and the value from the given object
Throws:
PropertyNotFoundException - if the requested property cannot be found
See Also:
NameValuePair

getPropertyNameAndValue

public static NameValuePair getPropertyNameAndValue(java.lang.String[] pPropertyNames,
                                                    java.lang.Object pResContainer,
                                                    ComponentConfiguration pCFC,
                                                    DynamoHttpServletRequest pRequest,
                                                    DynamoHttpServletResponse pResponse)
                                             throws RestException
This method returns the property value for a property that is a child or grandchild of the resource container.

Parameters:
pPropertyNames - a String array containing the sub-properties
pResContainer - the object containing the resource
pCFC - a ComponentConfiguration object which contains filtering information
pRequest - the servlet request
pResponse - the servle response
Returns:
the property value for a property that is a child or grandchild of the resource container
Throws:
RestException - if the requested property cannot be found or if an io exception occurs

getPropertyNameAndValue

public static NameValuePair getPropertyNameAndValue(java.lang.String pPropertyName,
                                                    java.lang.Object pResContainer,
                                                    ComponentConfiguration pCFC,
                                                    DynamoHttpServletRequest pRequest,
                                                    DynamoHttpServletResponse pResponse)
                                             throws RestException
Convenience method for getting the property name from the given property descriptor and the value from the given resource container.

Parameters:
pPropertyName - the property name of the property to retrieve
pResContainer - the object to get the value from
pCFC - a ComponentConfiguration object which contains filtering information
pRequest - the servlet request
pResponse - the servle response
Returns:
a NameValuePair object containing the property name and the value from the given object
Throws:
RestException - if the requested property cannot be found or if an io exception occurs
See Also:
NameValuePair

getFilteredPropertyValue

public static java.lang.Object getFilteredPropertyValue(PropertyConfiguration pPropertyConfig,
                                                        java.lang.Object pResContainer,
                                                        DynamoHttpServletRequest pRequest,
                                                        DynamoHttpServletResponse pResponse)
                                                 throws RestException,
                                                        java.io.IOException
This method a filtered property value. This method takes filtering configuration into account.

Parameters:
pPropertyConfig - the PropertyConfiguration object which contains the filtering information
pResContainer - the object container which is the resource
pRequest - the servlet request
pResponse - the servlet response
Throws:
RestException - if an error occurs processing the REST request
java.io.IOException - if an error occurs writing data to the output object

getMultivaluedElement

protected static java.lang.Object getMultivaluedElement(java.lang.Object pContainer,
                                                        java.lang.String pProperty)
                                                 throws PropertyNotFoundException
Returns the element in a List or array which is located in the slot specified by pProperty

Parameters:
pContainer - the container which contains the element desired
pProperty - a string representation of the number which specifies the element to retrieve in the List or array
Returns:
the desired element from the List or array
Throws:
PropertyNotFoundException - if pProperty is not numeric and the string in pProperty is not a valid property of pContainer

setArrayEntryValue

public static void setArrayEntryValue(java.lang.Object pArray,
                                      java.lang.String pIndex,
                                      java.lang.String pValue,
                                      DynamoHttpServletRequest pRequest,
                                      DynamoHttpServletResponse pResponse)
                               throws RestException
Sets the given value into an array element

Parameters:
pArray - the array to set the value into
pIndex - the array index to set
pValue - the value to set
pRequest - the servlet request
pResponse - the servlet response
Throws:
RestException - if data cannot be converted to correct type
java.lang.IllegalArgumentException - if the value is not compatible with the array type or pArray is not an array

convertDataToType

public static java.lang.Object convertDataToType(java.lang.Class<?> pClass,
                                                 java.lang.String pValue,
                                                 DynamoHttpServletRequest pRequest,
                                                 DynamoHttpServletResponse pResponse)
                                          throws RestException
This method converts the given value to an object of the given Class type. If the string "atg-rest-null" is passed as pValue, it is interpreted as a null value and null is returned.

Parameters:
pClass - a Class object representing the type that pValue should be converted to
pValue - a String representation of the value to be converted
pRequest - the servlet request
pResponse - the servlet response
Returns:
an object of the given class type with the value which is converted from pValue. Returns null if pValue is the string "null".
Throws:
java.lang.IllegalArgumentException - if a value which is to be converted to a repository item cannot be converted or the type was not handled
RestException - if data cannot be converted to specified type

convertDataToType

public static java.lang.Object convertDataToType(java.lang.Class<?> pClass,
                                                 java.lang.Class<?> pKeyClass,
                                                 java.lang.Class<?> pComponentClass,
                                                 java.lang.String pValue,
                                                 boolean pUseStandardJSON,
                                                 JSONObject pControlParamsForJSON,
                                                 DynamoHttpServletRequest pRequest,
                                                 DynamoHttpServletResponse pResponse)
                                          throws RestException
This method converts the given value to an object of the given Class type. If the string "atg-rest-null" is passed as pValue, it is interpreted as a null value and null is returned.

Parameters:
pClass - a Class object representing the type that pValue should be converted to
pKeyClass - a Class object representing the type of the keys in the map, if the data is a map
pComponentClass - a Class object representing the type of the components of the data, if the data is a multi value
pValue - a String representation of the value to be converted
pUseStandardJSON - flag indicating whether pValue is standard json
pRequest - the servlet request
pResponse - the servlet response
Returns:
an object of the given class type with the value which is converted from pValue. Returns null if pValue is the string "null".
Throws:
java.lang.IllegalArgumentException - if a value which is to be converted to a repository item cannot be converted or the type was not handled
RestException - if data cannot be converted to specified type

convertPrimitiveType

protected static java.lang.Object convertPrimitiveType(java.lang.Class<?> pClass,
                                                       java.lang.String pValue)
This method converts the given value to an object of the given primitive Class type.

Parameters:
pClass - a Class object representing the primitive type that pValue should be converted to
pValue - a String representation of the value to be converted
Returns:
an object of the given class type with the value which is converted from pValue

convertCollectionType

protected static java.util.Collection<?> convertCollectionType(java.lang.Class<?> pClass,
                                                               java.lang.String pValue,
                                                               DynamoHttpServletRequest pRequest,
                                                               DynamoHttpServletResponse pResponse)
                                                        throws RestException
Converts the given string into an object of the specified Collection type.

Parameters:
pClass - a Class object representing the collection type that pValue should be converted to
pValue - a String representation of the value to be converted
pRequest - the servlet request
pResponse - the servlet response
Returns:
a subclass of java.util.Collection representing the value from pValue
Throws:
java.lang.IllegalArgumentException - if the collection cannot be parsed or if the format is incorrect
RestException - if data cannot be converted to collection

convertCollectionType

protected static java.util.Collection<?> convertCollectionType(java.lang.Class<?> pClass,
                                                               java.lang.Class<?> pComponentClass,
                                                               java.lang.String pValue,
                                                               boolean pUseStandardJSON,
                                                               JSONObject pControlParamsForJSON,
                                                               DynamoHttpServletRequest pRequest,
                                                               DynamoHttpServletResponse pResponse)
                                                        throws RestException
Converts the given string into an object of the specified Collection type.

Parameters:
pClass - a Class object representing the collection type that pValue should be converted to
pComponentClass - a Class object representing the type of the components of the data, if the data is a multi value
pValue - a String representation of the value to be converted
pUseStandardJSON - flag indicating whether pValue is standard json
pRequest - the servlet request
pResponse - the servlet response
Returns:
a subclass of java.util.Collection representing the value from pValue
Throws:
java.lang.IllegalArgumentException - if the collection cannot be parsed or if the format is incorrect
RestException - if data cannot be converted to collection

convertMapType

protected static java.util.Map<?,?> convertMapType(java.lang.Class<?> pClass,
                                                   java.lang.String pValue,
                                                   DynamoHttpServletRequest pRequest,
                                                   DynamoHttpServletResponse pResponse)
                                            throws RestException
Converts the given string into an object of the specified Map type.

Parameters:
pClass - a Class object representing the map type that pValue should be converted to
pValue - a String representation of the value to be converted
pRequest - the servlet request
pResponse - the servlet response
Returns:
a subclass of java.util.Map representing the value from pValue
Throws:
java.lang.IllegalArgumentException - if the map cannot be parsed or if the format is incorrect
RestException - if data cannot be converted to a Map

convertMapType

protected static java.util.Map<?,?> convertMapType(java.lang.Class<?> pClass,
                                                   java.lang.Class<?> pKeyClass,
                                                   java.lang.Class<?> pValueClass,
                                                   java.lang.String pValue,
                                                   boolean pUseStandardJSON,
                                                   JSONObject pControlParamsForJSON,
                                                   DynamoHttpServletRequest pRequest,
                                                   DynamoHttpServletResponse pResponse)
                                            throws RestException
Converts the given string into an object of the specified Map type.

Parameters:
pClass - a Class object representing the map type that pValue should be converted to
pKeyClass - a Class object representing the type of the keys in the map
pValueClass - a Class object representing the type of the values in the map
pValue - a String representation of the value to be converted
pUseStandardJSON - flag indicating whether pValue is standard json
pRequest - the servlet request
pResponse - the servlet response
Returns:
a subclass of java.util.Map representing the value from pValue
Throws:
java.lang.IllegalArgumentException - if the map cannot be parsed or if the format is incorrect
RestException - if data cannot be converted to a Map

convertPrimitiveArrayType

protected static java.lang.Object convertPrimitiveArrayType(java.lang.Class<?> pClass,
                                                            java.lang.String pValue)
This method converts the given value to an object of the given primitive array Class type.

Parameters:
pClass - a Class object representing the primitive array type that pValue should be converted to
pValue - a String representation of the value to be converted
Returns:
an object of the given array class type with the value which is converted from pValue

convertObjectArrayType

protected static java.lang.Object convertObjectArrayType(java.lang.Class<?> pClass,
                                                         java.lang.String pValue,
                                                         DynamoHttpServletRequest pRequest,
                                                         DynamoHttpServletResponse pResponse)
                                                  throws RestException
This method converts the given value to an object of the given object array Class type.

Parameters:
pClass - a Class object representing the object array type that pValue should be converted to
pValue - a String representation of the value to be converted
Returns:
an object of the given array class type with the value which is converted from pValue
Throws:
RestException

convertObjectArrayType

protected static java.lang.Object convertObjectArrayType(java.lang.Class<?> pClass,
                                                         java.lang.String pValue,
                                                         boolean pUseStandardJSON,
                                                         DynamoHttpServletRequest pRequest,
                                                         DynamoHttpServletResponse pResponse)
                                                  throws RestException
This method converts the given value to an object of the given object array Class type.

Parameters:
pClass - a Class object representing the object array type that pValue should be converted to
pValue - a String representation of the value to be converted
pUseStandardJSON - flag indicating whether pValue is standard json
Returns:
an object of the given array class type with the value which is converted from pValue
Throws:
RestException

convertDateTimeType

protected static java.util.Date convertDateTimeType(java.lang.Class<?> pClass,
                                                    java.lang.String pValue)
Converts the given string into an object of the specified "date" or "time" type.

Parameters:
pClass - a Class object representing the date or time type that pValue should be converted to
pValue - a String representation of the value to be converted
Returns:
a java.util.Date, java.sql.Date, java.sql.Timestamp, or java.sql.Time object representing the value from pValue
Throws:
java.lang.IllegalArgumentException - if the date cannot be parsed or if the date format is incorrect

formatStringForDate

public static java.lang.String formatStringForDate(java.util.Date pDate,
                                                   java.lang.String pTimeZoneId)
get the string format for a date object

Parameters:
pDate - the date object
Returns:
the string format for the date, using the SimpleDateFormat

removeBrackets

public static java.lang.String removeBrackets(java.lang.String pValue)
Convenience method for removing brackets [ and ] from a String if it contains them.

Parameters:
the - String from which to remove the brackets
Returns:
the String without the brackets

removeQuotes

public static java.lang.String removeQuotes(java.lang.String pValue)
Convenience method for removing quotes " or ' from a String if it contains them.

Parameters:
the - String from which to remove the quotes
Returns:
the String without the quotes

convertObjectToInteger

public static java.lang.Integer convertObjectToInteger(java.lang.Object pObj)