Nuxeo Enterprise Platform 5.1

org.nuxeo.ecm.core.api.model.impl
Class AbstractProperty

java.lang.Object
  extended by org.nuxeo.ecm.core.api.model.impl.AbstractProperty
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Property>, Property
Direct Known Subclasses:
ComplexProperty, ListProperty, ScalarProperty

public abstract class AbstractProperty
extends Object
implements Property

Author:
Bogdan Stefanescu
See Also:
Serialized Form

Field Summary
protected  Object data
           
protected  int flags
           
static int IS_READONLY
          Whether or not this property is read only.
static int IS_VALIDATING
          Whether or not this property is validating values when they are set.
static int KEYED_DATA
          Whether ot not the data field contains keyed data.
protected  Property parent
           
 
Fields inherited from interface org.nuxeo.ecm.core.api.model.Property
DIRTY_MASK, IS_DIRTY, IS_MODIFIED, IS_MOVED, IS_NEW, IS_PHANTOM, IS_REMOVED, NONE
 
Constructor Summary
protected AbstractProperty(Property parent)
           
protected AbstractProperty(Property parent, int flags)
           
 
Method Summary
protected  void appendDirtyFlags(int dirtyFlags)
           
 boolean areFlagsSet(long flags)
           
 void clearDirtyFlags()
          Notify the property that its changes was stored so it can safely remove dirty flags.
 void clearFlags(long flags)
           
protected  Path collectPath(Path path)
           
<T> T
convertTo(Serializable value, Class<T> toType)
          Converts the given normalized value to the given type.
 Object getData()
          application data impl.
 Object getData(String key)
          Returns the application defined data associated with the receiver under the given key, or null if it has not been set.
 int getDirtyFlags()
          Get the dirty flags that are set on this property
 Property getParent()
          Gets the property parent.
 String getPath()
          Gets the path of this property relative to the owner document.
 DocumentPart getRoot()
          Gets the root property.
 Schema getSchema()
          Gets the document schema defining the property tree from which the property belongs.
 Serializable getValue()
          Gets the property normalized value.
<T> T
getValue(Class<T> type)
          Gets the property value as the given type.
<T> T
getValue(Class<T> type, String path)
          Gets the value of the property resolved using the given path.
 Serializable getValue(String path)
          Gets the value of the property resolved using the given path.
 void init(Serializable value)
          Intializes the property with the given normalized value.
abstract  Serializable internalGetValue()
           
abstract  void internalSetValue(Serializable value)
          Sets the given normalized value.
 boolean isComplex()
          Tests whether this property is of a map (complex) type.
 boolean isDirty()
          Tests whether a property is dirty.
 boolean isList()
          Tests whether this property is of a list type.
 boolean isModified()
          Tests if a property value was modified
 boolean isMoved()
          Tests if a property value was moved to another index in the parent list if any
 boolean isNew()
          Tests if this property is new (just created but not yet stored).
 boolean isNormalized(Object value)
          Checks if the given value is a normalized one.
 boolean isPhantom()
          Tests if the property is a phantom.
 boolean isReadOnly()
          Whether the property is read only
 boolean isRemoved()
          Tests if a property is flagged as removed.
 boolean isScalar()
          Tests whether this property is of a scalar type.
 boolean isValidating()
          Check whether this propertty is validating values when set
 Iterator<Property> iterator()
           
 void moveTo(int index)
          Moves a property position into the parent container list.
 Object newInstance()
          Creates a new and empty instance of a normalized value.
 Serializable normalize(Object value)
          Normalizes the given value as dictated by the property type.
 Serializable remove()
          Remove this property from the tree.
 void removePhantomFlag()
           
 Property resolvePath(Path path)
          Resolves the given path relative to the current property and return the property if any is found otherwise throws an exception.
 Property resolvePath(String path)
          Same as Property.resolvePath(Path) but with a string path as argument.
 Property set(int index, Object value)
          Sets a child property value given its index.
 void setData(Object value)
          Sets the application-defined data to associated it with the receiver property.
 void setData(String key, Object value)
          Sets the application defined data associated with the receiver under the given key.
protected  void setDirtyFlags(int dirtyFlags)
           
 void setFlags(long flags)
           
 void setIsModified()
          THis method is public because of DataModelimpl which use it TODO after removing DataModelImpl make it protected
protected  void setIsMoved()
           
protected  void setIsNew()
           
protected  void setIsRemoved()
           
 void setReadOnly(boolean value)
          Set the read only flag
 void setValidating(boolean value)
          Set the validating flag
 void setValue(Object value)
          Sets this property value.
 void setValue(String path, Object value)
          Sets the value of the property resolved using the given path.
 int size()
          Get the count of the children properties.
 String toString()
           
 boolean validate(Serializable value)
          Validates the given normalized value.
 boolean validateType(Class<?> type)
          Validates the given value type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.nuxeo.ecm.core.api.model.Property
