Home » Modeling » OCL » Pivot OCL Evaluation
| |
Re: Pivot OCL Evaluation [message #827379 is a reply to message #826954] |
Fri, 23 March 2012 08:44 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
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", "http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot");
mainOCLAnnotation.getDetails().put("settingDelegates", "http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot");
//mainOCLAnnotation.getDetails().put("settingDelegates", "org.eclipse.ocl.ecore.OCL");
mainOCLAnnotation.getDetails().put("validationDelegates", "http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot");
modelPackage.getEAnnotations().add(mainOCLAnnotation);
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName(prmClass.getName());
modelPackage.getEClassifiers().add(eClass);
EAttribute eAttribute= EcoreFactory.eINSTANCE.createEAttribute();
eAttribute.setName("test");
eAttribute.setUpperBound(1);
eAttribute.setLowerBound(1);
eAttribute.setEType(EcorePackage.eINSTANCE.getELongObject());
eClass.getEStructuralFeatures().add(eAttribute);
eAttribute.setDerived(true);
eAttribute.setVolatile(true);
EAnnotation driveAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
driveAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot");
//driveAnnotation.setSource("org.eclipse.ocl.ecore.OCL");
driveAnnotation.getDetails().put("derivation", "2*2");
eAttribute.getEAnnotations().add(driveAnnotation);
//////instantiation of ecore model
EFactory iModelPackage = modelPackage.getEFactoryInstance();
EObject eObject = iModelPackage.create(eClass);
URI uri = "some path";
URI uri1 = "some path";
ResourceSet resourceSet1 = new ResourceSetImpl();
resourceSet1.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
Resource resource1 = resourceSet1.createResource(uri1);
resource1.getContents().add(modelPackage);
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource resource = resourceSet.createResource(uri);
resource.getContents().add(iModelPackage);
////////////////////////// evaluate
org.eclipse.ocl.examples.pivot.OCL.initialize(null);
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.helper.OCLHelper oclHelper = newInstance.createOCLHelper();
try {
ExpressionInOcl createQuery = oclHelper.createQuery("2*2");
long start = System.currentTimeMillis();
Value evaluate = newInstance.evaluate(eObject, createQuery);
long end = System.currentTimeMillis();
String print = print(evaluate.asObject());
print+=":::Execution Time = " + ((double)(end-start)/1000) + " Sec";
return print;
} catch (org.eclipse.ocl.examples.pivot.ParserException ex) {
Exceptions.printStackTrace(ex);
}
/////////////////////////// delegate
String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put
(oclDelegateURI, new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put
(oclDelegateURI, new OCLSettingDelegateFactory.Global());
Object eGet = eObject.eGet(eAttribute, false);
now in case if i use evalution/delegate part i get
Caused by: java.lang.ExceptionInInitializerError
at org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot$Factory.<init>(UML2Ecore2Pivot.java:48)
at org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot$Factory.<init>(UML2Ecore2Pivot.java:47)
at org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot.<clinit>(UML2Ecore2Pivot.java:124)
hope it is compilable...
thanks for assistance
regards,
[Updated on: Fri, 23 March 2012 08:49] Report message to a moderator
|
|
| |
Re: Pivot OCL Evaluation [message #827493 is a reply to message #827434] |
Fri, 23 March 2012 12:00 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
Hi,
Here is complete file containing main method. I did not attach jar files(JUNO) are there are many jar files and i hope you already have them on your machine.
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.manager.MetaModelManager;
import org.eclipse.ocl.examples.pivot.utilities.PivotEnvironmentFactory;
public class TestPivot {
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);
modelPackage.getEClassifiers().add(eClass);
URI uri1 = URI.createFileURI("test.ecore");
ecoreResourceSet = new ResourceSetImpl();
ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
Resource resource1 = ecoreResourceSet.createResource(uri1);
resource1.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() {
//try with null or object both result same exception
//org.eclipse.ocl.examples.pivot.OCL.initialize(null);
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.helper.OCLHelper oclHelper = newInstance.createOCLHelper();
try {
ExpressionInOcl createQuery = oclHelper.createQuery("2*2");
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() {
//try with null or object both result same exception
//org.eclipse.ocl.examples.pivot.OCL.initialize(null);
org.eclipse.ocl.examples.pivot.OCL.initialize(xmiResourceSet);
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put
(oclDelegateURI, new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put
(oclDelegateURI, new OCLSettingDelegateFactory.Global());
Object eGet = eObject.eGet(eAttribute, false);
System.out.println("value = " + eGet.toString());
}
public static void main(String args[]) {
TestPivot tp = new TestPivot();
tp.makeMataModel();
tp.createModel();
tp.evaluate();
tp.useDelegates();
}
}
here both evaluate() and useDeletegates() methods are throwing the same exception
I have also tried to
org.eclipse.ocl.examples.pivot.OCL.initialize(null); but it has the same exception
java.lang.ExceptionInInitializerError
at org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot$Factory.<init>(UML2Ecore2Pivot.java:48)
at org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot$Factory.<init>(UML2Ecore2Pivot.java:47)
at org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot.<clinit>(UML2Ecore2Pivot.java:124)
at org.eclipse.ocl.examples.pivot.manager.MetaModelManager.<clinit>(MetaModelManager.java:386)
........
........
.....
Caused by: org.eclipse.emf.common.util.WrappedException: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (jar:file:/C:/project/AbstractModellerPrm/lib/org.eclipse.uml2.uml_4.0.0.v20120130-1013.jar!/org/eclipse/uml2/uml/internal/impl/uml.ecore, 3, 129)
at org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.loadPackage(UMLPackageImpl.java:17007)
at org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.init(UMLPackageImpl.java:1903)
at org.eclipse.uml2.uml.UMLPackage.<clinit>(UMLPackage.java:82)
... 14 more
Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (jar:file:/C:/project/AbstractModellerPrm/lib/org.eclipse.uml2.uml_4.0.0.v20120130-1013.jar!/org/eclipse/uml2/uml/internal/impl/uml.ecore, 3, 129)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:77)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:185)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:240)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1284)
at org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.loadPackage(UMLPackageImpl.java:17005)
please help me fixing this.
Regards,
[Updated on: Fri, 23 March 2012 12:14] Report message to a moderator
|
|
|
Re: Pivot OCL Evaluation [message #827557 is a reply to message #827493] |
Fri, 23 March 2012 13:49 |
Ed Willink Messages: 7669 Registered: July 2009 |
Senior Member |
|
|
Hi
I'm not clear how you are running to get the exception trace you report,
but in order to run a 'plugin' containing your java code I need to add:
public static void main(String args[]) {
EssentialOCLStandaloneSetup.doSetup();
OCLstdlib.install();
TestPivot tp = new TestPivot();
Regards
Ed Willink
On 23/03/2012 08:00, ModelGeek Mising name wrote:
> Hi,
>
> Here is complete file containing main method. I did not attach jar
> files(JUNO) are there are many jar files and i hope you already have
> them on your machine.
>
> 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.manager.MetaModelManager;
> import org.eclipse.ocl.examples.pivot.utilities.PivotEnvironmentFactory;
> /**
> *
> * @author khurrams
> */
> public class TestPivot {
> 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;
> 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);
> modelPackage.getEClassifiers().add(eClass);
> URI uri1 = URI.createFileURI("test.ecore");
> ResourceSet resourceSet1 = new ResourceSetImpl();
>
> resourceSet1.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
> new EcoreResourceFactoryImpl());
> Resource resource1 = resourceSet1.createResource(uri1);
> resource1.getContents().add(modelPackage);
> }
> public void createModel() {
> iModelPackage = modelPackage.getEFactoryInstance();
> eObject = iModelPackage.create(eClass);
> URI uri = URI.createFileURI("test.xmi");
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
> new XMIResourceFactoryImpl());
> Resource resource = resourceSet.createResource(uri);
> resource.getContents().add(iModelPackage);
> }
> public void evaluate() {
> //org.eclipse.ocl.examples.pivot.OCL.initialize(null);
> 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.helper.OCLHelper oclHelper =
> newInstance.createOCLHelper();
> try {
> ExpressionInOcl createQuery = oclHelper.createQuery("2*2");
> 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() {
> 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());
> Object eGet = eObject.eGet(eAttribute, false);
> System.out.println("value = " + eGet.toString());
> }
> public static void main(String args[]) {
> TestPivot tp = new TestPivot();
> tp.makeMataModel();
> tp.createModel();
> tp.evaluate();
> tp.useDelegates();
> }
> }
>
> here both evaluates and useDeletegates() methods are throwing the same
> exception
> java.lang.ExceptionInInitializerError
> at
> org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot$Factory.<init>(UML2Ecore2Pivot.java:48)
> at
> org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot$Factory.<init>(UML2Ecore2Pivot.java:47)
> at
> org.eclipse.ocl.examples.pivot.uml.UML2Ecore2Pivot.<clinit>(UML2Ecore2Pivot.java:124)
> at
> org.eclipse.ocl.examples.pivot.manager.MetaModelManager.<clinit>(MetaModelManager.java:386)
> .......
> .......
> ....
> Caused by: org.eclipse.emf.common.util.WrappedException:
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature
> 'xmi' not found.
> (jar:file:/C:/project/AbstractModellerPrm/lib/org.eclipse.uml2.uml_4.0.0.v20120130-1013.jar!/org/eclipse/uml2/uml/internal/impl/uml.ecore,
> 3, 129)
> at
> org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.loadPackage(UMLPackageImpl.java:17007)
> at
> org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.init(UMLPackageImpl.java:1903)
> at org.eclipse.uml2.uml.UMLPackage.<clinit>(UMLPackage.java:82)
> ... 14 more
> Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException:
> Feature 'xmi' not found.
> (jar:file:/C:/project/AbstractModellerPrm/lib/org.eclipse.uml2.uml_4.0.0.v20120130-1013.jar!/org/eclipse/uml2/uml/internal/impl/uml.ecore,
> 3, 129)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:77)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:185)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:240)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1284)
> at
> org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.loadPackage(UMLPackageImpl.java:17005)
>
> please help me fixing this.
>
> Regards,
>
>
>
|
|
|
Re: Pivot OCL Evaluation [message #827587 is a reply to message #827557] |
Fri, 23 March 2012 14:39 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
Hi,
Actually i am using netbeans for this code. I have attached all libraries required in netbeans project(org.eclipse.emf.. , org.eclipse.ocl.example....).
Do i need add EssentialOCLStandaloneSetup.doSetup(); and stdlib.install(); even when i am not using xtext?
It is just running TestPivot class like a test case.
thanks for assistance!
Regards,
[Updated on: Fri, 23 March 2012 14:45] Report message to a moderator
|
|
| | | |
Goto Forum:
Current Time: Mon Sep 09 19:23:40 GMT 2024
Powered by FUDForum. Page generated in 0.05247 seconds
|