package xmi; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.OutputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import org.eclipse.emf.ecore.util.EcoreUtil; import schemas.templatedefiner._goonyhwmeekedd8bbul2tg._40.TemplateSpec; import uml.Model; import xmm.PackagedElement; public class XMIMarshaller { public static XMI loadXMI(InputStream is) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(XMI.class); Unmarshaller u = jc.createUnmarshaller(); XMI mimi = (XMI) u.unmarshal(is); return mimi; } public static void printXMI(XMI xmi, OutputStream os) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(XMI.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(xmi, os); } public static void main(String[] args) throws FileNotFoundException, JAXBException { XMI xmi = new XMI(); TemplateSpec ts = new TemplateSpec(); ts.setId(EcoreUtil.generateUUID()); xmi.getTemplateSpec().add(ts); Model model = new Model(); xmi.setModel(model); PackagedElement pe = new PackagedElement(); model.getPackagedElement().add(pe); pe.setId("test"); //printXMI(xmi, System.out); XMI xmi2 = loadXMI(new FileInputStream("/home/aboufahj/workspaceTopcased/nblock-model/models/nblock.uml")); for (PackagedElement packagedElement : xmi2.getModel().getPackagedElement()) { if (packagedElement.getType() != null && packagedElement.getType().equals("uml:Class")) System.out.println("mapListNBlockToUMLId.put(\"" + packagedElement.getName() + "\", \"" + packagedElement.getId() + "\");"); } //printXMI(xmi2, System.out); } }