public abstract class AbstractProperty extends Object implements Property
Modifier and Type | Field and Description |
---|---|
protected Property |
deprecatedFallback |
protected int |
flags |
boolean |
forceDirty
for SimpleDocumentModel uses
|
static int |
IS_READONLY
Whether or not this property is read only.
|
protected Boolean |
isDeprecated |
protected static Pattern |
NON_CANON_INDEX |
Property |
parent |
DIRTY_MASK, IS_DIRTY, IS_MODIFIED, IS_MOVED, IS_NEW, IS_PHANTOM, IS_REMOVED, NONE
Modifier | Constructor and Description |
---|---|
protected |
AbstractProperty(Property parent) |
protected |
AbstractProperty(Property parent,
int flags) |
Modifier and Type | Method and Description |
---|---|
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) |
protected Property |
computeRemovedProperty(String name)
Returns the
RemovedProperty if it is a removed property or null otherwise. |
<T> T |
convertTo(Serializable value,
Class<T> toType)
Converts the given normalized value to the given type.
|
protected Serializable |
getDefaultValue() |
protected AbstractProperty |
getDeprecatedParent() |
int |
getDirtyFlags()
Get the dirty flags that are set on this property.
|
PropertyObjectResolver |
getObjectResolver() |
Property |
getParent()
Gets the property parent.
|
String |
getPath()
Deprecated.
|
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.
|
protected Serializable |
getValueDeprecation() |
Serializable |
getValueForWrite()
Gets the property normalized value for write.
|
String |
getXPath()
Gets the xpath of this property.
|
protected void |
getXPath(StringBuilder buf) |
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.
|
protected boolean |
isDeprecated() |
boolean |
isDirty()
Tests whether a property is dirty.
|
boolean |
isForceDirty()
only for SimpleDocumentModel
|
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.
|
protected boolean |
isSameValue(Serializable value1,
Serializable value2) |
boolean |
isScalar()
Tests whether this property is of a scalar type.
|
Iterator<Property> |
iterator() |
void |
moveTo(int index)
Moves a property position into the parent container list.
|
protected StringBuilder |
newDeprecatedMessage() |
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. |
protected void |
setDirtyFlags(int dirtyFlags) |
void |
setFlags(long flags) |
void |
setForceDirty(boolean forceDirty)
only for SimpleDocumentModel
|
void |
setIsModified()
This method is public because of DataModelImpl which use it.
|
protected void |
setIsMoved() |
protected void |
setIsNew() |
protected void |
setIsRemoved() |
void |
setReadOnly(boolean value)
Sets the read only 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.
|
protected void |
setValueDeprecation(Object value,
boolean setFallback)
If this property is deprecated and has a fallback, set value to fallback.
|
int |
size()
Get the count of the children properties.
|
String |
toString() |
boolean |
validateType(Class<?> type)
Validates the given value type.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
accept, addEmpty, addValue, addValue, get, get, getChildren, getDirtyChildren, getField, getName, getType, isContainer, isSameAs
forEach, spliterator
protected static final Pattern NON_CANON_INDEX
public static final int IS_READONLY
public boolean forceDirty
protected int flags
protected Boolean isDeprecated
protected Property deprecatedFallback
protected AbstractProperty(Property parent)
protected AbstractProperty(Property parent, int flags)
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 getXPath()
Property
The xpath is of the form pref:foo/mylist/123/elem
, of note:
/
foo/bar[123]/baz
but the new syntax foo/123/baz
protected void getXPath(StringBuilder buf)
@Deprecated public String getPath()
Property
The path for top level properties is the same to the property name.
NOTE the path returned contains an initial /
and expresses list indexes using an old syntax
protected Path collectPath(Path path)
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.
protected final void setDirtyFlags(int dirtyFlags)
protected final void appendDirtyFlags(int dirtyFlags)
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 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.
protected void setIsNew()
protected void setIsRemoved()
protected void setIsMoved()
protected boolean isDeprecated()
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
protected void setValueDeprecation(Object value, boolean setFallback) throws PropertyException
PropertyException
protected boolean isSameValue(Serializable value1, Serializable value2)
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
PropertyException
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
PropertyException
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
protected Serializable getValueDeprecation()
protected StringBuilder newDeprecatedMessage()
protected AbstractProperty getDeprecatedParent()
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
protected Serializable getDefaultValue()
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 resolvedprotected Property computeRemovedProperty(String name)
RemovedProperty
if it is a removed property or null otherwise.public 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 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 PropertyObjectResolver getObjectResolver()
getObjectResolver
in interface Property
PropertyObjectResolver
to manage this property reference to external entities, null if this
property's type has no resolver.public boolean isForceDirty()
Property
isForceDirty
in interface Property
public void setForceDirty(boolean forceDirty)
Property
setForceDirty
in interface Property
Copyright © 2018 Nuxeo. All rights reserved.