Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Acceleo invoking a Java Service Wrapping OCL
Acceleo invoking a Java Service Wrapping OCL [message #900691] Wed, 08 August 2012 07:58 Go to next message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

I need to get the OCL model of conditions contained in UML edges from an ACCELEO script navigating the main UML model. To this end I have defined the following Java class:
    public class GetOCLModel {
	public Constraint getOCLModel(Classifier context, String expression){
				
		OCL<Package, Classifier, Operation, Property, EnumerationLiteral, Parameter, 
		State, CallOperationAction, SendSignalAction, Constraint, Class, EObject> ocl;
		//CL.newInstance(EcoreEnvironmentFactory.INSTANCE);
		UMLEnvironmentFactory uef = new UMLEnvironmentFactory();
		ocl = OCL.newInstance(uef.createEnvironment());
		OCLHelper<Classifier, Operation, Property, Constraint> helper = ocl.createOCLHelper();
		helper.setContext(context);
		Constraint expr= null;
		try {
			expr= (Constraint) helper.createInvariant(expression);
			System.out.println("Hunky Dory!");
			
		} catch (ParserException e) {
			e.printStackTrace();
		}
		return expr;
	}
}


This is the ACCELEO Module wrapping it:
    [module     generateOclModel('[url]http://www.eclipse.org/ocl/1.1.0/UML[/url]','[url]http://www.eclipse.org/uml2/2.1.0/UML[/url]')/]
    
    [query public getOclModel(cl:Classifier, str:String): Constraint = invoke('sfg.baleno.src.services.GetOCLModel',
						  'getOCLModel(org.eclipse.uml2.uml.Classifier, java.lang.String)',Sequence{cl,str}) /]


And here is how I am trying to invoke it from the main ACCELEO module:

        
    [c.getOclModel('self.name=\'Testclass\'')._context.name/]

the helper outputs this exception

org.eclipse.ocl.SemanticException: Unrecognized variable: (name)


what am I doing wrong? is it about the context?

[Updated on: Wed, 08 August 2012 07:59]

Report message to a moderator

Re: Acceleo invoking a Java Service Wrapping OCL [message #900727 is a reply to message #900691] Wed, 08 August 2012 10:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The Eclipse OCL project provides 3 meta-model bindings.

You are using the UML binding.

Acceleo currently uses the Ecore binding, so you are passing an EClass
as a Class.

Regards

Ed Willink


On 08/08/2012 08:58, Andrea Sindico wrote:
> I need to get the OCL model of conditions contained in UML edges from
> an ACCELEO script navigating the main UML model. To this end I have
> defined the following Java class:
>
> public class GetOCLModel {
> public Constraint getOCLModel(Classifier context, String expression){
>
> OCL<Package, Classifier, Operation, Property,
> EnumerationLiteral, Parameter, State, CallOperationAction,
> SendSignalAction, Constraint, Class, EObject> ocl;
> //CL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> UMLEnvironmentFactory uef = new UMLEnvironmentFactory();
> ocl = OCL.newInstance(uef.createEnvironment());
> OCLHelper<Classifier, Operation, Property, Constraint> helper
> = ocl.createOCLHelper();
> helper.setContext(context);
> Constraint expr= null;
> try {
> expr= (Constraint) helper.createInvariant(expression);
> System.out.println("Hunky Dory!");
>
> } catch (ParserException e) {
> e.printStackTrace();
> }
> return expr;
> }
> }
>
> This is the ACCELEO Module wrapping it:
>
> [module
> generateOclModel('http://www.eclipse.org/ocl/1.1.0/UML','http://www.eclipse.org/uml2/2.1.0/UML')/]
> [query public getOclModel(cl:Classifier, str:String): Constraint
> = invoke('sfg.baleno.src.services.GetOCLModel',
> 'getOCLModel(org.eclipse.uml2.uml.Classifier,
> java.lang.String)',Sequence{cl,str}) /]
>
>
> And here is how I am trying to invoke it from the main ACCELEO module:
> [c.getOclModel('self.name=\'Testclass\'')._context.name/]
>
> the helper outputs this exception
>
> org.eclipse.ocl.SemanticException: Unrecognized variable: (name)
>
>
> what am I doing wrong? is it about the context?
Re: Acceleo invoking a Java Service Wrapping OCL [message #900754 is a reply to message #900727] Wed, 08 August 2012 12:04 Go to previous messageGo to next message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

actually the ACCELEO script wrapping the Java service using the OCL parser uses the OCL and UML metamodels
 
[module generateOclModel('http://www.eclipse.org/ocl/1.1.0/UML','http://www.eclipse.org/uml2/2.1.0/UML')/]

and the passed class is passed as a UML:Classifier


Follow me on Twitter @andreasindico

Re: Acceleo invoking a Java Service Wrapping OCL [message #900768 is a reply to message #900754] Wed, 08 August 2012 12:27 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You are confusing the user and tooling meta-models.

As a user, you are transforming on a UML model that conform,s to the UML
meta-model.

The Acceleo tooling is using an Ecore representation of the the UML
meta-model.

Regards

Ed Willink

On 08/08/2012 13:04, Andrea Sindico wrote:
> actually the ACCELEO script wrapping the Java service using the OCL
> parser uses the OCL and UML metamodels
>
> [module
> generateOclModel('http://www.eclipse.org/ocl/1.1.0/UML','http://www.eclipse.org/uml2/2.1.0/UML')/]
>
> and the passed class is passed as a UML:Classifier
Re: Acceleo invoking a Java Service Wrapping OCL [message #900778 is a reply to message #900768] Wed, 08 August 2012 13:02 Go to previous messageGo to next message
Andrea Sindico is currently offline Andrea SindicoFriend
Messages: 266
Registered: November 2010
Senior Member

Thank you Ed
I have changed the Java class this way:
package sfg.baleno.src.services;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ocl.ecore.*;
import org.eclipse.ocl.ecore.Constraint;
import org.eclipse.ocl.ecore.OCLExpression;
import org.eclipse.ocl.*;
import org.eclipse.ocl.OCL;
import org.eclipse.ocl.uml.*;
import org.eclipse.ocl.helper.ConstraintKind;
import org.eclipse.ocl.helper.OCLHelper;
import org.eclipse.uml2.uml.*;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Package;
import org.eclipse.emf.ecore.*;

public class GetOCLModel {
	public Constraint getOCLModel(EClassifier context, String expression){
				
		OCL<?,EClassifier, ?,?, ?, ?, ?, ?, ?, ?, ?, ?> ocl;
		ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
		OCLHelper<EClassifier, ?, ?, ?> helper = ocl.createOCLHelper();
		helper.setContext(context);
		String res = null;
		Constraint expr= null;
		try {
			expr= (Constraint) helper.createInvariant(expression);
		} catch (ParserException e) {
			e.printStackTrace();
		}
		return expr;
		
	}
}


but I have not changed the ACCELEO wrapper. It no longer throws the exception but I can't see how to use the returned constraint (if any) in the ACCELEO script, is it a UML or ECORE Constraint? what is its structure? I'd like to explore it as a model in ACCELEO and produce text from it


Follow me on Twitter @andreasindico

Re: Acceleo invoking a Java Service Wrapping OCL [message #900803 is a reply to message #900778] Wed, 08 August 2012 14:13 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The Java declaration tells you that it is an
org.eclipse.ocl.ecore.Constraint and if you trace the EClass and
EPackage you will find that it is http://www.eclipse.org/ocl/1.1.0/Ecore
in /org.eclipse.ocl.ecore/model/OCLEcore.ecore.

You didn't say why you wanted an OCL model so that it's difficult to say
what to do with it.

The model is a proprietary Ecore-flavouring of the OCL specification.

If you want something that prototypes a resolution of the XMI issues in
the OCL specification you might want to use the Pivot OCL binding. You
can find examples of Acceleo templates using the Piviot OCL model in GIT
org.eclipse.ocl examples/org.eclipse.ocl.examples.build.

But generally it is best to avoid using the OCL model directly.

Regards

Ed Willink

On 08/08/2012 14:02, Andrea Sindico wrote:
> Thank you Ed
> I have changed the Java class this way:
>
> package sfg.baleno.src.services;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.ocl.ecore.*;
> import org.eclipse.ocl.ecore.Constraint;
> import org.eclipse.ocl.ecore.OCLExpression;
> import org.eclipse.ocl.*;
> import org.eclipse.ocl.OCL;
> import org.eclipse.ocl.uml.*;
> import org.eclipse.ocl.helper.ConstraintKind;
> import org.eclipse.ocl.helper.OCLHelper;
> import org.eclipse.uml2.uml.*;
> import org.eclipse.uml2.uml.Class;
> import org.eclipse.uml2.uml.Package;
> import org.eclipse.emf.ecore.*;
>
> public class GetOCLModel {
> public Constraint getOCLModel(EClassifier context, String
> expression){
>
> OCL<?,EClassifier, ?,?, ?, ?, ?, ?, ?, ?, ?, ?> ocl;
> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> OCLHelper<EClassifier, ?, ?, ?> helper = ocl.createOCLHelper();
> helper.setContext(context);
> String res = null;
> Constraint expr= null;
> try {
> expr= (Constraint) helper.createInvariant(expression);
> } catch (ParserException e) {
> e.printStackTrace();
> }
> return expr;
>
> }
> }
>
>
> but I have not changed the ACCELEO wrapper. It no longer throws the
> exception but I can't see how to use the returned constraint (if any)
> in the ACCELEO script, is it a UML or ECORE Constraint? what is its
> structure? I'd like to explore it as a model in ACCELEO and produce
> text from it
Previous Topic:Concat collection
Next Topic:OCL Pivot Setting delegates in standalone application
Goto Forum:
  


Current Time: Thu Apr 18 23:11:52 GMT 2024

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

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

Back to the top