Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » "misplaced contructs" using second import statement
"misplaced contructs" using second import statement [message #1081506] Wed, 07 August 2013 05:58 Go to next message
Jens Reimann is currently offline Jens Reimann
Messages: 2
Registered: June 2013
Junior Member
Hello,

I struggle a bit with an issue of having two import statements. I do have some OCL validation rules that need to models for validating.

import 'platform:/plugin/org.openscada.configuration.component.model/model/component.ecore'
import 'platform:/plugin/org.openscada.configuration.infrastructure.model/model/infrastructure.ecore'

package component

context CalculationComponent
def: all_component_inputs: Set(ComponentReferenceInputDefinition) = inputs->select( i : InputDefinition | i.oclIsKindOf(ComponentReferenceInputDefinition))
def: all_masters: Set(infrastructure::MasterServer) = all_component_inputs->collect(i: ComponentReferenceInputDefinition | i.component.masterOn)
inv all_master_contained: self.masterOn->includesAll(all_masters)

...

endpackage


The editor loads and validates the file fine. But when I load them using OCL.parse(...), as suggested by the OCL validation example, I do get the following exception:

!ENTRY org.openscada.configuration.validation 4 1 2013-08-07 11:52:49.075
!MESSAGE Failed to parse OCL constraints in org.openscada.configuration.validation:constraints/comp.ocl
!STACK 0
org.eclipse.ocl.SyntaxException: 1:1:1:102 "import component: 'platform:/plugin/org.openscada.configuration.component.model/model/component.ecore'" misplaced construct(s)
	at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:356)
	at org.eclipse.ocl.OCL.parse(OCL.java:323)
	at org.openscada.configuration.validation.ocl.OCLConstraintProvider.parseConstraints(OCLConstraintProvider.java:168)
	at org.openscada.configuration.validation.ocl.OCLConstraintProvider.parseConstraints(OCLConstraintProvider.java:141)
	at org.openscada.configuration.validation.ocl.OCLConstraintProvider.setInitializationData(OCLConstraintProvider.java:98)
	at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:251)
	at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
	at org.eclipse.emf.validation.internal.service.ProviderDescriptor.getProvider(ProviderDescriptor.java:268)
	at org.eclipse.emf.validation.internal.service.ConstraintCache.execute(ConstraintCache.java:285)
	at org.eclipse.emf.validation.internal.service.ConstraintCache.getBatchConstraints(ConstraintCache.java:386)


I am not sure what I am doing wrong.

Using Eclipse Kepler 4.3.

Thanks for helping.
Re: "misplaced contructs" using second import statement [message #1081628 is a reply to message #1081506] Wed, 07 August 2013 09:29 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

The OCL specification has no import statement, which makes Complete OCL
almost unuseable.

For a while I tried to support external metadata in a Model Registry,
which can be used by the Classic Eclipse OCL.

Eventually I had to accept that the lack of an import statement is a
language bug and so the Pivot/Xtyext-based Eclipse OCL rectifies it. (I
think Dresden OCL also has an import statement extension).

For Juno we improved the Classic OCL parser to parse but ignore import
statements, so that files developed by the new edirtor could be used. It
remains a responsibility of a Classic Eclipse OCL user to populate the
package regiustry with all relevant models.

Your error message is not consistent with your claimed imports so I'm
not confident that you are presenting the true problem.

It generally saves everyone a lot of time to attach a simple zipped project.

Regards

Ed Willink

On 07/08/2013 13:12, Jens Reimann wrote:
> Hello,
>
> I struggle a bit with an issue of having two import statements. I do
> have some OCL validation rules that need to models for validating.
>
> import
> 'platform:/plugin/org.openscada.configuration.component.model/model/component.ecore'
> import
> 'platform:/plugin/org.openscada.configuration.infrastructure.model/model/infrastructure.ecore'
>
> package component
>
> context CalculationComponent
> def: all_component_inputs: Set(ComponentReferenceInputDefinition) =
> inputs->select( i : InputDefinition |
> i.oclIsKindOf(ComponentReferenceInputDefinition))
> def: all_masters: Set(infrastructure::MasterServer) =
> all_component_inputs->collect(i: ComponentReferenceInputDefinition |
> i.component.masterOn)
> inv all_master_contained: self.masterOn->includesAll(all_masters)
>
> ...
>
> endpackage
>
> The editor loads and validates the file fine. But when I load them
> using OCL.parse(...), as suggested by the OCL validation example, I do
> get the following exception:
>
>
> !ENTRY org.openscada.configuration.validation 4 1 2013-08-07 11:52:49.075
> !MESSAGE Failed to parse OCL constraints in
> org.openscada.configuration.validation:constraints/comp.ocl
> !STACK 0
> org.eclipse.ocl.SyntaxException: 1:1:1:102 "import component:
> 'platform:/plugin/org.openscada.configuration.component.model/model/component.ecore'"
> misplaced construct(s)
> at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:356)
> at org.eclipse.ocl.OCL.parse(OCL.java:323)
> at
> org.openscada.configuration.validation.ocl.OCLConstraintProvider.parseConstraints(OCLConstraintProvider.java:168)
> at
> org.openscada.configuration.validation.ocl.OCLConstraintProvider.parseConstraints(OCLConstraintProvider.java:141)
> at
> org.openscada.configuration.validation.ocl.OCLConstraintProvider.setInitializationData(OCLConstraintProvider.java:98)
> at
> org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:251)
> at
> org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
> at
> org.eclipse.emf.validation.internal.service.ProviderDescriptor.getProvider(ProviderDescriptor.java:268)
> at
> org.eclipse.emf.validation.internal.service.ConstraintCache.execute(ConstraintCache.java:285)
> at
> org.eclipse.emf.validation.internal.service.ConstraintCache.getBatchConstraints(ConstraintCache.java:386)
>
>
> I am not sure what I am doing wrong.
>
> Using Eclipse Kepler 4.3.
>
> Thanks for helping.
Re: "misplaced contructs" using second import statement [message #1187855 is a reply to message #1081628] Fri, 15 November 2013 05:06 Go to previous messageGo to next message
Stefan Mijatov is currently offline Stefan Mijatov
Messages: 44
Registered: March 2010
Location: Vienna, Austria
Member
@Edit

Hi Ed, Hi Jens,

I have found the problem: I omitted the package declaration.
Furthermore, I also forgot to give complete qualified name declaration of the context class.

Now everything works perfect, and I include new version of the project for anyone who might end up with similar or same problem..

Best regards,
Stefan

------------------------------------------------------------------------------------

Hi Ed, Hi Jens,

I am not sure I understand the solution to this problem Smile

I am using Eclipse Juno and have the simple project where I am loading my dinamic instance model from XMI file and OCL constraint from an ocl file.
I Included the whole project here.

What the problem is, is that when I call parse() method of OCL class on my input ocl file, I get the error with the import declaration being the problem:

StackTrace:

org.eclipse.ocl.SyntaxException: 1:1:1:55 "import 'platform:/resource/example/model/example.ecore'" misplaced construct(s)
at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:356)
at org.eclipse.ocl.OCL.parse(OCL.java:323)
at ocl.ExampleOclUtil.getConstraints(ExampleOclUtil.java:39)
at ocl.Main.main(Main.java:19)

