Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [emf-dev] Understanding Eclipse modelling framework.........

Hi Ajay Kumar,
 
If you want to use EMF in read/write UML Model serialized with XMI…you should use Eclipse UML2 Project http://www.eclipse.org/modeling/mdt/ .
 
Basic Sample as an attachment.
 
---
Brahim LOUKIL
2007/1/28, Ajay Kumar <ajaykumarns@xxxxxxxxx>:
Hi,
      I was searching on the internet for understanding xmi formats and to convert uml diagrams to xmi and vice versa. And i found emf. The documentation was readily available , besides the usage of emf in eclipse has been explained .However i would like to use the apis for readin and writing xmi . Are there any resources explaining the purpose of the interfaces , or maybe small sniplets explaining their usage ??? .
             For example , how to create a single class and add methods to it........for example in what way is 'EAnnotation' interface used ? and what do you mean by setSource ....etc......? Please dont consider these queries as silly . I am rather interested in EMF and i want to understand how to use it .

--
thanking you  ,
Nadathur Srinivasan Ajay Kumar

_______________________________________________
emf-dev mailing list
emf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/emf-dev



package hellouml;

import java.io.File;
import java.io.IOException;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.internal.resource.UMLResourceFactoryImpl;

public class Sample1 {
	public static void main(String[] args) throws IOException {
		/*
		 * Create a resource set to hold the resources.
		 */
		ResourceSet resourceSet = new ResourceSetImpl();
		/*
		 * Register the appropriate resource factory to handle all file
		 */
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
						new UMLResourceFactoryImpl());

		resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
				UMLPackage.eINSTANCE);
		
		/*
		 * Initialize Path
		 */
		String path = new File("test/sample.uml")
		.getAbsolutePath();
		URI uri = URI.createFileURI(path);
		
		/*
		 * Initailize resource
		 */
		
		Resource resource = resourceSet.createResource(uri);
		/*
		 * Create the Model Root
		 */
		Model myModel = UMLFactory.eINSTANCE.createModel();
		myModel.setName("Root");
		/*
		 * Create Person Class
		 */
		Class myClass = UMLFactory.eINSTANCE.createClass();
		myClass.setName("Person");
		/*
		 * Add Person to the Model root
		 */
		myModel.getPackagedElements().add(myClass);
		
		/*
		 * Add the model to resource
		 */
		resource.getContents().add(myModel);
		
		/*
		 * Save content into File
		 */
		resource.save(null);
		
		/*
		 * Display content in the console.
		 */
		
		resource.save(System.out,null);
		
		
	}

}

Back to the top