public ModelNode fromChangeset ( Map < String , Object > changeSet , String ... wildcards ) { ClassInfo clazz = null ; Class < ? > currentType = getType ( ) ; while ( clazz == null ) { clazz = index . getClassByName ( DotName . createSimple ( currentType . getCanonicalName ( ) ) ) ; if ( clazz == null ) { currentType = currentType . getSuperclass ( ) ; if ( currentType == null ) { throw new RuntimeException ( "Unable to determine ClassInfo" ) ; } } } Address addressMeta = currentType . getDeclaredAnnotation ( Address . class ) ; AddressTemplate address = AddressTemplate . of ( addressMeta . value ( ) ) ; ModelNode protoType = new ModelNode ( ) ; protoType . get ( ADDRESS ) . set ( address . resolve ( NOOP_CTX , wildcards ) ) ; protoType . get ( OP ) . set ( WRITE_ATTRIBUTE_OPERATION ) ; ModelNode operation = new ModelNode ( ) ; operation . get ( OP ) . set ( COMPOSITE ) ; operation . get ( ADDRESS ) . setEmptyList ( ) ; List < ModelNode > steps = new ArrayList < ModelNode > ( ) ; for ( MethodInfo method : clazz . methods ( ) ) { if ( method . hasAnnotation ( IndexFactory . BINDING_META ) ) { try { Method target = currentType . getMethod ( method . name ( ) ) ; Class < ? > propertyType = target . getReturnType ( ) ; ModelNodeBinding binding = target . getDeclaredAnnotation ( ModelNodeBinding . class ) ; String detypedName = binding . detypedName ( ) ; String javaPropName = method . name ( ) ; // in our case it's same as the method name Object value = changeSet . get ( javaPropName ) ; if ( value == null ) continue ; ModelNode step = protoType . clone ( ) ; step . get ( NAME ) . set ( javaPropName ) ; ModelNode modelNode = step . get ( VALUE ) ; try { ModelType dmrType = Types . resolveModelType ( propertyType ) ; if ( dmrType == ModelType . LIST ) { new ListTypeAdapter ( ) . toDmr ( modelNode . get ( detypedName ) , ( List ) value ) ; } else if ( dmrType == ModelType . OBJECT ) { new MapTypeAdapter ( ) . toDmr ( modelNode . get ( detypedName ) , ( Map ) value ) ; } else { new SimpleTypeAdapter ( ) . toDmr ( modelNode . get ( detypedName ) , dmrType , value ) ; } } catch ( RuntimeException e ) { throw new RuntimeException ( "Failed to adopt value " + propertyType . getName ( ) , e ) ; } steps . add ( step ) ; } catch ( NoSuchMethodException e ) { e . printStackTrace ( ) ; } } } operation . get ( STEPS ) . set ( steps ) ; return operation ; }
Turns a changeset into a composite write attribute operation . The keys to the changeset are the java property names of the attributes that have been modified .