Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Strange behavior on MS/Win with OCL
Strange behavior on MS/Win with OCL [message #1779153] Wed, 03 January 2018 09:26 Go to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Hi all,

I use an Eclipse Modeling Oxygen with:
OCL Classic SDK: Ecore/UML Parsers,Evaluator,Edit 5.3.0.v20170607-1133
OCL Examples and Editors SDK 6.3.0.v20170613-1432

Let us consider this simple metamodel
package test : test = 'http://test/ecore'

{

class Model

{

property classa : Class[*|1] { ordered composes };

property imports : Model[*|1] { ordered };

attribute name : String[?];

invariant ClassDependsLocalOrImported: classa.depends->forAll(let model = oclContainer()

in model = self or imports->includes(model));

}

class Class

{

property depends : Class[*|1] { ordered };

attribute name : String[?];

}

}


index.php/fa/31713/0/

The ClassDependsLocalOrImported invariant allows checking that all depended classes must be contained by the current model or imported ones.

Then, I generate the different EMF tooling.

Then, I use this model to do some process (generation, etc.).

However, before starting this process I do the OCL validation programmatically as shown in the following

public class ValidatorAction implements IObjectActionDelegate {

	private Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
	private ISelection selection;
	private static final String ECORE_PLATFORM_URI = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore";
	private ResourceSet resourceSet = new ResourceSetImpl();

	public ValidatorAction() {
		super();
	}

	@Override
	public void run(IAction action) {
		// TODO Auto-generated method stub
		IFile file = (IFile) ((IStructuredSelection) selection).getFirstElement();
		System.out.println("file " + file);
		EPackage.Registry.INSTANCE.put(ECORE_PLATFORM_URI, EcorePackage.eINSTANCE);
		resourceSet = new ResourceSetImpl();
		Model model = (Model) getRootElement(resourceSet, "file:" + file.getLocation().toString());
		validate(model);
	}

	private void validate(Model model) {
		Map<Object, Object> validationContext = LabelUtil.createDefaultContext(Diagnostician.INSTANCE);
		BasicDiagnostic diagnostics = Diagnostician.INSTANCE.createDefaultDiagnostic(model);
		if (!Diagnostician.INSTANCE.validate(model, diagnostics, validationContext)) {
			StringBuilder message = null;
			for (Diagnostic diagnostic : diagnostics.getChildren()) {
				if (diagnostic.getData().size() > 0) {
					if (message == null) {
						message = new StringBuilder();
					} else {
						message.append("\n");
					}
					message.append(diagnostic.getMessage());
				}
			}
			if (message != null) {
				MessageDialog.openError(shell, "Invalid Model", message.toString());
				return;
			}
		}
		else {
			MessageDialog.openInformation(shell, "Valid Model", "The requested model is valid");
		}
	}

	public void selectionChanged(IAction action, ISelection selection) {
		this.selection = selection;
	}

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();
	}

	public static EObject getRootElement(ResourceSet resourceSet, String path) {
		org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(URI.createURI(path), true);
		EcoreUtil.resolveAll(resource);
		return resource.getContents().get(0);
	}
}




The strange behavior is that the same model, which is valid under a MacOS/Linux, becomes invalid under Windows OS.

Let's consider two conforming models: model1 and model2
model1 is located in My.test

<?xml version="1.0" encoding="UTF-8"?>

<test:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://test/ecore" name="model1">

  <classa name="A"/>

</test:Model>



and model2 is located in My1.test

<?xml version="1.0" encoding="UTF-8"?>
<test:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:test="http://test/ecore" name="model2">
  <classa name="B"/>
  <classa name="C">
    <depends href="My.test#//@classa.0"/>
    <depends href="#//@classa.0"/>
  </classa>
  <imports href="My.test#/"/>
</test:Model>



When I use a MacOS/Linux machine and I execute my validation code on the model2, the validation passes.
However, with the same model, using a Windows machine, I obtain a validation error as shown in the following.
index.php/fa/31714/0/

Any idea about this behavior?
If someone wants to reproduce this behavior, I just provided the code and the models in an archive at the attachment.

