Error: EMF4SW Trasformation

25 views
Skip to first unread message

dpndeveloper

unread,
Mar 23, 2011, 11:21:36 AM3/23/11
to emftriple-discuss
Hello,
referring to your guide for Trasformation EMF/RDF (http://
code.google.com/a/eclipselabs.org/p/emftriple/wiki/RDFIzerGuide), at
this time I'm able to run the transformation from an EMF model (saved
into an xmi file) to a RDF but not the viceversa

I create a RDF file by
Model2RDF m2r = new Model2RDF();
Resource rdf = m2r.transform(resource, null);

and when perform the line
Resource model = r2m.transform(resource);

using the generated file, i have this exception:

java.lang.NullPointerException
at com.atl.common.utils.Preconditions.checkNotNull(Preconditions.java:
57)
at com.atl.common.models.Models.emptyModel(Models.java:93)
at com.atl.common.utils.Parameters.initOneOutput(Parameters.java:95)
at com.atl.common.trans.Transformations$1.apply(Transformations.java:
120)
at com.atl.common.trans.Transformations$1.apply(Transformations.java:
1)
at
com.atl.common.trans.Transformations.transform(Transformations.java:
60)
at com.emf4sw.rdf.transform.RDF2Model.transform(RDF2Model.java:44)
at
it.ietsistemi.tmseprob.model.trasformation.ModelTransformation.transformToEmf(ModelTransformation.java:
101)
at
it.ietsistemi.tmseprob.resource.SeprobResource.load(SeprobResource.java:
182)
at
it.ietsistemi.tmseprob.core.search.SeprobSearch.search(SeprobSearch.java:
36)
at
it.ietsistemi.tmseprob.core.search.SeprobSearch.find(SeprobSearch.java:
22)
at
it.ietsistemi.tmseprob.ui.common.model.view.BusinessBaseView.performSearch(BusinessBaseView.java:
367)
at
it.ietsistemi.tmseprob.ui.common.model.view.BusinessBaseView.widgetDefaultSelected(BusinessBaseView.java:
288)
at
it.ietsistemi.tmseprob.ui.common.model.view.BusinessBaseView.widgetSelected(BusinessBaseView.java:
374)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:
234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:
4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:
2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:
332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:
663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:
149)
at
it.ietsistemi.tmseprob.application.SeprobApplication.start(SeprobApplication.java:
113)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:
196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:
110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:
79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
369)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
java.lang.NullPointerException
at com.atl.common.utils.Preconditions.checkNotNull(Preconditions.java:
57)
at com.atl.common.models.Models.emptyModel(Models.java:93)
at com.atl.common.utils.Parameters.initOneOutput(Parameters.java:95)
at com.atl.common.trans.Transformations$1.apply(Transformations.java:
120)
at com.atl.common.trans.Transformations$1.apply(Transformations.java:
1)
at
com.atl.common.trans.Transformations.transform(Transformations.java:
60)
at com.emf4sw.rdf.transform.RDF2Model.transform(RDF2Model.java:44)
at
it.ietsistemi.tmseprob.model.trasformation.ModelTransformation.transformToEmf(ModelTransformation.java:
101)
at
it.ietsistemi.tmseprob.resource.SeprobResource.load(SeprobResource.java:
182)
at
it.ietsistemi.tmseprob.core.search.SeprobSearch.search(SeprobSearch.java:
36)
at
it.ietsistemi.tmseprob.core.search.SeprobSearch.find(SeprobSearch.java:
22)
at
it.ietsistemi.tmseprob.ui.common.model.view.BusinessBaseView.performSearch(BusinessBaseView.java:
367)
at
it.ietsistemi.tmseprob.ui.common.model.view.BusinessBaseView.widgetDefaultSelected(BusinessBaseView.java:
288)
at
it.ietsistemi.tmseprob.ui.common.model.view.BusinessBaseView.widgetSelected(BusinessBaseView.java:
374)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:
234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:
4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:
2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:
332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:
663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:
149)
at
it.ietsistemi.tmseprob.application.SeprobApplication.start(SeprobApplication.java:
113)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:
196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:
110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:
79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
369)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)

