[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Customizing serialization and de-serialization.

Hi!

I am trying to customize the serialization and de-serialization of a given meta model in order to create XML code that adheres to a provided DTD.

Using annotations and customizing XMLSave I was able to generate the XML I need. The problem I am stuck with now is that I don't seem to be able properly re-load the XML.

I have a class System, itself contained by another class, which has an attribute #definition.

The XML code I need to generate looks like:
<...>
  <...></...>
  <system>TEXT</system>
</...>

Thus Because I don't want #definition to appear as tag <definition> in the XML code I overwrote XMLSave.saveElement():

protected void saveElement(EObject obj, EStructuralFeature structFeat) {
	EClass eClass = obj.eClass();
	EClassifier eType = structFeat.getEType();
	
	if (eClass.equals(SomePackage.eINSTANCE.getSystem())) {
		String str = extendedMetaData.getName(eClass);
		this.doc.startElement("system");
		this.doc.endContentElement(((System)obj).getDefinition());
	}
	else {
		super.saveElement(obj, structFeat);
	}
}


However when the XML code is de-serialized, the content between the <system></system> tags is ignored and #definition is not set. (Which, I guess, makes sense)



Thus my question is, what would be the best way to achieve the behaviour I need.


At the beginning I was hoping I could achieve everything I need to do using annotations. Then I was hoping I just need to modify createObject(EFactory factory, EClassifier type) . However I am not sure how/where to get the TEXT to set the #definition attribute.

Furthermore:
Is overwriting saveElement() actually the best way to generate the needed XML code. Can this be achieved using annotations as well? Or can at least system from <this.doc.startElement("system");> somehow be retrieved from the annotations? Every time I look at the xmlMap it is actually empty


Is there more information available about using annotations and XMLSave/XMLLoad and XMLHelper and so on to customize serialization and de-serialization.

I would appreciate any help
Lothar