Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » add Package to Model
add Package to Model [message #623675] Mon, 16 July 2007 13:38
Jan Reimann is currently offline Jan ReimannFriend
Messages: 90
Registered: July 2009
Member
Hello NG,
it's me again ;)
I have a Package with some elements in it and a Model. Now I want to add
the Package to the Model and save it. That was my way:

private static Model createModel(Package pack, String name) {
Model model = umlFactory.createModel();
model.setName(name);
model.setNestingPackage(pack);
if (SAVE_MODELS) {
saveModel(name, model);
}

return 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();
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("Saving failed!");
}
}

But in my method createModel the Package won't be added to the model
with setNestingPackage. The saved file only contains the model without
any elements. How can I do this?

greets
J.R.
Previous Topic:creating Resource
Next Topic:add Package to Model
Goto Forum:
  


Current Time: Tue Apr 16 16:15:18 GMT 2024

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

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

Back to the top