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
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();
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();


Iterator<Element> allContents = model.getOwnedElements().iterator();
while (allContents.hasNext()) {

EObject eObject = (EObject);

if (eObject instanceof Element) {
contents.addAll(((Element) eObject).getStereotypeApplications());
try {;

} 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?

Previous Topic:creating Resource
Next Topic:add Package to Model
Goto Forum:

Current Time: Mon Jun 25 12:22:16 GMT 2018

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

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

Back to the top