Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » how to get the "absolute" classifier ID
how to get the "absolute" classifier ID [message #474508] Tue, 24 July 2007 08:43 Go to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

Hello,

I would like to use the generic method
org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(EClass eClass) to create a UML
element.

Let's say that I have a property element, and then that I would like to
create another property.

I did something like that

Property myProperty = getAProperty();
Property newProperty;

newProperty = UMLFactory.eINSTANCE.create(myProperty.eClass())

but it fails.

The create method looks at the getClassifierID(). It returns 36, but the
eUMLPackage.PROPERTY is 46

I guess that has something to do with the "relative" id, but I am lost.

--
F. Lagarde
Re: how to get the "absolute" classifier ID [message #474510 is a reply to message #474508] Tue, 24 July 2007 11:15 Go to previous messageGo to next message
Andrew Carton is currently offline Andrew CartonFriend
Messages: 104
Registered: July 2009
Senior Member
Hi François,

How do you mean it fails? Do you get an error message?

When I do the following code it works

Property oldProperty = UMLFactory.eINSTANCE.createProperty();
Property newProperty = (Property)
UMLFactory.eINSTANCE.create(oldProperty.eClass());
System.out.println(oldProperty);
System.out.println(newProperty);
System.out.println(newProperty.eClass().getClassifierID() + " " +
UMLFactory.eINSTANCE.getUMLPackage().PROPERTY);

Both objects are created and print out ok. Both values are printed out
as 36 for me. Perhaps the oldProperty is null or incorrect?

Regards,
Andrew.

Ar 24/07/2007 09:43, Scríobh François Lagarde:
> Hello,
>
> I would like to use the generic method
> org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(EClass eClass) to create a UML
> element.
>
> Let's say that I have a property element, and then that I would like to
> create another property.
>
> I did something like that
>
> Property myProperty = getAProperty();
> Property newProperty;
>
> newProperty = UMLFactory.eINSTANCE.create(myProperty.eClass())
>
> but it fails.
>
> The create method looks at the getClassifierID(). It returns 36, but the
> eUMLPackage.PROPERTY is 46
>
> I guess that has something to do with the "relative" id, but I am lost.
>
Re: how to get the "absolute" classifier ID [message #474511 is a reply to message #474508] Tue, 24 July 2007 11:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
François,

Is it possible that you have a derived property class not provided by
UML directly. I.e., are you sure that myProperty.eClass().getEPackage()
== UMLPackage.eINSTANCE. In general, you likely should use
EcoreUtil.create(myProperty.eClass()) so that you actually use the
EFactory associated with the EClass' EPackage.


François Lagarde wrote:
> Hello,
>
> I would like to use the generic method
> org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(EClass eClass) to create a UML
> element.
>
> Let's say that I have a property element, and then that I would like to
> create another property.
>
> I did something like that
>
> Property myProperty = getAProperty();
> Property newProperty;
>
> newProperty = UMLFactory.eINSTANCE.create(myProperty.eClass())
>
> but it fails.
>
> The create method looks at the getClassifierID(). It returns 36, but the
> eUMLPackage.PROPERTY is 46
>
> I guess that has something to do with the "relative" id, but I am lost.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to get the "absolute" classifier ID [message #474512 is a reply to message #474510] Tue, 24 July 2007 12:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 07/24 about 01h, "Andrew" (Andrew Carton) wrote:

Andrew> Hi François, How do you mean it fails? Do you get an error
Andrew> message? [...] When I do the following code it works

hello,

Sorry for my previous post, it was unclear.

I read again my code and I think that I found out (partially) why it didn't
work.

I am working with the OCL plugin. The element that I use is given by a variable
typed getOCLStandardLibrary().getOclType().

So when I use the value of this variable, it is not a property (or anything
else) but a Classifier which may represent its type:

Classifier element = (Classifier) args[0];
Element newElement = (Element) org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(element.eCl ass());
System.out.println("initial element: " + element);
System.out.println("new element: " + newElement);

I get:
initial element: org.eclipse.uml2.uml.internal.impl.ClassImpl@650cb3 (name:
Property, visibility: <unset>)
new element: org.eclipse.uml2.uml.internal.impl.ClassImpl@11fa1ed (name:
<unset>, visibility: <unset>)

do you know how may I deal with it.

--
F. Lagarde
Re: how to get the "absolute" classifier ID [message #474513 is a reply to message #474512] Tue, 24 July 2007 13:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
François,

Well, you're getting a blank new instance. Maybe you want to use
EcoreUtil.copy to create a copy? It's of course completely unclear what
goal you are trying to achieve and I would caution you about assuming
that an instance's EClass belongs to the UMLPackage since a Classifier
instance might be in a derived instance from heavy weight extension's
package...


François Lagarde wrote:
> In the last post, on 07/24 about 01h, "Andrew" (Andrew Carton) wrote:
>
> Andrew> Hi François, How do you mean it fails? Do you get an error
> Andrew> message? [...] When I do the following code it works
>
> hello,
>
> Sorry for my previous post, it was unclear.
>
> I read again my code and I think that I found out (partially) why it didn't
> work.
>
> I am working with the OCL plugin. The element that I use is given by a variable
> typed getOCLStandardLibrary().getOclType().
>
> So when I use the value of this variable, it is not a property (or anything
> else) but a Classifier which may represent its type:
>
> Classifier element = (Classifier) args[0];
> Element newElement = (Element) org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(element.eCl ass());
> System.out.println("initial element: " + element);
> System.out.println("new element: " + newElement);
>
> I get:
> initial element: org.eclipse.uml2.uml.internal.impl.ClassImpl@650cb3 (name:
> Property, visibility: <unset>)
> new element: org.eclipse.uml2.uml.internal.impl.ClassImpl@11fa1ed (name:
> <unset>, visibility: <unset>)
>
> do you know how may I deal with it.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to get the "absolute" classifier ID [message #474514 is a reply to message #474513] Tue, 24 July 2007 13:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 07/24 about 03h, "Ed" (Ed Merks) wrote:

Ed> It's of course completely unclear what goal you are trying to
Ed> achieve.

I should have started with my goal.

I would like to add a helper in a UML-OCL environment to create a new model
element (at least just to know if it is possible, and how). For example, in the
context of a Package, I would make possible this query:

self.createElement(uml::Class)

--
F. Lagarde
Re: how to get the "absolute" classifier ID [message #474515 is a reply to message #474514] Tue, 24 July 2007 14:28 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

It may not matter to your application, but OCL is intrinsically a
side-effect-free language. OCL expressions are not permitted to modify the
state of the model on which they are executed. This is ensured by the
assertion that all operations called in an expression are "isQuery = true"
(for languages such as UML that have this concept; Ecore does not) and by
the absence of a property/variable assignment syntax. Your createElement()
operation would definitely not be a query.

Of course, in your application, this may not matter. However, if your OCL
expressions are to be used in an application such as is generated by GMF,
you may find them causing trouble in transactional editing domains when
evaluated in read-only transactions :-)

Cheers,

Christian


François Lagarde wrote:

> In the last post, on 07/24 about 03h, "Ed" (Ed Merks) wrote:
>
> Ed> It's of course completely unclear what goal you are trying to
> Ed> achieve.
>
> I should have started with my goal.
>
> I would like to add a helper in a UML-OCL environment to create a new
> model element (at least just to know if it is possible, and how). For
> example, in the context of a Package, I would make possible this query:
>
> self.createElement(uml::Class)
>
Re: how to get the "absolute" classifier ID [message #624046 is a reply to message #474508] Tue, 24 July 2007 11:15 Go to previous message
Andrew Carton is currently offline Andrew CartonFriend
Messages: 104
Registered: July 2009
Senior Member
Hi François,

How do you mean it fails? Do you get an error message?

When I do the following code it works

Property oldProperty = UMLFactory.eINSTANCE.createProperty();
Property newProperty = (Property)
UMLFactory.eINSTANCE.create(oldProperty.eClass());
System.out.println(oldProperty);
System.out.println(newProperty);
System.out.println(newProperty.eClass().getClassifierID() + " " +
UMLFactory.eINSTANCE.getUMLPackage().PROPERTY);

Both objects are created and print out ok. Both values are printed out
as 36 for me. Perhaps the oldProperty is null or incorrect?

Regards,
Andrew.

Ar 24/07/2007 09:43, Scríobh François Lagarde:
> Hello,
>
> I would like to use the generic method
> org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(EClass eClass) to create a UML
> element.
>
> Let's say that I have a property element, and then that I would like to
> create another property.
>
> I did something like that
>
> Property myProperty = getAProperty();
> Property newProperty;
>
> newProperty = UMLFactory.eINSTANCE.create(myProperty.eClass())
>
> but it fails.
>
> The create method looks at the getClassifierID(). It returns 36, but the
> eUMLPackage.PROPERTY is 46
>
> I guess that has something to do with the "relative" id, but I am lost.
>
Re: how to get the "absolute" classifier ID [message #624047 is a reply to message #474508] Tue, 24 July 2007 11:37 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
François,

Is it possible that you have a derived property class not provided by
UML directly. I.e., are you sure that myProperty.eClass().getEPackage()
== UMLPackage.eINSTANCE. In general, you likely should use
EcoreUtil.create(myProperty.eClass()) so that you actually use the
EFactory associated with the EClass' EPackage.


François Lagarde wrote:
> Hello,
>
> I would like to use the generic method
> org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(EClass eClass) to create a UML
> element.
>
> Let's say that I have a property element, and then that I would like to
> create another property.
>
> I did something like that
>
> Property myProperty = getAProperty();
> Property newProperty;
>
> newProperty = UMLFactory.eINSTANCE.create(myProperty.eClass())
>
> but it fails.
>
> The create method looks at the getClassifierID(). It returns 36, but the
> eUMLPackage.PROPERTY is 46
>
> I guess that has something to do with the "relative" id, but I am lost.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to get the "absolute" classifier ID [message #624048 is a reply to message #474510] Tue, 24 July 2007 12:25 Go to previous message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 07/24 about 01h, "Andrew" (Andrew Carton) wrote:

Andrew> Hi François, How do you mean it fails? Do you get an error
Andrew> message? [...] When I do the following code it works

hello,

Sorry for my previous post, it was unclear.

I read again my code and I think that I found out (partially) why it didn't
work.

I am working with the OCL plugin. The element that I use is given by a variable
typed getOCLStandardLibrary().getOclType().

So when I use the value of this variable, it is not a property (or anything
else) but a Classifier which may represent its type:

Classifier element = (Classifier) args[0];
Element newElement = (Element) org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(element.eCl ass());
System.out.println("initial element: " + element);
System.out.println("new element: " + newElement);

I get:
initial element: org.eclipse.uml2.uml.internal.impl.ClassImpl@650cb3 (name:
Property, visibility: <unset>)
new element: org.eclipse.uml2.uml.internal.impl.ClassImpl@11fa1ed (name:
<unset>, visibility: <unset>)

do you know how may I deal with it.

--
F. Lagarde
Re: how to get the "absolute" classifier ID [message #624049 is a reply to message #474512] Tue, 24 July 2007 13:07 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
François,

Well, you're getting a blank new instance. Maybe you want to use
EcoreUtil.copy to create a copy? It's of course completely unclear what
goal you are trying to achieve and I would caution you about assuming
that an instance's EClass belongs to the UMLPackage since a Classifier
instance might be in a derived instance from heavy weight extension's
package...


François Lagarde wrote:
> In the last post, on 07/24 about 01h, "Andrew" (Andrew Carton) wrote:
>
> Andrew> Hi François, How do you mean it fails? Do you get an error
> Andrew> message? [...] When I do the following code it works
>
> hello,
>
> Sorry for my previous post, it was unclear.
>
> I read again my code and I think that I found out (partially) why it didn't
> work.
>
> I am working with the OCL plugin. The element that I use is given by a variable
> typed getOCLStandardLibrary().getOclType().
>
> So when I use the value of this variable, it is not a property (or anything
> else) but a Classifier which may represent its type:
>
> Classifier element = (Classifier) args[0];
> Element newElement = (Element) org.eclipse.uml2.uml.UMLFactory.eINSTANCE.create(element.eCl ass());
> System.out.println("initial element: " + element);
> System.out.println("new element: " + newElement);
>
> I get:
> initial element: org.eclipse.uml2.uml.internal.impl.ClassImpl@650cb3 (name:
> Property, visibility: <unset>)
> new element: org.eclipse.uml2.uml.internal.impl.ClassImpl@11fa1ed (name:
> <unset>, visibility: <unset>)
>
> do you know how may I deal with it.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to get the "absolute" classifier ID [message #624050 is a reply to message #474513] Tue, 24 July 2007 13:17 Go to previous message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 07/24 about 03h, "Ed" (Ed Merks) wrote:

Ed> It's of course completely unclear what goal you are trying to
Ed> achieve.

I should have started with my goal.

I would like to add a helper in a UML-OCL environment to create a new model
element (at least just to know if it is possible, and how). For example, in the
context of a Package, I would make possible this query:

self.createElement(uml::Class)

--
F. Lagarde
Re: how to get the "absolute" classifier ID [message #624051 is a reply to message #474514] Tue, 24 July 2007 14:28 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

It may not matter to your application, but OCL is intrinsically a
side-effect-free language. OCL expressions are not permitted to modify the
state of the model on which they are executed. This is ensured by the
assertion that all operations called in an expression are "isQuery = true"
(for languages such as UML that have this concept; Ecore does not) and by
the absence of a property/variable assignment syntax. Your createElement()
operation would definitely not be a query.

Of course, in your application, this may not matter. However, if your OCL
expressions are to be used in an application such as is generated by GMF,
you may find them causing trouble in transactional editing domains when
evaluated in read-only transactions :-)

Cheers,

Christian


François Lagarde wrote:

> In the last post, on 07/24 about 03h, "Ed" (Ed Merks) wrote:
>
> Ed> It's of course completely unclear what goal you are trying to
> Ed> achieve.
>
> I should have started with my goal.
>
> I would like to add a helper in a UML-OCL environment to create a new
> model element (at least just to know if it is possible, and how). For
> example, in the context of a Package, I would make possible this query:
>
> self.createElement(uml::Class)
>
Previous Topic:how to get the "absolute" classifier ID
Next Topic:Re: Code generation from UML model
Goto Forum:
  


Current Time: Fri Apr 19 13:10:03 GMT 2024

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

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

Back to the top