|
|
|
Re: EMF XML Serialization - change xsi:type to another attribute [message #1847219 is a reply to message #1847171] |
Tue, 19 October 2021 15:36 |
Daniel Winkels Messages: 3 Registered: September 2021 |
Junior Member |
|
|
Hello Ed,
the problem has become simpler.
Case 1: xsi:type is present
Nothing to be done. The 3rd party software ignores the attribute. So there is no need to change the serialization.
<element xsi:type="Textbox" id="textbox6" name="textbox6" type="Textbox" page="page2" section="section3" row="row14" column="column11" label="Text1"/>
Case 2: xsi:type not present (i want to load a model from the 3rd party application)
<element id="textbox6" name="textbox6" type="Textbox" page="page2" section="section3" row="row14" column="column11" label="Text1"/>
Here I extended SAXXMLHandler with my custom implementation. If the attribute "xsi:type" is missing read the value of "type", which has to contain the correct value by design.
public class DialogSAXXMLHandler extends SAXXMLHandler {
public DialogSAXXMLHandler(XMLResource xmiResource, XMLHelper helper, Map<?, ?> options) {
super(xmiResource, helper, options);
}
@Override
protected String getXSIType() {
String xsiValue = attribs.getValue(ExtendedMetaData.XSI_URI, XMLResource.TYPE);
if (xsiValue == null || xsiValue.isEmpty()) {
return attribs.getValue("type");
}
return isNamespaceAware ? attribs.getValue(ExtendedMetaData.XSI_URI, XMLResource.TYPE)
: attribs.getValue(TYPE_ATTRIB);
}
}
For those who are as clueless as i was:
I needed to extend XMLLoadImpl to get an instance of my DialogSAXXMLHandler.
public class DialogXMLLoadImpl extends XMLLoadImpl {
public DialogXMLLoadImpl(XMLHelper helper) {
super(helper);
// TODO Auto-generated constructor stub
}
@Override
protected DefaultHandler makeDefaultHandler() {
return new DialogSAXXMLHandler(resource, helper, options);
}
}
The DialogXMLLoadImpl instance is created in my implementation of the Resource.
public class DialogResourceImpl extends XMLResourceImpl {
/**
* Creates an instance of the resource.
* <!-- begin-user-doc --> <!--
* end-user-doc -->
* @param uri the URI of the new resource.
* @generated
*/
public DialogResourceImpl(URI uri) {
super(uri);
}
@Override
protected XMLHelper createXMLHelper() {
return new DialogResourceXMLHelper();
}
@Override
protected XMLLoad createXMLLoad() {
return new DialogXMLLoadImpl(createXMLHelper());
}
/**
* @since 2.7
*/
@Override
protected XMLLoad createXMLLoad(Map<?, ?> options) {
return createXMLLoad();
}
@Override
protected XMLSave createXMLSave() {
return new DialogXMLSaveImpl(createXMLHelper());
}
/**
* @since 2.7
*/
@Override
protected XMLSave createXMLSave(Map<?, ?> options) {
return createXMLSave();
}
} // DialogResourceImpl
|
|
|
Powered by
FUDForum. Page generated in 0.01776 seconds