Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » packageImport
packageImport [message #877419] Sat, 26 May 2012 13:42
Eclipse User
Hello,

how can i programmatically access contents of imported package? for the
following exapmle, traverse elements of Ecore.metamodel.uml#_0

> <packageImport xmi:id="_packageImport.0">
> <importedPackage xmi:type="uml:Model" href="Ecore.metamodel.uml#_0"/>
> </packageImport>

I use following two methods to aggregate all elements (from all models
in a file) into one list. How should it be changed to aggregate also
elements from external file?

> private static EList<Element> agregateElements(Resource resource) {
> EList<Element> list = new BasicEList<Element>();
> for (Object obj : EcoreUtil.getObjectsByType(resource.getContents(),
> UMLPackage.Literals.ELEMENT)) {
> Element elem = (Element) obj;
> list.addAll(agregateElementsRecursive(elem));
> }
>
> return list;
> }
>
> private static EList<Element> agregateElementsRecursive(Element parentElem) {
>
> EList<Element> list = new BasicEList<Element>();
>
> list.add(parentElem);
>
> for (Element elem : parentElem.getOwnedElements()) {
> if (elem instanceof PackageImpl
> || elem instanceof ModelImpl) {
> list.addAll(agregateElementsRecursive(elem));
> } else {
> list.add(elem);
> }
> }
>
> return list;
> }
Previous Topic:Unable to read the stereotypes from Papyrus SysML model in standalone mode
Next Topic:UML Metamodel question
Goto Forum:
  


Current Time: Thu Apr 24 11:28:39 EDT 2014

Powered by FUDForum. Page generated in 0.03277 seconds