|
Re: emf does not resolve reference on load [message #1703204 is a reply to message #1703201] |
Wed, 29 July 2015 10:43 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Clemens,
What value does m1genFile have? Is it an absolute path? Better use use
URI.createFileURI than what you did (because on Linux it will produce
file://path), assuming the path is absolute in the first place. You can
also try casting instantiator.getTarget() to InternalEObject so you can
inspect the eProxyURI of it.
On 29/07/2015 12:21 PM, Clemens Schneider wrote:
> Hello,
>
> I have a function where I try to load a m1gen-file and then to resolve the resourceSet to get the referenced ecore-file. After that the target of the instantiators should be available. But they aren't. The line System.out.println("instantiator: " + instantiator.getTarget().getName()); produces every time null value for the name...
>
> @Mojo(name = "generate")
> public class GeneratorMojo extends AbstractMojo {
>
> @Parameter
> private File m1genFile;
>
> public void execute() throws MojoExecutionException {
>
> List<ClassInstantiator> instantiators = new ArrayList<ClassInstantiator>();
> List<Goal> goals = new ArrayList<Goal>();
>
> EPackage.Registry packReg = EPackage.Registry.INSTANCE;
> packReg.put(M1genPackage.eNS_URI, M1genPackage.eINSTANCE);
>
> Resource.Factory.Registry fReg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = fReg.getExtensionToFactoryMap();
> m.put("m1gen", new XMIResourceFactoryImpl());
> m.put("ecore", new XMIResourceFactoryImpl());
>
> ResourceSet resSetIn = new ResourceSetImpl();
> resSetIn.setPackageRegistry(packReg);
> resSetIn.setResourceFactoryRegistry(fReg);
>
> Resource resourceIn = resSetIn.getResource(URI.createURI("file:/" + m1genFile.toString()), true);
>
> try {
> resourceIn.load(m);
> } catch (IOException e1) {
> e1.printStackTrace();
> }
> EcoreUtil.resolveAll(resSetIn);
>
> TreeIterator<EObject> instances = resourceIn.getAllContents();
>
> M1GenModel m1gen = (M1GenModel) instances.next();
> EPackageImpl ePackage = (EPackageImpl) m1gen.getRefers().get(0);
>
> EObject next = null;
> while (instances.hasNext()) {
> next = instances.next();
>
> if (next instanceof Goal) {
> goals.add((Goal) next);
> }
>
> if (next instanceof ClassInstantiator) {
> instantiators.add((ClassInstantiator) next);
> }
> }
>
> for (ClassInstantiator instantiator : instantiators) {
> System.out.println("instantiator: " + instantiator.getTarget().getName());
> }
> }
> }
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.05703 seconds