Skip navigation links


org.identityconnectors.test.common
Class PropertyBag

java.lang.Object
  extended by org.identityconnectors.test.common.PropertyBag


public final class PropertyBag
extends java.lang.Object

Encapsulates a read-only bag of properties, which can be accessed in a type-safe manner.

The simplest way to obtain a required (i.e., the property must be in the bag, otherwise an exception is thrown) property value is getProperty(String, Class). If the property is not a required one, the getProperty(String, Class, Object) method can be used, which also takes a default value which is returned when the property is not present in the bag.


Method Summary
<T> T
getProperty(java.lang.String name, java.lang.Class<T> type)
          Gets the value of a required property in a type-safe manner.
<T> T
getProperty(java.lang.String name, java.lang.Class<T> type, T def)
          Gets a property value, returning a default value when no property with the specified name exists in the bag.
 java.lang.String getStringProperty(java.lang.String name)
          Gets a required property value known to be of string type.
 java.lang.String toString()
           

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Method Detail

getProperty

public <T> T getProperty(java.lang.String name,
                         java.lang.Class<T> type)
Gets the value of a required property in a type-safe manner. If no property exists with the given name, IllegalArgumentException is thrown.
Type Parameters:
T - the type of the property.
Parameters:
name - the name of the property.
type - the Class representing the type of the property.
Returns:
the value of the property in bag; null if the value of the property was null.
Throws:
java.lang.IllegalArgumentException - if no property with the given name name exists in the bag.
java.lang.ClassCastException - if the property exists, but is not of the specified type.

getProperty

public <T> T getProperty(java.lang.String name,
                         java.lang.Class<T> type,
                         T def)
Gets a property value, returning a default value when no property with the specified name exists in the bag.
Type Parameters:
T - the type of the property.
Parameters:
name - the name of the property.
type - the Class representing the type of the property.
def - the default value returned when no property with the specified name exists in the bag.
Returns:
the value of the property in bag or the default value; null if the value of the property was null.
Throws:
java.lang.ClassCastException - if the property exists, but is not of the specified type.

getStringProperty

public java.lang.String getStringProperty(java.lang.String name)
Gets a required property value known to be of string type. The method expects that the value is an instance of String. It does not attempt to call Object.toString() on the value.
Parameters:
name - the name of the property.
Returns:
the value of the property in bag; null if the value of the property was null.
Throws:
java.lang.IllegalArgumentException - if no property with the given name exists in the bag.
java.lang.ClassCastException - if the property exists, but is not an instance of String.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Skip navigation links


Copyright © 2012, Oracle and/or its affiliates. All rights reserved.