Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Re: Reading UML Profile Elements in Java
Re: Reading UML Profile Elements in Java [message #627336] Tue, 20 January 2009 06:09
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Regardless how you create a UML2-based model (using UML2 Tools, Papyrus,
the EMF generated editor), you are going to read it the same way, i.e.
using EMF and UML2 API. So your question is indeed a MDT UML2 question.

The UML2 metamodel implementation works much like any other EMF-based
metamodel implementation. The way you load an EMF-based model into
memory is something like this:

URI modelURI = URI.createURI("uri/to/your/model.uml");

ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(modelURI);

Once loaded into memory, you can, for instance, traverse through all
named elements in the model using the following code:

for (
TreeIterator<EObject> i = resource.getAllContents();
i .hasNext();
) {
EObject current = i.next();
if (!(current instanceof NamedElement))
i.prune();
NamedElement asNamed = (NamedElement) current;
System.out.println(asNamed.getQualifiedName()
+ " : " + asNamed.eClass().getName());
}

Other than the assumption that model elements are UML NamedElements, the
code above is pretty much based on pure EMF API. Once you get to UML2
specific model elements, then you can extract whatever UML-specific
information you need. See the following Javadoc:

http://tinyurl.com/8wqerd

HTH,

Rafael Chaves
http://abstratt.com/blog/

Waqas wrote:
> Thanks Rafael. The tutorials you have referred are for creating new UML
> projects/models. I have created a project using these steps (although
> not using Java code). Now i want to read the UML elements from this
> model/project to display their names on a Java GUI. I am posting this
> problem here because i have created the project in UML2tool's component
> diagram.
>
> /Waqas
>
Previous Topic:UML meta-levels mapping in Eclipse
Next Topic:Why is a Port always owned by a Component?
Goto Forum:
  


Current Time: Thu Apr 25 19:23:17 GMT 2024

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

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

Back to the top