Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » generic emf factory for any URI
generic emf factory for any URI [message #428476] Mon, 23 March 2009 15:30 Go to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Hi all

I have written a translator from XMI to N3 ( a variety of RDF):
http://eulergui.sourceforge.net/tmp/XMIToN3Converter.java

This works ,I have written a generic traversal following EObject and
EClass objects. There remains still a problem. What I do is completely
generic, I use only the eCore API. But to read file UML (or another
specific data) I do not know if one can avoid a call like this :

resourceSet.getPackageRegistry () .put ( UMLPackage.eNS_URI,
UMLPackage.eINSTANCE );

So I get a runtime dependency that I would like to avoid.

I tested that but that does not work either:
resourceSet.getPackageRegistry () .put (UMLPackage.eNS_URI,
EcorePackage.eINSTANCE );

In other words I need a EPackage able to instanciate for any URI.
Or another way to read an XMI ...
Re: generic emf factory for any URI [message #428479 is a reply to message #428476] Mon, 23 March 2009 17:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Jean-Marc,

Comments below.

Jean-Marc Vanel wrote:
> Hi all
>
> I have written a translator from XMI to N3 ( a variety of RDF):
> http://eulergui.sourceforge.net/tmp/XMIToN3Converter.java
>
> This works ,I have written a generic traversal following EObject and
> EClass objects. There remains still a problem. What I do is completely
> generic, I use only the eCore API. But to read file UML (or another
> specific data) I do not know if one can avoid a call like this :
>
> resourceSet.getPackageRegistry () .put ( UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE );
> So I get a runtime dependency that I would like to avoid.
When running in an OSGi environment, it's not necessary because the
plugin.xml registrations do this for you.
>
> I tested that but that does not work either:
> resourceSet.getPackageRegistry () .put (UMLPackage.eNS_URI,
> EcorePackage.eINSTANCE );
I don't imagine it's good to register the wrong package...
> In other words I need a EPackage able to instanciate for any URI. Or
> another way to read an XMI ...
I'm not sure if this option helps. In general, if you want to build an
instance of a model, you really need the model to be registered. And
some models need special resource implementations to handle them
correctly, in which case those need to be registered as well.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: generic emf factory for any URI [message #428517 is a reply to message #428479] Tue, 24 March 2009 14:57 Go to previous messageGo to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Ed Merks wrote:

> Jean-Marc,

> Comments below.

> Jean-Marc Vanel wrote:
>> Hi all
>>
>> I have written a translator from XMI to N3 ( a variety of RDF):
>> http://eulergui.sourceforge.net/tmp/XMIToN3Converter.java
>>
>> This works ,I have written a generic traversal following EObject and
>> EClass objects. There remains still a problem. What I do is completely
>> generic, I use only the eCore API. But to read file UML (or another
>> specific data) I do not know if one can avoid a call like this :
>>
>> resourceSet.getPackageRegistry () .put ( UMLPackage.eNS_URI,
>> UMLPackage.eINSTANCE );
>> So I get a runtime dependency that I would like to avoid.
> When running in an OSGi environment, it's not necessary because the
> plugin.xml registrations do this for you.

Good to know, but currently I'm not .

...
>> In other words I need a EPackage able to instanciate for any URI. Or
>> another way to read an XMI ...
> I'm not sure if this option helps. In general, if you want to build an
> instance of a model, you really need the model to be registered. And
> some models need special resource implementations to handle them
> correctly, in which case those need to be registered as well.

If you saw my code, you would see that I'm traversing the UML model just
like it were a plain eCore model (and by the way, I'm as much critic as
you regarding UML, I heard you in Paris this winter).

So, what I'm asking is : is there a way to instantiate plain eCore objects
from an XMI, disregarding the actual package ?

From what you answered I'm afraid that the answer is no, and that my use
case was never considered.

Maybe it's enough to redefine this method in
org.eclipse.emf.ecore.xmi.impl.XMLHandler :
protected EFactory getFactoryForPrefix(String prefix)

Before being independent like now, I spent 2 years building an EMF-like
framework with generator in Java, generating C++. And I did exactly that,
an XMI parser that instantiates plain vanilla MOF classes. But I doubt if
can use my work for an OSS project.
Re: generic emf factory for any URI [message #428520 is a reply to message #428517] Tue, 24 March 2009 15:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070603050308030002010206
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Jean-Marc,

Without a model, XMI is just XML "noise". We can certainly process such
arbitrary content, but it ends up looking just like DOM.
< http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava>

http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava


Jean-Marc Vanel wrote:
> Ed Merks wrote:
>
>> Jean-Marc,
>
>> Comments below.
>
>> Jean-Marc Vanel wrote:
>>> Hi all
>>>
>>> I have written a translator from XMI to N3 ( a variety of RDF):
>>> http://eulergui.sourceforge.net/tmp/XMIToN3Converter.java
>>>
>>> This works ,I have written a generic traversal following EObject and
>>> EClass objects. There remains still a problem. What I do is
>>> completely generic, I use only the eCore API. But to read file UML
>>> (or another specific data) I do not know if one can avoid a call
>>> like this :
>>>
>>> resourceSet.getPackageRegistry () .put ( UMLPackage.eNS_URI,
>>> UMLPackage.eINSTANCE );
>>> So I get a runtime dependency that I would like to avoid.
>> When running in an OSGi environment, it's not necessary because the
>> plugin.xml registrations do this for you.
>
> Good to know, but currently I'm not .
>
> ..
>>> In other words I need a EPackage able to instanciate for any URI. Or
>>> another way to read an XMI ...
>> I'm not sure if this option helps. In general, if you want to build
>> an instance of a model, you really need the model to be registered.
>> And some models need special resource implementations to handle them
>> correctly, in which case those need to be registered as well.
>
> If you saw my code, you would see that I'm traversing the UML model
> just like it were a plain eCore model (and by the way, I'm as much
> critic as you regarding UML, I heard you in Paris this winter).
>
> So, what I'm asking is : is there a way to instantiate plain eCore
> objects from an XMI, disregarding the actual package ?
>
> From what you answered I'm afraid that the answer is no, and that my
> use case was never considered.
>
> Maybe it's enough to redefine this method in
> org.eclipse.emf.ecore.xmi.impl.XMLHandler :
> protected EFactory getFactoryForPrefix(String prefix)
>
> Before being independent like now, I spent 2 years building an
> EMF-like framework with generator in Java, generating C++. And I did
> exactly that, an XMI parser that instantiates plain vanilla MOF
> classes. But I doubt if can use my work for an OSS project.
>

--------------070603050308030002010206
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jean-Marc,<br>
<br>
Without a model, XMI is just XML "noise".


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: generic emf factory for any URI [message #428530 is a reply to message #428520] Tue, 24 March 2009 16:48 Go to previous messageGo to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Ed Merks wrote:

> Jean-Marc,

> Without a model, XMI is just XML "noise". We can certainly process such
> arbitrary content, but it ends up looking just like DOM.
> < http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava>

Ed,

I agree about the usefulness of models, it's just that I'm developing a
framework based on RDF, OWL, and rule engines
(http://eulergui.sourceforge.net/ ) were models are leveraged after XMI
parsing, not during.

After reading most of your article, and before delving into code, I just
want to ask if I can use the AnyType stuff for XMI things, not XML as such
as in the article.

Kind regards
--
Jean-Marc Vanel
Consulting, services, training,
Rule-based programming, Semantic Web
http://jmvanel.free.fr/
Re: generic emf factory for any URI [message #428532 is a reply to message #428530] Tue, 24 March 2009 16:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Jean-Marc,

XMI is just XML, so I think it would work at that level. Perhaps even
the same kinds of options as work with the XMLResourceImpl will work
with XMIResourceImpl and thereby dull down the XMI noise that's captured
in the "DOM".

Cheers,
Ed


Jean-Marc Vanel wrote:
> Ed Merks wrote:
>
>> Jean-Marc,
>
>> Without a model, XMI is just XML "noise". We can certainly process
>> such arbitrary content, but it ends up looking just like DOM.
>> < http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava>
>
> Ed,
>
> I agree about the usefulness of models, it's just that I'm developing
> a framework based on RDF, OWL, and rule engines
> (http://eulergui.sourceforge.net/ ) were models are leveraged after
> XMI parsing, not during.
>
> After reading most of your article, and before delving into code, I
> just want to ask if I can use the AnyType stuff for XMI things, not
> XML as such as in the article.
>
> Kind regards
> --
> Jean-Marc Vanel
> Consulting, services, training,
> Rule-based programming, Semantic Web
> http://jmvanel.free.fr/
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: generic emf factory for any URI [message #428537 is a reply to message #428532] Tue, 24 March 2009 17:54 Go to previous messageGo to next message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Ed Merks wrote:

> Jean-Marc,

> XMI is just XML, so I think it would work at that level. Perhaps even
> the same kinds of options as work with the XMLResourceImpl will work
> with XMIResourceImpl and thereby dull down the XMI noise that's captured
> in the "DOM".

So I took this from your article :
// Loading an instance with EMF requires exactly the same setup as for
saving.

ResourceSet resourceSet = new ResourceSetImpl();
final ExtendedMetaData extendedMetaData =
new BasicExtendedMetaData(resourceSet.getPackageRegistry());
resourceSet.getLoadOptions().put
(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new GenericXMLResourceFactoryImpl());

But that is not enough to silence the factory; I think that I need
something like a GenericXMIResourceFactoryImpl ... that doesn't exist.

Problem loading
file:/home/jmv/workspace_test/test_with_uml/default.umlorg.e clipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWr appedException:
org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
'http://www.eclipse.org/uml2/2.1.0/UML' not found.
(file:/home/jmv/workspace_test/test_with_uml/default.uml, 2, 179)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:315)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:274)
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:397)
at XMIToN3ConverterGeneric.loadECoreURI(XMIToN3ConverterGeneric .java:239)
at XMIToN3ConverterGeneric.loadEcoreFile(XMIToN3ConverterGeneri c.java:200)
at XMIToN3ConverterGeneric.main(XMIToN3ConverterGeneric.java:52 )
Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package
with uri 'http://www.eclipse.org/uml2/2.1.0/UML' not found.
(file:/home/jmv/workspace_test/test_with_uml/default.uml, 2, 179)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2576)

I updated the code snapshot here; you have also the input and expected
output :

http://eulergui.sourceforge.net/tmp/

Cheers,
Jean-Marc
Re: generic emf factory for any URI [message #428539 is a reply to message #428537] Tue, 24 March 2009 18:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Jean-Marc,

I tried changing the LibraryExample.java to use GenericXMLResourceImpl
and then supplied a command line argument points at a UML file and it
worked for me. Use the debugger to confirm that in fact
GenericXMLResourceFactoryImpl is being used to create the resource
because from what you show below I imagine that's not the case. I
imagine a version of this factory but one that creates an
XMIResourceImpl might be more to your needs...



Jean-Marc Vanel wrote:
> Ed Merks wrote:
>
>> Jean-Marc,
>
>> XMI is just XML, so I think it would work at that level. Perhaps
>> even the same kinds of options as work with the XMLResourceImpl will
>> work with XMIResourceImpl and thereby dull down the XMI noise that's
>> captured in the "DOM".
>
> So I took this from your article :
> // Loading an instance with EMF requires exactly the same setup as for
> saving.
>
> ResourceSet resourceSet = new ResourceSetImpl();
> final ExtendedMetaData extendedMetaData = new
> BasicExtendedMetaData(resourceSet.getPackageRegistry());
> resourceSet.getLoadOptions().put
> (XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION, new
> GenericXMLResourceFactoryImpl());
>
> But that is not enough to silence the factory; I think that I need
> something like a GenericXMIResourceFactoryImpl ... that doesn't exist.
>
> Problem loading
> file:/home/jmv/workspace_test/test_with_uml/default.umlorg.e clipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWr appedException:
> org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
> 'http://www.eclipse.org/uml2/2.1.0/UML' not found.
> (file:/home/jmv/workspace_test/test_with_uml/default.uml, 2, 179)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDe mandLoadException(ResourceSetImpl.java:315)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:274)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:397)
>
> at
> XMIToN3ConverterGeneric.loadECoreURI(XMIToN3ConverterGeneric .java:239)
> at
> XMIToN3ConverterGeneric.loadEcoreFile(XMIToN3ConverterGeneri c.java:200)
> at XMIToN3ConverterGeneric.main(XMIToN3ConverterGeneric.java:52 )
> Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package
> with uri 'http://www.eclipse.org/uml2/2.1.0/UML' not found.
> (file:/home/jmv/workspace_test/test_with_uml/default.uml, 2, 179)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:2576)
>
>
> I updated the code snapshot here; you have also the input and expected
> output :
>
> http://eulergui.sourceforge.net/tmp/
>
> Cheers,
> Jean-Marc
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: generic emf factory for any URI [message #428603 is a reply to message #428539] Wed, 25 March 2009 10:51 Go to previous message
Jean-Marc Vanel is currently offline Jean-Marc VanelFriend
Messages: 23
Registered: July 2009
Junior Member
Ed Merks wrote:

> Jean-Marc,

> I tried changing the LibraryExample.java to use GenericXMLResourceImpl
> and then supplied a command line argument points at a UML file and it
> worked for me. Use the debugger to confirm that in fact
> GenericXMLResourceFactoryImpl is being used to create the resource
> because from what you show below I imagine that's not the case. I
> imagine a version of this factory but one that creates an
> XMIResourceImpl might be more to your needs...

Indeed, I left some code that was resetting the Factory to
EcoreResourceFactoryImpl .
After looking at traversal output, and a night's thought, I think it is
wiser to stick to the original design for now.

The design flaw in XMI is that when you have values like :
general="__I2CkBIREd6JhZv7DW6I_g"
type="__I2CkBIREd6JhZv7DW6I_g"

they refer to an Id :
XMI_2.1:id="__I2CkBIREd6JhZv7DW6I_g"

But without a model, it is hard to know what is an Id reference, and what
is a plain string.

In fact, as you know, there is an alternate syntax for XMI that
distinguishes strings and id's; instead of :

<generalization xmi:id="_HDiBMBISEd6JhZv7DW6I_g"
general="__I2CkBIREd6JhZv7DW6I_g"/>

it is possible , and XMI 2.X compliant, to write :

<generalization xmi:id="_HDiBMBISEd6JhZv7DW6I_g"
<general xmi:idref="__I2CkBIREd6JhZv7DW6I_g"/>
</generalization>

But few softwares do that, and not EMF. And I regret that, because it
would allow to translate easily between XMI and RDF.

So for now , I will keep the 2.3Mb UML2 jar that I never call directly :( .
Thanks for your help

Cheers,
Jean-Marc
Previous Topic:[emf]generate xml without xmlns:xmi and xmlns:XXX
Next Topic:[CDP] MySQL jdbc jar and where to put it
Goto Forum:
  


Current Time: Fri Apr 26 19:11:35 GMT 2024

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

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

Back to the top