我需要从导航主UML模型的ACCELEO脚本中获取UML边缘中包含的OCL模型。为此,我定义了以下Java类:
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;
}
}
这是包装它的ACCELEO模块:
[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}) /]
以下是我试图从主ACCELEO模块调用它的方法:
[c.getOclModel('self.name=\'Testclass\'')._context.name/]
它不起作用,我不知道为什么,任何想法?
更新
我意识到帮助者实际上正在输出此异常
org.eclipse.ocl.SemanticException: Unrecognized variable: (name)
我做错了什么?