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

Ed:

I chose DOM as it is random-access and allows me to "peek" at element children to determine how to decorate with xsi:type. I was thinking of overriding other load methods (InputSource, InputStream) to use DOM as well.

Ed Merks wrote:

John,

Comments below.


John T.E. Timm wrote:
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>
Something needs to be constructed as soon as <elementA> is seen. It can't wait until other nested elements are processed.

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.
Easier said then done...
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?
I would have expected overrides of the XMLHandler, but it sounds like you expect always to create directly from DOM...

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?
EClass.getEPackage().getNsURI().

Given that you need to process a nested element to decide how to process <elementA> I think it's very tough. I don't know how to do that... An xsi:type is always an attribute that can be processed as the opening element bracket is processed...

Thanks,

JT