* {@inheritDoc}
*
* @see javax.jcr.Session#getValueFactory()
*/
public ValueFactory getValueFactory() {
final ValueFactories valueFactories = executionContext.getValueFactories();
final SessionCache sessionCache = this.cache;
return new ValueFactory() {
public Value createValue( String value,
int propertyType ) throws ValueFormatException {
return new JcrValue(valueFactories, sessionCache, propertyType, convertValueToType(value, propertyType));
}
public Value createValue( Node value ) throws RepositoryException {
if (!value.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(JcrSession.this.namespaces()))) {
throw new RepositoryException(JcrI18n.nodeNotReferenceable.text());
}
String uuid = valueFactories.getStringFactory().create(value.getUUID());
return new JcrValue(valueFactories, sessionCache, PropertyType.REFERENCE, uuid);
}
public Value createValue( InputStream value ) {
Binary binary = valueFactories.getBinaryFactory().create(value);
return new JcrValue(valueFactories, sessionCache, PropertyType.BINARY, binary);
}
public Value createValue( Calendar value ) {
DateTime dateTime = valueFactories.getDateFactory().create(value);
return new JcrValue(valueFactories, sessionCache, PropertyType.DATE, dateTime);
}
public Value createValue( boolean value ) {
return new JcrValue(valueFactories, sessionCache, PropertyType.BOOLEAN, value);
}
public Value createValue( double value ) {
return new JcrValue(valueFactories, sessionCache, PropertyType.DOUBLE, value);
}
public Value createValue( long value ) {
return new JcrValue(valueFactories, sessionCache, PropertyType.LONG, value);
}
public Value createValue( String value ) {
return new JcrValue(valueFactories, sessionCache, PropertyType.STRING, value);
}
Object convertValueToType( Object value,
int toType ) throws ValueFormatException {
switch (toType) {
case PropertyType.BOOLEAN:
try {
return valueFactories.getBooleanFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.DATE:
try {
return valueFactories.getDateFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.NAME:
try {
return valueFactories.getNameFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.PATH:
try {
return valueFactories.getPathFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.REFERENCE:
try {
return valueFactories.getReferenceFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.DOUBLE:
try {
return valueFactories.getDoubleFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.LONG:
try {
return valueFactories.getLongFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
// Anything can be converted to these types
case PropertyType.BINARY:
try {
return valueFactories.getBinaryFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.STRING:
try {
return valueFactories.getStringFactory().create(value);
} catch (org.jboss.dna.graph.property.ValueFormatException vfe) {
throw new ValueFormatException(vfe);
}
case PropertyType.UNDEFINED:
return value;