[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Add xsi:type hint to element during load

I have a situation where I would like to add xsi:type information when I load an XML document before it gets materialized into an Ecore object model.

<elementA>
  <!-- no id element corresponds to instance of ClassA -->
  ...
</elementA>

<elementA>
<!-- id element indicates that elementA corresponds to instance of ClassA subclass -->
<id value="1.2.3"/>
...
</elementA>


The input format may not contain the xsi:type hints for subclasses as it may have been produced outside of EMF. However, if elementA corresponds to an instance of ClassA, then elementA with an id element directly underneath it corresponds to a subclass of ClassA. What I need to do is intercept the parsing mechanism and add the xsi:type attribute depending on the value of the id element. My initial approach is to create a subclass of XMLLoadImpl that overrides traverse and traverseElement to inspect children of element nodes and determine whether I should create type hint before handing control over to super.traverse/traverseElement. Is there a better way to accomplish this through a different extension mechanism?

Additionally, I will have a registry that maps id's to fully qualified class names. Given a class name, what is the best way to find the correct EPackage and get the prefix and nsURI?

Thanks,

JT