|
|
|
|
Re: SemanticException [message #636010 is a reply to message #634261] |
Thu, 28 October 2010 22:38 |
Eban Escott 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 |
Ed Willink Messages: 7670 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;
> }
> }
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04317 seconds