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

Bug 345502

Summary: Empty model element should be deleted from source
Product: z_Archived Reporter: Ling Hao <ling.hao>
Component: SapphireAssignee: Konstantin Komissarchik <konstantin>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: konstantin, shenxue.zhou
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Ling Hao CLA 2011-05-11 17:02:21 EDT
1. sapphire-gallery.xml -> Element Properties -> Homogeneous -> select "Include child element"
2. deselect "Include child element"
3. Go to source and notice the following still in source code. 
<homogeneous>
</homogeneous>

Same issue with the heterogeneous element properties.
Comment 1 Konstantin Komissarchik CLA 2011-05-13 15:15:43 EDT
There may be cases where this is desired (such as implied element properties), but we will not in general remove empty parent elements when content is deleted. Before we can remove an element, we need to know that its presence doesn't carry semantic information.

In the sited cases, the bindings are defined as follows:

@XmlElementBinding( path = "homogeneous", mappings = @XmlElementBinding.Mapping( element = "child", type = IChildElement.class ) )

@XmlElementBinding
(
    path = "heterogeneous", 
    mappings = 
    {
        @XmlElementBinding.Mapping( element = "child", type = IChildElement.class ),
        @XmlElementBinding.Mapping( element = "child-with-integer", type = IChildElementWithInteger.class ),
        @XmlElementBinding.Mapping( element = "child-with-enum", type = IChildElementWithEnum.class )
    }
)

In these cases, we do know that element specified in the path attribute ("homogeneous" and "heterogeneous") are just structural and do not carry semantic information. They are created as necessary and the can be deleted if empty.

Targeting to 0.3 for now in order to review cases.
Comment 2 Konstantin Komissarchik CLA 2011-06-06 23:05:15 EDT
This was already implemented for value and list property bindings, but element property bindings (implied and explicit) weren't acting in the same manner. Fixed that.

Please verify.
Comment 3 Ling Hao CLA 2011-06-08 13:20:47 EDT
Verified with sapphire-gallery.xml and the coherence use case.
Comment 4 Shenxue Zhou CLA 2011-06-10 18:41:07 EDT
The fix causes a regression when the model element only contains xml attributes. For example, the following generated xml:

<?xml version="1.0" encoding="UTF-8"?>
<adfc-config xmlns="http://xmlns.oracle.com/adf/controller" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/adf/controller http://xmlns.oracle.com/adf/controller/1.0">
    <task-flow-definition id="task-flow-definition">
</adfc-config>

becomes:

<?xml version="1.0" encoding="UTF-8"?>
<adfc-config xmlns="http://xmlns.oracle.com/adf/controller" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/adf/controller http://xmlns.oracle.com/adf/controller/1.0">
</adfc-config>

Using the same code snippet:

XmlResourceStore xmlStore = new XmlResourceStore( new WorkspaceFileResourceStore(taskFlowFile));

IADFController controller = IADFController.TYPE.instantiate(new RootXmlResource(xmlStore));
controller.getTaskFlow().setTaskFlowId(id);
xmlStore.save();
Comment 5 Konstantin Komissarchik CLA 2011-06-10 20:34:42 EDT
Fixed the issue with attributes. TestXmlBinding0008 now covers this scenario, including the attributes corner case.

Please re-verify the original scenarios too.
Comment 6 Shenxue Zhou CLA 2011-06-13 12:01:33 EDT
I've verified with my use case.
Comment 7 Ling Hao CLA 2011-06-13 12:44:40 EDT
Verified with sapphire-gallery.xml and the coherence use case again.