com.tensegrity.generic.persistence
Class BuilderUtilities

java.lang.Object
  extended bycom.tensegrity.generic.persistence.BuilderUtilities

public class BuilderUtilities
extends java.lang.Object

This class contains utility-methods needed during the creation of objects by a builder-instance. As true for most classes containing utility-methods it can not be instantiated, all methods are declared static.

Version:
$Id: BuilderUtilities.java,v 1.25 2004/10/25 15:47:58 MichaelKegel Exp $
Author:
Gilles Iachelini

Method Summary
static void assertContains(AttributeCollection attributes, java.lang.String name)
          This method verifies whether a given AttributeCollection contains an Attribute with the given name.
static void assertContains(AttributeCollection attributes, java.lang.String[] names)
          Method assertContains verifies whether a list of attributes identified by the list of names are in a given AttributeCollection.
static void assertContains(AttributeCollection attributes, java.lang.String[] names, int atleast)
          Method assertContains verifies if an AttributeCollection contains a certain amount of Attributes identified by the given list of names.
static void assertContainsMax(AttributeCollection attributes, java.lang.String[] names, int max)
          Checks whether a given AttributeCollection contains more than max attributes with the specified name.
static void assertNotNull(Attribute attribute, AttributeCollection attributes, java.lang.String attributeName)
          Method assertNotNull checks whether a given Attribute is not null and throws a BuildException with a detailed error message.
static void assertNotNull(java.lang.Object value, AttributeCollection attributes, java.lang.String attributeName)
          Method assertNotNull checks whether a given object is not null and throws a BuildException with a detailed error message.
static Attribute getAttribute(AttributeList list, java.lang.String name, boolean doAssertNotNull)
          Method to ease the Attribute retrieval on AttributeLists.
static Attribute getAttributeMayBeNull(AttributeList list, java.lang.String name)
          Method to ease the Attribute retrieval on AttributeList instances.
static java.lang.Object getAttributeValue(AttributeList list, java.lang.String name, java.lang.Class type)
          Method to ease the Attribute value retrieval on AttributeLists.
static java.lang.Object getAttributeValue(AttributeList list, java.lang.String name, java.lang.Class type, boolean doAssertNotNull)
          Method to ease the Attribute value retrieval on AttributeLists.
static java.lang.String getAttributeValueMayBeNull(AttributeList list, java.lang.String name)
          This method uses the getAttributeValueMayBeNull(AttributeList, String, Class) method but assumes that the retrieve value is of type String.
static java.lang.Object getAttributeValueMayBeNull(AttributeList list, java.lang.String name, java.lang.Class type)
          Method to ease the Attribute value retrieval on AttributeList instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

assertNotNull

public static final void assertNotNull(java.lang.Object value,
                                       AttributeCollection attributes,
                                       java.lang.String attributeName)
                                throws BuildException
Method assertNotNull checks whether a given object is not null and throws a BuildException with a detailed error message. This should help to track down syntax errors within the underlying xml file.

Parameters:
value - the value to check.
attributes - the AttributeCollection from which the value has been read.
attributeName - the name of the attribute of which this value has been read.
Throws:
BuildException - thrown if the value is null.

assertNotNull

public static final void assertNotNull(Attribute attribute,
                                       AttributeCollection attributes,
                                       java.lang.String attributeName)
                                throws BuildException
Method assertNotNull checks whether a given Attribute is not null and throws a BuildException with a detailed error message. This should help to track down syntax errors within the underlying xml file.

Parameters:
attribute - the value to check.
attributes - the AttributeCollection from which the value has been read.
attributeName - the name of the attribute of which this value has been read.
Throws:
BuildException - thrown if the value is null.

assertContains

public static final void assertContains(AttributeCollection attributes,
                                        java.lang.String name)
                                 throws BuildException
This method verifies whether a given AttributeCollection contains an Attribute with the given name. If the AttributeCollection is empty or no such Attribute is found a BuildException is thrown.

Parameters:
attributes - the AttributeCollection to look over.
name - the name of the attribute to be checked.
Throws:
BuildException - if no such attribute exists or the list is empty.

assertContains

public static final void assertContains(AttributeCollection attributes,
                                        java.lang.String[] names)
                                 throws BuildException
Method assertContains verifies whether a list of attributes identified by the list of names are in a given AttributeCollection. If one of these names is not found a BuildException is thrown.

Parameters:
attributes - the AttributeCollection to check.
names - the names of the Attributes.
Throws:
BuildException - thrown if none of the given names exist.

assertContains

public static final void assertContains(AttributeCollection attributes,
                                        java.lang.String[] names,
                                        int atleast)
                                 throws BuildException
