Home » Modeling » OCL » ocl, uml, can't start.
ocl, uml, can't start. [message #4377] |
Sat, 10 February 2007 09:56  |
Eclipse User |
|
|
|
Originally posted by: firstname.name.gmail.com
Hello,
Sorry to ask help again, but I didn't success to make any query with the last
OCL plugin (I200702011837). I would like to use this plugin to express OCL
constraints with associations capabilities on UML models.
I would like to query the user model, itself with an embedded query named
myQuery within a class context.
This my code:
Class aClass= (Class) sResults.iterator().next();
UMLEnvironmentFactory environmentFactory = new UMLEnvironmentFactory(resourceSet);
UMLEnvironment myEnvironment = environmentFactory.createEnvironment();
Environment<Package, Classifier, Operation, Property, EnumerationLiteral,
Parameter, State, CallOperationAction, SendSignalAction, Constraint, Class,
EObject>
environmentClass = environmentFactory.createClassifierContext(myEnvironment, (Classifier) aClass);
OCL myOcl = org.eclipse.ocl.uml.OCL.newInstance(environmentClass);
myOcl.setEvaluationTracingEnabled(true);
myOcl.setParseTracingEnabled(true);
//UMLEvaluationEnvironment umlEvaluation = new UMLEvaluationEnvironment(resourceSet.getPackageRegistry());
//umlEvaluation.add("tata", element);
OCLHelper oclHelper = myOcl.createOCLHelper();
OCLExpression oclInv=null;
try {
oclInv = oclHelper.createQuery(myQuery);
} catch (ParserException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
myOcl.check(aClass, oclInv);
I get a
org.eclipse.ocl.ParserException
Caused by: java.lang.NullPointerException
at org.eclipse.ocl.internal.parser.OCLParser.<init>(OCLParser.java:198)
this line OCLParser.java:119 is
this.environmentFactory = environment.getFactory();
and when I use the debugging mode, I can see that oclHelper has a non null
UMLEnvironmentFactory.
Thanks in advance.
,----
| Help, I need somebody
| Help, not just anybody
| Help, you know I need someone, help
`----
--
F. Lagarde
|
|
| |
Re: ocl, uml, can't start. [message #5077 is a reply to message #4377] |
Mon, 12 February 2007 12:10  |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Francois,
The problem is, that you need to specify the context of the constraint in
the helper when you are using a helper (the OCL's context is only used for
parsing OCL documents). For example:
Class aClass= (Class) sResults.iterator().next();
OCL myOcl = org.eclipse.ocl.uml.OCL.newInstance(resourceSet);
myOcl.setEvaluationTracingEnabled(true);
myOcl.setParseTracingEnabled(true);
OCLHelper oclHelper = myOcl.createOCLHelper();
// set the helper's context to be the UML metaclass of 'aClass'
oclHelper.setInstanceContext(aClass);
OCLExpression oclInv=null;
try {
oclInv = oclHelper.createQuery(myQuery);
} catch (ParserException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
myOcl.check(aClass, oclInv);
Note that you don't need to bother with creating Environments and working
with the UML metamodel.
HTH,
Christian
François Lagarde wrote:
> Class aClass= (Class) sResults.iterator().next();
> UMLEnvironmentFactory environmentFactory = new
> UMLEnvironmentFactory(resourceSet); UMLEnvironment myEnvironment =
> environmentFactory.createEnvironment(); Environment<Package, Classifier,
> Operation, Property, EnumerationLiteral, Parameter, State,
> CallOperationAction, SendSignalAction, Constraint, Class, EObject>
> environmentClass =
> environmentFactory.createClassifierContext(myEnvironment, (Classifier)
> aClass); OCL myOcl =
> org.eclipse.ocl.uml.OCL.newInstance(environmentClass);
> myOcl.setEvaluationTracingEnabled(true);
> myOcl.setParseTracingEnabled(true); //UMLEvaluationEnvironment
> umlEvaluation = new
> UMLEvaluationEnvironment(resourceSet.getPackageRegistry());
> //umlEvaluation.add("tata", element); OCLHelper oclHelper =
> myOcl.createOCLHelper(); OCLExpression oclInv=null; try { oclInv =
> oclHelper.createQuery(myQuery); } catch (ParserException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> myOcl.check(aClass, oclInv);
>
|
|
|
Goto Forum:
Current Time: Mon Apr 28 01:39:01 EDT 2025
Powered by FUDForum. Page generated in 0.03771 seconds
|