I read the issue 26, referred to an example and the RDFIzer
https://code.google.com/a/eclipselabs.org/p/emftriple/issues/detail?id=26#makechanges
What can i do to fix the exception?

Thanks

Domenico Pio Novelli

Guillaume Hillairet

unread,
Mar 23, 2011, 11:53:51 AM3/23/11
to emftriple-discuss
Do you register the target metamodel before launching RDF2Model.

{{{
// Register the targeted metamodel
Models.register(Models.resource("metamodel.ecore", true));
}}}

BRs,
Guillaume
> 79)
>         at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
> 369)
>         at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:
> 179)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
>         at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
>         at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
>         at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
>
> I read the issue 26, referred to an example and the RDFIzerhttps://code.google.com/a/eclipselabs.org/p/emftriple/issues/detail?i...

dpndeveloper

unread,
Mar 23, 2011, 12:02:31 PM3/23/11
to emftriple-discuss
Hi,
yes, i register the model using the EPackage

this is my code

public EObject transformToEmf(InputStream inputStreamRDF) {

try {

// Register Resource Factories

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",
new XMIResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
new XMIResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("rdf",
new RDFXMLResourceFactory());

Models.register(ModelPackage.eINSTANCE);

// Load the RDF document
Resource rdfModel = new
RDFXMLResource(URI.createURI("model.rdf")) ; //$NON-NLS-1$
rdfModel.load(inputStreamRDF, Collections.EMPTY_MAP);
RDF2Model r2m = new RDF2Model(ModelPackage.eINSTANCE);
Resource model = r2m.transform(rdfModel);
model.save(null);

if (model!=null){
return model.getContents().get(0);
}

} catch (Exception e) {
e.printStackTrace();
}
return null;
}

I load original rdf resource from an inputStream

Any suggestions?

Regards
Domenico Novelli
Message has been deleted

Guillaume Hillairet

unread,
Mar 24, 2011, 7:04:30 AM3/24/11
to emftriple-discuss
I have to test this on a generated model as you do.
Can you try this code in the mean time:

Models.register(ModelPackage.eINSTANCE);

Resource resource = Models.resource(URI.createURI("model.rdf"));
resource.load(null);

RDF2Model r2m = new
RDF2Model(Models.getMetamodelByUri(ModelPackage.eNS_URI));
Resource model = r2m.transform(resource);


BRs,
Guillaume
> ...
>
> read more »

dpndeveloper

unread,
Mar 24, 2011, 8:18:09 AM3/24/11
to emftriple-discuss
Hi,
I tryed your code, but i have the same error

Domenico
> ...
>
> leggi tutto

Guillaume Hillairet

unread,
Mar 27, 2011, 2:07:16 PM3/27/11
to emftriple-discuss
Hi,

I've tested on a generated model and it works for me, with the code
you used in the first time.
I put an example in the svn that uses a generated model, see :
http://code.google.com/a/eclipselabs.org/p/emftriple/source/browse/trunk/examples/emf4sw.rdf.examples/src/emf4sw/RDFTransformExample.java

BRs,
Guillaume
> ...
>
> read more »

dpndeveloper

unread,
Mar 28, 2011, 8:46:55 AM3/28/11
to emftriple-discuss
My problem is generated by target platform
I reproduced the same error by your example and fixed my problem

Thanks for help
Domenico

On 27 Mar, 20:07, Guillaume Hillairet <g.hillai...@gmail.com> wrote:
> Hi,
>
> I've tested on a generated model and it works for me, with the code
> you used in the first time.
> I put an example in the svn that uses a generated model, see :http://code.google.com/a/eclipselabs.org/p/emftriple/source/browse/tr...
> ...
>
> leggi tutto

dpndeveloper

unread,
Mar 31, 2011, 6:14:36 AM3/31/11
to emftriple-discuss
Hi,
i have the same problem again.

