com.softwareag.centrasite.appl.framework.utils
Class CollectionUtils

java.lang.Object
  extended by com.softwareag.centrasite.appl.framework.utils.CollectionUtils

public final class CollectionUtils
extends java.lang.Object

Utility class providing convenient methods over Collections.


Method Summary
static void applyChanges(java.util.List<? extends javax.xml.registry.infomodel.RegistryObject> registryObjects, java.util.List<? extends RegistryBean> beans, ChangeHandler changeHandler)
          Compares the two List instances based on objects key and determines the removed, created and updated objects.
static java.lang.Class<RegistryBean> getAssociationTargetType(java.lang.reflect.Method getter, Association associationAnnotation)
          Determines the type of mapped to an association registry bean.
static java.lang.Class<RegistryBean> getClassificationTargetType(java.lang.reflect.Method getter, Classification classificationAnnotation)
          Determines the type of mapped to a classification registry bean.
static java.lang.Class<?> getSlotTargetType(java.lang.reflect.Method getter, Slot slotAnnotation)
          Determines the type of mapped to a slot property.
static java.lang.Class<RegistryBean> getTargetType(java.lang.reflect.Method getter, java.lang.Class<?> annotationTargetType)
          If the getter method returns Collection returns the annotation target type, otherwise returns the getter return type.
static java.util.Collection<?> initCollection(java.lang.Class<?> collectionType)
          Creates empty implementation for List, Collection, or Set.
static boolean isCollection(java.lang.Class<?> type)
          Determines if the given type is a Collection.
static void setCollectionProperty(java.lang.Object pBean, java.lang.reflect.Method pSetter, java.lang.reflect.Method pGetter, java.util.Collection<?> pValue)
          Adds the passed collection values to the collection property specified with the getter and setter methods.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initCollection

public static java.util.Collection<?> initCollection(java.lang.Class<?> collectionType)
Creates empty implementation for List, Collection, or Set.

Returns:
Empty implementation for the given collection type.
Throws:
java.lang.IllegalArgumentException - If the argument is not List, Collection or Set.

applyChanges

public static void applyChanges(java.util.List<? extends javax.xml.registry.infomodel.RegistryObject> registryObjects,
                                java.util.List<? extends RegistryBean> beans,
                                ChangeHandler changeHandler)
                         throws javax.xml.registry.JAXRException,
                                MappingException
Compares the two List instances based on objects key and determines the removed, created and updated objects. For each of those groups invokes the corresponding method of the ChangeHandler instance passed as an argument

Parameters:
registryObjects - The List of existing registry objects.
beans - The List of registry beans representing the registry objects.
changeHandler - Provides the logic for applying the changes.
Throws:
javax.xml.registry.JAXRException
MappingException

setCollectionProperty

public static void setCollectionProperty(java.lang.Object pBean,
                                         java.lang.reflect.Method pSetter,
                                         java.lang.reflect.Method pGetter,
                                         java.util.Collection<?> pValue)
Adds the passed collection values to the collection property specified with the getter and setter methods.

Parameters:
pBean - The bean on which the collection is being set.
pSetter - The collections setter. This is only used, if the collection is currently null.
pGetter - The collections getter. This is used to retrieve the collection from the bean. If the getter returns non-null, then the value will be added to the collection.
pValue - The collection value to add.

getAssociationTargetType

public static java.lang.Class<RegistryBean> getAssociationTargetType(java.lang.reflect.Method getter,
                                                                     Association associationAnnotation)
Determines the type of mapped to an association registry bean. If the property getter method returns Collection the mapped type is determined by the Association.targetType() attribute. Otherwise this method returns the return type of the getter method.

Parameters:
getter - The Method representing the mapped property.
associationAnnotation - The Association annotation specified by the user for the property represented by the getter method.
Returns:
The type of the registry bean mapped to a given property.

getClassificationTargetType

public static java.lang.Class<RegistryBean> getClassificationTargetType(java.lang.reflect.Method getter,
                                                                        Classification classificationAnnotation)
Determines the type of mapped to a classification registry bean. If the property getter method returns Collection the mapped type is determined by the Classification.targetType() attribute. Otherwise this method returns the return type of the getter method.

Parameters:
getter - The Method representing the mapped property.
classificationAnnotation - The Classification annotation specified by the user for the property represented by the getter method.
Returns:
The type of the registry bean mapped to a given property.

getSlotTargetType

public static java.lang.Class<?> getSlotTargetType(java.lang.reflect.Method getter,
                                                   Slot slotAnnotation)
Determines the type of mapped to a slot property. If the property getter method returns Collection the mapped type is determined by the Slot.targetType() attribute. Otherwise this method returns the return type of the getter method.

Parameters:
getter - The Method representing the mapped property.
slotAnnotation - The Slot annotation specified by the user for the property represented by the getter method.
Returns:
The type of the Java object mapped to a given property.

getTargetType

public static java.lang.Class<RegistryBean> getTargetType(java.lang.reflect.Method getter,
                                                          java.lang.Class<?> annotationTargetType)
If the getter method returns Collection returns the annotation target type, otherwise returns the getter return type.


isCollection

public static boolean isCollection(java.lang.Class<?> type)
Determines if the given type is a Collection. This means instance of Collection or its subclass.

Parameters:
type -
Returns:
true if the given class is instance of Collection or one of its subclasses. false otherwise.