com.ibm.commerce.giftregistry.util

Class GiftRegistryUtils

  • java.lang.Object
    • com.ibm.commerce.giftregistry.util.GiftRegistryUtils


  • public class GiftRegistryUtils
    extends java.lang.Object
    This class contains a number of static utility methods that are used by the IBM Gift Center for WebSphere Commerce
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String CLASS_NAME
      The name of this class
      static java.lang.String COPYRIGHT
      The IBM Copyright notice field.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static boolean addToCollection(java.lang.Object collection, java.lang.Object element)
      Adds an element into a collection object.
      static void checkConfirmBODAndThrowExceptionOnError(ConfirmBOD confirmBOD, java.lang.String className, java.lang.String methodName)
      Inspects a ConfirmBOD and throws an ECApplicationException that the StoreErrorDataBean know how to handle, if the ConfirmBOD fails
      static java.lang.Object convertStringToAtomicType(java.lang.String value, java.lang.Class type)
      Converts a string to a given atomic type.
      static BusinessObjectDocument createBOD(java.lang.Class klass, CommandContext context, Verb verb, BaseVO noun)
      Creates a concrete instance of the BusinessObjectDocument.
      static BusinessObjectDocument createBOD(java.lang.Class klass, CommandContext context, Verb verb, BaseVO[] nouns)
      Creates a concrete instance of the BusinessObjectDocument.
      static ActivityToken getActivityToken()
      Gets the ActivityToken to be used in a request
      static java.lang.Class[] getAtomicTypes() 
      static com.ibm.commerce.giftregistry.util.ECEncryptionCmd getECEncryptionCmd(CommandContext context)
      Gets an instance of ECEncryptionCmd's implementation, and assign the given command context to the command.
      static TypedProperty getRequestProperties(javax.servlet.http.HttpServletRequest request)
      Retrieves the request properties from the given HttpServletRequest object.
      static java.lang.String getStackTrace(java.lang.Throwable e)
      Converts the stack trace of a throwable instance to a string
      static VerbPath getVerbPath(BaseVO aNode, java.lang.String attribute)
      Constructs a verb path starting from the leaf
      static boolean isAtomicType(java.lang.Class klass)
      Determines if a class is one of the types returned by getAtomicTypes().
      static boolean isCollection(java.lang.Object value)
      Determines if a given object is a collection.
      static boolean isEmpty(java.util.Collection c)
      Determines if a given collection is empty.
      static java.lang.String join(java.lang.String[] strings)
      Joins a list of strings into one string.
      static java.lang.String makeParameterName(java.lang.String name, java.lang.Integer index)
      Constructs an HTTP request parameter name based on given name and index.
      static java.util.Map resolveValues(java.lang.String name, TypedProperty aRequestProperty, boolean isArray)
      A wrapper for ResolveParameter.resolveValues.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        The IBM Copyright notice field.
        See Also:
        Constant Field Values
      • CLASS_NAME

        public static final java.lang.String CLASS_NAME
        The name of this class
    • Constructor Detail

      • GiftRegistryUtils

        public GiftRegistryUtils()
    • Method Detail

      • resolveValues

        public static java.util.Map resolveValues(java.lang.String name,
                                                  TypedProperty aRequestProperty,
                                                  boolean isArray)
        A wrapper for ResolveParameter.resolveValues. The wrapped method returns null whenever a value is not set in the given request property. If we use that, we have to check for null every time we use it. It's much better to use an empty map to mean "no value found"
        Parameters:
        name -
        aRequestProperty -
        isArray -
        Returns:
      • getVerbPath

        public static VerbPath getVerbPath(BaseVO aNode,
                                           java.lang.String attribute)
        Constructs a verb path starting from the leaf
        Parameters:
        node - the node that contains the given attribute
        attribute - the leaf of the node
        Returns:
        A VerbPath that leads to the given attribute. The first step of the path will be DataArea#getRootNode and the predicate of root can be used to identify the root of a value object graph.
      • createBOD

        public static BusinessObjectDocument createBOD(java.lang.Class klass,
                                                       CommandContext context,
                                                       Verb verb,
                                                       BaseVO[] nouns)
                                                throws ECException
        Creates a concrete instance of the BusinessObjectDocument. It is up to the caller to downcast the instance to its concrete type.
        Parameters:
        klass - The class of the instance to be created
        context - The context in which the BOD is to be created.
        verb - The verb of the BOD
        nouns - a list of nouns that is to be stored in the BOD
        Returns:
        an instance of BusinessObjectDocument
        Throws:
        The - exception gets thrown when creation of the BOD fails. Normally, the creation fails due to a programming error or a system error. Possible programming error that will cause the failure will be the passed parameters being null, the klass being not a BusinessObjectDocument type, and there is no public constructor that takes a ActivityToken and a DataArea as parameters in the given klass.
        ECException
      • createBOD

        public static BusinessObjectDocument createBOD(java.lang.Class klass,
                                                       CommandContext context,
                                                       Verb verb,
                                                       BaseVO noun)
                                                throws ECException
        Creates a concrete instance of the BusinessObjectDocument. It is up to the caller to downcast the instance to its concrete type.
        Parameters:
        klass - The class of the instance to be created
        context - The context in which the BOD is to be created.
        verb - The verb of the BOD
        nouns - a list of nouns that is to be stored in the BOD
        Returns:
        an instance of BusinessObjectDocument
        Throws:
        ECException - The exception gets thrown when creation of the BOD fails. Normally, the creation fails due to a programming error or a system error. Possible programming error that will cause the failure will be the passed parameters being null, the klass being not a BusinessObjectDocument type, and there is no public constructor that takes a ActivityToken and a DataArea as parameters in the given klass.
      • getActivityToken

        public static ActivityToken getActivityToken()
        Gets the ActivityToken to be used in a request
        Returns:
        ActivityToken the activity token used in a request
      • isEmpty

        public static boolean isEmpty(java.util.Collection c)
        Determines if a given collection is empty.
        Parameters:
        c - A collection instance
        Returns:
        true if c is either null or empty. False otherwise.
      • isCollection

        public static boolean isCollection(java.lang.Object value)
        Determines if a given object is a collection.
        Parameters:
        value - the given object to be determined
        Returns:
        true if the given object is a Collection or an array. False otherwise.
      • join

        public static java.lang.String join(java.lang.String[] strings)
        Joins a list of strings into one string.
        Parameters:
        strings - a list of strings
        Returns:
        If the given list is null or there is no string in the list, this method will return Null. Otherwise, a string obtained from concatenating all the strings in the given list. The order is preserved. For example {"a", "b", "c"} will be joined to return "abc".
      • addToCollection

        public static boolean addToCollection(java.lang.Object collection,
                                              java.lang.Object element)
        Adds an element into a collection object. The element will be added only if the collection accepts the element. If one of the parameters is null, nothing will be added.
        Parameters:
        collection - a collection object. It can be a java.util.Collection, or an array.
        element - An element to be added to the given collection object. If the collection object is an array, the element has to an acceptable type of the array.
        Returns:
        true if the element is added. False otherwise.
      • isAtomicType

        public static boolean isAtomicType(java.lang.Class klass)
        Determines if a class is one of the types returned by getAtomicTypes().
        Parameters:
        klass - the class to be analyzed
        Returns:
        true if the given class is in the list return by getAtomicTypes(). Otherwise, false. If the given class is null, null will be returned.
      • getAtomicTypes

        public static java.lang.Class[] getAtomicTypes()
        Returns:
        The list of classes that are atomic.
      • convertStringToAtomicType

        public static java.lang.Object convertStringToAtomicType(java.lang.String value,
                                                                 java.lang.Class type)
        Converts a string to a given atomic type.
        Parameters:
        value - the String to the converted
        The - type to which the given string is converted
        Returns:
        The converted result if the conversion is successful. Null if no conversion is available.
      • checkConfirmBODAndThrowExceptionOnError

        public static void checkConfirmBODAndThrowExceptionOnError(ConfirmBOD confirmBOD,
                                                                   java.lang.String className,
                                                                   java.lang.String methodName)
                                                            throws ECApplicationException
        Inspects a ConfirmBOD and throws an ECApplicationException that the StoreErrorDataBean know how to handle, if the ConfirmBOD fails
        Parameters:
        confirmBOD -
        className -
        methodName -
        Throws:
        ECApplicationException
      • getECEncryptionCmd

        public static com.ibm.commerce.giftregistry.util.ECEncryptionCmd getECEncryptionCmd(CommandContext context)
                                                                                     throws ECException
        Gets an instance of ECEncryptionCmd's implementation, and assign the given command context to the command. The returned command has not been executed or been changed other than being instantiated. It is update the user of the returned command to set required parameters, and then execute the command.
        Parameters:
        context - the context the returned command will be using
        Returns:
        a just instantiated instance of ECEncryptionCmd
        Throws:
        ECException - thrown if the command instance can not be instantiated properly
      • makeParameterName

        public static java.lang.String makeParameterName(java.lang.String name,
                                                         java.lang.Integer index)
        Constructs an HTTP request parameter name based on given name and index. This utility method is intended to handle parameter names that conforms to WebSphere Commerce conventions. That is, if a parameter is of form param_i, than the name is param, and the index is i, if any only if iv is greated than 0. If the parameter is param, then the name is param, and the index is 0.
        Parameters:
        name - the name of a parameter without any index
        index - the potential index of a parameter
        Returns:
        name if the index is not greater than 0. Otherwise, name_index.
      • getStackTrace

        public static java.lang.String getStackTrace(java.lang.Throwable e)
        Converts the stack trace of a throwable instance to a string
        Parameters:
        e - a Throwable that contains stack trace
        Returns:
        null if the given throwable is null or the stack trace is null. Otherwise, this method returns the string that describes the stack trace.
      • getRequestProperties

        public static TypedProperty getRequestProperties(javax.servlet.http.HttpServletRequest request)
        Retrieves the request properties from the given HttpServletRequest object.
        Parameters:
        request - the request that contains the desired request properties
        Returns:
        The set of request properties in the request, if any.