Home » Modeling » UML2 » how to find out the type of element in a package
|
Re: how to find out the type of element in a package [message #476922 is a reply to message #476921] |
Mon, 11 February 2008 02:42 |
Rafael Chaves Messages: 362 Registered: July 2009 |
Senior Member |
|
|
Zengyu,
Like with any ECore based metamodel, you can retrieve the metaclass of
the model element (or EObject) invoking the eClass() operation.
You can then compare the result with the metaclass literal obtained via
<metamodel>Package.Literals.<metaclass constant>. For example,
UMLPackage.Literals.CLASS, UMLPackage.Literals.INTERFACE,
UMLPackage.Literals.COMPONENT etc.
HTH,
Rafael
Zengyu Lu wrote:
> Hi,
>
> Supposed a UML2 package has been loaded. I want to traverse this package
> and find out the type of each element like class, interface, or
> component programmatically. How could I do it?
>
> Thanks for any solutions.
>
> Zengyu
|
|
|
Re: how to find out the type of element in a package [message #476923 is a reply to message #476922] |
Mon, 11 February 2008 06:40 |
Eclipse User |
|
|
|
Originally posted by: antti.evesti.vtt.fi
I have made it as follows in my code.
EList<Element> el = package.getOwnedElements();
for(Object o : el) {
if(o instanceof StateMachine) {
stateMachine((StateMachine) o);
} else if (o instanceof Activity){
activity((Activity) o);
} else if(o instanceof Collaboration) {
sequenceDiagram((Collaboration) o);
} else if(o instanceof Component) {
componentDiagram((Component) o);
} else {
//System.out.println("Unknown diagram type");
}
I don't know is this the best way, but it looks working.
BR,
Antti
"Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
news:foocm6$517$1@build.eclipse.org...
> Zengyu,
>
> Like with any ECore based metamodel, you can retrieve the metaclass of
> the model element (or EObject) invoking the eClass() operation.
>
> You can then compare the result with the metaclass literal obtained via
> <metamodel>Package.Literals.<metaclass constant>. For example,
> UMLPackage.Literals.CLASS, UMLPackage.Literals.INTERFACE,
> UMLPackage.Literals.COMPONENT etc.
>
> HTH,
>
> Rafael
>
> Zengyu Lu wrote:
>> Hi,
>>
>> Supposed a UML2 package has been loaded. I want to traverse this package
>> and find out the type of each element like class, interface, or
>> component programmatically. How could I do it?
>>
>> Thanks for any solutions.
>>
>> Zengyu
|
|
| |
Re: how to find out the type of element in a package [message #476933 is a reply to message #476923] |
Wed, 13 February 2008 19:49 |
kevin Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Antti,
Actually I had a solution that is very similar like yours. Just use
if(obj instanceof internal.ClassImpl) and other implementations to find
out the type of each element in package. Well, it works. But I do not
think it is a good idea to access internal things directly. Neither does
Eclipse. :)
But thanks anyway!
Zengyu
Antti Evesti wrote:
> I have made it as follows in my code.
> EList<Element> el = package.getOwnedElements();
> for(Object o : el) {
> if(o instanceof StateMachine) {
> stateMachine((StateMachine) o);
> } else if (o instanceof Activity){
> activity((Activity) o);
> } else if(o instanceof Collaboration) {
> sequenceDiagram((Collaboration) o);
> } else if(o instanceof Component) {
> componentDiagram((Component) o);
> } else {
> //System.out.println("Unknown diagram type");
> }
>
> I don't know is this the best way, but it looks working.
>
> BR,
> Antti
>
> "Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
> news:foocm6$517$1@build.eclipse.org...
>> Zengyu,
>>
>> Like with any ECore based metamodel, you can retrieve the metaclass of
>> the model element (or EObject) invoking the eClass() operation.
>>
>> You can then compare the result with the metaclass literal obtained via
>> <metamodel>Package.Literals.<metaclass constant>. For example,
>> UMLPackage.Literals.CLASS, UMLPackage.Literals.INTERFACE,
>> UMLPackage.Literals.COMPONENT etc.
>>
>> HTH,
>>
>> Rafael
>>
>> Zengyu Lu wrote:
>>> Hi,
>>>
>>> Supposed a UML2 package has been loaded. I want to traverse this package
>>> and find out the type of each element like class, interface, or
>>> component programmatically. How could I do it?
>>>
>>> Thanks for any solutions.
>>>
>>> Zengyu
>
>
|
|
|
Re: how to find out the type of element in a package [message #626000 is a reply to message #476921] |
Mon, 11 February 2008 02:42 |
Rafael Chaves Messages: 362 Registered: July 2009 |
Senior Member |
|
|
Zengyu,
Like with any ECore based metamodel, you can retrieve the metaclass of
the model element (or EObject) invoking the eClass() operation.
You can then compare the result with the metaclass literal obtained via
<metamodel>Package.Literals.<metaclass constant>. For example,
UMLPackage.Literals.CLASS, UMLPackage.Literals.INTERFACE,
UMLPackage.Literals.COMPONENT etc.
HTH,
Rafael
Zengyu Lu wrote:
> Hi,
>
> Supposed a UML2 package has been loaded. I want to traverse this package
> and find out the type of each element like class, interface, or
> component programmatically. How could I do it?
>
> Thanks for any solutions.
>
> Zengyu
|
|
|
Re: how to find out the type of element in a package [message #626022 is a reply to message #476922] |
Mon, 11 February 2008 06:40 |
Eclipse User |
|
|
|
Originally posted by: antti.evesti.vtt.fi
I have made it as follows in my code.
EList<Element> el = package.getOwnedElements();
for(Object o : el) {
if(o instanceof StateMachine) {
stateMachine((StateMachine) o);
} else if (o instanceof Activity){
activity((Activity) o);
} else if(o instanceof Collaboration) {
sequenceDiagram((Collaboration) o);
} else if(o instanceof Component) {
componentDiagram((Component) o);
} else {
//System.out.println("Unknown diagram type");
}
I don't know is this the best way, but it looks working.
BR,
Antti
"Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
news:foocm6$517$1@build.eclipse.org...
> Zengyu,
>
> Like with any ECore based metamodel, you can retrieve the metaclass of
> the model element (or EObject) invoking the eClass() operation.
>
> You can then compare the result with the metaclass literal obtained via
> <metamodel>Package.Literals.<metaclass constant>. For example,
> UMLPackage.Literals.CLASS, UMLPackage.Literals.INTERFACE,
> UMLPackage.Literals.COMPONENT etc.
>
> HTH,
>
> Rafael
>
> Zengyu Lu wrote:
>> Hi,
>>
>> Supposed a UML2 package has been loaded. I want to traverse this package
>> and find out the type of each element like class, interface, or
>> component programmatically. How could I do it?
>>
>> Thanks for any solutions.
>>
>> Zengyu
|
|
| |
Re: how to find out the type of element in a package [message #626032 is a reply to message #476923] |
Wed, 13 February 2008 19:49 |
kevin Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Antti,
Actually I had a solution that is very similar like yours. Just use
if(obj instanceof internal.ClassImpl) and other implementations to find
out the type of each element in package. Well, it works. But I do not
think it is a good idea to access internal things directly. Neither does
Eclipse. :)
But thanks anyway!
Zengyu
Antti Evesti wrote:
> I have made it as follows in my code.
> EList<Element> el = package.getOwnedElements();
> for(Object o : el) {
> if(o instanceof StateMachine) {
> stateMachine((StateMachine) o);
> } else if (o instanceof Activity){
> activity((Activity) o);
> } else if(o instanceof Collaboration) {
> sequenceDiagram((Collaboration) o);
> } else if(o instanceof Component) {
> componentDiagram((Component) o);
> } else {
> //System.out.println("Unknown diagram type");
> }
>
> I don't know is this the best way, but it looks working.
>
> BR,
> Antti
>
> "Rafael Chaves" <rafael@no.spam.abstratt.com> wrote in message
> news:foocm6$517$1@build.eclipse.org...
>> Zengyu,
>>
>> Like with any ECore based metamodel, you can retrieve the metaclass of
>> the model element (or EObject) invoking the eClass() operation.
>>
>> You can then compare the result with the metaclass literal obtained via
>> <metamodel>Package.Literals.<metaclass constant>. For example,
>> UMLPackage.Literals.CLASS, UMLPackage.Literals.INTERFACE,
>> UMLPackage.Literals.COMPONENT etc.
>>
>> HTH,
>>
>> Rafael
>>
>> Zengyu Lu wrote:
>>> Hi,
>>>
>>> Supposed a UML2 package has been loaded. I want to traverse this package
>>> and find out the type of each element like class, interface, or
>>> component programmatically. How could I do it?
>>>
>>> Thanks for any solutions.
>>>
>>> Zengyu
>
>
|
|
|
Goto Forum:
Current Time: Wed Apr 24 19:38:40 GMT 2024
Powered by FUDForum. Page generated in 0.06164 seconds
|