Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Transformate OclText2OclModel
Transformate OclText2OclModel [message #29605] Mon, 25 June 2007 08:08 Go to next message
Eclipse User
Originally posted by: Matthias_Krebber.mra.man.de

I try to solve the task to transformate Ocl Constraints considered in an
OCL File (*.ocl) into Java Code. In order to solve this task first I want
to create an OCL Model (Text2Model Transformation). I want to use OCL MDT
to solve this.

To get experiences with MDT OCL I have written a Test Class. I have taken
your OCLTest.uml Model + test_constraints.ocl of your Testclasses and
tried to produce an ocl model (*.xmi)


I want to use my application standalone so I first have made some
registrations. (URIConverter.URI_MAP, Environment.Registry.INSTANCE,
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ),
EPackage.Registry.INSTANCE,
Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap() )
Examples:
// local Variables
/** contains the absolute path of the uml2.uml.resource jar file. */
String umlResources = "jar:file:" + getUMLArchive(new
JarArchiveFileNameFilter("org.eclipse.uml2.uml.resources_")) + "!";
String oclStdlib = "jar:file:" + getUMLArchive(new
JarArchiveFileNameFilter("org.eclipse.ocl.uml_")) + "!";

URIConverter.URI_MAP.put(URI.createURI("http://www.eclipse.org/ocl/1.1.0/oclstdlib.uml"),URI.createURI(oclStdlib
+"/model/oclstdlib.uml"));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),URI.createURI(umlResources
+ "/libraries/"));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),URI.createURI(umlResources
+ "/metamodels/"));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),URI.createURI(umlResources
+ "/profiles/"));


At next Step I load the UML Model together with the UML Metamodel and the
UML Primitive Types library into a resource Set, create the outputResource
and at this into an OCL facade.
/** Resource Set, containing the referenced Resources of the UML Model */
ResourceSet rs = this.getResources(pathUMLModel);

/** This Resource is used to persist the OCL Model*/
this.outputResource = rs.createResource(URI.createFileURI(new
File(locationOutputModel).getAbsolutePath()));

// Create the ocl facade. OCL Constraints are embedded in an UML
Environment
this.oclEnvironment = OCL.newInstance(new
UMLEnvironmentFactory(this.outputResource.getResourceSet()),
this.outputResource);
this.oclEnvironment.setEvaluationTracingEnabled(true);
this.oclEnvironment.setParseTracingEnabled(true);


Then I parse the ocl_constraints and add the constraints to the output
Resource.
// parse the OCL Constraints -> AST
List<Constraint> constraints = this.parseOclConstraints(this.oclEnvironment,
pathOclText);

// Add the AST to the output Resource
this.outputResource.getContents().addAll(0,constraints);


Add last step I persist the output model
this.outputResource.save(Collections.singletonMap(XMLResourc e.OPTION_SAVE_TYPE_INFORMATION,
Boolean.TRUE));

But If I want to open the created *.xmi File I get error messages like
this:
UnresolvedReferenceException: Unresolved reference
'/0/@specification/self'.
(platform:/resource/OCLText2OclModel/model/output/oclModel.x mi, 18, 104)

in XMI File:
<argument xsi:type="ocl.uml:VariableExp" name="self"
referredVariable="/0/@specification/self">

