Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL Pivot Setting delegates in standalone application
OCL Pivot Setting delegates in standalone application [message #901240] Fri, 10 August 2012 09:18 Go to previous message
ModelGeek Mising name is currently offline ModelGeek Mising name
Messages: 351
Registered: June 2011
Senior Member
Hi,

I am writing a simple standalone class to evavluate emf model using setting delegates but i am getting following exception.

Exception in thread "main" java.lang.ExceptionInInitializerError
at org.eclipse.ocl.examples.pivot.uml.UMLUtils.initializeContents(UMLUtils.java:221)
at org.eclipse.ocl.examples.pivot.uml.UMLUtils.initializeContents(UMLUtils.java:142)
at org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.init(EssentialOCLStandaloneSetup.java:48)
at org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.createInjectorAndDoEMFRegistration(EssentialOCLStandaloneSetup.java:73)
at org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.doSetup(EssentialOCLStandaloneSetup.java:39)
at abstractmodeller.model.prm.TestPivot.main(TestPivot.java:133)
Caused by: org.eclipse.emf.common.util.WrappedException: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (jar:file:/C:/juno/eclipse-SDK-4.2M5-win32/eclipse/plugins/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)
... 6 more
Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'xmi' not found. (jar:file:/C:/juno/eclipse-SDK-4.2M5-win32/eclipse/plugins/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)

Here is complete class

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.model.OCLstdlib;
import org.eclipse.ocl.examples.pivot.utilities.PivotEnvironmentFactory;
import org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup;
import org.openide.util.Exceptions;

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 TestPivot() {
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 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 resource = ecoreResourceSet.createResource(uri1);
resource.getContents().add(modelPackage);

try {
resource.save(null);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}

}

private 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 useDelegates() {
Object eGet = eObject.eGet(eAttribute, false);
System.out.println("value = " + eGet.toString());
}

public static void main(String args[]) {
EssentialOCLStandaloneSetup.doSetup();
OCLstdlib.install();
TestPivot tp = new TestPivot();
tp.useDelegates();
}
}

 
Read Message
Read Message
Read Message
Read Message
Previous Topic:Acceleo invoking a Java Service Wrapping OCL
Next Topic:processing AST, finding out if current parsed part is the body of the OCL expression
Goto Forum:
  


Current Time: Sat May 25 05:21:28 EDT 2013

Powered by FUDForum. Page generated in 0.01625 seconds