Home » Modeling » EMF » Getting a list of all Namespace URIs, including that of cross referenced packages
Getting a list of all Namespace URIs, including that of cross referenced packages [message #422330] |
Sun, 31 August 2008 11:11 |
Thomas Rheker Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Hi all,
I will first describe the general idea of what I try to achieve before
coming to my specific problem.
I generically transform EMF models to graphs. For that, I have to check
if there are any two EClasses having the same Class name, so I can
assign different identifiers to these. Also, I have to store a list of
namespace URIs so I can find the packages when transforming back from
the graph.
This all works well for self-contained packages, that is, if all
referenced classes are in the same package. But if there are cross
references to other ecore-Packages, I do not find these using either
EPackage.getAllContents() nor EcoreUtils.getAllContents(EPackage, true).
What method would I have to use to get cross referenced classes?
Below, see a snippet of my code.
Thanks for any help,
Thomas Rheker
EPackage ecorePackage = EPackage.Registry.INSTANCE.getEPackage(nsUri);
TreeIterator<EObject> ti = ecorePackage.eAllContents();
while (ti.hasNext()) {
EObject eo = ti.next();
String otherNsUri = eo.eClass().getEPackage().getNsURI();
if (!nsUriList.contains(otherNsUri)) {
if(otherNsUri.equals("http://www.eclipse.org/emf/2002/Ecore"))
continue;
nsUriList.add(eo.eClass().getEPackage().getNsURI());
GxlUtils.addEdge(gxlGraph, nsUriNode.getId(),
nsUriNode.getId(), "DMM_NsUri_" + otherNsUri);
}
}
// preprocess the package to solve class name collisions
BidiMap<URI, String> classNameMap = EcoreUtils
.preProcessPackage(nsUriList);
|
|
|
Re: Getting a list of all Namespace URIs, including that of cross referenced packages [message #422331 is a reply to message #422330] |
Sun, 31 August 2008 11:44 |
|
Hi Thomas,
We are doing something similar. Perhaps this is helpful for you:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse /emf/internal/cdo/util/CompletePackageClosure.java?root=Mode ling_Project&view=co
Cheers
/Eike
Thomas Rheker schrieb:
> Hi all,
>
> I will first describe the general idea of what I try to achieve before
> coming to my specific problem.
>
> I generically transform EMF models to graphs. For that, I have to check
> if there are any two EClasses having the same Class name, so I can
> assign different identifiers to these. Also, I have to store a list of
> namespace URIs so I can find the packages when transforming back from
> the graph.
> This all works well for self-contained packages, that is, if all
> referenced classes are in the same package. But if there are cross
> references to other ecore-Packages, I do not find these using either
> EPackage.getAllContents() nor EcoreUtils.getAllContents(EPackage, true).
> What method would I have to use to get cross referenced classes?
>
> Below, see a snippet of my code.
>
> Thanks for any help,
> Thomas Rheker
>
> EPackage ecorePackage = EPackage.Registry.INSTANCE.getEPackage(nsUri);
> TreeIterator<EObject> ti = ecorePackage.eAllContents();
> while (ti.hasNext()) {
> EObject eo = ti.next();
> String otherNsUri = eo.eClass().getEPackage().getNsURI();
> if (!nsUriList.contains(otherNsUri)) {
> if(otherNsUri.equals("http://www.eclipse.org/emf/2002/Ecore"))
> continue;
> nsUriList.add(eo.eClass().getEPackage().getNsURI());
> GxlUtils.addEdge(gxlGraph, nsUriNode.getId(),
> nsUriNode.getId(), "DMM_NsUri_" + otherNsUri);
> }
> }
>
> // preprocess the package to solve class name collisions
> BidiMap<URI, String> classNameMap = EcoreUtils
> .preProcessPackage(nsUriList);
>
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: Getting a list of all Namespace URIs, including that of cross referenced packages [message #422332 is a reply to message #422331] |
Sun, 31 August 2008 12:52 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Guys,
Comments below.
Eike Stepper wrote:
> Hi Thomas,
>
> We are doing something similar. Perhaps this is helpful for you:
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse /emf/internal/cdo/util/CompletePackageClosure.java?root=Mode ling_Project&view=co
>
>
Note that when visiting an ETypedElement (like a feature or operation)
it's not necessary to visit both the eType and the eGenericType. Same
for EClass.eSuperTypes and eGenericSuperTypes. Remember that operations
has eExceptionTypes/eGenericExceptionTypes, where that's also the case.
That's because the eType will always be the eRawType of the
EGenericType, which you are visiting anyway. Also keep in mind that
EPackages can have eSubpackages.
> Cheers
> /Eike
>
>
> Thomas Rheker schrieb:
>> Hi all,
>>
>> I will first describe the general idea of what I try to achieve before
>> coming to my specific problem.
>>
>> I generically transform EMF models to graphs. For that, I have to check
>> if there are any two EClasses having the same Class name, so I can
>> assign different identifiers to these. Also, I have to store a list of
>> namespace URIs so I can find the packages when transforming back from
>> the graph.
>> This all works well for self-contained packages,
Where two classifier scan't have the same name.
>> that is, if all
>> referenced classes are in the same package. But if there are cross
>> references to other ecore-Packages, I do not find these using either
>> EPackage.getAllContents() nor EcoreUtils.getAllContents(EPackage, true).
A generic walker would take into consideration EObject.eCrossReferences
for each contained object to find the non-containment references it has.
>> What method would I have to use to get cross referenced classes?
>>
>> Below, see a snippet of my code.
>>
>> Thanks for any help,
>> Thomas Rheker
>>
>> EPackage ecorePackage = EPackage.Registry.INSTANCE.getEPackage(nsUri);
>> TreeIterator<EObject> ti = ecorePackage.eAllContents();
>> while (ti.hasNext()) {
>> EObject eo = ti.next();
>> String otherNsUri = eo.eClass().getEPackage().getNsURI();
But here you've walked from the instance object, an object in some Ecore
model, to it's metadata, which given this is an Ecore model instance
will be an EClass from EcorePackage.eINSTANCE.
>> if (!nsUriList.contains(otherNsUri)) {
>> if(otherNsUri.equals("http://www.eclipse.org/emf/2002/Ecore"))
>> continue;
>> nsUriList.add(eo.eClass().getEPackage().getNsURI());
>> GxlUtils.addEdge(gxlGraph, nsUriNode.getId(),
>> nsUriNode.getId(), "DMM_NsUri_" + otherNsUri);
>> }
>> }
Is there somewhere that you are actually walking the tree of your
instance objects or are you working purely with Ecore instances?
>>
>> // preprocess the package to solve class name collisions
>> BidiMap<URI, String> classNameMap = EcoreUtils
>> .preProcessPackage(nsUriList);
>>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Getting a list of all Namespace URIs, including that of cross referenced packages [message #422334 is a reply to message #422333] |
Sun, 31 August 2008 19:08 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Eike,
Yes, it makes a difference. Visiting the eType is like visiting only
the eRawType of the EGenericType, and hence visiting only the eType will
miss any type arguments specified on the EGenericType and of course
recursively everything below those as well.
Eike Stepper wrote:
> Ed Merks schrieb:
>> Guys,
>>
>> Comments below.
>>
>> Eike Stepper wrote:
>>> Hi Thomas,
>>>
>>> We are doing something similar. Perhaps this is helpful for you:
>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse /emf/internal/cdo/util/CompletePackageClosure.java?root=Mode ling_Project&view=co
>>>
>>>
>> Note that when visiting an ETypedElement (like a feature or
>> operation) it's not necessary to visit both the eType and the
>> eGenericType. Same for EClass.eSuperTypes and eGenericSuperTypes.
>> Remember that operations has eExceptionTypes/eGenericExceptionTypes,
>> where that's also the case. That's because the eType will always be
>> the eRawType of the EGenericType, which you are visiting anyway.
> Does it make a difference which of the two forms (generic or not) is
> used, i.e. does only one include the other?
>
> Cheers
> /Eike
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Getting a list of all Namespace URIs, including that of cross referenced packages [message #422335 is a reply to message #422334] |
Sun, 31 August 2008 19:21 |
|
Ed Merks schrieb:
> Eike,
>
> Yes, it makes a difference. Visiting the eType is like visiting only
> the eRawType of the EGenericType, and hence visiting only the eType
> will miss any type arguments specified on the EGenericType and of
> course recursively everything below those as well.
I see! Then I will remove all traversals of the non-generic forms to
spare an unnecessary set lookup.
Thank you
/Eike
>
>
> Eike Stepper wrote:
>> Ed Merks schrieb:
>>> Guys,
>>>
>>> Comments below.
>>>
>>> Eike Stepper wrote:
>>>> Hi Thomas,
>>>>
>>>> We are doing something similar. Perhaps this is helpful for you:
>>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf.cdo/plugins/org.eclipse.emf.cdo/src/org/eclipse /emf/internal/cdo/util/CompletePackageClosure.java?root=Mode ling_Project&view=co
>>>>
>>>>
>>> Note that when visiting an ETypedElement (like a feature or
>>> operation) it's not necessary to visit both the eType and the
>>> eGenericType. Same for EClass.eSuperTypes and eGenericSuperTypes.
>>> Remember that operations has eExceptionTypes/eGenericExceptionTypes,
>>> where that's also the case. That's because the eType will always be
>>> the eRawType of the EGenericType, which you are visiting anyway.
>> Does it make a difference which of the two forms (generic or not) is
>> used, i.e. does only one include the other?
>>
>> Cheers
>> /Eike
>>
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Goto Forum:
Current Time: Thu Apr 25 14:31:51 GMT 2024
Powered by FUDForum. Page generated in 0.03708 seconds
|