Search in sources :

Example 86 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class DecimalValue method getDate.

/**
 * The decimal is converted to a long and interpreted as the number of
 * milliseconds since 00:00 (UTC) 1 January 1970 (1970-01-01T00:00:00.000Z).
 * If the resulting value is out of range for a date,
 * a {@link ValueFormatException} is thrown.
 */
@Override
public Calendar getDate() throws ValueFormatException {
    if (value.compareTo(MIN_DATE) >= 0 && value.compareTo(MAX_DATE) <= 0) {
        Calendar date = Calendar.getInstance();
        date.setTimeInMillis(getLong());
        return date;
    } else {
        throw new ValueFormatException("Decimal value is outside the date range: " + value);
    }
}
Also used : Calendar(java.util.Calendar) ValueFormatException(javax.jcr.ValueFormatException)

Example 87 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class PropertyReadMethodsTest method testGetNode.

/**
 * Tests if Property.getNode() fails with ValueFormatException for
 * multivalued properties.
 *
 * @throws RepositoryException
 * @throws NotExecutableException
 */
public void testGetNode() throws RepositoryException, NotExecutableException {
    Property prop = PropertyUtil.searchMultivalProp(testRootNode);
    if (prop == null) {
        throw new NotExecutableException("Test Property.getNode is throwing a " + "ValueFormaException not executable in case of a multivalued property.");
    } else {
        try {
            prop.getNode();
            fail("Property.getNode should throw a ValueFormatException in case of " + "a multivalued property.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 88 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class PropertyReadMethodsTest method testGetValue.

/**
 * Tests failure of Property.getValue() method for a multivalue property.
 */
public void testGetValue() throws RepositoryException, NotExecutableException {
    Property multiValProp = PropertyUtil.searchMultivalProp(testRootNode);
    if (multiValProp != null) {
        try {
            multiValProp.getValue();
            fail("Property.getValue() called on a multivalue property " + "should throw a ValueFormatException.");
        } catch (ValueFormatException vfe) {
        // ok
        }
    } else {
        throw new NotExecutableException();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 89 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class ReferencePropertyTest method testGetDouble.

/**
 * Tests failure from Reference type to Double type.
 */
public void testGetDouble() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getDouble();
        fail("Conversion from a Reference value to a Double value " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Example 90 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit by apache.

the class ReferencePropertyTest method testGetLong.

/**
 * Tests failure of conversion from Reference type to Long type.
 */
public void testGetLong() throws RepositoryException {
    try {
        Value val = PropertyUtil.getValue(prop);
        val.getLong();
        fail("Conversion from a Reference value to a Long value " + "should throw a ValueFormatException.");
    } catch (ValueFormatException vfe) {
    // ok
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException)

Aggregations

ValueFormatException (javax.jcr.ValueFormatException)106 Value (javax.jcr.Value)53 Property (javax.jcr.Property)34 RepositoryException (javax.jcr.RepositoryException)16 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 Calendar (java.util.Calendar)10 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 Node (javax.jcr.Node)10 QValue (org.apache.jackrabbit.spi.QValue)10 PathNotFoundException (javax.jcr.PathNotFoundException)6 Name (org.apache.jackrabbit.spi.Name)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)5 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 InputStream (java.io.InputStream)4 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 Path (org.apache.jackrabbit.spi.Path)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3