private Object getValueForProperty ( PropertyDescriptor propertyDescriptor , EDBObject object ) { Method setterMethod = propertyDescriptor . getWriteMethod ( ) ; String propertyName = propertyDescriptor . getName ( ) ; Object value = object . getObject ( propertyName ) ; Class < ? > parameterType = setterMethod . getParameterTypes ( ) [ 0 ] ; // TODO: OPENENGSB-2719 do that in a better way than just an if-else series if ( Map . class . isAssignableFrom ( parameterType ) ) { List < Class < ? > > classes = getGenericMapParameterClasses ( setterMethod ) ; value = getMapValue ( classes . get ( 0 ) , classes . get ( 1 ) , propertyName , object ) ; } else if ( List . class . isAssignableFrom ( parameterType ) ) { Class < ? > clazz = getGenericListParameterClass ( setterMethod ) ; value = getListValue ( clazz , propertyName , object ) ; } else if ( parameterType . isArray ( ) ) { Class < ? > clazz = parameterType . getComponentType ( ) ; value = getArrayValue ( clazz , propertyName , object ) ; } else if ( value == null ) { return null ; } else if ( OpenEngSBModel . class . isAssignableFrom ( parameterType ) ) { Object timestamp = object . getObject ( EDBConstants . MODEL_TIMESTAMP ) ; Long time = System . currentTimeMillis ( ) ; if ( timestamp != null ) { try { time = Long . parseLong ( timestamp . toString ( ) ) ; } catch ( NumberFormatException e ) { LOGGER . warn ( "The model with the oid {} has an invalid timestamp." , object . getOID ( ) ) ; } } EDBObject obj = edbService . getObject ( ( String ) value , time ) ; value = convertEDBObjectToUncheckedModel ( parameterType , obj ) ; object . remove ( propertyName ) ; } else if ( parameterType . equals ( FileWrapper . class ) ) { FileWrapper wrapper = new FileWrapper ( ) ; String filename = object . getString ( propertyName + FILEWRAPPER_FILENAME_SUFFIX ) ; String content = ( String ) value ; wrapper . setFilename ( filename ) ; wrapper . setContent ( Base64 . decodeBase64 ( content ) ) ; value = wrapper ; object . remove ( propertyName + FILEWRAPPER_FILENAME_SUFFIX ) ; } else if ( parameterType . equals ( File . class ) ) { return null ; } else if ( object . containsKey ( propertyName ) ) { if ( parameterType . isEnum ( ) ) { value = getEnumValue ( parameterType , value ) ; } } object . remove ( propertyName ) ; return value ; }
Generate the value for a specific property of a model out of an EDBObject .