public static < T > T readValue ( Value value , Class < T > type ) throws RepositoryException { try { if ( null == value ) return null ; if ( type . isAssignableFrom ( value . getClass ( ) ) ) return type . cast ( value ) ; if ( Long . class . equals ( type ) ) return type . cast ( value . getLong ( ) ) ; if ( Integer . class . equals ( type ) ) return type . cast ( value . getLong ( ) ) ; if ( Short . class . equals ( type ) ) return type . cast ( ( short ) value . getLong ( ) ) ; if ( Byte . class . equals ( type ) ) return type . cast ( ( byte ) value . getLong ( ) ) ; if ( Float . class . equals ( type ) ) return type . cast ( ( float ) value . getLong ( ) ) ; if ( Double . class . equals ( type ) ) return type . cast ( value . getDouble ( ) ) ; if ( String . class . equals ( type ) ) return type . cast ( value . getString ( ) ) ; if ( Boolean . class . equals ( type ) ) return type . cast ( value . getBoolean ( ) ) ; if ( java . net . URI . class . equals ( type ) ) return type . cast ( new URI ( value . getString ( ) ) ) ; if ( java . net . URL . class . equals ( type ) ) return type . cast ( new URL ( value . getString ( ) ) ) ; if ( Date . class . equals ( type ) ) return type . cast ( value . getDate ( ) . getTime ( ) ) ; if ( Calendar . class . equals ( type ) ) return type . cast ( value . getDate ( ) ) ; if ( BigDecimal . class . equals ( type ) ) return type . cast ( value . getDecimal ( ) ) ; if ( Binary . class . equals ( type ) ) return type . cast ( value . getBinary ( ) ) ; if ( InputStream . class . equals ( type ) ) return type . cast ( value . getBinary ( ) . getStream ( ) ) ; Class defaultType = DEFAULT_PROPERTY_TYPES . get ( value . getType ( ) ) ; if ( null != defaultType && type . isAssignableFrom ( defaultType ) ) return type . cast ( readValue ( value , defaultType ) ) ; throw new IllegalArgumentException ( "Type " + type + " not supported yet." ) ; } catch ( URISyntaxException | MalformedURLException | RuntimeException e ) { throw new ValueFormatException ( "Can't convert to " + type , e ) ; } }
Reads the value of a property as the given type .