JCR_ACTIVITY, JCR_AUTOCREATED, JCR_BASE_VERSION, JCR_CHILD_VERSION_HISTORY, JCR_CONFIGURATION, JCR_CONTENT, JCR_COPIED_FROM, JCR_CREATED, JCR_CREATED_BY, JCR_CURRENT_LIFECYCLE_STATE, JCR_DATA, JCR_DEFAULT_PRIMARY_TYPE, JCR_DEFAULT_VALUES, JCR_DESCRIPTION, JCR_ENCODING, JCR_FROZEN_MIXIN_TYPES, JCR_FROZEN_PRIMARY_TYPE, JCR_FROZEN_UUID, JCR_HAS_ORDERABLE_CHILD_NODES, JCR_HOST, JCR_ID, JCR_IS_ABSTRACT, JCR_IS_CHECKED_OUT, JCR_IS_MIXIN, JCR_LANGUAGE, JCR_LAST_MODIFIED, JCR_LAST_MODIFIED_BY, JCR_LIFECYCLE_POLICY, JCR_LOCK_IS_DEEP, JCR_LOCK_OWNER, JCR_MANDATORY, JCR_MERGE_FAILED, JCR_MIMETYPE, JCR_MIXIN_TYPES, JCR_MULTIPLE, JCR_NAME, JCR_NODE_TYPE_NAME, JCR_ON_PARENT_VERSION, JCR_PATH, JCR_PORT, JCR_PREDECESSORS, JCR_PRIMARY_ITEM_NAME, JCR_PRIMARY_TYPE, JCR_PROTECTED, JCR_PROTOCOL, JCR_REPOSITORY, JCR_REQUIRED_PRIMARY_TYPES, JCR_REQUIRED_TYPE, JCR_ROOT, JCR_SAME_NAME_SIBLINGS, JCR_STATEMENT, JCR_SUCCESSORS, JCR_SUPERTYPES, JCR_TITLE, JCR_UUID, JCR_VALUE_CONSTRAINTS, JCR_VERSION_HISTORY, JCR_VERSIONABLE_UUID, JCR_WORKSPACE| Modifier and Type | Method and Description |
|---|---|
<T> T |
getAs(Class<T> type)
Converts the value(s) of the property (if possible) to the specified type.
|
<T> T |
getAs(Class<T> type,
int index)
Converts the value of the property located at the given index to the specified type.
|
getBinary, getBoolean, getDate, getDecimal, getDefinition, getDouble, getLength, getLengths, getLong, getNode, getProperty, getStream, getString, getType, getValue, getValues, isMultiple, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueaccept, getAncestor, getDepth, getName, getParent, getPath, getSession, isModified, isNew, isNode, isSame, refresh, remove, save<T> T getAs(Class<T> type) throws ValueFormatException, RepositoryException
StringLongDoubleBooleanBigDecimalCalendarDateDateTimeBinaryBinaryInputStreamNodeNodeIteratorString[]Long[]Double[]Boolean[]BigDecimal[]Calendar[]Date[]DateTime[]Binary[]Binary[]InputStream[]Node[]NodeIterator
For single-valued properties, this method attempts to convert the actual value into the specified type.
For multi-valued properties, this method attempts to convert the actual values into an array of the specified
type; the only exception to this rule is that in the
case of multi-valued reference properties a simple NodeIterator type is expected:
getAs(NodeIterator.class).
For example, the following shows how to obtain the value of a single-valued property as a String value:
Property prop = ...
String value = prop.getAs(String.class);
If the property is multi-valued, then the values can be obtained by passing in the desired array type:
String[] values = prop.getAs(String[].class);
This example will always work, since all property values can be converted to a String.
The following attempts to convert all values to Date instances:
Date[] values = prop.getAs(Date[].class);
Finally, a single- or multi-valued property whose value(s) are references can easily be obtained as a
NodeIterator, which can represent one or multiple Node instances:
NodeIterator iter = prop.getAs(NodeIterator.class);
T - the type-argument for typetype - a Class representing the type to which to convert the values of the property; may not be null
and is expected to be one of the above types.ValueFormatException - if the conversion cannot be performed. This can occur for a number of reasons: type
incompatibility or passing in an array type for a single value property or passing in a non-array type for a multi-valued
property.RepositoryException - if anything else unexpected fails when attempting to perform the conversion.<T> T getAs(Class<T> type, int index) throws ValueFormatException, IndexOutOfBoundsException, RepositoryException
index property is '0', or multi-valued properties. Array types should not be supplied
as the first parameter.
For example, this is a property usage of this method to obtain the value of a single-valued property or
the first value of a multi-valued property as a long:
Long value = prop.getAs(Long.class, 0)
Likewise, the following usage will only work for multi-valued properties, since only a multi-valued property
can have 2 or more values:
Long value = prop.getAs(Long.class, 1)
T - the type-argument for typetype - a Class representing the type to which to convert the value of the property; may not be null
and is expected to be one of the types from getAs(Class).index - the position of the property in the array of values.index converted to the given type.ValueFormatException - if the conversion cannot be performed or if this method is called for single-valued properties.IndexOutOfBoundsException - if index is outside the array of values for the property.RepositoryException - if anything unexpected fails.Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.