Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Problem OCL + Ecore Validation
Problem OCL + Ecore Validation [message #792536] Tue, 07 February 2012 05:04 Go to next message
David Mendez-Acuna is currently offline David Mendez-AcunaFriend
Messages: 2
Registered: February 2012
Junior Member
Hi,

I am working on provide EMFConformance and the OCLConformance validation in a single validator. However, I have two restrictions: (1) the OCL constraints must be in a separate file than the ecore model. So, one could create several combinations of ecore + ocl and obtain several restriction levels; and (2) I need to support xmi dynamic instances, so I do not have the ecore model code.

I implemented the following code. It works great the first time I validate the xmi file. However, after the first validation it fails. I mean, if I validate the same xmi file twice the first validation is correct, the second one fails because of an OCLInvalid answer.

Can any give some glues about what I am doing wrong? I have checked this code during days and I cannot find the error.

//Registering the previously-loaded ecore model
EPackage.Registry registry = new EPackageRegistryImpl();
registry.put(mmPackage.getNsURI(), mmPackage);

//Initializing the OCL environment
EcoreEnvironmentFactory environmentFactory = new EcoreEnvironmentFactory(registry);
OCL ocl = OCL.newInstance(environmentFactory);

InputStream in = oclMetamodelFile.getContents();
Map<String, Constraint> constraintMap = new HashMap<String, Constraint>();
OCLInput input = new OCLInput(in, oclMetamodelFile.getCharset());

//Obtaining the constraints
List<Constraint> constraints = ocl.parse(input);

for (Constraint next : constraints) {
constraintMap.put(next.getName(), next);

OCLExpression<EClassifier> body = next.getSpecification().getBodyExpression();

//This obtains the set of EObjects of the context EClass. xmiRootObject previously-loaded
List<EObject> evaluationElements = new ArrayList<EObject>();
getEvaluationElements(next.getConstrainedElements().get(0), xmiRootObject, evaluationElements);

for (EObject evaluationElement : evaluationElements) {

Object evaluationResult = ocl.check(evaluationElement, next);

//Managing the evaluation result...
}
}

Again, this code perfectly works during the first execution, after that, it fails.

Thanks in advance,


Re: Problem OCL + Ecore Validation [message #792565 is a reply to message #792536] Tue, 07 February 2012 05:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi

(1) ecore + ocl is exactly what a complementary Complete OCL document
supports.
(2) dynamic instances should be no problem; EMF hides the distinction
from tools

You don't show how much is repeated and how much is shared by the second
execution and don't diagnose the OclInvalid answer so I can only guess
as to why the first execution influences the second. Inconsistent
caches, duplicate/ambiguous names, stale references.

You have no ocl.dispose() which will give a memory leak and might affect
the second execution.

I would start by finding out where the second execution produces an
OclInvalid result.

You could gradually share less initialization and fewer variables
between executions. If you've really got your code completely
independent then you have an issue with double initialization of OCL or
the EMF global registries.

You have one working and one failing execution so you can compare the
two in the debugger if all else fails.

[You might be interested in the current work in the bug/368612 branch
for Juno to support Loading a Complete OCL document into the Sample
Reflective Ecore Editor so that you can have enhanced meta-model
constraints.]

Regards

Ed Willink


On 07/02/2012 05:04, David Mendez-Acuna wrote:
> Hi,
>
> I am working on provide EMFConformance and the OCLConformance
> validation in a single validator. However, I have two restrictions:
> (1) the OCL constraints must be in a separate file than the ecore
> model. So, one could create several combinations of ecore + ocl and
> obtain several restriction levels; and (2) I need to support xmi
> dynamic instances, so I do not have the ecore model code.
> I implemented the following code. It works great the first time I
> validate the xmi file. However, after the first validation it fails. I
> mean, if I validate the same xmi file twice the first validation is
> correct, the second one fails because of an OCLInvalid answer.
> Can any give some glues about what I am doing wrong? I have checked
> this code during days and I cannot find the error.
> //Registering the previously-loaded ecore model
> EPackage.Registry registry = new EPackageRegistryImpl();
> registry.put(mmPackage.getNsURI(), mmPackage);
>
> //Initializing the OCL environment
> EcoreEnvironmentFactory environmentFactory = new
> EcoreEnvironmentFactory(registry);
> OCL ocl = OCL.newInstance(environmentFactory);
>
> InputStream in = oclMetamodelFile.getContents();
> Map<String, Constraint> constraintMap = new HashMap<String,
> Constraint>();
> OCLInput input = new OCLInput(in, oclMetamodelFile.getCharset());
>
> //Obtaining the constraints
> List<Constraint> constraints = ocl.parse(input);
>
> for (Constraint next : constraints) {
> constraintMap.put(next.getName(), next);
> OCLExpression<EClassifier> body =
> next.getSpecification().getBodyExpression();
> //This obtains the set of EObjects of the
> context EClass. xmiRootObject previously-loaded
> List<EObject> evaluationElements = new ArrayList<EObject>();
>
> getEvaluationElements(next.getConstrainedElements().get(0),
> xmiRootObject, evaluationElements);
> for (EObject evaluationElement :
> evaluationElements) {
>
> Object evaluationResult = ocl.check(evaluationElement, next);
>
> //Managing the evaluation result... }
> }
>
> Again, this code perfectly works during the first execution, after
> that, it fails.
> Thanks in advance,
>
>
>
Re: Problem OCL + Ecore Validation [message #793265 is a reply to message #792565] Wed, 08 February 2012 00:11 Go to previous messageGo to next message
David Mendez-Acuna is currently offline David Mendez-AcunaFriend
Messages: 2
Registered: February 2012
Junior Member
Hi Ed,

I made a quite similar analysis. However, I didn't think that double initialization could cause problems like those.

At the end, the error was that I was loading the validated model using the same resouce set always. In this moment I do not understand why it fails but it fails.

Now, I initialize the resource set for each execution. It works!

Thanks a lot,

-- Dave
Re: Problem OCL + Ecore Validation [message #793433 is a reply to message #793265] Wed, 08 February 2012 05:46 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi

I'm glad you have a workaround.

Your code snippet didn't show a ResourceSet at all and I'm not clear
exactly what 'initialize the resource set' means to you.

I suspect that you are loading multiple copies of resources, which is at
best just wasteful. Multiple copies can lead to further problems, so I
recommend you investigate 'initialize the resource set' to see what it
is doing that is necessary, otherwise you are just storing up a nasty
problem to hit you later.

Regards

Ed Willink


On 08/02/2012 00:11, David Mendez-Acuna wrote:
> Hi Ed,
>
> I made a quite similar analysis. However, I didn't think that double
> initialization could cause problems like those.
>
> At the end, the error was that I was loading the validated model using
> the same resouce set always. In this moment I do not understand why it
> fails but it fails.
>
> Now, I initialize the resource set for each execution. It works!
>
> Thanks a lot,
>
> -- Dave
Previous Topic:OCL Console using CompleteOCL
Next Topic:CompleteOCLEObjectValidator and UML meta model
Goto Forum:
  


Current Time: Wed Nov 26 16:50:50 GMT 2014

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

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