Home » Modeling » UML2 » Re: Navigating on UML metamodel
Re: Navigating on UML metamodel [message #516099] |
Mon, 22 February 2010 13:38 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
I think it's best to ask about UML specific details on the UML2
newsgroup, which I've added to the "to" list of the reply, so no need to
repost.
CaribeanAlien wrote:
> Hi,
>
> I would like to create a standalone program able to display the list
> of elements available inside of the UML metamodel. To do this, I've
> tried to register into the resourceSet the path to the UML jar
> (org.eclipse.uml2.uml.resources_2.2.0.v200805131030.jar), as shown in
> the FAQ. Then, my thought was to access to the resource representing
> the UML Metamodel :
> Resource res =
> _resourceSet.getResource(URI.createURI(UMLResource.UML_METAM
> ODEL_URI), true);
> and to navigate over it.
>
> I didn't get error, but unexpected results. When I display elements
> name, It seems to be all the same. A lot of MetaElement, ... But no
> access to the real name! It seems to be a real mess. Does anyone has
> an idea?
> here is the test code I'm working on : http://www.pastebin.com/f44dc1608
>
> I'm currently waiting for the EMF book, hoping this to help me. Thanks
> in advance for any help!
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: Navigating on UML metamodel [message #516488 is a reply to message #516348] |
Wed, 24 February 2010 08:41 |
CaribeanAlien Messages: 15 Registered: February 2010 |
Junior Member |
|
|
Mmm, I have tried this either unfortunately, but it doesn't change anything.
To explain in better words the result I want to reach, here is my problem :
I need to implement a program loading the UML metamodel, in order to modify it. The first step before the modification is at least to display UML elements.
So this is what I do with my program : I load the jar file, try to parse the correct resource. this is what I get : http://picasaweb.google.com/lh/photo/n-y68jEsK7ks-TkInrZZdQ? feat=directlink
This tool has also the possibility to load any ecore metamodel. So I found an ecore version of the UML metamodel, and tried to load it.
Here is what we can see, it seems to be a much better result, more understandable.
http://picasaweb.google.com/lh/photo/ErucF-ZTGduGOOViZIP6Cw? feat=directlink
That is great! the problem is that I need absolutely to work on the jar, in order to modify the metamodel in the jar (hoping it will be possible to do it...).
Then, the final goal is to use this new metamodel in another EMF program (as source for EMF UML Metamodel, replacing the jar in the line
"URI uri = URI.createURI(" jar:file:/C:/org.eclipse.uml2.uml.resources_2.2.0.v200805131 030.jar!/ ");" in any EMF program.
Do you see my point?
Thank you for the help!
|
|
| |
Re: Navigating on UML metamodel [message #516559 is a reply to message #516488] |
Wed, 24 February 2010 11:52 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Comments below,
CaribeanAlien wrote:
> Mmm, I have tried this either unfortunately, but it doesn't change
> anything. To explain in better words the result I want to reach, here
> is my problem : I need to implement a program loading the UML
> metamodel, in order to modify it. The first step before the
> modification is at least to display UML elements.
> So this is what I do with my program : I load the jar file, try to
> parse the correct resource. this is what I get :
> http://picasaweb.google.com/lh/photo/n-y68jEsK7ks-TkInrZZdQ? feat=directlink
>
The AnyType instances and much of what I see here is what I'd expect if
the namespace in the serialization doesn't end up properly mapping to a
EPackage's nsURI. That likely means you've not registered all the
packages needed to read the instance.
>
> This tool has also the possibility to load any ecore metamodel. So I
> found an ecore version of the UML metamodel, and tried to load it.
> Here is what we can see, it seems to be a much better result, more
> understandable.
> http://picasaweb.google.com/lh/photo/ErucF-ZTGduGOOViZIP6Cw? feat=directlink
>
Yes, this looks like it's working well.
>
> That is great! the problem is that I need absolutely to work on the
> jar, in order to modify the metamodel in the jar (hoping it will be
> possible to do it...). Then, the final goal is to use this new
> metamodel in another EMF program (as source for EMF UML Metamodel,
> replacing the jar in the line "URI uri = URI.createURI("
> jar:file:/C:/org.eclipse.uml2.uml.resources_2.2.0.v200805131 030.jar!/
> ");" in any EMF program.
>
> Do you see my point?
Yes. It's just not clear looking at the source what little thing might
be wrong or missing. It looks like you registered the package
correctly. I tried running it and it worked correctly for me. Go figure.
>
> Thank you for the help!
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Navigating on UML metamodel [message #516576 is a reply to message #516559] |
Wed, 24 February 2010 12:56 |
CaribeanAlien Messages: 15 Registered: February 2010 |
Junior Member |
|
|
Ed Merks wrote on Wed, 24 February 2010 06:52 | Comments below,
Yes. It's just not clear looking at the source what little thing might
be wrong or missing. It looks like you registered the package
correctly. I tried running it and it worked correctly for me. Go figure.
|
Are you saying that you succeed in displaying the elements? It's quite new for me, maybe I have correct information, but I need to look deeply into the results. From the TreeIterator I got, I just parse the first level of the tree (shorting it with the prune() method), and I got some elements (mainly the first was "Model", and most of the others were "MetaClass").
So I will try in a close future to check if something is wrong with the registering of packages, but I'm not so convinced about my chances of solving it...
Anyway, if this can help to solve the problem : when I tried to access features of elements, I got this strange thing : I catch the list of features for one element, and then, I parse this list in order to do :
element.get(feature);
=> but sometimes, this instruction returns "element doesn't have this feature", despite the fact that I got the list from the element itself. Isn't it weird?
|
|
|
Re: Navigating on UML metamodel [message #516637 is a reply to message #516576] |
Wed, 24 February 2010 16:01 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Comments below.
CaribeanAlien wrote:
> Ed Merks wrote on Wed, 24 February 2010 06:52
>> Comments below,
>>
>>
>> Yes. It's just not clear looking at the source what little thing
>> might be wrong or missing. It looks like you registered the package
>> correctly. I tried running it and it worked correctly for me. Go
>> figure.
>
>
>
> Are you saying that you succeed in displaying the elements?
Yes.
> It's quite new for me, maybe I have correct information, but I need to
> look deeply into the results. From the TreeIterator I got, I just
> parse the first level of the tree (shorting it with the prune()
> method), and I got some elements (mainly the first was "Model", and
> most of the others were "MetaClass").
Not sure what you refer to as "MetaClass". If I eliminate your lookup
loop, I see objects like this:
>org.eclipse.uml2.uml.internal.resource.UMLResourceImpl@2bee2bee
uri='pathmap://UML_METAMODELS/UML.metamodel.uml'
>>org.eclipse.uml2.uml.internal.impl.ModelImpl 2125758132
>>org.eclipse.uml2.uml.internal.impl.PackageImportImpl 624567610
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 360846722
>>org.eclipse.uml2.uml.internal.impl.CommentImpl 806760470
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 845689448
>>org.eclipse.uml2.uml.internal.impl.CommentImpl 859583292
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 882128020
>>org.eclipse.uml2.uml.internal.impl.CommentImpl 1837526406
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 1863085836
Someone has already pointed out that you shouldn't be calling eGet on
the eClass() itself but rather on the instance.
System.out.println("\t" + esf.getName() + " : " + eobj.eGet(esf));
>
> So I will try in a close future to check if something is wrong with
> the registering of packages, but I'm not so convinced about my chances
> of solving it... :(
It looks to me like it's all working correctly. What appears to be wrong?
>
> Anyway, if this can help to solve the problem : when I tried to access
> features of elements, I got this strange thing : I catch the list of
> features for one element, and then, I parse this list in order to do :
> element.get(feature); => but sometimes, this instruction returns
> "element doesn't have this feature", despite the fact that I got the
> list from the element itself. Isn't it weird?
I'm not seeing that either. It helps to very clearly explain your
problem and to provide code others can use to reproduce the issue. This
example works for me: (Obviously you'd have to point it at where the
jar is on your system.)
package snippet;
import java.util.ListIterator;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
public class Snippet
{
public static void main(String arg[])
{
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Map uriMap = resourceSet.getURIConverter().getURIMap();
URI uri =
URI.createURI(" jar:file:/c:/sandbox/galileo.modeling.sr1/eclipse/plugins/or g.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/ ");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uri.appendSegment("profiles").appendSegment(""));
System.out.println("[readMM] : try to access to " +
UMLResource.UML_METAMODEL_URI);
Resource res =
resourceSet.getResource(URI.createURI(UMLResource.UML_METAMO DEL_URI), true);
EcoreUtil.resolveAll(res);
System.out.println(">" + res.toString());
TreeIterator<EObject> it = res.getAllContents();
while (it.hasNext())
{
EObject eobj = (EObject)it.next();
System.out.println(">>" + eobj.getClass().getName() + " " +
eobj.hashCode());
if (eobj.eIsProxy())
{
System.out.println("proxy PROBLEM");
System.out.println(eobj.eClass().getName());
EObject eobjResolved = EcoreUtil.resolve(eobj, resourceSet);
if (eobjResolved.equals(eobj))
{
System.err.println("Proxy not solved");
}
else
{
System.out.println("Proxy solved : " +
eobjResolved.hashCode());
eobj = eobjResolved;
}
}
EList<EStructuralFeature> listee =
eobj.eClass().getEAllStructuralFeatures();
ListIterator<EStructuralFeature> li = listee.listIterator();
while (li.hasNext())
{
EStructuralFeature esf = li.next();
try
{
System.out.println("\t" + esf.getName() + " : " +
eobj.eGet(esf));
}
catch (Exception e)
{//e.printStackTrace();
}
}
if (eobj.eClass() instanceof EClass)
{// if
if (eobj.eContainer() == null)
{
System.out.println("this element has a null container : is
it the root element? ");
}
}
//it.prune();
}
}
}
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Navigating on UML metamodel [message #516656 is a reply to message #516637] |
Wed, 24 February 2010 16:55 |
Tim Myer Messages: 81 Registered: July 2009 |
Member |
|
|
Hi CaribeanAlien:
Is it perhaps a version issue?
Just out of curiosity, what does your classpath look like? I was able
to get a result similar to yours when I loaded up the UML2 2.2.0
resources jar (what you have in your code) when using the 3.0 versions
of EMF and UML2 on my classpath. The code works for me, too, when I use
UML2 3.0 resources.
---Tim---
Ed Merks wrote:
> Comments below.
>
> CaribeanAlien wrote:
>> Ed Merks wrote on Wed, 24 February 2010 06:52
>>> Comments below,
>>>
>>>
>>> Yes. It's just not clear looking at the source what little thing
>>> might be wrong or missing. It looks like you registered the package
>>> correctly. I tried running it and it worked correctly for me. Go
>>> figure.
>>
>>
>>
>> Are you saying that you succeed in displaying the elements?
> Yes.
>> It's quite new for me, maybe I have correct information, but I need to
>> look deeply into the results. From the TreeIterator I got, I just
>> parse the first level of the tree (shorting it with the prune()
>> method), and I got some elements (mainly the first was "Model", and
>> most of the others were "MetaClass").
> Not sure what you refer to as "MetaClass". If I eliminate your lookup
> loop, I see objects like this:
>
> >org.eclipse.uml2.uml.internal.resource.UMLResourceImpl@2bee2bee
> uri='pathmap://UML_METAMODELS/UML.metamodel.uml'
> >>org.eclipse.uml2.uml.internal.impl.ModelImpl 2125758132
> >>org.eclipse.uml2.uml.internal.impl.PackageImportImpl 624567610
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 360846722
> >>org.eclipse.uml2.uml.internal.impl.CommentImpl 806760470
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 845689448
> >>org.eclipse.uml2.uml.internal.impl.CommentImpl 859583292
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 882128020
> >>org.eclipse.uml2.uml.internal.impl.CommentImpl 1837526406
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 1863085836
>
> Someone has already pointed out that you shouldn't be calling eGet on
> the eClass() itself but rather on the instance.
>
> System.out.println("\t" + esf.getName() + " : " + eobj.eGet(esf));
>>
>> So I will try in a close future to check if something is wrong with
>> the registering of packages, but I'm not so convinced about my chances
>> of solving it... :(
> It looks to me like it's all working correctly. What appears to be wrong?
>>
>> Anyway, if this can help to solve the problem : when I tried to access
>> features of elements, I got this strange thing : I catch the list of
>> features for one element, and then, I parse this list in order to do :
>> element.get(feature); => but sometimes, this instruction returns
>> "element doesn't have this feature", despite the fact that I got the
>> list from the element itself. Isn't it weird?
> I'm not seeing that either. It helps to very clearly explain your
> problem and to provide code others can use to reproduce the issue. This
> example works for me: (Obviously you'd have to point it at where the
> jar is on your system.)
>
> package snippet;
>
> import java.util.ListIterator;
> import java.util.Map;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.TreeIterator;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EClass;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.ecore.EStructuralFeature;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UMLResource;
>
> public class Snippet
> {
> public static void main(String arg[])
> {
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Map uriMap = resourceSet.getURIConverter().getURIMap();
> URI uri =
> URI.createURI(" jar:file:/c:/sandbox/galileo.modeling.sr1/eclipse/plugins/or g.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/ ");
>
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> uri.appendSegment("profiles").appendSegment(""));
>
>
> System.out.println("[readMM] : try to access to " +
> UMLResource.UML_METAMODEL_URI);
> Resource res =
> resourceSet.getResource(URI.createURI(UMLResource.UML_METAMO DEL_URI),
> true);
> EcoreUtil.resolveAll(res);
> System.out.println(">" + res.toString());
> TreeIterator<EObject> it = res.getAllContents();
>
> while (it.hasNext())
> {
> EObject eobj = (EObject)it.next();
>
> System.out.println(">>" + eobj.getClass().getName() + " " +
> eobj.hashCode());
>
> if (eobj.eIsProxy())
> {
> System.out.println("proxy PROBLEM");
> System.out.println(eobj.eClass().getName());
>
> EObject eobjResolved = EcoreUtil.resolve(eobj, resourceSet);
> if (eobjResolved.equals(eobj))
> {
> System.err.println("Proxy not solved");
> }
> else
> {
> System.out.println("Proxy solved : " +
> eobjResolved.hashCode());
> eobj = eobjResolved;
> }
> }
>
> EList<EStructuralFeature> listee =
> eobj.eClass().getEAllStructuralFeatures();
> ListIterator<EStructuralFeature> li = listee.listIterator();
> while (li.hasNext())
> {
> EStructuralFeature esf = li.next();
> try
> {
> System.out.println("\t" + esf.getName() + " : " +
> eobj.eGet(esf));
> }
> catch (Exception e)
> {//e.printStackTrace();
>
> }
> }
>
> if (eobj.eClass() instanceof EClass)
> {// if
> if (eobj.eContainer() == null)
> {
> System.out.println("this element has a null container : is
> it the root element? ");
> }
> }
>
> //it.prune();
> }
>
> }
> }
>
>
|
|
| | | | | |
Re: Navigating on UML metamodel [message #628252 is a reply to message #628246] |
Wed, 24 February 2010 08:41 |
CaribeanAlien Messages: 15 Registered: February 2010 |
Junior Member |
|
|
Mmm, I have tried this either unfortunately, but it doesn't change anything.
To explain in better words the result I want to reach, here is my problem :
I need to implement a program loading the UML metamodel, in order to modify it. The first step before the modification is at least to display UML elements.
So this is what I do with my program : I load the jar file, try to parse the correct resource. this is what I get : http://picasaweb.google.com/lh/photo/n-y68jEsK7ks-TkInrZZdQ? feat=directlink
This tool has also the possibility to load any ecore metamodel. So I found an ecore version of the UML metamodel, and tried to load it.
Here is what we can see, it seems to be a much better result, more understandable.
http://picasaweb.google.com/lh/photo/ErucF-ZTGduGOOViZIP6Cw? feat=directlink
That is great! the problem is that I need absolutely to work on the jar, in order to modify the metamodel in the jar (hoping it will be possible to do it...).
Then, the final goal is to use this new metamodel in another EMF program (as source for EMF UML Metamodel, replacing the jar in the line
"URI uri = URI.createURI(" jar:file:/C:/org.eclipse.uml2.uml.resources_2.2.0.v200805131 030.jar!/ ");" in any EMF program.
Do you see my point?
Thank you for the help!
|
|
| |
Re: Navigating on UML metamodel [message #628254 is a reply to message #628252] |
Wed, 24 February 2010 11:52 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Comments below,
CaribeanAlien wrote:
> Mmm, I have tried this either unfortunately, but it doesn't change
> anything. To explain in better words the result I want to reach, here
> is my problem : I need to implement a program loading the UML
> metamodel, in order to modify it. The first step before the
> modification is at least to display UML elements.
> So this is what I do with my program : I load the jar file, try to
> parse the correct resource. this is what I get :
> http://picasaweb.google.com/lh/photo/n-y68jEsK7ks-TkInrZZdQ? feat=directlink
>
The AnyType instances and much of what I see here is what I'd expect if
the namespace in the serialization doesn't end up properly mapping to a
EPackage's nsURI. That likely means you've not registered all the
packages needed to read the instance.
>
> This tool has also the possibility to load any ecore metamodel. So I
> found an ecore version of the UML metamodel, and tried to load it.
> Here is what we can see, it seems to be a much better result, more
> understandable.
> http://picasaweb.google.com/lh/photo/ErucF-ZTGduGOOViZIP6Cw? feat=directlink
>
Yes, this looks like it's working well.
>
> That is great! the problem is that I need absolutely to work on the
> jar, in order to modify the metamodel in the jar (hoping it will be
> possible to do it...). Then, the final goal is to use this new
> metamodel in another EMF program (as source for EMF UML Metamodel,
> replacing the jar in the line "URI uri = URI.createURI("
> jar:file:/C:/org.eclipse.uml2.uml.resources_2.2.0.v200805131 030.jar!/
> ");" in any EMF program.
>
> Do you see my point?
Yes. It's just not clear looking at the source what little thing might
be wrong or missing. It looks like you registered the package
correctly. I tried running it and it worked correctly for me. Go figure.
>
> Thank you for the help!
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Navigating on UML metamodel [message #628255 is a reply to message #516559] |
Wed, 24 February 2010 12:56 |
CaribeanAlien Messages: 15 Registered: February 2010 |
Junior Member |
|
|
Ed Merks wrote on Wed, 24 February 2010 06:52
> Comments below,
>
>
> Yes. It's just not clear looking at the source what little thing might
> be wrong or missing. It looks like you registered the package
> correctly. I tried running it and it worked correctly for me. Go figure.
Are you saying that you succeed in displaying the elements? It's quite new for me, maybe I have correct information, but I need to look deeply into the results. From the TreeIterator I got, I just parse the first level of the tree (shorting it with the prune() method), and I got some elements (mainly the first was "Model", and most of the others were "MetaClass").
So I will try in a close future to check if something is wrong with the registering of packages, but I'm not so convinced about my chances of solving it... :(
Anyway, if this can help to solve the problem : when I tried to access features of elements, I got this strange thing : I catch the list of features for one element, and then, I parse this list in order to do :
element.get(feature);
=> but sometimes, this instruction returns "element doesn't have this feature", despite the fact that I got the list from the element itself. Isn't it weird?
|
|
|
Re: Navigating on UML metamodel [message #628257 is a reply to message #628255] |
Wed, 24 February 2010 16:01 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Comments below.
CaribeanAlien wrote:
> Ed Merks wrote on Wed, 24 February 2010 06:52
>> Comments below,
>>
>>
>> Yes. It's just not clear looking at the source what little thing
>> might be wrong or missing. It looks like you registered the package
>> correctly. I tried running it and it worked correctly for me. Go
>> figure.
>
>
>
> Are you saying that you succeed in displaying the elements?
Yes.
> It's quite new for me, maybe I have correct information, but I need to
> look deeply into the results. From the TreeIterator I got, I just
> parse the first level of the tree (shorting it with the prune()
> method), and I got some elements (mainly the first was "Model", and
> most of the others were "MetaClass").
Not sure what you refer to as "MetaClass". If I eliminate your lookup
loop, I see objects like this:
>org.eclipse.uml2.uml.internal.resource.UMLResourceImpl@2bee2bee
uri='pathmap://UML_METAMODELS/UML.metamodel.uml'
>>org.eclipse.uml2.uml.internal.impl.ModelImpl 2125758132
>>org.eclipse.uml2.uml.internal.impl.PackageImportImpl 624567610
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 360846722
>>org.eclipse.uml2.uml.internal.impl.CommentImpl 806760470
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 845689448
>>org.eclipse.uml2.uml.internal.impl.CommentImpl 859583292
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 882128020
>>org.eclipse.uml2.uml.internal.impl.CommentImpl 1837526406
>>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 1863085836
Someone has already pointed out that you shouldn't be calling eGet on
the eClass() itself but rather on the instance.
System.out.println("\t" + esf.getName() + " : " + eobj.eGet(esf));
>
> So I will try in a close future to check if something is wrong with
> the registering of packages, but I'm not so convinced about my chances
> of solving it... :(
It looks to me like it's all working correctly. What appears to be wrong?
>
> Anyway, if this can help to solve the problem : when I tried to access
> features of elements, I got this strange thing : I catch the list of
> features for one element, and then, I parse this list in order to do :
> element.get(feature); => but sometimes, this instruction returns
> "element doesn't have this feature", despite the fact that I got the
> list from the element itself. Isn't it weird?
I'm not seeing that either. It helps to very clearly explain your
problem and to provide code others can use to reproduce the issue. This
example works for me: (Obviously you'd have to point it at where the
jar is on your system.)
package snippet;
import java.util.ListIterator;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
public class Snippet
{
public static void main(String arg[])
{
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Map uriMap = resourceSet.getURIConverter().getURIMap();
URI uri =
URI.createURI(" jar:file:/c:/sandbox/galileo.modeling.sr1/eclipse/plugins/or g.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/ ");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uri.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uri.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uri.appendSegment("profiles").appendSegment(""));
System.out.println("[readMM] : try to access to " +
UMLResource.UML_METAMODEL_URI);
Resource res =
resourceSet.getResource(URI.createURI(UMLResource.UML_METAMO DEL_URI), true);
EcoreUtil.resolveAll(res);
System.out.println(">" + res.toString());
TreeIterator<EObject> it = res.getAllContents();
while (it.hasNext())
{
EObject eobj = (EObject)it.next();
System.out.println(">>" + eobj.getClass().getName() + " " +
eobj.hashCode());
if (eobj.eIsProxy())
{
System.out.println("proxy PROBLEM");
System.out.println(eobj.eClass().getName());
EObject eobjResolved = EcoreUtil.resolve(eobj, resourceSet);
if (eobjResolved.equals(eobj))
{
System.err.println("Proxy not solved");
}
else
{
System.out.println("Proxy solved : " +
eobjResolved.hashCode());
eobj = eobjResolved;
}
}
EList<EStructuralFeature> listee =
eobj.eClass().getEAllStructuralFeatures();
ListIterator<EStructuralFeature> li = listee.listIterator();
while (li.hasNext())
{
EStructuralFeature esf = li.next();
try
{
System.out.println("\t" + esf.getName() + " : " +
eobj.eGet(esf));
}
catch (Exception e)
{//e.printStackTrace();
}
}
if (eobj.eClass() instanceof EClass)
{// if
if (eobj.eContainer() == null)
{
System.out.println("this element has a null container : is
it the root element? ");
}
}
//it.prune();
}
}
}
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Navigating on UML metamodel [message #628259 is a reply to message #516637] |
Wed, 24 February 2010 16:55 |
Tim Myer Messages: 81 Registered: July 2009 |
Member |
|
|
Hi CaribeanAlien:
Is it perhaps a version issue?
Just out of curiosity, what does your classpath look like? I was able
to get a result similar to yours when I loaded up the UML2 2.2.0
resources jar (what you have in your code) when using the 3.0 versions
of EMF and UML2 on my classpath. The code works for me, too, when I use
UML2 3.0 resources.
---Tim---
Ed Merks wrote:
> Comments below.
>
> CaribeanAlien wrote:
>> Ed Merks wrote on Wed, 24 February 2010 06:52
>>> Comments below,
>>>
>>>
>>> Yes. It's just not clear looking at the source what little thing
>>> might be wrong or missing. It looks like you registered the package
>>> correctly. I tried running it and it worked correctly for me. Go
>>> figure.
>>
>>
>>
>> Are you saying that you succeed in displaying the elements?
> Yes.
>> It's quite new for me, maybe I have correct information, but I need to
>> look deeply into the results. From the TreeIterator I got, I just
>> parse the first level of the tree (shorting it with the prune()
>> method), and I got some elements (mainly the first was "Model", and
>> most of the others were "MetaClass").
> Not sure what you refer to as "MetaClass". If I eliminate your lookup
> loop, I see objects like this:
>
> >org.eclipse.uml2.uml.internal.resource.UMLResourceImpl@2bee2bee
> uri='pathmap://UML_METAMODELS/UML.metamodel.uml'
> >>org.eclipse.uml2.uml.internal.impl.ModelImpl 2125758132
> >>org.eclipse.uml2.uml.internal.impl.PackageImportImpl 624567610
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 360846722
> >>org.eclipse.uml2.uml.internal.impl.CommentImpl 806760470
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 845689448
> >>org.eclipse.uml2.uml.internal.impl.CommentImpl 859583292
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 882128020
> >>org.eclipse.uml2.uml.internal.impl.CommentImpl 1837526406
> >>org.eclipse.uml2.uml.internal.impl.PrimitiveTypeImpl 1863085836
>
> Someone has already pointed out that you shouldn't be calling eGet on
> the eClass() itself but rather on the instance.
>
> System.out.println("\t" + esf.getName() + " : " + eobj.eGet(esf));
>>
>> So I will try in a close future to check if something is wrong with
>> the registering of packages, but I'm not so convinced about my chances
>> of solving it... :(
> It looks to me like it's all working correctly. What appears to be wrong?
>>
>> Anyway, if this can help to solve the problem : when I tried to access
>> features of elements, I got this strange thing : I catch the list of
>> features for one element, and then, I parse this list in order to do :
>> element.get(feature); => but sometimes, this instruction returns
>> "element doesn't have this feature", despite the fact that I got the
>> list from the element itself. Isn't it weird?
> I'm not seeing that either. It helps to very clearly explain your
> problem and to provide code others can use to reproduce the issue. This
> example works for me: (Obviously you'd have to point it at where the
> jar is on your system.)
>
> package snippet;
>
> import java.util.ListIterator;
> import java.util.Map;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.TreeIterator;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EClass;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.ecore.EStructuralFeature;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UMLResource;
>
> public class Snippet
> {
> public static void main(String arg[])
> {
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> Map uriMap = resourceSet.getURIConverter().getURIMap();
> URI uri =
> URI.createURI(" jar:file:/c:/sandbox/galileo.modeling.sr1/eclipse/plugins/or g.eclipse.uml2.uml.resources_3.0.0.v200906011111.jar!/ ");
>
> uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
> uri.appendSegment("libraries").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
> uri.appendSegment("metamodels").appendSegment(""));
> uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
> uri.appendSegment("profiles").appendSegment(""));
>
>
> System.out.println("[readMM] : try to access to " +
> UMLResource.UML_METAMODEL_URI);
> Resource res =
> resourceSet.getResource(URI.createURI(UMLResource.UML_METAMO DEL_URI),
> true);
> EcoreUtil.resolveAll(res);
> System.out.println(">" + res.toString());
> TreeIterator<EObject> it = res.getAllContents();
>
> while (it.hasNext())
> {
> EObject eobj = (EObject)it.next();
>
> System.out.println(">>" + eobj.getClass().getName() + " " +
> eobj.hashCode());
>
> if (eobj.eIsProxy())
> {
> System.out.println("proxy PROBLEM");
> System.out.println(eobj.eClass().getName());
>
> EObject eobjResolved = EcoreUtil.resolve(eobj, resourceSet);
> if (eobjResolved.equals(eobj))
> {
> System.err.println("Proxy not solved");
> }
> else
> {
> System.out.println("Proxy solved : " +
> eobjResolved.hashCode());
> eobj = eobjResolved;
> }
> }
>
> EList<EStructuralFeature> listee =
> eobj.eClass().getEAllStructuralFeatures();
> ListIterator<EStructuralFeature> li = listee.listIterator();
> while (li.hasNext())
> {
> EStructuralFeature esf = li.next();
> try
> {
> System.out.println("\t" + esf.getName() + " : " +
> eobj.eGet(esf));
> }
> catch (Exception e)
> {//e.printStackTrace();
>
> }
> }
>
> if (eobj.eClass() instanceof EClass)
> {// if
> if (eobj.eContainer() == null)
> {
> System.out.println("this element has a null container : is
> it the root element? ");
> }
> }
>
> //it.prune();
> }
>
> }
> }
>
>
|
|
| | | |
Goto Forum:
Current Time: Thu Sep 26 18:34:20 GMT 2024
Powered by FUDForum. Page generated in 0.06371 seconds
|