Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » ocl, uml, can't start.
ocl, uml, can't start. [message #4377] Sat, 10 February 2007 09:56 Go to next message
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 #4937 is a reply to message #4377] Mon, 12 February 2007 06:07 Go to previous messageGo to next message
Eclipse User
Originally posted by: firstname.name.gmail.com

In the last post, on 02/10 about 03h, "François" (François Lagarde) wrote:

François> I would like to query the user model, itself with an embedded
François> query named myQuery within a class context.

I did a lot of mistakes. I success to query the user model with the following
code (I don't know if it is the best way to do it):

String myQuery = "name = 'aName'";
NamedElement aClass= (NamedElement) sResults.iterator().next();
// load the metamodel uri
// doesn't know why it is not automaticly loaded
resourceSet.getResource(URI.createURI(UMLResource.UML_METAMO DEL_URI), true);
OCL myOcl = org.eclipse.ocl.uml.OCL.newInstance(resourceSet);
OCLHelper oclHelper = myOcl.createOCLHelper();
Object metaClass = OCLUMLUtil.getMetaclass(aClass);
oclHelper.setContext(metaClass);
oclHelper.setValidating(true);
Object oclInv=null;
try {
oclInv = oclHelper.createQuery(myQuery);
} catch (ParserException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Object result = myOcl.evaluate(aClass, (OCLExpression) oclInv);
_logger.info("OCL expression: ["+myQuery+"] is [" + myOcl.isInvalid(result) +"] [ on ["+ aClass.getName()+"]");

--
F. Lagarde
Re: ocl, uml, can't start. [message #5077 is a reply to message #4377] Mon, 12 February 2007 12:10 Go to previous message
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);
>
Previous Topic:OCL fan-in & fan-out
Next Topic:Re: IRJA0029W No parser for the "OCL".
Goto Forum:
  


Current Time: Sat Aug 30 12:35:03 EDT 2014

Powered by FUDForum. Page generated in 0.01689 seconds