accept, add, add, add, get, get, getChildren, getDirtyChildren, getField, getName, getType, isContainer, isSameAs, set
 

Field Detail

IS_READONLY

public static final int IS_READONLY
Whether or not this property is read only.

See Also:
Constant Field Values

IS_VALIDATING

public static final int IS_VALIDATING
Whether or not this property is validating values when they are set.

See Also:
Constant Field Values

KEYED_DATA

public static final int KEYED_DATA
Whether ot not the data field contains keyed data.

See Also:
Constant Field Values

parent

protected final Property parent

flags

protected int flags

data

protected Object data
Constructor Detail

AbstractProperty

protected AbstractProperty(Property parent)

AbstractProperty

protected AbstractProperty(Property parent,
                           int flags)
Method Detail

internalSetValue

public abstract void internalSetValue(Serializable value)
                               throws PropertyException
Sets the given normalized value.

This applies only for nodes that physicaly store a value (that means non container nodes). Container nodes does nothing.

Parameters:
value -
Throws:
PropertyException

internalGetValue

public abstract Serializable internalGetValue()
                                       throws PropertyException
Throws:
PropertyException

init

public void init(Serializable value)
          throws PropertyException
Description copied from interface: Property
Intializes the property with the given normalized value.

The given value must be normalized - note that no check is done on that.

The phantom flag is unset by tthis operation.

This method should be used to initializate properties.

Specified by:
init in interface Property
Parameters:
value - the normalized value to set
Throws:
PropertyException

removePhantomFlag

public void removePhantomFlag()

set

public Property set(int index,
                    Object value)
             throws PropertyException,
                    UnsupportedOperationException
Description copied from interface: Property
Sets a child property value given its index. This method is required only for List properties.

If this method is not supported, an UnsupportedOperationException must be thrown.

This method will mark the child value as dirty for existing values and in the case of map properties it will mark phantom properties as new properties.

Specified by:
set in interface Property
value - the new value
Returns:
the property that was set
Throws:
PropertyException
UnsupportedOperationException

size

public int size()
Description copied from interface: Property
Get the count of the children properties. This includes phatom properties. So the returned size will be equal to the onbe returned by the property ComplexType.getFieldsCount()

Specified by:
size in interface Property
Returns:
the children properties count

iterator

public Iterator<Property> iterator()
Specified by:
iterator in interface Iterable<Property>

remove

public Serializable remove()
                    throws PropertyException
Description copied from interface: Property
Remove this property from the tree. This method is marking the property as dirty and setting it's value to null

Specified by:
remove in interface Property
Returns:
the old property value
Throws:
PropertyException

getParent

public Property getParent()
Description copied from interface: Property
Gets the property parent.

Specified by:
getParent in interface Property
Returns:
the property parent for sub properties or null for top level properties

getPath

public String getPath()
Description copied from interface: Property
Gets the path of this property relative to the owner document.

The path for top level properties is the same to the property name.

Specified by:
getPath in interface Property
Returns:
the path

collectPath

protected Path collectPath(Path path)

getSchema

public Schema getSchema()
Description copied from interface: Property
Gets the document schema defining the property tree from which the property belongs.

Specified by:
getSchema in interface Property
Returns:
the document schema owning the field corresponding to the property

isList

public boolean isList()
Description copied from interface: Property
Tests whether this property is of a list type.

Specified by:
isList in interface Property
Returns:
true if the property is of list type, false otherwise

isComplex

public boolean isComplex()
Description copied from interface: Property
Tests whether this property is of a map (complex) type.

Specified by:
isComplex in interface Property
Returns:
true if the property is of map type, false otherwise

isScalar

public boolean isScalar()
Description copied from interface: Property
Tests whether this property is of a scalar type.

Specified by:
isScalar in interface Property
Returns:
true if the property is of a scalar type, false otherwise

isNew

public boolean isNew()
Description copied from interface: Property
Tests if this property is new (just created but not yet stored).

A property is new when added to a collection. This is trhe typical state for a new property added to a list

Specified by:
isNew in interface Property
Returns:
true if this property is new, false otherwise

isRemoved

public boolean isRemoved()
Description copied from interface: Property
Tests if a property is flagged as removed. Removed properties are child property that were removed from their container.

Specified by:
isRemoved in interface Property
Returns:
if the property was removed, false otherwise

isMoved

public boolean isMoved()
Description copied from interface: Property
Tests if a property value was moved to another index in the parent list if any

Specified by:
isMoved in interface Property
Returns:
if the property was removed, false otherwise

isModified

public boolean isModified()
Description copied from interface: Property
Tests if a property value was modified

Specified by:
isModified in interface Property
Returns:
if the property was removed, false otherwise

isPhantom