How can I dissolve this errors?
Re: Transformate OclText2OclModel [message #30319 is a reply to message #29605] Mon, 25 June 2007 21:00 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Matthias,

The Ecore binding of the OCL metamodel extends the Ecore metamodel, so it
inherits the hierarchical-name-based fragment URIs of Ecore's
ENamedElements (viz. the EModelElementImpl methods eURIFragmentSegment and
eObjectForURIFragmentSegment).

It looks like something is going wrong with the resolution of these URI
fragments. Would you mind raising a bug for that?

In the mean-time, to work around this, try using a custom resource
implementation that uses extrinsic UUIDs as URI fragments, instead of the
fragments computed by the objects, themselves.

Cheers,

Christian


Matthias Krebber wrote:

> I try to solve the task to transformate Ocl Constraints considered in an
> OCL File (*.ocl) into Java Code. In order to solve this task first I want
> to create an OCL Model (Text2Model Transformation). I want to use OCL MDT
> to solve this.
>
> To get experiences with MDT OCL I have written a Test Class. I have taken
> your OCLTest.uml Model + test_constraints.ocl of your Testclasses and
> tried to produce an ocl model (*.xmi)
>
>
> I want to use my application standalone so I first have made some
> registrations. (URIConverter.URI_MAP, Environment.Registry.INSTANCE,
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ),
> EPackage.Registry.INSTANCE,
> Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap() )
> Examples:
> // local Variables
> /** contains the absolute path of the uml2.uml.resource jar file. */
> String umlResources = "jar:file:" + getUMLArchive(new
> JarArchiveFileNameFilter("org.eclipse.uml2.uml.resources_")) + "!";
> String oclStdlib = "jar:file:" + getUMLArchive(new
> JarArchiveFileNameFilter("org.eclipse.ocl.uml_")) + "!";
>
>
URIConverter.URI_MAP.put(URI.createURI("http://www.eclipse.org/ocl/1.1.0/oclstdlib.uml"),URI.createURI(oclStdlib
> +"/model/oclstdlib.uml"));
>
URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES _PATHMAP),URI.createURI(umlResources
> + "/libraries/"));
>
URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODEL S_PATHMAP),URI.createURI(umlResources
> + "/metamodels/"));
>
URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_ PATHMAP),URI.createURI(umlResources
> + "/profiles/"));
>
>
> At next Step I load the UML Model together with the UML Metamodel and the
> UML Primitive Types library into a resource Set, create the outputResource
> and at this into an OCL facade.
> /** Resource Set, containing the referenced Resources of the UML Model */
> ResourceSet rs = this.getResources(pathUMLModel);
>
> /** This Resource is used to persist the OCL Model*/
> this.outputResource = rs.createResource(URI.createFileURI(new
> File(locationOutputModel).getAbsolutePath()));
>
> // Create the ocl facade. OCL Constraints are embedded in an UML
> Environment
> this.oclEnvironment = OCL.newInstance(new
> UMLEnvironmentFactory(this.outputResource.getResourceSet()),
> this.outputResource);
> this.oclEnvironment.setEvaluationTracingEnabled(true);
> this.oclEnvironment.setParseTracingEnabled(true);
>
>
> Then I parse the ocl_constraints and add the constraints to the output
> Resource.
> // parse the OCL Constraints -> AST
> List<Constraint> constraints =
> this.parseOclConstraints(this.oclEnvironment, pathOclText);
>
> // Add the AST to the output Resource
> this.outputResource.getContents().addAll(0,constraints);
>
>
> Add last step I persist the output model
>
this.outputResource.save(Collections.singletonMap(XMLResourc e.OPTION_SAVE_TYPE_INFORMATION,
> Boolean.TRUE));
>
> But If I want to open the created *.xmi File I get error messages like
> this:
> UnresolvedReferenceException: Unresolved reference
> '/0/@specification/self'.
> (platform:/resource/OCLText2OclModel/model/output/oclModel.x mi, 18, 104)
>
> in XMI File:
> <argument xsi:type="ocl.uml:VariableExp" name="self"
> referredVariable="/0/@specification/self">
>
> How can I dissolve this errors?
Re: Transformate OclText2OclModel [message #30391 is a reply to message #30319] Tue, 26 June 2007 06:53 Go to previous messageGo to next message
Eclipse User
Originally posted by: Matthias_Krebber.mra.man.de

Thank your for your answer. I will raise a Bug for this.

I have another question about MDT OCLŽs Metadata Architecture.

Like Meta Object Facility (MOF) defines, there are existing four Meta
Layers:
M3: The MDT OCL Metametamodel is conform to ECORE (ECORE Metamodel)
-> Are the metametamodels at org.eclipse.ocl/model (OCL.ecore,
OCL.uml)?
-> I donŽt understand the models OCLCST.ecore and OCLCST.uml at
org.eclipse.ocl/model
M2: There are existing bindings for UML and ECORE (Extensions of ECORE
Metamodell). These are the metamodels.
-> ECORE Binding: org.eclipse.ocl.ecore/model OCLEcore.ecore ?
-> UML Binding: org.eclipse.ocl.uml/model OCLUML.uml or OCLUML.ecore ?
M1: Are these the models that I may serialize after parsing?
- For example: oclOutput.xmi
M0: Dynamic EMF Objects
Re: Transformate OclText2OclModel [message #30598 is a reply to message #30391] Tue, 26 June 2007 14:15 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Matthias,

The meta-metamodel for OCL is UML, which for all practical purposes is
equivalent to Ecore because the OCL.uml model is used as the source for
OCL.genmodel, from which the code is generated via the OCL.ecore.

OCLCST.uml is the model of the OCL concrete syntax, which is an intermediate
representation of OCL text. The OCL parser works in two phases: parsing
the text into the concrete-syntax tree (CST), then parsing this tree to
produce the abstract-syntax tree (AST).

The UML binding model is OCLUML.uml. For any UML model, you will always see
a corresponding Ecore model because that is an artifact of the EMF code
generation process, and the schema of an EPackage is always represented as
Ecore despite its having originated in a UML model.

Yes, the M1 layer of models is in your world: the UML, Ecore, Library,
Employee, etc. models on which you are defining OCL constraints and
queries. You can serialize OCL constraints as separate resources or
embedded in your models; that is up to you.

Dynamic EObjects are one option for M0 models, yes, but so are the instances
of Java classes that you generate using EMF (the static EObjects).

Cheers,

Christian


Matthias Krebber wrote:

> Thank your for your answer. I will raise a Bug for this.
>
> I have another question about MDT OCLŽs Metadata Architecture.
>
> Like Meta Object Facility (MOF) defines, there are existing four Meta
> Layers:
> M3: The MDT OCL Metametamodel is conform to ECORE (ECORE Metamodel)
> -> Are the metametamodels at org.eclipse.ocl/model (OCL.ecore,
> OCL.uml)?
> -> I donŽt understand the models OCLCST.ecore and OCLCST.uml at
> org.eclipse.ocl/model
> M2: There are existing bindings for UML and ECORE (Extensions of ECORE
> Metamodell). These are the metamodels.
> -> ECORE Binding: org.eclipse.ocl.ecore/model OCLEcore.ecore ?
> -> UML Binding: org.eclipse.ocl.uml/model OCLUML.uml or OCLUML.ecore ?
> M1: Are these the models that I may serialize after parsing?
> - For example: oclOutput.xmi
> M0: Dynamic EMF Objects
Re: Transformate OclText2OclModel [message #30882 is a reply to message #30598] Wed, 27 June 2007 06:05 Go to previous messageGo to next message
Eclipse User
Originally posted by: Matthias_Krebber.mra.man.de

Okay,
Like I told I want to generate an OCL Model with MDT OCL. (Transformate
OclText2OclModel) After solving this task I will use ATL to transformate a
Java Model conforming to a Java Metamodel (Transformate OCLModel2JavaModel)

ATL needs as input model(s) conforming to their metamodel(s) and
transformate target model(s) conforming to their metamodel(s).

To work with ATL I have to know the input metamodel of my OCL Model.
Actually I just want to persist the OCL Text (*.ocl file) into a model
conforming to a metamodel. The metamodel has either be conformed to ecore
or to MOF because this are the metamodel technologies ATL provides. It is
important for me not to lose the informations about the OCL Constraint
types like pre:, post:, inv: etc. I do not want to evaluate OCL
Constraints against an UML model.

I parse the Ocl Text in order to get the AST. First, after parsing, I
persisted the OCL Expression into a XMI Model. But I noticed that I lose
informations about the constraint type (pre, post etc.) For now I persist
the Constraint themselves because it contains the informations about the
OCL Type.
Is the metamodel of these Constraint Model UML (UML.Metamodel.uml) ?
(Constraints are embedded in an UML Model)

Is there another alternative to persist the OCL Text into a model without
losing all informations with MDT OCL (for example persist the AST Model
conforms to a AST metamodel)? (I do not want to persist the OCL
Constraints together with the according UML Model)
Re: Transformate OclText2OclModel [message #30952 is a reply to message #30882] Wed, 27 June 2007 14:36 Go to previous messageGo to next message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Matthias,

For the purposes of ATL, the metamodel of MDT OCL can be considered to be
Ecore (with UML2-generated models, you can always choose to work with them
on UML or on Ecore terms since the code-generation always transforms the
UML to Ecore anyway). Moreover, since you are not dealing with UML models,
anyway, you would be using OCL's Ecore binding, so you are working only in
Ecore terms.

You should not be losing information about the kind of constraint if you are
persisting constraints (rather than just the expressions). Ecore
constraints (the org.eclipse.ocl.ecore.Constraint metaclass) have a
"stereotype" property whose value is "invariant", "precondition", etc.
according to the kind of constraint. In UML constraints
(org.eclipse.uml2.uml.Constraint), these values are applied as keywords to
the Constraint element. The values of this stereotype attribute are
enumerated in the org.eclipse.ocl.utilities.UMLReflection interface.

The metamodel for the org.eclipse.ocl.ecore.Constraint is Ecore.

HTH,

Christian

Matthias Krebber wrote:

> Okay,
> Like I told I want to generate an OCL Model with MDT OCL. (Transformate
> OclText2OclModel) After solving this task I will use ATL to transformate a
> Java Model conforming to a Java Metamodel (Transformate
> OCLModel2JavaModel)
>
> ATL needs as input model(s) conforming to their metamodel(s) and
> transformate target model(s) conforming to their metamodel(s).
>
> To work with ATL I have to know the input metamodel of my OCL Model.
> Actually I just want to persist the OCL Text (*.ocl file) into a model
> conforming to a metamodel. The metamodel has either be conformed to ecore
> or to MOF because this are the metamodel technologies ATL provides. It is
> important for me not to lose the informations about the OCL Constraint
> types like pre:, post:, inv: etc. I do not want to evaluate OCL
> Constraints against an UML model.
>
> I parse the Ocl Text in order to get the AST. First, after parsing, I
> persisted the OCL Expression into a XMI Model. But I noticed that I lose
> informations about the constraint type (pre, post etc.) For now I persist
> the Constraint themselves because it contains the informations about the
> OCL Type.
> Is the metamodel of these Constraint Model UML (UML.Metamodel.uml) ?
> (Constraints are embedded in an UML Model)
>
> Is there another alternative to persist the OCL Text into a model without
> losing all informations with MDT OCL (for example persist the AST Model
> conforms to a AST metamodel)? (I do not want to persist the OCL
> Constraints together with the according UML Model)
Re: Transformate OclText2OclModel [message #31091 is a reply to message #30952] Thu, 28 June 2007 05:53 Go to previous messageGo to next message
Eclipse User
Originally posted by: Matthias_Krebber.mra.man.de

Hi,
thank you for the answer.

First I tried to use org.eclipse.ocl.ecore.OCL but I get problems to parse
ocl constraints that are embedded in an UML Model. Therefore I exchanged
to org.eclipse.ocl.uml.OCL.

The idea of my work is, that a software architect creates for example with
MagicDraw an UML model together with ocl constraints.

These embedded constraints, first I want to put into a separate file
(*.ocl)
At next step I want to parse them and build the ocl model. After that I
want to transformate this Ocl model into a Java model and than into Java
code. (MDA)

How can I parse ocl constraints, based on an UML Model (for example
created with MagicDraw) with org.eclipse.ocl.ecore binding?
Re: Transformate OclText2OclModel [message #31160 is a reply to message #30319] Thu, 28 June 2007 12:41 Go to previous messageGo to next message
Eclipse User
Originally posted by: Matthias_Krebber.mra.man.de

Hi,
just a little completion.

I compared the created OCL ECORE XMI File with the OCL UML XMI file (I
persist constraints, and loaded TestOCL.uml, TestOcl.ecore). This are the
differences:
UML:
<source xsi:type="ocl.uml:VariableExp" name="self"
referredVariable="/1/@specification/self">

ECORE:
<source xsi:type="ocl.ecore:VariableExp" name="self"
referredVariable="/0/@specification/@contextVariable">

UML takes the name (self) after specification
ECORE: @specification/@contextVariable

My Manuell Changes in UML:
<source xsi:type="ocl.uml:VariableExp" name="self"
referredVariable="/1/@specification/@contextVariable">

Maybe this will help you
Re: Transformate OclText2OclModel [message #31195 is a reply to message #31091] Thu, 28 June 2007 14:06 Go to previous message
Eclipse User
Originally posted by: cdamus.ca.ibm.com

Hi, Matthias,

If you are parsing OCL constraints on UML models, then usually the
org.eclipse.ocl.uml.OCL is the better fit because UML's metamodel is UML
(i.e., the UML2 project defines the UML metamodel using UML and generates
the code from that UML model).

However, since Ecore is more convenient for your transformation, the
org.eclipse.ocl.ecore.OCL should work, too. The main disadvantage is that
it does not support such UML-isms as:

- disallowing calls on Operations for which isQuery is not true
- navigating non-navigable association ends
- (others that are less relevant because the UML metamodel does not employ
constructs such as association classes and association-end qualifiers)

Can you describe the problems that you are having? Any error messages,
stack traces, log entries would be useful. It really should just *work* as
it does for Ecore models.

Cheers,

Christian


Matthias Krebber wrote:

> Hi,
> thank you for the answer.
>
> First I tried to use org.eclipse.ocl.ecore.OCL but I get problems to parse
> ocl constraints that are embedded in an UML Model. Therefore I exchanged
> to org.eclipse.ocl.uml.OCL.
>
> The idea of my work is, that a software architect creates for example with
> MagicDraw an UML model together with ocl constraints.
>
> These embedded constraints, first I want to put into a separate file
> (*.ocl)
> At next step I want to parse them and build the ocl model. After that I
> want to transformate this Ocl model into a Java model and than into Java
> code. (MDA)
>
> How can I parse ocl constraints, based on an UML Model (for example
> created with MagicDraw) with org.eclipse.ocl.ecore binding?
Previous Topic:Re: [OCL] String Operations
Next Topic:Re: Multiple metamodels not supported?
Goto Forum:
  


Current Time: Sat Oct 25 19:01:11 GMT 2014

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

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