Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Loading ecore model from a standalone java app
Loading ecore model from a standalone java app [message #504594] Mon, 21 December 2009 17:18 Go to next message
Dameer Joog is currently offline Dameer JoogFriend
Messages: 17
Registered: July 2009
Junior Member
Hi.

I am trying to load the UML_21.ecore file from the eclipse emf source tree.

I can parse the metamodel successfully so far. However when i try to loop over the eClass obects in it i keep getting null when i try to get the superclass for the EModelElement.

The strange thing is the getEPackage is only null when i get to the EModelElement(only).

The Element class eClass.getEGenericSuperTypes() returns a single type (EmodelElement) but doing getEClassifier().getEPackage() on that type always returns null.

Here is the loop i use to go over the super types for each class.

for (superType : eClass.getEGenericSuperTypes ) {
superType.getEClassifier().getEPackage()
}

why am i getting null wheni do getEClassifier().getEPackage() on the EModelElement class only ?

The emf i am using is the libs that come with galileo. i copied the emf jar files.
Re: Loading ecore model from a standalone java app [message #504609 is a reply to message #504594] Mon, 21 December 2009 13:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Dameer,

Comments below.

Dameer Joog wrote:
> Hi.
>
> I am trying to load the UML_21.ecore file from the eclipse emf source
> tree.
They've got online documentation for standalone use of UML.
>
> I can parse the metamodel successfully so far. However when i try to
> loop over the eClass obects in it i keep getting null when i try to
> get the superclass for the EModelElement.
>
> The strange thing is the getEPackage is only null when i get to the
> EModelElement(only).
>
> The Element class eClass.getEGenericSuperTypes() returns a single type
> (EmodelElement) but doing getEClassifier().getEPackage() on that type
> always returns null.
It sounds like a broken proxy. Does EObject.eIsProxy return ttrue?
>
> Here is the loop i use to go over the super types for each class.
>
> for (superType : eClass.getEGenericSuperTypes ) {
> superType.getEClassifier().getEPackage()
> }
>
> why am i getting null wheni do getEClassifier().getEPackage() on the
> EModelElement class only ?
Likely you've missed an important registration step needed for
standalone. Are you following all the documented steps?
>
> The emf i am using is the libs that come with galileo. i copied the
> emf jar files.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading ecore model from a standalone java app [message #504610 is a reply to message #504609] Mon, 21 December 2009 18:33 Go to previous messageGo to next message
Dameer Joog is currently offline Dameer JoogFriend
Messages: 17
Registered: July 2009
Junior Member
This is the code i scraped to do model loading

// Create a resource set to hold the resources.
ResourceSet resourceSet = new ResourceSetImpl();

Map<String, Object> options = resourceSet.getResourceFactoryRegistry()
.getExtensionToFactoryMap();

// options.put("xml", new XMLResourceFactoryImpl());

// Register the appropriate resource factory to handle all file
// extensions.
options.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());

// URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()):
// URI.createURI(args[0]);

URI uri = URI.createFileURI(resPath);

resource = resourceSet.getResource(uri, true);
System.out.println("Loaded " + uri);
Re: Loading ecore model from a standalone java app [message #504637 is a reply to message #504610] Mon, 21 December 2009 20:55 Go to previous messageGo to next message
Dameer Joog is currently offline Dameer JoogFriend
Messages: 17
Registered: July 2009
Junior Member
---
This is the code i use to go over the supertypes

//EGenericType superType=null;
System.out.println(" class " + eClass.getName() +" {");
for (EGenericType superType : eClass.getEGenericSuperTypes()) {

//String typeName = getTypeName(superType, eClass);

EPackage currPackage = superType.getEClassifier().getEPackage();
if(currPackage==null){
System.out.println("eClass proxy:"+eClass.eIsProxy());
System.out.println("superType proxy:"+superType.eIsProxy());
System.out.println("classifier proxy:"+superType.getEClassifier().eIsProxy());
//System.out.println("Element:null");
}else {
}

}

The code above outputs :
[java] class Element {
[java] eClass proxy:false
[java] superType proxy:false
[java] classifier proxy:true
[java] }
Re: Loading ecore model from a standalone java app [message #504689 is a reply to message #504637] Tue, 22 December 2009 08:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Dameer,

Please look at the UML documentation for how to work with UML stand
alone; specialized registrations are required, not just the general EMF
ones. If it's not working, ask on the UML2 newsgroup about it.

Dameer Joog wrote:
> ---
> This is the code i use to go over the supertypes
>
> //EGenericType superType=null;
> System.out.println(" class " + eClass.getName() +" {");
> for (EGenericType superType : eClass.getEGenericSuperTypes()) {
> //String typeName = getTypeName(superType, eClass);
>
> EPackage currPackage = superType.getEClassifier().getEPackage();
> if(currPackage==null){
> System.out.println("eClass proxy:"+eClass.eIsProxy());
> System.out.println("superType proxy:"+superType.eIsProxy());
> System.out.println("classifier
> proxy:"+superType.getEClassifier().eIsProxy());
> //System.out.println("Element:null");
> }else {
> }
> }
>
> The code above outputs :
> [java] class Element {
> [java] eClass proxy:false
> [java] superType proxy:false
> [java] classifier proxy:true
> [java] }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading ecore model from a standalone java app [message #505514 is a reply to message #504689] Thu, 31 December 2009 10:52 Go to previous messageGo to next message
Dameer Joog is currently offline Dameer JoogFriend
Messages: 17
Registered: July 2009
Junior Member
Hi Ed.

Now ... I think i am facing the same issue as http://www.openarchitectureware.org/forum/viewtopic.php?show topic=8392

I think that when its running standalone it is not able to find the Ecore.ecore file in the file path. So i maybe need to do this urimap prgaramatically. Ca you tell me what i will need to do this in java ?

Thanks a lot for all your help !

p.s.
i also asked the same question in the uml groups but i think this may not be related to UML.

http://www.eclipse.org/forums/index.php?t=msg&th=159800& amp;start=0&
Re: Loading ecore model from a standalone java app [message #505532 is a reply to message #505514] Thu, 31 December 2009 14:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Dameer,

What have you tried? What URI are you using to load the initial resource?


Dameer Joog wrote:
> Hi Ed.
>
> Now ... I think i am facing the same issue as
> http://www.openarchitectureware.org/forum/viewtopic.php?show topic=8392
>
> I think that when its running standalone it is not able to find the
> Ecore.ecore file in the file path. So i maybe need to do this urimap
> prgaramatically. Ca you tell me what i will need to do this in java ?
>
> Thanks a lot for all your help !
>
> p.s.
> i also asked the same question in the uml groups but i think this may
> not be related to UML.
>
> http://www.eclipse.org/forums/index.php?t=msg&th=159800& amp;start=0&
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading ecore model from a standalone java app [message #505537 is a reply to message #505532] Thu, 31 December 2009 21:11 Go to previous messageGo to next message
Dameer Joog is currently offline Dameer JoogFriend
Messages: 17
Registered: July 2009
Junior Member

Hi Ed.

I am using the latest emf that came with galileo btw.

This is the method i pasted before to load the initial resource its all in one method:

// Create a resource set to hold the resources.
ResourceSet resourceSet = new ResourceSetImpl();

Map<String, Object> options = resourceSet.getResourceFactoryRegistry()
.getExtensionToFactoryMap();

options.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());

URI uri = URI.createFileURI(resPath);

resource = resourceSet.getResource(uri, true);
System.out.println("Loaded " + uri);

The app is standalone with emf jar files in the class path. I did not see more things that i need to perform the uri mapping.

Thanks.
Re: Loading ecore model from a standalone java app [message #505541 is a reply to message #505537] Thu, 31 December 2009 18:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Dameer,

Comments below.

Dameer Joog wrote:
>
> Hi Ed.
>
> I am using the latest emf that came with galileo btw.
>
> This is the method i pasted before to load the initial resource its
> all in one method:
>
> // Create a resource set to hold the resources.
> ResourceSet resourceSet = new ResourceSetImpl();
>
> Map<String, Object> options = resourceSet.getResourceFactoryRegistry()
> getExtensionToFactoryMap();
>
> options.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new XMIResourceFactoryImpl());
Ecore resources should use EcoreResourceFactoryImpl.
>
> URI uri = URI.createFileURI(resPath);
>
> resource = resourceSet.getResource(uri, true);
> System.out.println("Loaded " + uri);
What's the actual value of resPath? Where are you trying to load Ecore
resources from?
>
> The app is standalone with emf jar files in the class path. I did not
> see more things that i need to perform the uri mapping.
>
> Thanks.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading ecore model from a standalone java app [message #505544 is a reply to message #505541] Thu, 31 December 2009 23:22 Go to previous messageGo to next message
Dameer Joog is currently offline Dameer JoogFriend
Messages: 17
Registered: July 2009
Junior Member
I am loading the ecore file from src/test/UML_21.ecore and it is getting successfully loaded except that something is borked on the proxy *only* on a single class called ELement that derives from EmodelElement. All other classes are fine !

Since EmodelElemnt is in Ecore.ecore it has to find it .

Here is the modified code

// Create a resource set to hold the resources.
ResourceSet resourceSet = new ResourceSetImpl();

EPackage.Registry reg1;
reg1 = resourceSet.getPackageRegistry();
reg1.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);

XMIResourceFactoryImpl xmiFactory = new XMIResourceFactoryImpl();
EcoreResourceFactoryImpl ecoreFactory = new EcoreResourceFactoryImpl();

Map<String, Object> options = resourceSet.getResourceFactoryRegistry()
.getExtensionToFactoryMap();

// Register the appropriate resource factory to handle all file
// extensions.
options.put("xmi", xmiFactory);
options.put("ecore", ecoreFactory);

URI uri = URI.createFileURI(resPath);

resource = resourceSet.getResource(uri, true);
System.out.println("Loaded " + uri);
Re: Loading ecore model from a standalone java app [message #505547 is a reply to message #504594] Thu, 31 December 2009 23:50 Go to previous messageGo to next message
Dameer Joog is currently offline Dameer JoogFriend
Messages: 17
Registered: July 2009
Junior Member
I added :

File fullPath = getFullPath(resPath);
URI uri = URI.createFileURI(fullPath.getAbsolutePath());

And all seems to work ... thank you so much for all your help !
Re: Loading ecore model from a standalone java app [message #505556 is a reply to message #505544] Fri, 01 January 2010 15:09 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Dameer,

I see that resource references
platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore so you'll need
to be able to load Ecore.ecore has well. You'll need to specify a URI
mapping from platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore to
wherever you put Ecore.ecore. It's located as source in
org.eclipse.emf.ecore/model/Ecore.ecore.


Dameer Joog wrote:
> I am loading the ecore file from src/test/UML_21.ecore and it is
> getting successfully loaded except that something is borked on the
> proxy *only* on a single class called ELement that derives from
> EmodelElement. All other classes are fine !
>
> Since EmodelElemnt is in Ecore.ecore it has to find it .
>
> Here is the modified code
>
> // Create a resource set to hold the resources.
> ResourceSet resourceSet = new ResourceSetImpl();
>
> EPackage.Registry reg1;
> reg1 = resourceSet.getPackageRegistry();
> reg1.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
>
> XMIResourceFactoryImpl xmiFactory = new XMIResourceFactoryImpl();
> EcoreResourceFactoryImpl ecoreFactory = new
> EcoreResourceFactoryImpl();
>
> Map<String, Object> options =
> resourceSet.getResourceFactoryRegistry()
> .getExtensionToFactoryMap();
>
> // Register the appropriate resource factory to handle all file
> // extensions.
> options.put("xmi", xmiFactory);
> options.put("ecore", ecoreFactory);
>
> URI uri = URI.createFileURI(resPath);
>
> resource = resourceSet.getResource(uri, true);
> System.out.println("Loaded " + uri);
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Is EMF suitable to implement key/keyref pairs?
Next Topic:Persistence of Multiplicity-Many Reference
Goto Forum:
  


Current Time: Fri Mar 29 08:17:31 GMT 2024

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

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

Back to the top