use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class StringPropertyTest method testGetLong.
/**
* Tests conversion from String type to Long type.
*/
public void testGetLong() throws RepositoryException {
Value val = PropertyUtil.getValue(prop);
String str = val.getString();
try {
Long.parseLong(str);
long l = val.getLong();
assertEquals("Wrong conversion from String to Long.", new Long(l), Long.valueOf(str));
} catch (NumberFormatException nfe) {
try {
val.getLong();
fail("Conversion from malformed String to Long " + "should throw ValueFormatException.");
} catch (ValueFormatException vfe) {
// ok
}
}
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class PropertyImpl method setValue.
/**
* @see Property#setValue(javax.jcr.Value[])
*/
public void setValue(Value[] values) throws ValueFormatException, VersionException, LockException, RepositoryException {
checkIsWritable(true);
// assert equal types for all values entries
int valueType = PropertyType.UNDEFINED;
if (values != null) {
for (int i = 0; i < values.length; i++) {
if (values[i] == null) {
// skip null values as those will be purged later
continue;
}
if (valueType == PropertyType.UNDEFINED) {
valueType = values[i].getType();
} else if (valueType != values[i].getType()) {
String msg = "Inhomogeneous type of values (" + safeGetJCRPath() + ")";
log.debug(msg);
throw new ValueFormatException(msg);
}
}
}
int targetType = getDefinition().getRequiredType();
if (targetType == PropertyType.UNDEFINED) {
targetType = (valueType == PropertyType.UNDEFINED) ? PropertyType.STRING : valueType;
}
// convert to internal values of correct type
QValue[] qValues = null;
if (values != null) {
Value[] vs = ValueHelper.convert(values, targetType, session.getValueFactory());
qValues = ValueFormat.getQValues(vs, session.getNamePathResolver(), session.getQValueFactory());
}
setInternalValues(qValues, targetType);
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class PropertyImpl method getProperty.
/**
* @see Property#getProperty()
*/
public Property getProperty() throws RepositoryException {
Value value = getValue();
Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory());
String path = pathValue.getString();
boolean absolute;
try {
Path p = session.getPathResolver().getQPath(path);
absolute = p.isAbsolute();
} catch (RepositoryException e) {
throw new ValueFormatException("Property value cannot be converted to a PATH");
}
try {
return (absolute) ? session.getProperty(path) : getParent().getProperty(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class MultiValuedPropertyTest method testGetLengthFromMultivalued.
/**
* Tests if Property.getLength() fails for multivalued property.
*/
public void testGetLengthFromMultivalued() throws RepositoryException, NotExecutableException {
Property prop = PropertyUtil.searchMultivalProp(testRootNode);
if (prop == null) {
throw new NotExecutableException("No multivalued property found.");
}
try {
prop.getLength();
fail("Property.getLength() called on a multivalue property must fail (ValueFormatException).");
} catch (ValueFormatException vfe) {
// ok
}
}
use of javax.jcr.ValueFormatException in project jackrabbit by apache.
the class MultiValuedPropertyTest method testGetDoubleFromMultivalued.
/**
* Tests if Property.getDouble() fails for multivalued properties.
*
* @throws RepositoryException
* @throws NotExecutableException
*/
public void testGetDoubleFromMultivalued() throws RepositoryException, NotExecutableException {
Property prop = PropertyUtil.searchMultivalProp(testRootNode);
if (prop == null) {
throw new NotExecutableException("No multivalued property found.");
} else {
try {
prop.getDouble();
fail("Property.getDouble() must fail with ValueFormatException for any multivalued property.");
} catch (ValueFormatException vfe) {
// ok
}
}
}
Aggregations