Method assertContains verifies if an AttributeCollection contains a certain amount of Attributes identified by the given list of names. The given integer specifies how many names must be found.

 AttributeList ( (Age, 43), (Sex, male), (Name, Tom) )
 
 The following call to 
 assertContains(AttributeList, new String[]{Age, Sex, Occupation, Telephone},3)
 would throw an exception, because the AttributeList doesn't contain at 
 least 3 of the specified Attributes.
 

This method should be used whenever you encounter a variable AttributeList which may contain optional elements, but must contain at least n elements.

Parameters:
attributes - the list of attributes to verify.
names - the array of names which should be looked for.
atleast - the number of matches we have to find.
Throws:
BuildException - when the number of hits is smaller then the given integer at least.

assertContainsMax

public static final void assertContainsMax(AttributeCollection attributes,
                                           java.lang.String[] names,
                                           int max)
                                    throws BuildException
Checks whether a given AttributeCollection contains more than max attributes with the specified name.

Parameters:
attributes - The Collection to verify.
names - the list of names to check.
max - the maximum count of appearances of attributes with the given names.
Throws:
BuildException - thrown whenever more than max attributes are found.

getAttribute

public static final Attribute getAttribute(AttributeList list,
                                           java.lang.String name,
                                           boolean doAssertNotNull)
                                    throws BuildException
Method to ease the Attribute retrieval on AttributeLists. Returns the first Attribute with the given name. The value will be asserted through the assertNotNull method of this class.

Parameters:
list - the AttributeList instance of which you want the Attribute.
name - the name of the Attribute you want to receive.
doAssertNotNull - if set to true, the assertNotNull(Attribute, AttributeCollection, String) method is applied prior the retrieval of the Attribute.
Returns:
Attribute the Attribute identified by name.
Throws:
BuildException - thrown if the Attribute to retrieve must be not null but it is not found in the given AttributeList.

getAttributeMayBeNull

public static final Attribute getAttributeMayBeNull(AttributeList list,
                                                    java.lang.String name)
Method to ease the Attribute retrieval on AttributeList instances. Returns the first attribute with the given name. The returned Attribute may be null if it is not found in the given AttributeList.

Parameters:
list - the AttributeList instance from that you want to get the Attribute from.
name - the name of the Attribute you want to receive.
Returns:
Attribute the Attribute identified by name.

getAttributeValue

public static final java.lang.Object getAttributeValue(AttributeList list,
                                                       java.lang.String name,
                                                       java.lang.Class type)
                                                throws BuildException
Method to ease the Attribute value retrieval on AttributeLists. Returns the value of the first Attribute with the given name. The value will be asserted through the assertNotNull method of this class.

Parameters:
list - the AttributeList instance of which you want the Attribute.
name - the name of the Attribute you want to receive.
type - the type of the returned Object.
Returns:
Object the value of the Attribute identified by name.
Throws:
BuildException - thrown if getAttributeValue(AttributeList, String, Class, boolean) throws an exception.

getAttributeValueMayBeNull

public static final java.lang.String getAttributeValueMayBeNull(AttributeList list,
                                                                java.lang.String name)
                                                         throws BuildException
This method uses the getAttributeValueMayBeNull(AttributeList, String, Class) method but assumes that the retrieve value is of type String. Therefore no cast is required for the caller, nor the type Parameter has to be passed.

Parameters:
list - the AttributeList instance from that you want to get the Attribute from.
name - the name of the Attribute you want to receive.
Returns:
the value of the Attribute identified by name as String, or null.
Throws:
BuildException - delegates the exception of the getAttributeValue(AttributeList, String, Class) call.

getAttributeValueMayBeNull

public static final java.lang.Object getAttributeValueMayBeNull(AttributeList list,
                                                                java.lang.String name,
                                                                java.lang.Class type)
                                                         throws BuildException
Method to ease the Attribute value retrieval on AttributeList instances. Returns the value of the first attribute with the given name. The returned value may be null if it is not found in the attribute list.

Parameters:
list - the AttributeList instance from that you want to get the Attribute from.
name - the name of the Attribute you want to receive.
type - the type of the returned Object.
Returns:
the value of the Attribute identified by name.
Throws:
BuildException - delegates the exception of the getAttributeValue(AttributeList, String, Class, boolean) call.

getAttributeValue

public static final java.lang.Object getAttributeValue(AttributeList list,
                                                       java.lang.String name,
                                                       java.lang.Class type,
                                                       boolean doAssertNotNull)
                                                throws BuildException
Method to ease the Attribute value retrieval on AttributeLists. Returns the value of the first Attribute with the given name. The value will be asserted through the assertNotNull method if the boolean doAssert is set to true.

Parameters:
list - the AttributeList instance from that you want to get the Attribute.
name - the name of the Attribute you want to receive.
type - the Class you expect the value to be.
doAssertNotNull - if true, method assertNotNull() will get called.
Returns:
the value of the Attribute identified by name.
Throws:
BuildException - if assertNotNull or assertType throws such an exception.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.