public static PersistedValueData createValueData ( int type , int orderNumber , byte [ ] data ) throws IOException { switch ( type ) { case PropertyType . BINARY : case PropertyType . UNDEFINED : return new ByteArrayPersistedValueData ( orderNumber , data ) ; case PropertyType . BOOLEAN : return new BooleanPersistedValueData ( orderNumber , Boolean . valueOf ( getString ( data ) ) ) ; case PropertyType . DATE : try { return new CalendarPersistedValueData ( orderNumber , JCRDateFormat . parse ( getString ( data ) ) ) ; } catch ( ValueFormatException e ) { throw new IOException ( "Can't create Calendar value" , e ) ; } case PropertyType . DOUBLE : return new DoublePersistedValueData ( orderNumber , Double . valueOf ( getString ( data ) ) ) ; case PropertyType . LONG : return new LongPersistedValueData ( orderNumber , Long . valueOf ( getString ( data ) ) ) ; case PropertyType . NAME : try { return new NamePersistedValueData ( orderNumber , InternalQName . parse ( getString ( data ) ) ) ; } catch ( IllegalNameException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } case PropertyType . PATH : try { return new PathPersistedValueData ( orderNumber , QPath . parse ( getString ( data ) ) ) ; } catch ( IllegalPathException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } case PropertyType . REFERENCE : return new ReferencePersistedValueData ( orderNumber , new Identifier ( data ) ) ; case PropertyType . STRING : return new StringPersistedValueData ( orderNumber , getString ( data ) ) ; case ExtendedPropertyType . PERMISSION : return new PermissionPersistedValueData ( orderNumber , AccessControlEntry . parse ( getString ( data ) ) ) ; default : throw new IllegalStateException ( "Unknown property type " + type ) ; } }
Creates value data depending on its type . It avoids storing unnecessary bytes in memory every time .