Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to get a metaclass for Stereotype.createExtension()
How to get a metaclass for Stereotype.createExtension() [message #1006304] Wed, 30 January 2013 13:30 Go to previous message
Dominique Marcadet is currently offline Dominique Marcadet
Messages: 4
Registered: January 2013
Junior Member
Hello everybody,

I am trying to create a profile with a Java program.
I can create a Stereotype, but I am unable to create the extension to a UML metaclass (I got a IllegalArgumentException).

The debug shows that StereotypeOperations.createExtension() throws this exception because metaclass.isMetaclass() is false.

Here is the code, it shows that indeed my metaclass isn't one (it comes from my searches on Internet) :

public class ShowBug {

	private static final ResourceSet RESOURCE_SET = new ResourceSetImpl();

	public static void main(String[] args) throws Exception {
	    String JAR_FILE_ECLIPSE_UML2_UML_RESOURCES = "jar:file:/Users/marcadet/.eclipse/org.eclipse.platform_4.2.0_1211646801/plugins/org.eclipse.uml2.uml.resources_4.0.1.v20120913-1441.jar!/";

	    RESOURCE_SET.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
	    RESOURCE_SET.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
                       UMLResource.FILE_EXTENSION,UMLResource.Factory.INSTANCE);
	    Map<URI, URI> _resourceSetURIMap = RESOURCE_SET.getURIConverter().getURIMap();
	    URI uri = URI.createURI(JAR_FILE_ECLIPSE_UML2_UML_RESOURCES);
	    _resourceSetURIMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));

		String name = "Class";
		Model umlMetamodel2 =  (Model) load(URI.createURI(UMLResource.UML_METAMODEL_URI));
		final Class metaclass = (Class) umlMetamodel2.getOwnedType(name);
		System.out.println(name + " : " + metaclass.isMetaclass());
	}

	protected static Package load(URI uri) throws Exception {
		Resource resource = RESOURCE_SET.getResource(uri, true);
		return (Package) EcoreUtil.getObjectByType(resource.getContents(), Literals.PACKAGE);
	}

}


What is wrong ?

Regards,
Dominique
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic:Set Enumeration Type in Property of Stereotype
Next Topic:Building an GMF-based editor for an definde UML-profile
Goto Forum:
  


Current Time: Sat May 25 14:42:36 EDT 2013

Powered by FUDForum. Page generated in 0.01589 seconds