Discussion:
[mdr-users] Need an example of MDR usage
J***@SITA.aero
2007-03-09 14:40:29 UTC
Permalink
Hi I need to generate JMI interfaces from a uml1.4 xmi file exported by
argo uml. The code below throws class cast exception when i try to cast
umlMetaModel to ModelPackage in the for loop.
Alternatively can anyone point me to a basic example of programmatic JMI
interface genreation using MDR.

Thanks,
JS

public class MyMDR {

/**
* @param args
*/
public static void main(String[] args) {

MDRManager manager = MDRManager.getDefault();
MDRepository repository = manager.getDefaultRepository();
XMIReaderFactory factory = XMIReaderFactory.getDefault();
XMIReader reader = factory.createXMIReader();
RefPackage umlMetaModel;
repository.beginTrans(true);

try {
// put the UML metamodel into MDR

FileInputStream in = new FileInputStream(
"/xmi/01-02-15.xml");
umlMetaModel = repository.getExtent("UML-MetaModel");


MofPackage umlPackage = null;
for (Iterator it = ((ModelPackage)
umlMetaModel).getMofPackage()
.refAllOfClass().iterator(); it.hasNext();) {
MofPackage temp = (MofPackage) it.next();
if ("UML".equals(temp.getName())) {
umlPackage = temp;
break;
}
}

RefPackage umlInstance = repository.createExtent(
"umlInstance",
umlPackage);

JMIMapper mapper = JMIMapper.getDefault();

mapper.generate(new FileStreamFactory(new File(".")),
umlInstance);
} catch (Exception e) {
e.printStackTrace();
}

}

}



This document is strictly confidential and intended only for use by the addressee unless otherwise stated. If you are not the intended recipient, please notify the sender immediately and delete it from your system.
Martin Matula
2007-03-20 13:35:17 UTC
Permalink
Hi Jess,
you can generate JMI interfaces from MOF models only. JMI defines
MOF->Java mapping, not UML 1.4->Java mapping.
One thing you could do is to convert your UML 1.4 model to a MOF model
(using UML2MOF tool - see http://mdr.netbeans.org/uml2mof) - you just
need to make sure your UML model conforms to UML Profile for MOF defined
on the UML2MOF web page).
Then you can generate JMI interfaces from that MOF model.
Martin
Post by J***@SITA.aero
Hi I need to generate JMI interfaces from a uml1.4 xmi file exported by
argo uml. The code below throws class cast exception when i try to cast
umlMetaModel to ModelPackage in the for loop.
Alternatively can anyone point me to a basic example of programmatic JMI
interface genreation using MDR.
Thanks,
JS
public class MyMDR {
/**
*/
public static void main(String[] args) {
MDRManager manager = MDRManager.getDefault();
MDRepository repository = manager.getDefaultRepository();
XMIReaderFactory factory = XMIReaderFactory.getDefault();
XMIReader reader = factory.createXMIReader();
RefPackage umlMetaModel;
repository.beginTrans(true);
try {
// put the UML metamodel into MDR
FileInputStream in = new FileInputStream(
"/xmi/01-02-15.xml");
umlMetaModel = repository.getExtent("UML-MetaModel");
MofPackage umlPackage = null;
for (Iterator it = ((ModelPackage)
umlMetaModel).getMofPackage()
.refAllOfClass().iterator(); it.hasNext();) {
MofPackage temp = (MofPackage) it.next();
if ("UML".equals(temp.getName())) {
umlPackage = temp;
break;
}
}
RefPackage umlInstance = repository.createExtent(
"umlInstance",
umlPackage);
JMIMapper mapper = JMIMapper.getDefault();
mapper.generate(new FileStreamFactory(new File(".")),
umlInstance);
} catch (Exception e) {
e.printStackTrace();
}
}
}
This document is strictly confidential and intended only for use by the addressee unless otherwise stated. If you are not the intended recipient, please notify the sender immediately and delete it from your system.
Loading...