Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Libraries necessary to execute transformation programmatically in Juno
Libraries necessary to execute transformation programmatically in Juno [message #1063254] Wed, 12 June 2013 20:35 Go to next message
juan velez is currently offline juan velez
Messages: 10
Registered: June 2013
Junior Member
NOTE As this is my first message, it does not allow me to post links outside eclipse, so please prepend the missing http://

I am new to QVTO and I am learning through the tutorial at redpanda.nl/index.php?p=tutorial.

I am using JUNO SR2 and I am trying to create the same tutorial to be executed standalone as it is the purpose of the tool I am planning to use QVTO in.

I have looked at this http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava and I have modified it so I load the corresponding ecores for both the source and target models, register them and pass them as a parameter to the TransformationExecutor (using TransformationExecutor(URI, Registry). But when I run it I get a NPE. I am wondering if I am missing libraries.
Re: Libraries necessary to execute transformation programmatically in Juno [message #1063544 is a reply to message #1063254] Thu, 13 June 2013 11:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4109
Registered: July 2009
Senior Member
Hi

NPEs happen all the time so saying you get an NPE is of very little use.

You need to append at least the stack trace, and possibly a zipped project.

Regards

Ed Willink


On 13/06/2013 12:15, juan velez wrote:
> NOTE As this is my first message, it does not allow me to post links
> outside eclipse, so please prepend the missing http://
>
> I am new to QVTO and I am learning through the tutorial at
> redpanda.nl/index.php?p=tutorial.
>
> I am using JUNO SR2 and I am trying to create the same tutorial to be
> executed standalone as it is the purpose of the tool I am planning to
> use QVTO in.
>
> I have looked at this
> http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava and I have
> modified it so I load the corresponding ecores for both the source and
> target models, register them and pass them as a parameter to the
> TransformationExecutor (using TransformationExecutor(URI, Registry).
> But when I run it I get a NPE. I am wondering if I am missing libraries.
>
Re: Libraries necessary to execute transformation programmatically in Juno [message #1063687 is a reply to message #1063544] Thu, 13 June 2013 18:16 Go to previous messageGo to next message
juan velez is currently offline juan velez
Messages: 10
Registered: June 2013
Junior Member
Thanks for your reply Ed.

This is the stack trace

Exception in thread "main" java.lang.NullPointerException
	at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.<init>(EcoreEvaluationEnvironment.java:119)
	at org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEvaluationEnv.<init>(QvtOperationalEvaluationEnv.java:72)
	at org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEnvFactory.createEvaluationEnvironment(QvtOperationalEnvFactory.java:129)
	at org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.doExecute(InternalTransformationExecutor.java:181)
	at org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.execute(InternalTransformationExecutor.java:171)
	at org.eclipse.m2m.qvt.oml.TransformationExecutor.execute(TransformationExecutor.java:88)
	at com.emt.tutorial2.test.TestEcore.transform(TestEcore.java:62)
	at com.emt.tutorial2.test.TestEcore.main(TestEcore.java:87)


It seems I am not allowed to attach files yet, maybe I am too new. Is there another way I can send you the zipped project?

Thank you
Re: Libraries necessary to execute transformation programmatically in Juno [message #1063691 is a reply to message #1063687] Thu, 13 June 2013 18:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4109
Registered: July 2009
Senior Member
Hi

org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.<init>(EcoreEvaluationEnvironment.java:119)


looks like you're initialization is rubbish.

Start from an example that works and see why yours is different.

Regards

Ed Willink

On 13/06/2013 19:16, juan velez wrote:
> Thanks for your reply Ed.
> This is the stack trace
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.<init>(EcoreEvaluationEnvironment.java:119)
> at
> org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEvaluationEnv.<init>(QvtOperationalEvaluationEnv.java:72)
> at
> org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEnvFactory.createEvaluationEnvironment(QvtOperationalEnvFactory.java:129)
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.doExecute(InternalTransformationExecutor.java:181)
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.execute(InternalTransformationExecutor.java:171)
> at
> org.eclipse.m2m.qvt.oml.TransformationExecutor.execute(TransformationExecutor.java:88)
> at com.emt.tutorial2.test.TestEcore.transform(TestEcore.java:62)
> at com.emt.tutorial2.test.TestEcore.main(TestEcore.java:87)
>
> It seems I am not allowed to attach files yet, maybe I am too new. Is
> there another way I can send you the zipped project?
>
> Thank you
Re: Libraries necessary to execute transformation programmatically in Juno [message #1063695 is a reply to message #1063691] Thu, 13 June 2013 18:41 Go to previous messageGo to next message
juan velez is currently offline juan velez
Messages: 10
Registered: June 2013
Junior Member
This is the code, it is taken from the eclipse example http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava

package com.emt.tutorial2.test;

import java.net.URL;
import java.util.List;

import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
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.util.BasicExtendedMetaData;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.m2m.qvt.oml.BasicModelExtent;
import org.eclipse.m2m.qvt.oml.ExecutionContext;
import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
import org.eclipse.m2m.qvt.oml.ModelExtent;
import org.eclipse.m2m.qvt.oml.TransformationExecutor;

public class TestEcore {
    public TestEcore() {
    }
    
    private URI getUri(final String filename) {
        final URL url = this.getClass().getResource(filename);
        return URI.createURI(url.toString());
    }

    public EPackage readEPackage(final String ecoreFilename) {
        final ResourceSet resourceSet = new ResourceSetImpl();
        final ExtendedMetaData extendedMetaData =
            new BasicExtendedMetaData(resourceSet.getPackageRegistry());
        resourceSet.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
        final Resource resource = resourceSet.getResource(getUri(ecoreFilename), true);
        final EObject eObject = resource.getContents().get(0);

        return (EPackage) eObject;
    }

    public void registerEPackage(EPackage ePackage) {
        EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
    }
    
    public void transform(final String transformFilename, final String fileToTransform) {
        final URI transformUri = getUri(transformFilename);
        final TransformationExecutor executor =
            new TransformationExecutor(transformUri, EPackage.Registry.INSTANCE);
        final ExecutionContextImpl executionContext = new ExecutionContextImpl();
        final URI mmaInstance = getUri(fileToTransform);
        final ResourceSet resourceSet = new ResourceSetImpl();
        final Resource resource = resourceSet.getResource(mmaInstance, true);
        final EList<EObject> inputEObjectList = resource.getContents();
        final ModelExtent input = new BasicModelExtent(inputEObjectList);
        final ModelExtent output = new BasicModelExtent();
        executionContext.setConfigProperty("keepModeling", true);
        final ExecutionDiagnostic result = executor.execute(executionContext, input, output);
        if (result.getSeverity()==Diagnostic.OK) {
            List<EObject> outputEObjectList = output.getContents();
            for (EObject eObject : outputEObjectList) {
                eObject.getClass();
            }
        }
    }

    public static void initTestEcore() {
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
            "ecore", new EcoreResourceFactoryImpl());
        Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
            "mma", new XMIResourceFactoryImpl());
    }

    public static void main(String[] args) {
        initTestEcore();
        TestEcore testEcore = new TestEcore();
        EPackage fromEPackage = testEcore.readEPackage("/MMA.ecore");
        System.out.println("NSURI is " + fromEPackage.getNsURI());
        testEcore.registerEPackage(fromEPackage);
        EPackage toEPackage = testEcore.readEPackage("/MMB.ecore");
        System.out.println("NSURI is " + toEPackage.getNsURI());
        testEcore.registerEPackage(toEPackage);
        testEcore.transform("/MMATransformation.qvto", "/instance.mma");
    }
}
Re: Libraries necessary to execute transformation programmatically in Juno [message #1063701 is a reply to message #1063691] Thu, 13 June 2013 19:03 Go to previous messageGo to next message
juan velez is currently offline juan velez
Messages: 10
Registered: June 2013
Junior Member
Ed,

Is there an available example that works? I mean, one that it is not http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava.

Thank you

Ed Willink wrote on Thu, 13 June 2013 11:23
Hi

org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.<init>(EcoreEvaluationEnvironment.java:119)


looks like you're initialization is rubbish.

Start from an example that works and see why yours is different.

Regards

Ed Willink

On 13/06/2013 19:16, juan velez wrote:
> Thanks for your reply Ed.
> This is the stack trace
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.<init>(EcoreEvaluationEnvironment.java:119)
> at
> org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEvaluationEnv.<init>(QvtOperationalEvaluationEnv.java:72)
> at
> org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalEnvFactory.createEvaluationEnvironment(QvtOperationalEnvFactory.java:129)
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.doExecute(InternalTransformationExecutor.java:181)
> at
> org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor.execute(InternalTransformationExecutor.java:171)
> at
> org.eclipse.m2m.qvt.oml.TransformationExecutor.execute(TransformationExecutor.java:88)
> at com.emt.tutorial2.test.TestEcore.transform(TestEcore.java:62)
> at com.emt.tutorial2.test.TestEcore.main(TestEcore.java:87)
>
> It seems I am not allowed to attach files yet, maybe I am too new. Is
> there another way I can send you the zipped project?
>
> Thank you

Re: Libraries necessary to execute transformation programmatically in Juno [message #1063716 is a reply to message #1063691] Thu, 13 June 2013 20:17 Go to previous message
juan velez is currently offline juan velez
Messages: 10
Registered: June 2013
Junior Member
Just in case anyone ends up here, my problem indeed was the version of the libraries used. I am using Eclipse Juno SR2 20130225-0426 and since we use maven artifacts, I had found a version 3.0.0 of the OML libraries, but this version had a bug which is the NPE I get. Once I changed my maven dependencies to reflect the jar provided by my eclipse installation (%ECLIPSE_HOME%/plugins), my app ran successfully. What a shame that Eclipse does not provided mavenized artifacts for.
Previous Topic:[Announce] Eclipse QVT Operational 3.3.0 (Kepler) RC3 is now available
Next Topic:Can a mapping call itself?
Goto Forum:
  


Current Time: Thu Oct 30 12:14:05 GMT 2014

Powered by FUDForum. Page generated in 0.03147 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software