Could you please explain to me why and how to solve this issue? Smile

Thanks in advance,
Stefan

[Updated on: Fri, 15 November 2013 05:48]

Report message to a moderator

Re: "misplaced contructs" using second import statement [message #1187991 is a reply to message #1187855] Fri, 15 November 2013 06:36 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

Well done; a repro I can load quickly, even if I had to guess to run main.

If you open Model.ocl with the Complete OCL editor, you will see your
problem. You need to specify the package path either as

import 'platform:/resource/example/model/example.ecore'
context example::ClassA
inv bIsSet: classB->size()>0

or

import 'platform:/resource/example/model/example.ecore'
package example
context ClassA
inv bIsSet: classB->size()>0
endpackage

Unfortunately OMG OCL does not yet specify an import statement, so
import is an extension supported by the new code, based on a neutral
Pivot model that is used by the editors, or by using
org.eclipse.ocl.examples.pivot.OCL rather than
org.eclipse.ocl.ecore.OCL. The traditional code relies on a correctly
initialized registry just as your code does. For compatibility the
traditional parser ignores new-style imports. Unfortunately seemingly
only when there is an explicit package.

So if you change your Model.ocl to

import 'platform:/resource/example/model/example.ecore'
package example
context ClassA
inv bIsSet: classB->size()>0
endpackage

you're good to go.

Regards

Ed Willink






On 15/11/2013 10:06, Stefan Mijatov wrote:
> Hi Ed, Hi Jens,
>
> I am not sure I understand the solution to this problem :)
>
> I am using Eclipse Juno and have the simple project where I am loading my dinamic instance model from XMI file and OCL constraint from an ocl file.
> I Included the whole project here.
>
> What the problem is, is that when I call parse() method of OCL class on my input ocl file, I get the error with the import declaration being the problem:
>
> StackTrace:
>
> org.eclipse.ocl.SyntaxException: 1:1:1:55 "import 'platform:/resource/example/model/example.ecore'" misplaced construct(s)
> at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:356)
> at org.eclipse.ocl.OCL.parse(OCL.java:323)
> at ocl.ExampleOclUtil.getConstraints(ExampleOclUtil.java:39)
> at ocl.Main.main(Main.java:19)
>
> Could you please explain to me why and how to solve this issue? :)
>
> Thanks in advance,
> Stefan
Re: "misplaced contructs" using second import statement [message #1196527 is a reply to message #1187991] Tue, 19 November 2013 08:10 Go to previous messageGo to next message
Stefan Mijatov is currently offline Stefan Mijatov
Messages: 44
Registered: March 2010
Location: Vienna, Austria
Member
Hi,

I tried 2 days ago to load an OCL file, defined for a UML model.
Looking the the Pivot Programmers Guide I wrote the following code:

public void loadOCL(String path) throws FileNotFoundException, ParserException{
	EPackage.Registry registry = new EPackageRegistryImpl();
	registry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);		
	PivotEnvironmentFactory environmentFactory = new PivotEnvironmentFactory(registry, null);
	OCL ocl = OCL.newInstance(environmentFactory);
	URI uri = URI.createFileURI("./example/petstore/petstore_invariants.ocl");
	Resource resource = ocl.parse(uri);
	constraints = new ArrayList<Constraint>();
	for(TreeIterator<EObject> iterator = resource.getAllContents();iterator.hasNext();){
		EObject next = iterator.next();
		if(next instanceof Constraint){
			constraints.add((Constraint)next);
		}
	}
}

