Interface Value
- All Known Subinterfaces:
JackrabbitValue
- All Known Implementing Classes:
BaseValue
,BinaryValue
,BooleanValue
,DateValue
,DecimalValue
,DoubleValue
,ErrorValue
,LongValue
,NameValue
,PathValue
,QValueValue
,ReferenceValue
,StringValue
,URIValue
,WeakReferenceValue
Value
object can
be used without knowing the actual property type (STRING
,
DOUBLE
, BINARY
etc.).
The Binary
interface and its related methods in
Property
, Value
and ValueFactory
replace the deprecated Value.getStream
and
Property.getStream
methods from JCR 1.0. However, though
getStream
has been deprecated, for reasons of backward
compatibility its behavior must still conform to the following rules:
- A
Value
object can be read using type-specificget
methods. These methods are divided into two groups:- The non-stream
get
methodsgetString()
,getBinary()
,getDate()
,getDecimal()
,getLong()
,getDouble()
andgetBoolean()
. -
getStream()
.
- The non-stream
- Once a
Value
object has been read once usinggetStream()
, all subsequent calls togetStream()
will return the sameStream
object. This may mean, for example, that the stream returned is fully or partially consumed. In order to get a fresh stream theValue
object must be reacquired viaProperty.getValue()
orProperty.getValues()
. - Once a
Value
object has been read once usinggetStream()
, any subsequent call to any of the non-streamget
methods will throw anIllegalStateException
. In order to successfully invoke a non-streamget
method, theValue
must be reacquired viaProperty.getValue()
orProperty.getValues()
. - Once a
Value
object has been read once using a non-stream get method, any subsequent call togetStream()
will throw anIllegalStateException
. In order to successfully invokegetStream()
, theValue
must be reacquired viaProperty.getValue()
orProperty.getValues()
.
Two Value
instances, v1
and v2
, are
considered equal if and only if:
v1.getType() == v2.getType()
, and,v1.getString().equals(v2.getString())
Value
instances by converting them
to string form may not be practical in some cases (for example, if the values
are very large binaries). Consequently, the above is intended as a normative
definition of Value
equality but not as a procedural test of
equality. It is assumed that implementations will have efficient means of
determining equality that conform with the above definition.
An implementation is only required to support equality comparisons on
Value
instances that were acquired from the same
Session
and whose contents have not been read. The equality
comparison must not change the state of the Value
instances even
though the getString()
method in the above definition implies a
state change.
-
Method Summary
Modifier and TypeMethodDescriptionReturns aBinary
representation of this value.boolean
Returns aBoolean
representation of this value.getDate()
Returns aCalendar
representation of this value.Returns aBigDecimal
representation of this value.double
Returns adouble
representation of this value.long
getLong()
Returns along
representation of this value.Deprecated.Returns aString
representation of this value.int
getType()
Returns thetype
of thisValue
.
-
Method Details
-
getString
Returns aString
representation of this value.- Returns:
- A
String
representation of the value of this property. - Throws:
ValueFormatException
- if conversion to aString
is not possible.IllegalStateException
- ifgetStream
has previously been called on thisValue
instance. In this case a newValue
instance must be acquired in order to successfully call this method.RepositoryException
- if another error occurs.
-
getStream
Deprecated.As of JCR 2.0,getBinary()
should be used instead.Returns anInputStream
representation of this value. Uses the standard conversion to binary (see JCR specification).It is the responsibility of the caller to close the returned
InputStream
.- Returns:
- An
InputStream
representation of this value. - Throws:
RepositoryException
- if an error occurs.
-
getBinary
Returns aBinary
representation of this value. TheBinary
object in turn provides methods to access the binary data itself. Uses the standard conversion to binary (see JCR specification).- Returns:
- A
Binary
representation of this value. - Throws:
RepositoryException
- if an error occurs.- Since:
- JCR 2.0
-
getLong
Returns along
representation of this value.- Returns:
- A
long
representation of this value. - Throws:
ValueFormatException
- if conversion to anlong
is not possible.RepositoryException
- if another error occurs.
-
getDouble
Returns adouble
representation of this value.- Returns:
- A
double
representation of this value. - Throws:
ValueFormatException
- if conversion to adouble
is not possible.RepositoryException
- if another error occurs.
-
getDecimal
Returns aBigDecimal
representation of this value.- Returns:
- A
BigDecimal
representation of this value. - Throws:
ValueFormatException
- if conversion to aBigDecimal
is not possible.RepositoryException
- if another error occurs.- Since:
- JCR 2.0
-
getDate
Returns aCalendar
representation of this value.The object returned is a copy of the stored value, so changes to it are not reflected in internal storage.
- Returns:
- A
Calendar
representation of this value. - Throws:
ValueFormatException
- if conversion to aCalendar
is not possible.RepositoryException
- if another error occurs.
-
getBoolean
Returns aBoolean
representation of this value.- Returns:
- A
Boolean
representation of this value. - Throws:
ValueFormatException
- if conversion to aBoolean
is not possible.RepositoryException
- if another error occurs.
-
getType
int getType()Returns thetype
of thisValue
. One of:PropertyType.STRING
PropertyType.DATE
PropertyType.BINARY
PropertyType.DOUBLE
PropertyType.DECIMAL
PropertyType.LONG
PropertyType.BOOLEAN
PropertyType.NAME
PropertyType.PATH
PropertyType.REFERENCE
PropertyType.WEAKREFERENCE
PropertyType.URI
.PropertyType
The type returned is that which was set at property creation.
- Returns:
- an int
-
getBinary()
should be used instead.