I modified your example class, and i have a random behaviour.

The code is

public class RDFTransformExample {

public static void main(String[] args) throws IOException {
// Register Resource Factories

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",
new XMIResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ttl",
new TTLResourceFactory());

// Register Metamodel
Models.register(NetworkPackage.eINSTANCE);

// Create EObjects
SocialNetwork s =
NetworkFactory.eINSTANCE.createSocialNetwork();
s.setName("sc");

Person p1 = NetworkFactory.eINSTANCE.createPerson();
p1.setFirstName("John");
p1.setLastName("Smith");
p1.setId(1);

Person p2 = NetworkFactory.eINSTANCE.createPerson();
p2.setFirstName("Paul");
p2.setLastName("Robert");
p2.setId(2);
p2.getKnows().add(p1);

s.getMembers().add(p1);
s.getMembers().add(p2);

// Add root object to the resource
Resource resource = new XMIResourceImpl();
resource.getContents().add(s);

Map<String, Object> options = new HashMap<String, Object>();
options.put(RDFTransformation.OPTION_RDF_FORMAT,
RDFFormats.TURTLE_FORMAT);
// Execute Model2RDF
Model2RDF m2r = new Model2RDF();
Resource rdf = m2r.transform(resource, options);

// Save output RDF
rdf.setURI(URI.createURI("out/model.ttl"));
rdf.save(null);

for (int i=0; i<10; i++){
trasformToEmf(i, rdf);
}
}

private static void trasformToEmf(int index, Resource rdf) {
try{

System.out.println("Trasformation number: "+index);

// Register Metamodel
Models.register(NetworkPackage.eINSTANCE);

Map<String, Object> options = new HashMap<String, Object>();
options.put(RDFTransformation.OPTION_RDF_FORMAT,
RDFFormats.TURTLE_FORMAT);

// Execute RDF2Model
RDF2Model r2m = new RDF2Model(NetworkPackage.eINSTANCE);

//Note: added options, but it's the same with or without them
Resource model = r2m.transform(rdf, options);

// Save output XMI
model.setURI(URI.createURI("out/model"+index+".xmi"));
model.save(null);

}catch (Exception e) {
e.printStackTrace();
}

}
}

and and example of the output is

Trasformation number: 0
Trasformation number: 1
Trasformation number: 2
java.lang.NullPointerException
at com.atl.common.utils.Preconditions.checkNotNull(Preconditions.java:
57)
at com.atl.common.models.Models.emptyModel(Models.java:93)
[...]
Trasformation number: 3
java.lang.NullPointerException
at com.atl.common.utils.Preconditions.checkNotNull(Preconditions.java:
57)
at com.atl.common.models.Models.emptyModel(Models.java:93)
[...]
Trasformation number: 4
Trasformation number: 5
java.lang.NullPointerException
at com.atl.common.utils.Preconditions.checkNotNull(Preconditions.java:
57)
at com.atl.common.models.Models.emptyModel(Models.java:93)
[...]

Trasformation number: 6
java.lang.NullPointerException
at com.atl.common.utils.Preconditions.checkNotNull(Preconditions.java:
57)
at com.atl.common.models.Models.emptyModel(Models.java:93)
[...]
Trasformation number: 7
Trasformation number: 8
Trasformation number: 9

But it's not deterministic when exception is throwed.

Can you help me to fix it?

Thanks
Domenico
> ...
>
> leggi tutto

Guillaume Hillairet

unread,
Mar 31, 2011, 9:48:28 AM3/31/11
to emftriple-discuss
Hi,

I was able to reproduce the error. It seemed to come from atl-commons
which badly registered EPackages. I fixed it and it seems to work now.
You have to
update atl-commons and it should work. Let me now.

BRs,
Guillaume
> ...
>
> read more »

dpndeveloper

unread,
Mar 31, 2011, 10:20:28 AM3/31/11
to emftriple-discuss
It works now

Thanks for help
Domenico
> ...
>
> leggi tutto
Reply all
Reply to author
Forward
0 new messages