7.1.5.3 Creating Value Objects

In order to use methods that accept a Value object the application needs a way to produce such objects. This is done by using the methods of the ValueFactory object, which is acquired through Session.getValueFactory() (see 7.1 Writing Repository Content). ValueFactory provides the following methods:

javax.jcr.
ValueFactory

Value

createValue(String value)

Returns a Value object of PropertyType.STRING with the specified value.

Value

createValue(String value, int type)

Returns a Value object of the PropertyType specified by type with the specified value.

A ValueFormatException is thrown if the specified value cannot be converted to the specified type.

Value

createValue(long value)

Returns a Value object of PropertyType.LONG with the specified value.

Value

createValue(double value)

Returns a Value object of PropertyType.DOUBLE with the specified value.

Value

createValue(boolean value)

Returns a Value object of PropertyType.BOOLEAN with the specified value.

Value

createValue(Calendar value)

Returns a Value object of PropertyType.DATE with the specified value.

Value

createValue(InputStream value)

Returns a Value object of PropertyType.BINARY with a value consisting of the content of the specified InputStream.

Value

createValue(Node value)

Returns a Value object of PropertyType.REFERENCE that holds the UUID of the specified Node. This Value object can then be used to set a property that will be a reference to that Node.

A RepositoryException is thrown if the specified Node is not referenceable, the current Session is no longer active, or another error occurs.