When I run this code I get:

Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for './example/petstore/petstore_invariants.ocl'; a registered resource factory is needed
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
	at org.eclipse.ocl.examples.pivot.OCL.load(OCL.java:616)
	at org.eclipse.ocl.examples.pivot.OCL.parse(OCL.java:624)
	at org.modelexecution.fumltesting.ocl.OclUmlLoader.loadOCL(OclUmlLoader.java:30)
	at org.modelexecution.fumltesting.ocl.OclUtilTest.main(OclUtilTest.java:44)


I am unable to figure out how to load OCL invariants from an OCL file for a UML model with the API.. Sad

Please help,
thanks Stefan

[Updated on: Tue, 19 November 2013 08:11]

Report message to a moderator

Re: &amp;amp;quot;misplaced contructs&amp;amp;quot; using second import statement [message #1196544 is a reply to message #1196527] Tue, 19 November 2013 08:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
http://wiki.eclipse.org/OCL/ForumNetiquette

On 19/11/2013 13:10, Stefan Mijatov wrote:
> Hi,
>
> I tried 2 days ago to load an OCL file, defined for a UML model.
> Looking the the Pivot Programmers Guide I wrote the following code:
>
>
> public void loadOCL(String path) throws FileNotFoundException,
> ParserException{
> EPackage.Registry registry = new EPackageRegistryImpl();
> registry.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> PivotEnvironmentFactory environmentFactory = new
> PivotEnvironmentFactory(registry, null);
> OCL ocl = OCL.newInstance(environmentFactory);
> URI uri =
> URI.createFileURI("./example/petstore/petstore_invariants.ocl");
> Resource resource = ocl.parse(uri);
> constraints = new ArrayList<Constraint>();
> for(TreeIterator<EObject> iterator =
> resource.getAllContents();iterator.hasNext();){
> EObject next = iterator.next();
> if(next instanceof Constraint){
> constraints.add((Constraint)next);
> }
> }
> }
>
> When I run this code I get:
>
>
> Exception in thread "main" java.lang.RuntimeException: Cannot create a
> resource for './example/petstore/petstore_invariants.ocl'; a
> registered resource factory is needed
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:403)
> at org.eclipse.ocl.examples.pivot.OCL.load(OCL.java:616)
> at org.eclipse.ocl.examples.pivot.OCL.parse(OCL.java:624)
> at
> org.modelexecution.fumltesting.ocl.OclUmlLoader.loadOCL(OclUmlLoader.java:30)
> at
> org.modelexecution.fumltesting.ocl.OclUtilTest.main(OclUtilTest.java:44)
>
>
> I am unable to figure out how to load OCL invariants from an OCL file
> with the API..
>
> Please help,
> thanks Stefan
Re: &amp;amp;quot;misplaced contructs&amp;amp;quot; using second import statement [message #1196783 is a reply to message #1196544] Tue, 19 November 2013 10:44 Go to previous messageGo to next message
Stefan Mijatov is currently offline Stefan Mijatov
Messages: 44
Registered: March 2010
Location: Vienna, Austria
Member
@edit
Hi Ed,

I checked out the documentation. It was not so straightforward,
but I managed to make it work! Thanks!

Here is the updated code for anyone interested.

Best regards,
Stefan
-----------------------------------------------------------------------------

Hi Ed,

I admit, I was vague with the problem Smile
Here is a complete simple example project with the aforementioned problem.

Thanks a lot for checking it out!

Best regards,
Stefan

[Updated on: Wed, 20 November 2013 12:16]

Report message to a moderator

Re: &amp;amp;amp;quot;misplaced contructs&amp;amp;amp;quot; using second import statement [message #1196967 is a reply to message #1196783] Tue, 19 November 2013 12:35 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FPivotStandalone.html

On 19/11/2013 15:44, Stefan Mijatov wrote:
> Hi Ed,
>
> I admit, I was a vague with the problem :)
> Here is a complete simple example project with the aforementioned problem.
>
> Thanks a lot for checking it out!
>
> Best regards,
> Stefan
Previous Topic:Constraint reference contents in a subtype
Next Topic:Custom primitive types in OCL
Goto Forum:
  


Current Time: Thu Jul 24 13:59:12 EDT 2014

Powered by FUDForum. Page generated in 0.02512 seconds