public IBase cloneInto ( IBase theSource , IBase theTarget , boolean theIgnoreMissingFields ) { Validate . notNull ( theSource , "theSource must not be null" ) ; Validate . notNull ( theTarget , "theTarget must not be null" ) ; if ( theSource instanceof IPrimitiveType < ? > ) { if ( theTarget instanceof IPrimitiveType < ? > ) { ( ( IPrimitiveType < ? > ) theTarget ) . setValueAsString ( ( ( IPrimitiveType < ? > ) theSource ) . getValueAsString ( ) ) ; return theSource ; } if ( theIgnoreMissingFields ) { return theSource ; } throw new DataFormatException ( "Can not copy value from primitive of type " + theSource . getClass ( ) . getName ( ) + " into type " + theTarget . getClass ( ) . getName ( ) ) ; } BaseRuntimeElementCompositeDefinition < ? > sourceDef = ( BaseRuntimeElementCompositeDefinition < ? > ) myContext . getElementDefinition ( theSource . getClass ( ) ) ; BaseRuntimeElementCompositeDefinition < ? > targetDef = ( BaseRuntimeElementCompositeDefinition < ? > ) myContext . getElementDefinition ( theTarget . getClass ( ) ) ; List < BaseRuntimeChildDefinition > children = sourceDef . getChildren ( ) ; if ( sourceDef instanceof RuntimeExtensionDtDefinition ) { children = ( ( RuntimeExtensionDtDefinition ) sourceDef ) . getChildrenIncludingUrl ( ) ; } for ( BaseRuntimeChildDefinition nextChild : children ) for ( IBase nextValue : nextChild . getAccessor ( ) . getValues ( theSource ) ) { String elementName = nextChild . getChildNameByDatatype ( nextValue . getClass ( ) ) ; BaseRuntimeChildDefinition targetChild = targetDef . getChildByName ( elementName ) ; if ( targetChild == null ) { if ( theIgnoreMissingFields ) { continue ; } throw new DataFormatException ( "Type " + theTarget . getClass ( ) . getName ( ) + " does not have a child with name " + elementName ) ; } BaseRuntimeElementDefinition < ? > element = myContext . getElementDefinition ( nextValue . getClass ( ) ) ; IBase target = element . newInstance ( ) ; targetChild . getMutator ( ) . addValue ( theTarget , target ) ; cloneInto ( nextValue , target , theIgnoreMissingFields ) ; } return theTarget ; }
Clones all values from a source object into the equivalent fields in a target object