Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Help applying RDF/ODM profile
Help applying RDF/ODM profile [message #757531] Fri, 18 November 2011 14:22
mchicalski  is currently offline mchicalski
Messages: 1
Registered: November 2011
Junior Member
hi all,

first of all this is the first profile I'm trying to apply using the uml2 api..
also, I cant load this xmi file through eclipse..

profile: Ontology Definition Metamodel omg.org/spec/ODM/20080902/08-09-09.xmi

I was following the tutorial Introduction to UML2 Profiles..

I'll appreciate any advice!
thanks



sample code:

import java.util.Collection;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
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.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.XMI2UMLResource;
/**
*
* @author mauricio
*/
public class EMF {
private static ResourceSet RESOURCE_SET = new ResourceSetImpl();

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
URI uriprofile = URI.createURI("h**p:--www.omg.org/spec/ODM/20080902").appendSegment("08-09-09").appendFileExtension(XMI2UMLResource.FILE_EXTENSION);
registerResourceFactories();
System.out.println("URI-> "+ uriprofile);
Collection<Profile> profiles = loadProfiles(uriprofile);
Profile rdfProfile = null;
for (Profile p : profiles) {
if (p.getLabel().equals("RDF"))
rdfProfile = p;
}
EList<Stereotype> stps = rdfProfile.getOwnedStereotypes();
for (Stereotype stp : stps) {
System.out.println("stereotype-> " + stp.getKeyword());
}
//owlProfile.define();
rdfProfile.define();
org.eclipse.uml2.uml.Class myclass, otherclass;
Model model = UMLFactory.eINSTANCE.createModel();
model.setName("mymodel");
model.applyProfile(rdfProfile);
rdfProfile.define();
myclass = model.createOwnedClass("HelloWorld", true);
otherclass = model.createOwnedClass("OtherClass", false);
myclass.createGeneralization(otherclass);

//exception
myclass.applyStereotype(stps.get(14));

}

protected static void registerResourceFactories() {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
XMI2UMLResource.FILE_EXTENSION, XMI2UMLResource.Factory.INSTANCE);
}

protected static Collection<org.eclipse.uml2.uml.Profile> loadProfiles(URI uri) {
Collection<org.eclipse.uml2.uml.Profile> profiles = null;
try {
Resource resource = RESOURCE_SET.getResource(uri, true);
profiles = EcoreUtil.getObjectsByType(resource.getContents(), UMLPackage.Literals.PROFILE);
} catch (WrappedException we) {
we.printStackTrace();
System.exit(1);
}
return profiles;
}
}





stack trace:
Exception in thread "main" java.lang.IllegalArgumentException: org.eclipse.uml2.uml.internal.impl.StereotypeImpl@4c2b349d (name: rdfsClass, visibility: <unset>) (isLeaf: false, isAbstract: false) (isActive: false)
at org.eclipse.uml2.uml.internal.operations.ElementOperations.applyStereotype(ElementOperations.java:1413)
at org.eclipse.uml2.uml.internal.impl.ElementImpl.applyStereotype(ElementImpl.java:510)
at testexmi.EMF.main(EMF.java:64)
Java Result: 1
Previous Topic:Iterative export of ecore to UML2
Next Topic:How to add an InstanceSpecification to a Package
Goto Forum:
  


Current Time: Mon Jul 28 18:50:50 EDT 2014

Powered by FUDForum. Page generated in 0.01953 seconds