Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Extracting the compilation unit info(how to extract the compilation unit from a discovered XMI java model)
Extracting the compilation unit info [message #903693] Fri, 24 August 2012 19:40 Go to next message
Juan Castel is currently offline Juan Castel
Messages: 20
Registered: April 2012
Junior Member
Hi, all.

I have an XMI java model discovered by MoDisco but I need to extract the info the model is showing on the MoDisco Model Browser, as the image attached.

The code below loads the XMI file and I begin at the root model object: Dc3AdminEJB

Then I iterate over the 43 compilation units trying to know names like the real classes analized by the discoverer like the one in the image attached: BureauCharacteristicBO.java


Resource resource = resourceSet.getResource(uri, true);
		System.out.println("Loaded " + uri + "  " + resource);
		ModelImpl rootModel = null;
		for(EObject n : resource.getContents())
		{
			ModelImpl mo = (ModelImpl) n;
			String rootModelName = mo.getName();
			if(rootModelName.equalsIgnoreCase("Dc3AdminEJB"))
				rootModel = mo;
		}
		if(rootModel != null)
		{
			System.out.println("Model: " + rootModel.getName());
			EList<EObject> an = rootModel.eContents();
			List<EClass> javaClasses = new LinkedList<EClass>();
			for(EObject eo : an)
			{
				EClass eclass = eo.eClass();
				
				String eclassName = eclass.getName();
				//System.out.println("Java class: " + eclassName);
				if(eclassName.equalsIgnoreCase("CompilationUnit"))
				{
					;
					//CompilationUnit a = (CompilationUnit) eclass;
					
					System.out.println("Java class: " + eclass.eResource());
					
					javaClasses.add(eo.eClass());
				}
			}		
			
		}


The problem is that I keep getting the name CompilatioUnit not BureauCharacteristicBO, no matter what method I use.

Tried to cast to CompilationUnit class of the metamodel but it doesn't work:
org.eclipse.emf.ecore.impl.EClassImpl cannot be cast to javamm.CompilationUnit


Any advice on how to extract this info?

Thank you!
Re: Extracting the compilation unit info [message #903918 is a reply to message #903693] Mon, 27 August 2012 05:24 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
Hello Juan,

Have you tried to directly use the references as defined by the Java metamodel to navigate through your Java model?

For instance, from a Model element, there is a reference "compilationUnits" that points to the list of CompilationUnit elements: this could help you to check whether your model has been fully/correctly loaded in memory.

Best regards,

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: Extracting the compilation unit info [message #904070 is a reply to message #903918] Mon, 27 August 2012 13:31 Go to previous message
Juan Castel is currently offline Juan Castel
Messages: 20
Registered: April 2012
Junior Member
Hugo, as always, thank you so much. It worked perfectly navigating through the CompilationUnit list the root model has.

Again, thank you.
Previous Topic:Ignoring Elements completely in custom Match and Diff Engine
Next Topic:Do I need a new discoverer to pull out a metamodel described in xml
Goto Forum:
  


Current Time: Tue Jul 29 02:52:46 EDT 2014

Powered by FUDForum. Page generated in 0.02896 seconds