Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » SemanticException
SemanticException [message #634261] Thu, 21 October 2010 02:11 Go to next message
Eban Escott is currently offline Eban EscottFriend
Messages: 61
Registered: July 2009
Member
Hi, I am having problems with OCLHelper. I have the following code which is working fine. But when I change the expression to "price > 0" I get a SemanticException. Any ideas? Thanks in advance, Eban

Class umlClass = (Class)package.getOwnedMember("Product");
Property umlProperty = umlClass.getOwnedAttribute("price", null);
OCL ocl = OCL.newInstance();
OCLHelper helper = ocl.createOCLHelper();
helper.setAttributeContext(umlProperty.getOwner(), umlProperty);
String expression = "price = 0"
OCLExpression query = helper.createQuery(expression);

org.eclipse.ocl.SemanticException: Cannot find operation (>(Integer)) for the type (null)
at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:352 )
at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:322 )
at org.eclipse.ocl.internal.helper.HelperUtil.checkForErrors(He lperUtil.java:519)
at org.eclipse.ocl.internal.helper.HelperUtil.parseQuery(Helper Util.java:165)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createQuery(OC LHelperImpl.java:175)
at org.eclipse.ocl.uml.OCLHelperImpl.createQuery(OCLHelperImpl. java:91)
at org.eclipse.ocl.uml.OCLHelperImpl.createQuery(OCLHelperImpl. java:1)
Re: SemanticException [message #634314 is a reply to message #634261] Thu, 21 October 2010 08:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Eban

as the message says

Cannot find operation (>(Integer)) for the type (null)

price has a null type.

OclVoid supports = but not > so the change caused a useless evaluation
to change to a semantic probvlem.

Regards

Ed Willink

On 21/10/2010 03:11, Eban Escott wrote:
> Hi, I am having problems with OCLHelper. I have the following code
> which is working fine. But when I change the expression to "price > 0"
> I get a SemanticException. Any ideas? Thanks in advance, Eban
>
> Class umlClass = (Class)package.getOwnedMember("Product");
> Property umlProperty = umlClass.getOwnedAttribute("price", null);
> OCL ocl = OCL.newInstance();
> OCLHelper helper = ocl.createOCLHelper();
> helper.setAttributeContext(umlProperty.getOwner(), umlProperty);
> String expression = "price = 0"
> OCLExpression query = helper.createQuery(expression);
>
> org.eclipse.ocl.SemanticException: Cannot find operation (>(Integer))
> for the type (null)
> at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:352 )
> at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:322 )
> at org.eclipse.ocl.internal.helper.HelperUtil.checkForErrors(He
> lperUtil.java:519)
> at org.eclipse.ocl.internal.helper.HelperUtil.parseQuery(Helper
> Util.java:165)
> at org.eclipse.ocl.internal.helper.OCLHelperImpl.createQuery(OC
> LHelperImpl.java:175)
> at org.eclipse.ocl.uml.OCLHelperImpl.createQuery(OCLHelperImpl.
> java:91)
> at org.eclipse.ocl.uml.OCLHelperImpl.createQuery(OCLHelperImpl.
> java:1)
Re: SemanticException [message #635736 is a reply to message #634261] Wed, 27 October 2010 21:47 Go to previous messageGo to next message
Eban Escott is currently offline Eban EscottFriend
Messages: 61
Registered: July 2009
Member
Hi Ed, thanks for the reply Smile

I checked the uml model and I do have a type for price:

<ownedAttribute xmi:id="_YePi8IeiEd6G9vv1xOexfw" name="price" aggregation="composite">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_METAMODELS/Ecore.metamodel.uml#EBigDecimal"/>
</ownedAttribute>

Is this not a type it expects?

I also looked at the doc for getOwnedAttribute and I figured the 2nd param can be null as it would just search based in the name.

Property getOwnedAttribute(java.lang.String name,
Type type)
Retrieves the first Property with the specified 'Name', and 'Type' from the 'Owned Attribute' containment reference list.
Parameters:
name - The 'Name' of the Property to retrieve, or null.
type - The 'Type' of the Property to retrieve, or null.

Cheers
Eban
Re: SemanticException [message #635783 is a reply to message #635736] Thu, 28 October 2010 06:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Eban

If you have a problem, it is helpful to provide a reproducible test case.

Your original query was difficult to guess at because you didn't provide
a meta-model.

You now only provide one attribute.

If you understand the problem so well that this is sufficient, perhaps
you can supply the fix.

Otherwise please provide sufficient information to allow investigation.

Regards

Ed Willink


On 27/10/2010 22:47, Eban Escott wrote:
> Hi Ed, thanks for the reply :)
>
> I checked the uml model and I do have a type for price:
>
> <ownedAttribute xmi:id="_YePi8IeiEd6G9vv1xOexfw" name="price"
> aggregation="composite">
> <type xmi:type="uml:PrimitiveType"
> href="pathmap://UML_METAMODELS/Ecore.metamodel.uml#EBigDecimal"/>
> </ownedAttribute>
>
> Is this not a type it expects?
>
> I also looked at the doc for getOwnedAttribute and I figured the 2nd
> param can be null as it would just search based in the name.
>
> Property getOwnedAttribute(java.lang.String name,
> Type type)
> Retrieves the first Property with the specified 'Name', and 'Type'
> from the 'Owned Attribute' containment reference list.
> Parameters:
> name - The 'Name' of the Property to retrieve, or null.
> type - The 'Type' of the Property to retrieve, or null.
>
> Cheers
> Eban
Re: SemanticException [message #636010 is a reply to message #634261] Thu, 28 October 2010 22:38 Go to previous messageGo to next message
Eban Escott is currently offline Eban EscottFriend
Messages: 61
Registered: July 2009
Member
Hi Ed,

I wish a had a fix to the problem and I do apologise if I have not supplied enough information as I am new to OCL and still finding my feet.

Here is the isolated UML model and if you name it MyModel.uml and run the JUnit test it will give you the exception.

Cheers
Eban

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:profileM="http:///schemas/profileM/_bYwRQKwKEd6_R4nwdX_sDQ/0" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmlns:validation="http:///schemas/validation/_LIcqENZpEd-pV_SeKY8DIg/10" xsi:schemaLocation="http:///schemas/profileM/_bYwRQKwKEd6_R4nwdX_sDQ/0 ../../Profile/model/profileM.profile.uml#_bYxfYKwKEd6_R4nwdX_sDQ http:///schemas/validation/_LIcqENZpEd-pV_SeKY8DIg/10 ../../Profile/model/validation.profile.uml#_LIdRINZpEd-pV_SeKY8DIg">
  <uml:Package xmi:id="_Rl0wAHTSEd6tw7FQB0T26Q" name="MyPackage">
    <elementImport xmi:id="_RrcP0HTSEd6tw7FQB0T26Q">
      <importedElement xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Boolean"/>
    </elementImport>
    <elementImport xmi:id="_RrqSQHTSEd6tw7FQB0T26Q">
      <importedElement xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
    </elementImport>
    <elementImport xmi:id="_RrqSQXTSEd6tw7FQB0T26Q">
      <importedElement xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#UnlimitedNatural"/>
    </elementImport>
    <elementImport xmi:id="_RrqSQnTSEd6tw7FQB0T26Q">
      <importedElement xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
    </elementImport>
    <packagedElement xmi:type="uml:Class" xmi:id="_TxO3oHTSEd6tw7FQB0T26Q" name="Product">
      <ownedAttribute xmi:id="_QKQ5EH8nEd6YbOsakxhBTg" name="id" aggregation="composite">
        <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
      </ownedAttribute>
      <ownedAttribute xmi:id="_QciWUIeiEd6G9vv1xOexfw" name="name" aggregation="composite">
        <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
      </ownedAttribute>
      <ownedAttribute xmi:id="_YePi8IeiEd6G9vv1xOexfw" name="price" aggregation="composite">
        <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Integer"/>
      </ownedAttribute>
    </packagedElement>
  </uml:Package>
</xmi:XMI>


package transform.ocl;

import java.io.File;
import java.io.IOException;

import junit.framework.Assert;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.ocl.expressions.OCLExpression;
import org.eclipse.ocl.helper.OCLHelper;
import org.eclipse.ocl.uml.OCL;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Operation;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.junit.Test;

import transform.utils.TransformationUtils;

public class IsolationForEdTest {

	@Test
	public void ocl1() {
		try {
			Package umlPackage = loadModel();
			Class umlClass = (Class)umlPackage.getOwnedMember("Product");
			Property umlProperty = umlClass.getOwnedAttribute("price", null);
			
			OCL ocl = OCL.newInstance();
			OCLHelper helper = ocl.createOCLHelper();
			helper.setAttributeContext(umlProperty.getOwner(), umlProperty);
			OCLExpression query = helper.createQuery("price > 0");
		} catch (Exception e) {
			e.printStackTrace();
			Assert.assertTrue(false);
		}
	}
	
	private Package loadModel() throws IOException {
		ResourceSet resourceSet = new ResourceSetImpl();
		resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

		File file = new File("MyModel.uml");
		if(!file.exists()) {
			System.out.println("Cannot find file.");
		} else {
			System.out.println("Found " + file.getCanonicalPath());
		}

		URI uri = URI.createFileURI(file.getCanonicalPath());
		Resource resource = resourceSet.getResource(uri, true);
		Package inputPackage = (Package)resource.getContents().get(0);
		
		return inputPackage;
	}	
}

[Updated on: Thu, 28 October 2010 22:39]

Report message to a moderator

Re: SemanticException [message #636069 is a reply to message #636010] Fri, 29 October 2010 08:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Eban

Thanks for the excellent repro.

The confusion is that = should fail too. In fact both should be
diagnosed as an unresolved proxy
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=329011) because you have
omitted the required initialisation of UML pathmaps. This is awkward, so
OCL provides a helper.

You need to add:

String reason = OCL.initialize(resourceSet);
TestCase.assertNull("Initialization failed : " + reason, reason);

which will then give you some failures that will prompt you to add

-Dorg.eclipse.ocl.uml=${resource_loc:/org.eclipse.ocl.uml}
-Dorg.eclipse.uml2.uml.resources=${resource_loc:/org.eclipse .uml2.uml.resources}

to your launch configuration and to load

org.eclipse.ocl.uml
org.eclipse.uml2.uml.resources

into your workspace, since the standalone EMF support cannot extract UML
models from
plugin ZIP files.

Regards

Ed Willink


On 28/10/2010 23:38, Eban Escott wrote:
> Hi Ed,
>
> I wish a had a fix to the problem and I do apologise if I have not
> supplied enough information as I am new to OCL and still finding my feet.
>
> Here is the isolated UML model and if you name it MyModel.uml and run
> the JUnit test you it will give you the exception.
>
> Cheers
> Eban
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xmi:XMI xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:profileM="http:///schemas/profileM/_bYwRQKwKEd6_R4nwdX_sDQ/0"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmlns:validation="http:///schemas/validation/_LIcqENZpEd-pV_SeKY8DIg/10"
> xsi:schemaLocation="http:///schemas/profileM/_bYwRQKwKEd6_R4nwdX_sDQ/0
> ../../Profile/model/profileM.profile.uml#_bYxfYKwKEd6_R4nwdX _sDQ
> http:///schemas/validation/_LIcqENZpEd-pV_SeKY8DIg/10
> ../../Profile/model/validation.profile.uml#_LIdRINZpEd-pV_Se KY8DIg ">
> <uml:Package xmi:id="_Rl0wAHTSEd6tw7FQB0T26Q" name="MyPackage">
> <elementImport xmi:id="_RrcP0HTSEd6tw7FQB0T26Q">
> <importedElement xmi:type="uml:PrimitiveType"
> href=" pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Boolea n"/>
> </elementImport>
> <elementImport xmi:id="_RrqSQHTSEd6tw7FQB0T26Q">
> <importedElement xmi:type="uml:PrimitiveType"
> href=" pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
> </elementImport>
> <elementImport xmi:id="_RrqSQXTSEd6tw7FQB0T26Q">
> <importedElement xmi:type="uml:PrimitiveType"
> href=" pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Unlimi tedNatural"/>
> </elementImport>
> <elementImport xmi:id="_RrqSQnTSEd6tw7FQB0T26Q">
> <importedElement xmi:type="uml:PrimitiveType"
> href=" pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Intege r"/>
> </elementImport>
> <packagedElement xmi:type="uml:Class" xmi:id="_TxO3oHTSEd6tw7FQB0T26Q"
> name="Product">
> <ownedAttribute xmi:id="_QKQ5EH8nEd6YbOsakxhBTg" name="id"
> aggregation="composite">
> <type xmi:type="uml:PrimitiveType"
> href=" pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Intege r"/>
> </ownedAttribute>
> <ownedAttribute xmi:id="_QciWUIeiEd6G9vv1xOexfw" name="name"
> aggregation="composite">
> <type xmi:type="uml:PrimitiveType"
> href=" pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
> </ownedAttribute>
> <ownedAttribute xmi:id="_YePi8IeiEd6G9vv1xOexfw" name="price"
> aggregation="composite">
> <type xmi:type="uml:PrimitiveType"
> href=" pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#Intege r"/>
> </ownedAttribute>
> </packagedElement>
> </uml:Package>
> </xmi:XMI>
>
>
>
> package transform.ocl;
>
> import java.io.File;
> import java.io.IOException;
>
> import junit.framework.Assert;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.ocl.expressions.OCLExpression;
> import org.eclipse.ocl.helper.OCLHelper;
> import org.eclipse.ocl.uml.OCL;
> import org.eclipse.uml2.uml.Class;
> import org.eclipse.uml2.uml.Classifier;
> import org.eclipse.uml2.uml.Operation;
> import org.eclipse.uml2.uml.Package;
> import org.eclipse.uml2.uml.Property;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UMLResource;
> import org.junit.Test;
>
> import transform.utils.TransformationUtils;
>
> public class IsolationForEdTest {
>
> @Test
> public void ocl1() {
> try {
> Package umlPackage = loadModel();
> Class umlClass = (Class)umlPackage.getOwnedMember("Product");
> Property umlProperty = umlClass.getOwnedAttribute("price",
> null);
>
> OCL ocl = OCL.newInstance();
> OCLHelper helper = ocl.createOCLHelper();
> helper.setAttributeContext(umlProperty.getOwner(),
> umlProperty);
> OCLExpression query = helper.createQuery("price > 0");
> } catch (Exception e) {
> e.printStackTrace();
> Assert.assertTrue(false);
> }
> }
>
> private Package loadModel() throws IOException {
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> File file = new File("MyModel.uml");
> if(!file.exists()) {
> System.out.println("Cannot find file.");
> } else {
> System.out.println("Found " + file.getCanonicalPath());
> }
>
> URI uri = URI.createFileURI(file.getCanonicalPath());
> Resource resource = resourceSet.getResource(uri, true);
> Package inputPackage = (Package)resource.getContents().get(0);
>
> return inputPackage;
> }
> }
>
>
Re: SemanticException [message #638100 is a reply to message #636069] Tue, 09 November 2010 22:07 Go to previous message
Eban Escott is currently offline Eban EscottFriend
Messages: 61
Registered: July 2009
Member
Great, thanks Ed!

I unzipped the jar files into my workspace and added the extra config and it works.

I appreciate your effort Smile

Take care
Eban
Previous Topic:OCL iterate - help a begineer
Next Topic:derive Expression with stereotypes and tagged values
Goto Forum:
  


Current Time: Fri Apr 19 11:11:51 GMT 2024

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

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

Back to the top