|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.umber.bellows.Datum org.umber.bellows.validate.TypesafeDatum
A pass-through decorator to add typesafety control to an existing Datum object. All accessors check the type safety rules before getting or setting values. The original (inner) Datum object can still be accessed outside the typesafe wrapper, although any operations that short-circuit the wrapper might put the object into a non-typesafe state.
The typesafety wrapper adds methods to set up and monitor the type validation in the inner Datum object. The setTypeSafe() method turns type safety on and off. The isValid() method checks the object for validity. The get/setProperty() methods may throw IllegalArgumentException to express violations in the type names or values. The type constraints can be set individually with the declareProperty() method, or copied over from an existing Datum object with the copyTypes() method.
NOTE: This typesafety API will likely be replaced with a more comprehensive DTD-like validation system in the 0.3.0 release.
Field Summary |
Fields inherited from class org.umber.bellows.Datum |
DEFAULT_NAMESPACE, EMPTY_CHILDREN, NSURI_PROPERTY |
Method Summary | |
void |
copyTypes(TypesafeDatum datum)
Copies the property types from the supplied Datum into this Datum. |
void |
declareProperty(java.lang.String propertyName,
java.lang.Class propertyType,
java.lang.String namespace)
Declares a typing info for a property. |
java.lang.String |
getId()
Getter for property id, the instance-specific identifier for this Datum object. |
java.lang.String[] |
getKeyNames()
Retrieves a Set of all property keys in the default namespace of this Datum. |
java.lang.String[] |
getKeyNames(java.lang.String namespace)
Retrieves a Set of all property keys in the given namespace in this Datum. |
java.lang.Object |
getLocalProperty(java.lang.String name)
Retrieves a property for the given key value. |
java.lang.Object |
getLocalProperty(java.lang.String name,
java.lang.String namespace)
Retrieves a property for the given key value. |
java.lang.String[] |
getNamespaces()
Returns an array of all namespaces currently in use in this Datum. |
Datum |
getParent()
Getter for property parent. |
java.lang.Object |
getProperty(java.lang.String name)
Retrieves a property for the given key value. |
java.lang.Object |
getProperty(java.lang.String name,
java.lang.String namespace)
Retrieves a property for the given key value. |
java.lang.Class |
getPropertyType(java.lang.String propertyName,
java.lang.String namespace)
Retrieves the Java class set for the given property. |
java.lang.String |
getType()
Getter for property type, the name of the type for the Datum and its contents, similar to a class name. |
boolean |
isValid()
Returns the current type safety state of this Datum. |
void |
setParent(Datum parent)
Setter for property parent. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
Assigns a value to the stated property. |
void |
setProperty(java.lang.String name,
java.lang.Object value,
java.lang.String namespace)
Assigns a value to the stated property in the given namespace. |
void |
setType(java.lang.String type)
Setter for property type, the name of the type for the Datum and its contents, similar to a class name. |
static TypesafeDatum |
wrapDatum(Datum inner)
Creates a new instance of TypesafeDatum which wraps the Datum with a type safe API extension. |
Methods inherited from class org.umber.bellows.Datum |
extractPcdata, extractText, findKeys, getBooleanProperty, getBooleanProperty, getChildren, getEnumProperty, getEnumProperty, getIntegerProperty, getIntegerProperty, getNamespace, getPropertySpace, getStringProperty, getStringProperty, hasPcdataOnly, lookupUri, setNamespace, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
public static TypesafeDatum wrapDatum(Datum inner)
inner
- datum to encapsulate
public void setType(java.lang.String type)
setType
in class Datum
type
- New value of property type.public java.lang.String getType()
getType
in class Datum
public java.lang.String getId()
getId
in class Datum
public Datum getParent()
getParent
in class Datum
public void setParent(Datum parent)
setParent
in class Datum
parent
- New value of property parent.public java.lang.String[] getNamespaces()
getNamespaces
in class Datum
public void setProperty(java.lang.String name, java.lang.Object value)
setProperty
in class Datum
name
- the key name of the metadata propertyvalue
- the metadata value
java.lang.IllegalArgumentException
- if type safe and value cannot
be casted to the declared property typepublic void setProperty(java.lang.String name, java.lang.Object value, java.lang.String namespace)
setProperty
in class Datum
name
- the key name of the metadata propertyvalue
- the metadata valuenamespace
- the XML-style namespace for this property
java.lang.IllegalArgumentException
- if type safe and value cannot
be casted to the declared property typepublic java.lang.Object getLocalProperty(java.lang.String name)
getLocalProperty
in class Datum
name
- the key name of the property
java.lang.IllegalArgumentException
- if type safe and the current
value cannot be casted to the declared property typepublic java.lang.Object getLocalProperty(java.lang.String name, java.lang.String namespace)
getLocalProperty
in class Datum
name
- the key name of the propertynamespace
- the XML-style namespace for this property
java.lang.IllegalArgumentException
- if type safe and the current
value cannot be casted to the declared property typepublic java.lang.Object getProperty(java.lang.String name)
getProperty
in class Datum
name
- the key name of the property
java.lang.IllegalArgumentException
- if type safe and the current
value cannot be casted to the declared property typepublic java.lang.Object getProperty(java.lang.String name, java.lang.String namespace)
getProperty
in class Datum
name
- the key name of the propertynamespace
- the XML-style namespace for this property
java.lang.IllegalArgumentException
- if type safe and the current
value cannot be casted to the declared property typepublic java.lang.String[] getKeyNames()
getKeyNames
in class Datum
public java.lang.String[] getKeyNames(java.lang.String namespace)
getKeyNames
in class Datum
namespace
- the XML-style namespace for this property
public boolean isValid()
public void declareProperty(java.lang.String propertyName, java.lang.Class propertyType, java.lang.String namespace)
Property types declared in parent Datum objects are inherited similarly to property values, using the most-local value available. Thus, it is possible to change the type of a property between a parent and a child if both declare the same property with different propertyType.
If propertyType is null, the type of the property will not be checked, even with type safety enabled. This makes it possible to enforce property names without enforcing types, and on a property-by-property basis.
If namespace is null, the property declaration applies to the default namespace.
propertyName
- the property namepropertyType
- the optional type name of the propertynamespace
- the optional namespace for this property
declarationpublic void copyTypes(TypesafeDatum datum)
datum
- the source of the type definitions to initialize
this Datum topublic java.lang.Class getPropertyType(java.lang.String propertyName, java.lang.String namespace)
propertyName
- the property namenamespace
- the optional namespace for this property
declaration
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |