Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Pivot OCL
Pivot OCL [message #830392] Tue, 27 March 2012 11:13 Go to next message
ModelGeek Mising name is currently online ModelGeek Mising name
Messages: 500
Registered: June 2011
Senior Member
Hi,

I have a pivot model and i am trying to evaluate it but i am getting following exception

org.eclipse.ocl.examples.pivot.SemanticException: Errors in 'self.test'
Unresolved property 'test' for 'OclInvalid'
at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:153)
at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.resolveSpecification(PivotUtil.java:1024)
at org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createSpecification(OCLHelperImpl.java:70)
at org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:62)

Here is complete class. This class is used in a simple Example Eclipse RCP Plugin




import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.ocl.examples.pivot.delegate.*;
import org.eclipse.ocl.examples.domain.values.Value;
import org.eclipse.ocl.examples.pivot.ExpressionInOcl;
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.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.ocl.examples.pivot.OCL;
import org.eclipse.ocl.examples.pivot.manager.MetaModelManager;
import org.eclipse.ocl.examples.pivot.utilities.PivotEnvironmentFactory;
import org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup;
import org.eclipse.ocl.examples.pivot.model.OCLstdlib;


public class TestPivot {

public TestPivot() {
EssentialOCLStandaloneSetup.doSetup();
OCLstdlib.install();
org.eclipse.ocl.examples.pivot.OCL.initialize(null);
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put
(oclDelegateURI, new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put
(oclDelegateURI, new OCLSettingDelegateFactory.Global());
makeMataModel();
createModel();
}
private EPackage modelPackage = null;
private EClass eClass = null;
private EAttribute eAttribute = null;
private EFactory iModelPackage = null;
private EObject eObject = null;
private String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
private ResourceSet ecoreResourceSet;
private ResourceSet xmiResourceSet;
public void makeMataModel() {
modelPackage = EcoreFactory.eINSTANCE.createEPackage();
modelPackage.setName("temp");
modelPackage.setNsPrefix("Test");
modelPackage.setNsURI("http://www.eclipse.org/mdt/ocl/oclinecore/tutorial");
EAnnotation mainOCLAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
mainOCLAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore");
mainOCLAnnotation.getDetails().put("invocationDelegates", oclDelegateURI);
mainOCLAnnotation.getDetails().put("settingDelegates", oclDelegateURI);
mainOCLAnnotation.getDetails().put("validationDelegates", oclDelegateURI);
modelPackage.getEAnnotations().add(mainOCLAnnotation);
eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("TestClass");
eAttribute= EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("test");
eAttribute.setUpperBound(1);
eAttribute.setLowerBound(1);
eAttribute.setEType(EcorePackage.eINSTANCE.getELongObject());
eAttribute.setDerived(true);
eAttribute.setVolatile(true);
EAnnotation driveAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
driveAnnotation.setSource(oclDelegateURI);
driveAnnotation.getDetails().put("derivation", "2*2");
eAttribute.getEAnnotations().add(driveAnnotation);
eClass.getEStructuralFeatures().add(eAttribute);

EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
EAnnotation eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
eAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot");
eAnnotation.getDetails().put("body", "");
eOperation.setName("test");
eOperation.getEAnnotations().add(eAnnotation);

modelPackage.getEClassifiers().add(eClass);
URI uri1 = URI.createFileURI("test.ecore");
ecoreResourceSet = new ResourceSetImpl();
ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
Resource resource = ecoreResourceSet.createResource(uri1);
resource.getContents().add(modelPackage);


}

public void createModel() {
iModelPackage = modelPackage.getEFactoryInstance();
eObject = iModelPackage.create(eClass);
URI uri = URI.createFileURI("test.xmi");
xmiResourceSet = new ResourceSetImpl();
xmiResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource resource = xmiResourceSet.createResource(uri);
resource.getContents().add(iModelPackage);
resource.getContents().add(eObject);

}

public void evaluate() {
org.eclipse.ocl.examples.pivot.OCL.initialize(xmiResourceSet);
org.eclipse.ocl.examples.pivot.OCL newInstance = org.eclipse.ocl.examples.pivot.OCL.newInstance(new PivotEnvironmentFactory(iModelPackage.eResource().getResourceSet().getPackageRegistry(), new MetaModelManager(iModelPackage.eResource().getResourceSet())));
//org.eclipse.ocl.examples.pivot.OCL newInstance = OCL.newInstance();
org.eclipse.ocl.examples.pivot.helper.OCLHelper oclHelper = newInstance.createOCLHelper();
try {
oclHelper.setInstanceContext(eObject);
ExpressionInOcl createQuery = oclHelper.createQuery("self.test");
long start = System.currentTimeMillis();
Value evaluate = newInstance.evaluate(eObject, createQuery);
long end = System.currentTimeMillis();
String print = evaluate.asObject().toString();
print+=":::Execution Time = " + ((double)(end-start)/1000) + " Sec";
System.out.println("value = " + print);
} catch (org.eclipse.ocl.examples.pivot.ParserException ex) {
ex.printStackTrace();
}


}

public void useDelegates() {
Object eGet = eObject.eGet(eAttribute, false);
System.out.println("value = " + eGet.toString());
}

public static void main(String[] args) {
TestPivot tp = new TestPivot();
tp.evaluate();

}
}

Thanks in advance!

Regards,
Re: Pivot OCL [message #830704 is a reply to message #830392] Tue, 27 March 2012 21:14 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

Your problem is that you used the old API and hit a TODO stub.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=375485 raised. Thanks for
bringing this to my attention.

If you change

oclHelper.setInstanceContext(eObject);

to

MetaModelManager metaModelManager =
oclHelper.getOCL().getMetaModelManager();
EClass eClass = eObject.eClass();
Type pivotType =
metaModelManager.getPivotType(eClass.getName());
if (pivotType == null) {
Resource resource = eClass.eResource();
Ecore2Pivot ecore2Pivot =
Ecore2Pivot.getAdapter(resource, metaModelManager);
pivotType = ecore2Pivot.getCreated(Type.class, eClass);
}
oclHelper.setContext(pivotType);

it gives (after modifying to invoke twice)

value = 4:::Execution Time = 0.686 Sec
value = 4:::Execution Time = 0.0 Sec

showing the overhead of the first time parse that is cached for next
time. A direct code generator will be available in Juno.

Regards

Ed Willink


On 27/03/2012 11:13, ModelGeek Mising name wrote:
> Hi,
>
> I have a pivot model and i am trying to evaluate it but i am getting
> following exception
>
> org.eclipse.ocl.examples.pivot.SemanticException: Errors in 'self.test'
> Unresolved property 'test' for 'OclInvalid'
> at
> org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:153)
> at
> org.eclipse.ocl.examples.pivot.utilities.PivotUtil.resolveSpecification(PivotUtil.java:1024)
> at
> org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createSpecification(OCLHelperImpl.java:70)
> at
> org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:62)
>
> Here is complete class. This class is used in a simple Example Eclipse
> RCP Plugin
>
>
>
>
> import java.io.IOException;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EAnnotation;
> import org.eclipse.emf.ecore.EAttribute;
> import org.eclipse.emf.ecore.EClass; import
> org.eclipse.emf.ecore.EFactory;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.ecore.EOperation;
> import org.eclipse.emf.ecore.EPackage;
> import org.eclipse.emf.ecore.EcoreFactory;
> import org.eclipse.emf.ecore.EcorePackage;
> import org.eclipse.emf.ecore.EStructuralFeature;
> import org.eclipse.ocl.examples.pivot.delegate.*;
> import org.eclipse.ocl.examples.domain.values.Value;
> import org.eclipse.ocl.examples.pivot.ExpressionInOcl;
> 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.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
> import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
> import org.eclipse.ocl.examples.pivot.OCL;
> import org.eclipse.ocl.examples.pivot.manager.MetaModelManager;
> import org.eclipse.ocl.examples.pivot.utilities.PivotEnvironmentFactory;
> import
> org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup;
> import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
>
>
> public class TestPivot {
>
> public TestPivot() {
> EssentialOCLStandaloneSetup.doSetup();
> OCLstdlib.install();
> org.eclipse.ocl.examples.pivot.OCL.initialize(null);
>
> EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put
> (oclDelegateURI, new OCLInvocationDelegateFactory.Global());
>
> EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put
> (oclDelegateURI, new OCLSettingDelegateFactory.Global());
> makeMataModel();
> createModel(); }
> private EPackage modelPackage = null;
> private EClass eClass = null;
> private EAttribute eAttribute = null;
> private EFactory iModelPackage = null;
> private EObject eObject = null;
> private String oclDelegateURI =
> OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
> private ResourceSet ecoreResourceSet;
> private ResourceSet xmiResourceSet;
> public void makeMataModel() {
> modelPackage = EcoreFactory.eINSTANCE.createEPackage();
> modelPackage.setName("temp");
> modelPackage.setNsPrefix("Test");
>
> modelPackage.setNsURI("http://www.eclipse.org/mdt/ocl/oclinecore/tutorial");
> EAnnotation mainOCLAnnotation =
> EcoreFactory.eINSTANCE.createEAnnotation();
>
> mainOCLAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore");
> mainOCLAnnotation.getDetails().put("invocationDelegates",
> oclDelegateURI);
> mainOCLAnnotation.getDetails().put("settingDelegates",
> oclDelegateURI);
> mainOCLAnnotation.getDetails().put("validationDelegates",
> oclDelegateURI);
> modelPackage.getEAnnotations().add(mainOCLAnnotation);
> eClass = EcoreFactory.eINSTANCE.createEClass();
> eClass.setName("TestClass");
> eAttribute= EcoreFactory.eINSTANCE.createEAttribute();
> eAttribute.setName("test");
> eAttribute.setUpperBound(1);
> eAttribute.setLowerBound(1);
> eAttribute.setEType(EcorePackage.eINSTANCE.getELongObject());
> eAttribute.setDerived(true);
> eAttribute.setVolatile(true);
> EAnnotation driveAnnotation =
> EcoreFactory.eINSTANCE.createEAnnotation();
> driveAnnotation.setSource(oclDelegateURI);
> driveAnnotation.getDetails().put("derivation", "2*2");
> eAttribute.getEAnnotations().add(driveAnnotation);
> eClass.getEStructuralFeatures().add(eAttribute);
> EOperation eOperation =
> EcoreFactory.eINSTANCE.createEOperation();
> EAnnotation eAnnotation =
> EcoreFactory.eINSTANCE.createEAnnotation();
>
> eAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot");
> eAnnotation.getDetails().put("body", "");
> eOperation.setName("test");
> eOperation.getEAnnotations().add(eAnnotation);
> modelPackage.getEClassifiers().add(eClass);
> URI uri1 = URI.createFileURI("test.ecore");
> ecoreResourceSet = new ResourceSetImpl();
>
> ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
> new EcoreResourceFactoryImpl());
> Resource resource = ecoreResourceSet.createResource(uri1);
> resource.getContents().add(modelPackage);
> }
> public void createModel() {
> iModelPackage = modelPackage.getEFactoryInstance();
> eObject = iModelPackage.create(eClass);
> URI uri = URI.createFileURI("test.xmi");
> xmiResourceSet = new ResourceSetImpl();
>
> xmiResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
> new XMIResourceFactoryImpl());
> Resource resource = xmiResourceSet.createResource(uri);
> resource.getContents().add(iModelPackage);
> resource.getContents().add(eObject);
> }
> public void evaluate() {
> org.eclipse.ocl.examples.pivot.OCL.initialize(xmiResourceSet);
> org.eclipse.ocl.examples.pivot.OCL newInstance =
> org.eclipse.ocl.examples.pivot.OCL.newInstance(new
> PivotEnvironmentFactory(iModelPackage.eResource().getResourceSet().getPackageRegistry(),
> new MetaModelManager(iModelPackage.eResource().getResourceSet())));
> //org.eclipse.ocl.examples.pivot.OCL newInstance =
> OCL.newInstance();
> org.eclipse.ocl.examples.pivot.helper.OCLHelper oclHelper =
> newInstance.createOCLHelper();
> try {
> oclHelper.setInstanceContext(eObject);
> ExpressionInOcl createQuery =
> oclHelper.createQuery("self.test");
> long start = System.currentTimeMillis();
> Value evaluate = newInstance.evaluate(eObject, createQuery);
> long end = System.currentTimeMillis();
> String print = evaluate.asObject().toString();
> print+=":::Execution Time = " + ((double)(end-start)/1000)
> + " Sec";
> System.out.println("value = " + print);
> } catch (org.eclipse.ocl.examples.pivot.ParserException ex) {
> ex.printStackTrace();
> } }
> public void useDelegates() {
> Object eGet = eObject.eGet(eAttribute, false);
> System.out.println("value = " + eGet.toString());
> }
>
> public static void main(String[] args) {
> TestPivot tp = new TestPivot();
> tp.evaluate();
> }
> }
>
> Thanks in advance!
>
> Regards,
Re: Pivot OCL [message #830909 is a reply to message #830704] Wed, 28 March 2012 03:58 Go to previous message
ModelGeek Mising name is currently online ModelGeek Mising name
Messages: 500
Registered: June 2011
Senior Member
thanks!
Previous Topic:Extending OCL : visitor problems
Next Topic:cast to EFloat?
Goto Forum:
  


Current Time: Thu Jul 24 11:26:36 EDT 2014

Powered by FUDForum. Page generated in 0.01730 seconds