|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Emfatic text from Ecore [message #727136 is a reply to message #727135] |
Tue, 20 September 2011 13:48 |
|
Hi, i have no idea what OCLinEcore does,
but generally in xtext you create a resource with the extension, save it and it will work out of the box:
(pseudo code)
Injector i = new MyDslStandaloneSetup().createInjectorandDo ....
ResourceSet rs = i.getInstance(ResourceSet.class);
Resource r = rs.createResource(URI.createURI("....mydsl"))
r.getContents.add(modelRoot)
r.save(null);
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
Re: Emfatic text from Ecore [message #727231 is a reply to message #727225] |
Tue, 20 September 2011 16:46 |
|
P.S.:
package org.xtext.example.mydsl;
import java.io.IOException;
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.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.oclinEcoreCST.OCLinEcoreDocumentCS;
import org.eclipse.ocl.examples.xtext.oclinecore.resource.Ecore2OCLinEcore;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
OCLinEcoreStandaloneSetup.doSetup();
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.getResource(URI.createFileURI("../org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.ecore"), true);
System.out.println(r.getContents().get(0));
OCLinEcoreDocumentCS doc = Ecore2OCLinEcore.importFromEcore(rs, "alias", r);
Resource r2 = rs.createResource(URI.createURI("test.oclinecore"));
r2.getContents().add(doc);
r2.save(null);
}
}
works in Helios.
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
|
|
|
|
|
|
Re: Emfatic text from Ecore [message #727471 is a reply to message #727467] |
Wed, 21 September 2011 11:58 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
public static void main(String args[]) {
URI uri1 = URI.createFileURI("C:\\Users\\KhurramS\\Desktop\\ulrik\\test3.ecore");
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
Resource resource = resourceSet.getResource(uri1, true);
try {
OCLinEcoreStandaloneSetup.doSetup();
OCLinEcoreDocumentCS document = Ecore2OCLinEcore.importFromEcore(resourceSet, "alias", resource);
Resource r2 = resourceSet.createResource(uri1.trimFileExtension().appendFileExtension("oclinecore"), OCLinEcoreCSTPackage.eCONTENT_TYPE);
r2.getContents().add(document);
r2.save(null);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
i get exception : OCLinEcoreDocumentCS document = Ecore2OCLinEcore.importFromEcore(resourceSet, "alias", resource);
Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'xmi' not found. (file:/C:/Users/KhurramS/Desktop/ulrik/test3.ecore, 5, 80)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
}
-
Attachment: test3.ecore
(Size: 1.40KB, Downloaded 252 times)
[Updated on: Wed, 21 September 2011 11:59] Report message to a moderator
|
|
|
Re: Emfatic text from Ecore [message #727473 is a reply to message #727471] |
Wed, 21 September 2011 12:00 |
|
Strange things you do:
package org.xtext.example.mydsl;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
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.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.oclinEcoreCST.OCLinEcoreDocumentCS;
import org.eclipse.ocl.examples.xtext.oclinecore.resource.Ecore2OCLinEcore;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
EPackage p = EcoreFactory.eINSTANCE.createEPackage();
p.setName("test");
p.setNsPrefix("test");
p.setNsURI("http://www.example.com/test");
EClass c = EcoreFactory.eINSTANCE.createEClass();
c.setName("Dummy");
p.getEClassifiers().add(c);
OCLinEcoreStandaloneSetup.doSetup();
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.createResource(URI.createURI("dummy.ecore"));
r.getContents().add(p);
//Resource r = rs.getResource(URI.createFileURI("../org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.ecore"), true);
System.out.println(r.getContents().get(0));
OCLinEcoreDocumentCS doc = Ecore2OCLinEcore.importFromEcore(rs, "alias", r);
Resource r2 = rs.createResource(URI.createURI("test.oclinecore"));
r2.getContents().add(doc);
r2.save(null);
}
}
works for me
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
Re: Emfatic text from Ecore [message #727490 is a reply to message #727480] |
Wed, 21 September 2011 12:43 |
ModelGeek Mising name Messages: 550 Registered: June 2011 |
Senior Member |
|
|
hi,
I have checked my class path but i am still getting following exception from your main method, Do you have any idea why is this happening?
Exception in thread "main" com.google.inject.ProvisionException: Guice provision errors:
1) Error injecting method, org.eclipse.emf.common.util.WrappedException: org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'EClassifier' is not found or is abstract. (classpath:/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xmi, 18, 123)
at org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService.setGrammar(AbstractDeclarativeValueConverterService.java:50)
while locating org.eclipse.ocl.examples.xtext.oclinecore.services.OCLinEcoreValueConverterService
while locating org.eclipse.xtext.conversion.IValueConverterService
for field at org.eclipse.xtext.linking.impl.LinkingHelper.valueConverter(LinkingHelper.java:25)
while locating org.eclipse.xtext.linking.impl.LinkingHelper
for field at org.eclipse.xtext.parsetree.reconstr.impl.CrossReferenceSerializer.linkingHelper(CrossReferenceSerializer.java:33)
while locating org.eclipse.ocl.examples.xtext.oclinecore.services.OCLinEcoreCrossReferenceSerializer
while locating org.eclipse.xtext.parsetree.reconstr.ITokenSerializer$ICrossReferenceSerializer
for field at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.crossRefSerializer(AbstractParseTreeConstructor.java:58)
while locating org.eclipse.ocl.examples.xtext.oclinecore.parseTreeConstruction.OCLinEcoreParsetreeConstructor
while locating org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor
for parameter 0 at org.eclipse.xtext.parsetree.reconstr.Serializer.<init>(Serializer.java:38)
while locating org.eclipse.xtext.parsetree.reconstr.Serializer
for field at org.eclipse.xtext.resource.XtextResource.serializer(XtextResource.java:349)
while locating org.eclipse.xtext.linking.lazy.LazyLinkingResource
while locating org.eclipse.xtext.resource.XtextResource
Caused by: org.eclipse.emf.common.util.WrappedException: org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'EClassifier' is not found or is abstract. (classpath:/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xmi, 18, 123)
at org.eclipse.xtext.parser.BaseEPackageAccess.loadResource(BaseEPackageAccess.java:57)
at org.eclipse.xtext.parser.BaseEPackageAccess.loadGrammarFile(BaseEPackageAccess.java:44)
at org.eclipse.xtext.service.GrammarProvider.getGrammar(GrammarProvider.java:49)
at org.eclipse.ocl.examples.xtext.oclinecore.services.OCLinEcoreGrammarAccess.getGrammar(OCLinEcoreGrammarAccess.java:3525)
at org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService.setGrammar(AbstractDeclarativeValueConverterService.java:50)
at $org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService$$FastClassByGuice$$7fdb40ee.invoke(<generated>)
at com.google.inject.internal.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
at com.google.inject.SingleMethodInjector$1.invoke(SingleMethodInjector.java:59)
at com.google.inject.SingleMethodInjector.inject(SingleMethodInjector.java:91)
at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.InjectorImpl$4$1.call(InjectorImpl.java:758)
at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:804)
at com.google.inject.InjectorImpl$4.get(InjectorImpl.java:754)
at org.eclipse.xtext.resource.XtextResourceFactory.createResource(XtextResourceFactory.java:19)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:425)
at org.eclipse.ocl.examples.xtext.oclinecore.resource.Ecore2OCLinEcore.importResource(Ecore2OCLinEcore.java:822)
at org.eclipse.ocl.examples.xtext.oclinecore.resource.Ecore2OCLinEcore.getDocument(Ecore2OCLinEcore.java:815)
at org.eclipse.ocl.examples.xtext.oclinecore.resource.Ecore2OCLinEcore.importFromEcore(Ecore2OCLinEcore.java:119)
at abstractmodeller.model.prm.ECoreGenerator.main(ECoreGenerator.java:921)
Caused by: org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'EClassifier' is not found or is abstract. (classpath:/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xmi, 18, 123)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:23)
at org.eclipse.xtext.parser.BaseEPackageAccess.loadResource(BaseEPackageAccess.java:52)
... 44 more
Caused by: org.eclipse.emf.ecore.xmi.ClassNotFoundException: Class 'EClassifier' is not found or is abstract. (classpath:/org/eclipse/ocl/examples/xtext/oclinecore/OCLinEcore.xmi, 18, 123)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:2244)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.validateCreateObjectFromFactory(XMLHandler.java:2368)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFeatureType(XMLHandler.java:2163)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2035)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:134)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1840)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1023)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:87)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1001)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:712)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:169)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
|
|
|
|
|
|
|
|