public boolean isPhantom()
Description copied from interface: Property
Tests if the property is a phantom. This means it doesn't exists yet in the storage and it is not a new property. This is a paceholder for a property that is defined by the schema but was not yet set.

Specified by:
isPhantom in interface Property
Returns:
true if a phantom false otherwise

isDirty

public final boolean isDirty()
Description copied from interface: Property
Tests whether a property is dirty.

This tests whether or not a dirty flag is set on the property

Specified by:
isDirty in interface Property
Returns:
true if the property changed

setDirtyFlags

protected final void setDirtyFlags(int dirtyFlags)

appendDirtyFlags

protected final void appendDirtyFlags(int dirtyFlags)

isValidating

public boolean isValidating()
Description copied from interface: Property
Check whether this propertty is validating values when set

Specified by:
isValidating in interface Property
Returns:
true if validating false otherwise

isReadOnly

public boolean isReadOnly()
Description copied from interface: Property
Whether the property is read only

Specified by:
isReadOnly in interface Property
Returns:
true if read only false otherwise

setReadOnly

public void setReadOnly(boolean value)
Description copied from interface: Property
Set the read only flag

Specified by:
setReadOnly in interface Property
Parameters:
value - true to set this property read only false otherwise

setValidating

public void setValidating(boolean value)
Description copied from interface: Property
Set the validating flag

Specified by:
setValidating in interface Property
Parameters:
value - true to put validating on false otherwise

areFlagsSet

public final boolean areFlagsSet(long flags)

setFlags

public final void setFlags(long flags)

clearFlags

public final void clearFlags(long flags)

getDirtyFlags

public int getDirtyFlags()
Description copied from interface: Property
Get the dirty flags that are set on this property

Specified by:
getDirtyFlags in interface Property
Returns:
the dirty flags mask

clearDirtyFlags

public void clearDirtyFlags()
Description copied from interface: Property
Notify the property that its changes was stored so it can safely remove dirty flags.

Dirty flags are removed accordlying to the type of the modifications. This way if the property was REMOVED it becomes a PHANTOM otherwise all dirty flags are cleared.

This method should be used by storage implementors to notify the property it should reset its dirty flags. Note that clearing dirty flags is not probagated to the parent property or to children. You need to clear dirty flags explicitely for each property.

Specified by:
clearDirtyFlags in interface Property

setIsModified

public void setIsModified()
THis method is public because of DataModelimpl which use it TODO after removing DataModelImpl make it protected


setIsNew

protected void setIsNew()

setIsRemoved

protected void setIsRemoved()

setIsMoved

protected void setIsMoved()

getValue

public <T> T getValue(Class<T> type)
           throws PropertyException
Description copied from interface: Property
Gets the property value as the given type.

The value is converted using the registered converter to the given type.

If conversion is not supported a runtime exception will be triggered.

Specified by:
getValue in interface Property
Returns:
the property value or null if Property#isNull() return true
Throws:
PropertyException

setValue

public void setValue(Object value)
              throws PropertyException
Description copied from interface: Property
Sets this property value. The value will be first normalized and then set.

For complex or list properties the value will be set recursively (as a map or list value).

Specified by:
setValue in interface Property
Parameters:
value - the value to set
Throws:
PropertyException

setValue

public void setValue(String path,
                     Object value)
              throws PropertyException
Description copied from interface: Property
Sets the value of the property resolved using the given path.

This method is a shortcut for: resolvePath(path).setValue(value).

Specified by:
setValue in interface Property
Parameters:
path - the property path
value - the value
Throws:
PropertyNotFoundException - if the named peroperty doesn't exists
InvalidPropertyValueException - if the given value cannot be normalized
PropertyException

getValue

public <T> T getValue(Class<T> type,
                      String path)
           throws PropertyException
Description copied from interface: Property
Gets the value of the property resolved using the given path.

The value will be converted to the given type if possible, otherwise an exception will be thrown.

This method is a shortcut for: resolvePath(path).getValue(type).

Specified by:
getValue in interface Property
Type Parameters:
T - The type of the value to return
Parameters:
type - the class of the value
path - the java path of the property value
Returns:
the value
Throws:
PropertyNotFoundException
PropertyException

getValue

public Serializable getValue(String path)
                      throws PropertyException
Description copied from interface: Property
Gets the value of the property resolved using the given path.

This method is a shortcut for: resolvePath(path).getValue().

Specified by:
getValue in interface Property
Parameters:
path - the path to the property
Returns:
the property value
Throws:
PropertyNotFoundException
PropertyException

getValue

public Serializable getValue()
                      throws PropertyException
Description copied from interface: Property
Gets the property normalized value.

Normalized values are of the java type that correspond to the field type

Specified by:
getValue in interface Property
Returns:
the property value, or null if Property#isNull() return true
Throws:
PropertyException

moveTo

