if( world != null ) {
propertyReferences = world.getPropertyReferencesTo( this, HowMuch.INSTANCE_AND_ALL_DESCENDANTS, false, false );
keys = new String[ propertyReferences.length ];
}
for( int i=0; i<propertyReferences.length; i++ ) {
PropertyReference propertyReference = propertyReferences[ i ];
Element reference = propertyReference.getReference();
keys[ i ] = reference.getKey( world );
if( propertyReference instanceof ObjectArrayPropertyReference ) {
ObjectArrayPropertyReference objectArrayPropertyReference = (ObjectArrayPropertyReference)propertyReference;
ObjectArrayProperty objectArrayProperty = objectArrayPropertyReference.getObjectArrayProperty();
objectArrayProperty.set( objectArrayPropertyReference.getIndex(), null );
} else {
Property property = propertyReference.getProperty();
property.set( null );
//System.out.println( "null->"+property );
}
}
Element coercedElement;
try {
coercedElement = (Element)cls.newInstance();
} catch( IllegalAccessException iae ) {
throw new ExceptionWrapper( iae, cls.toString() );
} catch( InstantiationException ie ) {
throw new ExceptionWrapper( ie, cls.toString() );
}
Element parentValue = getParent();
if( parentValue != null ) {
int indexOfChild = parentValue.getIndexOfChild( this );
setParent( null );
parentValue.insertChildAt( coercedElement, indexOfChild );
}
Element[] children = getChildren();
for( int i=0; i<children.length; i++ ) {
children[i].setParent( coercedElement );
}
Property[] properties = getProperties();
for( int i=0; i<properties.length; i++ ) {
Property property = properties[i];
Property cProperty = coercedElement.getPropertyNamed( property.getName() );
if( cProperty != null ) {
cProperty.set( property.get() );
}
}
for( int i=0; i<propertyReferences.length; i++ ) {
PropertyReference propertyReference = propertyReferences[ i ];
String key = keys[ i ];
Element reference = world.getDescendantKeyed( key );
Property property = propertyReference.getProperty();
if( property.getOwner() == this ) {
property = coercedElement.getPropertyNamed( property.getName() );
}
if( property != null ) {
if( propertyReference instanceof ObjectArrayPropertyReference ) {