Strange behavior on MS/Win with OCL [message #1779153] |
Wed, 03 January 2018 09:26 |
Fy Za 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[?];
}
}
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.
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 401 times) -
Attachment: Capture.PNG
(Size: 190.74KB, Downloaded 439 times) -
Attachment: Archive.zip
(Size: 186.17KB, Downloaded 219 times)
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06623 seconds