Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 317357

Summary: XMLAnyObjectMapping has dead code in trunk
Product: z_Archived Reporter: Doug Clarke <douglas.clarke>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: blaise.doughan, david.mccann, david.twelves, eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Supporting tests
none
Proposed fix
none
Supporting tests none

Description Doug Clarke CLA 2010-06-19 09:13:02 EDT
Starting at line 350 of XMLAnyObjectMapping:

                    if (referenceDescriptor != null) {
                        ObjectBuilder builder = referenceDescriptor.getObjectBuilder();
                        objectValue = builder.buildObject(query, nestedRecord, joinManager);
                        Object updated = ((XMLDescriptor) referenceDescriptor).wrapObjectInXMLRoot(objectValue, next.getNamespaceURI(), next.getLocalName(), next.getPrefix(), false);
                        if(getConverter() != null) {
                            updated = getConverter().convertDataValueToObjectValue(objectValue, session, record.getUnmarshaller());
                        }
                        return updated;
                    } else if ((referenceDescriptor != null) && (getKeepAsElementPolicy() != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
                        return buildObjectAndWrapInXMLRoot(referenceDescriptor, getConverter(), query, record, nestedRecord, joinManager, session, next, null, null);
                    } else {                        

The else if condition will never be met since the initial if condition addressed referenceDescriptor != null
Comment 1 David McCann CLA 2010-12-10 14:53:34 EST
Created attachment 184988 [details]
Proposed fix
Comment 2 David McCann CLA 2010-12-10 15:59:29 EST
Created attachment 184997 [details]
Supporting tests
Comment 3 David McCann CLA 2010-12-14 15:02:06 EST
Created attachment 185163 [details]
Proposed fix
Comment 4 David McCann CLA 2010-12-14 15:02:25 EST
Created attachment 185164 [details]
Supporting tests
Comment 5 David McCann CLA 2010-12-14 15:24:23 EST
The fix involves more than just removing the unreachable code;  the logic in that block needs to be reworked.  

This DOM platform use case involves unmapped Elements whose mappings are set to use XMLRoot.  There are three cases we need to handle here:

1)  KEEP_ALL_AS_ELEMENT or (referenceDescriptor == null && KEEP_UNKNOWN_AS_ELEMENT):

  - in this case we want to return the element
  - the returned element will be wrapped in a XMLRoot if there is no reference descriptor
  - the returned element may/may not be wrapped in an XMLRoot if there is a reference descriptor, as the descriptor decides if the value should be wrapped or not (as is done in SAX)

2)  If criteria for 1) above is not met and there is a reference descriptor:

  - the reference descriptor is used to build the object to return
  - the returned object may/may not be wrapped in an XMLRoot, as the descriptor decides if the value should be wrapped or not (as is done in SAX)

3)  If criteria is not met for either 1) or 2) above:

  - if the first child of the unknown element is TEXT, and contains a non-empty String, the String value will be wrapped in an XMLRoot
  - if the schema type is known and maps to an XML type (i.e. boolean, dateTime, etc.), the String value will be converted to the XML type before being wrapped in an XMLRoot
Comment 6 David McCann CLA 2010-12-14 15:34:57 EST
The logic change will apply to the collection use case as well.
Comment 7 David McCann CLA 2010-12-15 09:47:40 EST
Reviewed by:  matt.macivor@oracle.com
Tests: all unit tests pass as expected; oxm.mappings.anyobject.withoutgroupingelement.AnyObjectKeepAllAsElementTestCases

Revision: 8710
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:35:36 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink