Skip to main content



      Home
Home » Modeling » UML2 » add Package to Model
add Package to Model [message #623675] Mon, 16 July 2007 09:38
Eclipse UserFriend
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: Fri Jul 04 17:34:10 EDT 2025

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

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

Back to the top