best regards,
  • Attachment: test.png
    (Size: 101.55KB, Downloaded 374 times)
  • Attachment: Capture.PNG
    (Size: 190.74KB, Downloaded 412 times)
  • Attachment: Archive.zip
    (Size: 186.17KB, Downloaded 207 times)
Re: Strange behavior on MS/Win with OCL [message #1779154 is a reply to message #1779153] Wed, 03 January 2018 09:35 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

EPackage.Registry.INSTANCE.put(ECORE_PLATFORM_URI, EcorePackage.eINSTANCE);

Never modify the global registry. It allows one activity to corrupt the behaviour of another. Perhaps Windows shares the class whereas Mac does not.

Rather than incorrectly initializing your own ResourceSet why not use OCL?

OCL ocl = OCL.newInstance();
ResourceSet resourceSet = ocl.getResourceSet();

Regards

Ed Willink

Re: Strange behavior on MS/Win with OCL [message #1779159 is a reply to message #1779154] Wed, 03 January 2018 11:05 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Hi,

I integrate your suggestions, as shown in the following.

	public void run(IAction action) {
		// TODO Auto-generated method stub
		IFile file = (IFile) ((IStructuredSelection) selection).getFirstElement();
		System.out.println("file " + file);
		//EPackage.Registry.INSTANCE.put(ECORE_PLATFORM_URI, EcorePackage.eINSTANCE);
		OCL ocl = OCL.newInstance();
		resourceSet = ocl.getResourceSet();
		Model model = (Model) getRootElement(resourceSet, "file:" + file.getLocation().toString());
		System.out.println("model " + model);
		validate(model);
		System.out.println("toto " + model.getClassa().get(1).getDepends().get(0));
	}


However, I have always the same behavior.

best,
Re: Strange behavior on MS/Win with OCL [message #1779163 is a reply to message #1779159] Wed, 03 January 2018 11:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It is far from clear to me what you are doing.

Please provide a simple sequence of instruction explaining how to use your Archive.zip to demonstrate your problem.

(Using throwaway names such as http://test/ecore or fr.inria.test is very dangerous. I have spent many unhappy hours debugging the co-existence of a new test case that shares the same name registrations as an old test case.)

Regards

Ed Willink
Re: Strange behavior on MS/Win with OCL [message #1779166 is a reply to message #1779163] Wed, 03 January 2018 12:07 Go to previous messageGo to next message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
So, you should:

1-unzip the archive
2- create a workspace containing
fr.inria.test
fr.inria.test.edit
fr.inria.test.editor
fr.inria.test.tests
fr.inria.test.validator

3- right-click on fr.inria.test then click run as Eclipse Application

4- A new instance of Eclipse is launched

5- import test-model project (available in the archive folder)
My.test and My1.test are loaded

6- right click on My1.test -> Test (at the bottom) -> Validate

7- A popup appears
Re: Strange behavior on MS/Win with OCL [message #1779181 is a reply to message #1779166] Wed, 03 January 2018 16:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

This is actually nothing to do with OCL at all.

Model model = (Model) getRootElement(resourceSet, "file:" + file.getLocation().toString());

Never mix file: and platform:. Within Eclipse you are always using platform: so never use file:

URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
Model model = (Model) resourceSet.getResource(uri, true).getContents().get(0);

(Your MAC/Linux/Windows differences are no doubt due to the magic of / and \. If you only use /, it works on Windows too.)

Regards

Ed Willink
Re: Strange behavior on MS/Win with OCL [message #1779259 is a reply to message #1779181] Thu, 04 January 2018 14:33 Go to previous message
Fy Za is currently offline Fy ZaFriend
Messages: 245
Registered: March 2010
Senior Member
Thanks Ed!

It works perfectly.

best regards,

Faiez
Previous Topic:Migrating from CompleteOCL to OCLinEcore
Next Topic:OCLinEcore editor broken after update
Goto Forum:
  


Current Time: Thu Mar 28 12:50:03 GMT 2024

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

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

Back to the top