Custom XML handler [message #666539] |
Wed, 20 April 2011 15:23  |
Eclipse User |
|
|
|
Hi,
I want to use a custom XML handler for my EMF models that extends the XML handler from EMF.
Currently my approach is basically the following:
a) let my generated ExampleResourceImpl extend from my class XMLResourceImpl2 instead of the EMF class XMLResourceImpl. My class XMLResourceImpl2 looks like this:
public class XMLResourceImpl2 extends XMLResourceImpl {
public XMLResourceImpl2(URI uri) { super(uri); }
@Override
protected XMLLoad createXMLLoad() {
return new XMLLoadImpl2(createXMLHelper());
}
}
b) let class XMLLoadImpl2 then return the desired handler MyXMLHandler, which extends the EMF SAXXMLHandler:
public class XMLLoadImpl2 extends XMLLoadImpl {
public XMLLoadImpl2(XMLHelper helper) { super(helper); }
@Override
protected DefaultHandler makeDefaultHandler() {
return new MyXMLHandler(helper);
}
}
Is this approach correct or should I doing it completely different to replace the XML handler?
If that is the suggested way, I'm wondering if I can somehow configure in the ecore or genmodel that I want to use a custom base class for the resource handling.
The only option that comes close to that is the "Resource Type" property in the genmodel which is available on the package element.
But here I can only select between NONE, BASIC, XML and XMI, but I cannot specify a concrete implementation base class.
So if there is no way to configure that in the ecore/genmodel, I assume I need to
1) select XML as resource type
2) generate my models
3) in the generated XYResourceImpl classes change "extends XMLResourceImpl" to "extends XMLResourceImpl" and remove the @generated tag attached to the class header
Is that also the correct approach?
Best regards
Jens
|
|
|
Re: Custom XML handler [message #666639 is a reply to message #666539] |
Thu, 21 April 2011 08:16  |
Eclipse User |
|
|
|
Jens,
Comments below.
Jens Keller wrote:
> Hi,
> I want to use a custom XML handler for my EMF models that extends the
> XML handler from EMF.
>
> Currently my approach is basically the following:
>
> a) let my generated ExampleResourceImpl extend from my class
> XMLResourceImpl2 instead of the EMF class XMLResourceImpl. My class
> XMLResourceImpl2 looks like this:
>
> public class XMLResourceImpl2 extends XMLResourceImpl {
> public XMLResourceImpl2(URI uri) { super(uri); }
>
> @Override
> protected XMLLoad createXMLLoad() {
> return new XMLLoadImpl2(createXMLHelper());
> }
> }
>
>
> b) let class XMLLoadImpl2 then return the desired handler
> MyXMLHandler, which extends the EMF SAXXMLHandler:
>
> public class XMLLoadImpl2 extends XMLLoadImpl {
> public XMLLoadImpl2(XMLHelper helper) { super(helper); }
>
> @Override
> protected DefaultHandler makeDefaultHandler() {
> return new MyXMLHandler(helper);
> }
> }
>
>
> Is this approach correct or should I doing it completely different to
> replace the XML handler?
That's the way.
>
> If that is the suggested way, I'm wondering if I can somehow configure
> in the ecore or genmodel that I want to use a custom base class for
> the resource handling.
> The only option that comes close to that is the "Resource Type"
> property in the genmodel which is available on the package element.
> But here I can only select between NONE, BASIC, XML and XMI, but I
> cannot specify a concrete implementation base class.
>
> So if there is no way to configure that in the ecore/genmodel, I
> assume I need to
> 1) select XML as resource type
> 2) generate my models
> 3) in the generated XYResourceImpl classes change "extends
> XMLResourceImpl" to "extends XMLResourceImpl"
These look identical to me...
> and remove the @generated tag attached to the class header
> Is that also the correct approach?
It sounds okay.
>
> Best regards
> Jens
|
|
|
Powered by
FUDForum. Page generated in 0.06139 seconds