creating Resource [message #623669] |
Mon, 16 July 2007 10:34 |
Jan Reimann 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.
|
|
|
Powered by
FUDForum. Page generated in 0.02168 seconds