public abstract class AbstractProperty extends Object implements Property
Modifier and Type | Field and Description |
---|---|
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 or not the data field contains keyed data.
|
DIRTY_MASK, IS_DIRTY, IS_MODIFIED, IS_MOVED, IS_NEW, IS_PHANTOM, IS_REMOVED, NONE
Modifier and Type | Method and Description |
---|---|
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) |
<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.
|
Serializable |
getValueForWrite()
Gets the property normalized value for write.
|
void |
init(Serializable value)
Initializes 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()
Checks whether this property 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()
Removes 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. |
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.
|
void |
setFlags(long flags) |
void |
setIsModified()
This method is public because of DataModelImpl which use it.
|
void |
setReadOnly(boolean value)
Sets the read only flag.
|
void |
setValidating(boolean value)
Sets the validating flag.
|
void |
setValue(int index,
Object value)
Sets a child property value given its index.
|
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.
|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
accept, addEmpty, addValue, addValue, get, get, getChildren, getDirtyChildren, getField, getName, getType, isContainer, isSameAs
public static final int IS_READONLY
public static final int IS_VALIDATING
public static final int KEYED_DATA
public abstract void internalSetValue(Serializable value) throws PropertyException
This applies only for nodes that physically store a value (that means non container nodes). Container nodes does nothing.
value
- PropertyException
public abstract Serializable internalGetValue() throws PropertyException
PropertyException
public void init(Serializable value) throws PropertyException
Property
The given value must be normalized - note that no check is done on that.
The phantom flag is unset by this operation.
This method should be used to initialize properties.
init
in interface Property
value
- the normalized value to setPropertyException
public void removePhantomFlag()
public void setValue(int index, Object value) throws PropertyException
Property
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.
setValue
in interface Property
value
- the new valuePropertyException
public int size()
Property
ComplexType.getFieldsCount()
.public Serializable remove() throws PropertyException
Property
This method marks the property as dirty and sets its value to null.
remove
in interface Property
PropertyException
public Property getParent()
Property
public String getPath()
Property
The path for top level properties is the same to the property name.
public Schema getSchema()
Property
public boolean isList()
Property
public boolean isComplex()
Property
public boolean isScalar()
Property
public boolean isNew()
Property
A property is new when added to a collection. This is the typical state for a new property added to a list
public boolean isRemoved()
Property
public boolean isMoved()
Property
public boolean isModified()
Property
isModified
in interface Property
public boolean isPhantom()
Property
public final boolean isDirty()
Property
This tests whether or not a dirty flag is set on the property.
public boolean isValidating()
Property
isValidating
in interface Property
public boolean isReadOnly()
Property
isReadOnly
in interface Property
public void setReadOnly(boolean value)
Property
setReadOnly
in interface Property
value
- true to set this property read only false otherwisepublic void setValidating(boolean value)
Property
setValidating
in interface Property
value
- true to put validating on false otherwisepublic final boolean areFlagsSet(long flags)
public final void setFlags(long flags)
public final void clearFlags(long flags)
public int getDirtyFlags()
Property
getDirtyFlags
in interface Property
public void clearDirtyFlags()
Property
Dirty flags are removed according 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 propagated to the parent property or to children. You need to clear dirty flags explicitly for each property.
clearDirtyFlags
in interface Property
public void setIsModified()
TODO after removing DataModelImpl make it protected.
public <T> T getValue(Class<T> type) throws PropertyException
Property
The value is converted using the registered converter to the given type.
If conversion is not supported a runtime exception will be triggered.
getValue
in interface Property
PropertyException
public void setValue(Object value) throws PropertyException
Property
For complex or list properties the value will be set recursively (as a map or list value).
setValue
in interface Property
value
- the value to setPropertyException
public void setValue(String path, Object value) throws PropertyException
Property
This method is a shortcut for:
resolvePath(path).setValue(value)
.
setValue
in interface Property
path
- the property pathvalue
- the valuePropertyException
public <T> T getValue(Class<T> type, String path) throws PropertyException
Property
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)
.
getValue
in interface Property
T
- The type of the value to returntype
- the class of the valuepath
- the java path of the property valuePropertyException
public Serializable getValue(String path) throws PropertyException
Property
This method is a shortcut for: resolvePath(path).getValue()
.
getValue
in interface Property
path
- the path to the propertyPropertyException
public Serializable getValue() throws PropertyException
Property
Normalized values are of the java type that correspond to the field type.
getValue
in interface Property
PropertyException
public Serializable getValueForWrite() throws PropertyException
Property
Can be different fropm Property.getValue()
in cases where the property
adapts the value it is given to store.
getValueForWrite
in interface Property
PropertyException
public void moveTo(int index)
Property
This method applies only for list item properties. The given index includes removed properties.
public DocumentPart getRoot()
Property
public Property resolvePath(String path) throws PropertyNotFoundException
Property
Property.resolvePath(Path)
but with a string path as
argument. This is the same as calling resolvePath(new Path(path))
.resolvePath
in interface Property
path
- the string path to resolve.PropertyNotFoundException
- if the path cannot be resolvedpublic Property resolvePath(Path path) throws PropertyNotFoundException
Property
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:
dc:title
attachments/item[2]/mimeType
../dc:title
resolvePath
in interface Property
path
- the path to resolve.PropertyNotFoundException
- if the path cannot be resolvedpublic Serializable normalize(Object value) throws PropertyConversionException
Property
Normalized values are the ones that are used for transportation over the net and that are given 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.
normalize
in interface Property
value
- the value to normalize according to the property typePropertyConversionException
public boolean isNormalized(Object value)
Property
Null values are considered as normalized.
isNormalized
in interface Property
value
- the value to checkpublic <T> T convertTo(Serializable value, Class<T> toType) throws PropertyConversionException
Property
If the value has already the given type it will be returned back.
convertTo
in interface Property
value
- the normalized value to converttoType
- the conversion typePropertyConversionException
- if the conversion cannot be made
because of type incompatibilitiespublic boolean validateType(Class<?> type)
Property
Tests if the given value type can be converted to a normalized type and thus a value of this type can be set to that property.
validateType
in interface Property
type
- the type to validatepublic boolean validate(Serializable value)
Property
Only normalized values can be validated.
If the value is not validated, returns false.
validate
in interface Property
value
- the value to validateProperty.validateType(Class)
public Object newInstance()
Property
Empty is used in the sense of a value that has not been initialized or
can be considered as an empty value. For example for the String
type the empty value will be the empty string ""
newInstance
in interface Property
public Object getData()
public Object getData(String key)
Property
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.
public void setData(Object value)
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
public void setData(String key, Object value)
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.
Copyright © 2014 Nuxeo SA. All Rights Reserved.