Skip to main content



      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
Eclipse UserFriend
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
Eclipse UserFriend
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
Re: Extracting the compilation unit info [message #904070 is a reply to message #903918] Mon, 27 August 2012 13:31 Go to previous message
Eclipse UserFriend
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: Thu May 15 19:59:50 EDT 2025

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

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

Back to the top