Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » creating Resource
creating Resource [message #474212] Mon, 16 July 2007 10:34 Go to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Hello NG,
I want to do something like the following to save a model:

private static void saveModel(String name, Model model) {
String filename = outDir + name + "." + UMLResource.FILE_EXTENSION;
File file = new File(filename);
URI uri = URI.createFileURI(file.getAbsolutePath());

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.setResourceFactoryRegistry(Registry.INSTANCE);
// problem on following line
Resource resource = resourceSet.createResource(uri);

EList<EObject> contents = resource.getContents();

contents.add(model);

Iterator<Element> allContents = model.getOwnedElements().iterator();
while (allContents.hasNext()) {
EObject eObject = (EObject) allContents.next();
if (eObject instanceof Element) {
contents.addAll(((Element) eObject).getStereotypeApplications());
}
}
try {
resource.save(null);

} catch (IOException ioe) {
System.out.println("Speichern schiefgegangen!");
}
}

but I have a problem on the marked line when creating the Resource. I
always get null. The Javadoc says that null is be returned when no
factory is registered. But I do register my factory(the standard one)
one line before, don't I? So where is my problem? Or better - what is
wrong in my code?

greets
J.R.
Re: creating Resource [message #474214 is a reply to message #474212] Mon, 16 July 2007 11:02 Go to previous messageGo to next message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
I want to add some information so maybe it is easier to help me.
My project was a normal Java-Project but then I converted it to an
Plugin-Project to facilitate managing my dependencies because I switched
the Eclipse-Version. So I don't need absolute pathes anymore.
Well, now I have a Plugin-project. But I don't want to run it as an
Eclipse-Application so I have a normal main-Method.
Re: creating Resource [message #474216 is a reply to message #474212] Mon, 16 July 2007 12:13 Go to previous message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Ok I found a workaround by using a JUnit-Plugin test.
Re: creating Resource [message #623671 is a reply to message #474212] Mon, 16 July 2007 11:02 Go to previous message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
I want to add some information so maybe it is easier to help me.
My project was a normal Java-Project but then I converted it to an
Plugin-Project to facilitate managing my dependencies because I switched
the Eclipse-Version. So I don't need absolute pathes anymore.
Well, now I have a Plugin-project. But I don't want to run it as an
Eclipse-Application so I have a normal main-Method.
Re: creating Resource [message #623673 is a reply to message #474212] Mon, 16 July 2007 12:13 Go to previous message
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Ok I found a workaround by using a JUnit-Plugin test.
Previous Topic:Combined Fragments
Next Topic:add Package to Model
Goto Forum:
  


Current Time: Wed Apr 24 21:09:05 GMT 2024

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

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

Back to the top