Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Custom XML handler
Custom XML handler [message #666539] Wed, 20 April 2011 19:23 Go to next message
keller_jens is currently offline keller_jensFriend
Messages: 21
Registered: March 2010
Location: Germany
Junior Member
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 12:16 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:TableViewer binding
Next Topic:Optimize menu entries
Goto Forum:
  


Current Time: Wed Sep 25 01:51:37 GMT 2024

Powered by FUDForum. Page generated in 0.06717 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top