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 |
Eclipse User |
|
|
|
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 #474512 is a reply to message #474510] |
Tue, 24 July 2007 12:25 |
Eclipse User |
|
|
|
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 |
Ed Merks Messages: 33218 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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #624047 is a reply to message #474508] |
Tue, 24 July 2007 11:37 |
Ed Merks Messages: 33218 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 |
Eclipse User |
|
|
|
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 |
Ed Merks Messages: 33218 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 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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)
>
|
|
|
Goto Forum:
Current Time: Wed Sep 25 23:09:57 GMT 2024
Powered by FUDForum. Page generated in 0.43806 seconds
|