protected static void registerResourceFactories(){
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().
put(UMLResource.FILE_EXTENSION, new UML22UMLResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().
put("ecore", new EcoreResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().
put("ecore2xml", new EcoreResourceFactoryImpl());
}
protected static void registerPathmaps(URI uri) {
URIConverter.URI_MAP.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uri.appendSegment("libraries").appendSegment(""));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uri.appendSegment("metamodels").appendSegment(""));
URIConverter.URI_MAP.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uri.appendSegment("profiles").appendSegment(""));
final String UML2_200_NS_URI = "http://www.eclipse.org/uml2/2.0.0/UML";
EPackage.Registry.INSTANCE.put(UML2_200_NS_URI,
EPackage.Registry.INSTANCE.get(UMLPackage.eINSTANCE.getNsURI()));
Ecore2XMLPackage.eINSTANCE.getEClassifiers();
}
private static void registerMapping(URI uri) {
final String ECORE2XML = "platform:/plugin/org.eclipse.uml2.uml/
model/UML2_2_UML.ecore2xml";
URIConverter.URI_MAP.put(URI.createURI(ECORE2XML),
uri.appendSegment("model").appendSegment("UML2_2_UML.ecore2xml"));
}
Mit Hilfe der vorhergehenden Initialisierungen lässt sich ein UML2-Profil (XMI Version 2.x) laden und kann zur Modellierung verwendet werden.
private Profile loadProfile() {
registerResourceFactories();
URI uri = URI.createURI("resources");
registerPathmaps(uri);
registerMapping(uri);
URI profileFile = URI.createFileURI("MyProfile.profile.uml");
Resource r = new ResourceSetImpl().getResource(profileFile, true);
Profile p = (Profile) EcoreUtil.getObjectByType(r.getContents(),
UMLPackage.Literals.PROFILE);
return p;
}