Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to get all the elements from a papyrus model (How to get all the elements from a papyrus model using MARTE stereotypes)
How to get all the elements from a papyrus model [message #1051060] Sun, 28 April 2013 06:11 Go to next message
Mariem Makni is currently offline Mariem MakniFriend
Messages: 46
Registered: February 2013
Member
Hi,

I've created a plug-in project which defines an extension point and I have created

another plug-in project used this extension point for modeling a real time operating

systems (RTOS) using Papyrus and using the Profile in Software Resource Modeling (SRM)

of Standard MARTE.

My requirement is how to retrieve all the elements(class, attributes,default values

of attributes,...) from my model using Java code.

I used this code to get my model:

RegisteredRTOSLibrary[] rtos = RegisteredRTOSLibrary.getRegisteredLibraries();
			
	URI modelUri = rtos[0].uri;
	ResourceSet resourceSet = new ResourceSetImpl();
	Resource inResources = resourceSet.getResource( modelUri, true);		



But I don't know how to retrieve the elements of my model.

Can you help me please.

Thanks in advance.

[Updated on: Sun, 28 April 2013 07:34]

Report message to a moderator

Re: How to get all the elements from a papyrus model [message #1057970 is a reply to message #1051060] Fri, 10 May 2013 08:38 Go to previous message
Simon Schwichtenberg is currently offline Simon SchwichtenbergFriend
Messages: 127
Registered: September 2011
Senior Member
The following code will not compile, but you will get the idea:

import org.eclipse.emf.ecore.util.EcoreUtil;

Collection<Class> classes = EcoreUtil.getObjectsByType(iterator2Collection(model.eResource().getAllContents()), UMLPackage.eINSTANCE.getClass_());

for(Class c:classes){
 for(Stereotype s:c.getAppliedStereotypes()){
  if(s.getName().startsWith("MARTE")){
   //do something
  }
 } 
}

    /**
     * @see de.cau.cs.kieler.core.model.util.ModelingUtil
     */
    public static <T> Collection<T> iterator2Collection(final Iterator<T> iter) {
        ArrayList<T> list = new ArrayList<T>();
        for (; iter.hasNext();) {
            T item = iter.next();
            list.add(item);
        }
        return list;
    } 
Previous Topic:Horizontal Instead of Vertically Oriented Regions for States in State Machine Diagrams
Next Topic:CDO repository hosting service
Goto Forum:
  


Current Time: Fri Apr 19 12:46:50 GMT 2024

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

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

Back to the top