public void moveTo(int index)
            throws UnsupportedOperationException
Description copied from interface: Property
Moves a property position into the parent container list.

This method applies only for list item properties. The given index includes removed properties.

Specified by:
moveTo in interface Property
Throws:
UnsupportedOperationException - if the operation is not supported by the target property

getRoot

public DocumentPart getRoot()
Description copied from interface: Property
Gets the root property.

Specified by:
getRoot in interface Property
Returns:
the root property

resolvePath

public Property resolvePath(String path)
                     throws PropertyNotFoundException
Description copied from interface: Property
Same as Property.resolvePath(Path) but with a string path as argument. This is the same as calling resolvePath(new Path(path))

Specified by:
resolvePath in interface Property
Parameters:
path - the string path to resolve.
Returns:
the resolved property
Throws:
PropertyNotFoundException - if the path cannot be resolved

resolvePath

public Property resolvePath(Path path)
                     throws PropertyNotFoundException
Description copied from interface: Property
Resolves the given path relative to the current property and return the property if any is found otherwise throws an exception.

The path format is a subset of XPath. Thus, / is used as path element separator, [n] for list element indexes. Attribute separator '@' are not supported since all properties are assumed to be elements. Also you .. and . can be used as element names.

Example of paths:

Specified by:
resolvePath in interface Property
Parameters:
path - the path to resolve.
Returns:
the resolved property
Throws:
PropertyNotFoundException - if the path cannot be resolved

normalize

public Serializable normalize(Object value)
                       throws PropertyConversionException
Description copied from interface: Property
Normalizes the given value as dictated by the property type.

Normalized values are the ones that are used for transportation over the net and that are givenm to the storage implementation to be stored in the repository

Normalized values must be Serializable

If the given value is already normalized it will be returned back.

Specified by:
normalize in interface Property
Parameters:
value - the value to normalize acordying to the property type
Returns:
the normalized value
Throws:
PropertyConversionException

isNormalized

public boolean isNormalized(Object value)
Description copied from interface: Property
Checks if the given value is a normalized one. This means the value has a type that is normalized.

Null values are considered as normalized.

Specified by:
isNormalized in interface Property
Parameters:
value - the value to check
Returns:
true if the value is nriomalized false otherwise

convertTo

public <T> T convertTo(Serializable value,
                       Class<T> toType)
            throws PropertyConversionException
Description copied from interface: Property
Converts the given normalized value to the given type.

If the value has already the given type it will be returned back.

Specified by:
convertTo in interface Property
Parameters:
value - the normalized value to convert
toType - the conversion type
Returns:
the converted value
Throws:
PropertyConversionException - If the conversion cannot be made because of type incompatibilities

validateType

public boolean validateType(Class<?> type)
Description copied from interface: Property
Validates the given value type.

Tests if the given value type can be converted to a normalized type and thus a value of this type can be set to tthat property.

Specified by:
validateType in interface Property
Parameters:
type - the type to validate
Returns:
true if the type is valide false otherwise

validate

public boolean validate(Serializable value)
Description copied from interface: Property
Validates the given normalized value.

Only normalized values can be validated.

If the value is not validated, returns false.

Specified by:
validate in interface Property
Parameters:
value - the value to validate
Returns:
true if the value is valid, false otherwise
See Also:
Property.validateType(Class)

newInstance

public Object newInstance()
                   throws InstantiationException,
                          IllegalAccessException
Description copied from interface: Property
Creates a new and empty instance of a normalized value.

Empty is used in the sense of a vbalue that has not been initialized or can be considered as an emtpy value. For example for the String type the empty value will be the empty string ""

Specified by:
newInstance in interface Property
Returns:
the empty instance the empty instance
Throws:
InstantiationException
IllegalAccessException

toString

public String toString()
Overrides:
toString in class Object

getData

public Object getData()
application data impl. was copied from eclipse Widget class

Specified by:
getData in interface Property

getData

public Object getData(String key)
Description copied from interface: Property
Returns the application defined data associated with the receiver under the given key, or null if it has not been set.

You are free to set any data you want on properties but be aware to use Serializable objects if you want to serialize them along with the property

Specified by:
getData in interface Property

setData

public void setData(Object value)
Description copied from interface: Property
Sets the application-defined data to associated it with the receiver property.

The property data is reserved for the implementation and you must not directly set it. Data attached with properties must be Serializable objects if you want to serialize them along with the property

Specified by:
setData in interface Property

setData

public void setData(String key,
                    Object value)
Description copied from interface: Property
Sets the application defined data associated with the receiver under the given key.

The property data is reserved for the implementation and you must not directly set it. Data attached with properties must be Serializable objects if you want to serialize them along with the property

Specified by:
setData in interface Property

Nuxeo Enterprise Platform 5.1

Copyright ? 2007 Nuxeo SAS. All Rights Reserved.