protected Object convertFromTimestampMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } if ( !( value instanceof Timestamp ) ) { handleConversionError( "Error. Expecting value of type Timestamp. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } Date dateValue; try { switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_STRING: dateValue = new Date( ( (Timestamp) value ).getTime() ); return datePattern.format( dateValue ); case ValueMetaInterface.TYPE_INTEGER: return ( (Timestamp) value ).getTime(); case ValueMetaInterface.TYPE_TIMESTAMP: return new Timestamp( ( (Timestamp) value ).getTime() ); case ValueMetaInterface.TYPE_DATE: return new Date( ( (Timestamp) value ).getTime() ); default: throwBadConversionCombination( ValueMetaInterface.TYPE_NUMBER, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_TIMESTAMP, targetValueMetaType, value, e ); } return value; }
protected Object convertFromDateMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } // value is expected to be of type Date if ( !( value instanceof Date ) ) { handleConversionError( "Error. Expecting value of type Date. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } try { Date dateValue = (Date) value; switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_INTEGER: return dateValue.getTime(); case ValueMetaInterface.TYPE_STRING: return datePattern.format( dateValue ); case ValueMetaInterface.TYPE_TIMESTAMP: return new Timestamp( dateValue.getTime() ); case ValueMetaInterface.TYPE_DATE: return new Date( dateValue.getTime() ); default: throwBadConversionCombination( ValueMetaInterface.TYPE_DATE, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_DATE, targetValueMetaType, value, e ); } return null; }
protected Object convertFromBooleanMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } if ( !( value instanceof Boolean ) ) { handleConversionError( "Error. Expecting value of type Boolean. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } try { switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_STRING: return Boolean.toString( (Boolean) value ); case ValueMetaInterface.TYPE_BOOLEAN: return new Boolean( (Boolean) value ); default: throwBadConversionCombination( ValueMetaInterface.TYPE_BOOLEAN, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_BOOLEAN, targetValueMetaType, value, e ); } return null; }
protected Object convertFromInetMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } if ( !( value instanceof InetAddress ) ) { handleConversionError( "Error. Expecting value of type InetAddress. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } InetAddress origInetAddress = (InetAddress) value; try { switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_INET: try { return InetAddress.getByName( origInetAddress.getHostAddress() ); } catch ( UnknownHostException e ) { return null; } case ValueMetaInterface.TYPE_STRING: return origInetAddress.getHostAddress(); default: throwBadConversionCombination( ValueMetaInterface.TYPE_INET, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_INET, targetValueMetaType, value, e ); } return null; }
protected Object convertFromSerializableMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } if ( !( value instanceof Serializable ) ) { handleConversionError( "Error. Expecting value of type Serializable. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } try { switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_SERIALIZABLE: return value; default: throwBadConversionCombination( ValueMetaInterface.TYPE_SERIALIZABLE, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_SERIALIZABLE, targetValueMetaType, value, e ); } return null; }
protected Object convertFromBinaryMetaInterface( int targetValueMetaType, Object value ) throws ValueMetaConversionException { if ( value == null ) { return null; } if ( !( value instanceof ByteBuffer ) && !( value instanceof byte[] ) ) { handleConversionError( "Error. Expecting value of type ByteBuffer. actual value type = '" + value.getClass() + "'. value = '" + value + "'." ); } try { switch ( targetValueMetaType ) { case ValueMetaInterface.TYPE_BINARY: if ( value instanceof byte[] ) { return value; } return ( (ByteBuffer) value ).array(); default: throwBadConversionCombination( ValueMetaInterface.TYPE_BINARY, targetValueMetaType, value ); } } catch ( Exception e ) { throwErroredConversion( ValueMetaInterface.TYPE_BINARY, targetValueMetaType, value, e ); } return null; }
throwErroredConversion( ValueMetaInterface.TYPE_INTEGER, targetValueMetaType, value, e );
throwErroredConversion( ValueMetaInterface.TYPE_BIGNUMBER, targetValueMetaType, value, e );
throwErroredConversion( ValueMetaInterface.TYPE_NUMBER, targetValueMetaType, value, e );
throwErroredConversion( ValueMetaInterface.TYPE_STRING, targetValueMetaType, value, e );