/******************************************************************************* * Copyright (c) 2009, 2011 David A Carlson and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * David A Carlson (XMLmodeling.com) - initial API and implementation *******************************************************************************/ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import net.ihe.gazelle.oasis.OASISFactory; import net.ihe.gazelle.v3.V3Factory; import net.ihe.gazelle.xdw.DocumentRoot; import net.ihe.gazelle.xdw.TXDWWorkflowDocument; import net.ihe.gazelle.xdw.XDWFactory; import net.ihe.gazelle.xdw.XDWPackage; import net.ihe.gazelle.xdw.util.XDWResourceFactoryImpl; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; import org.openhealthtools.uml.xdw.XDWResource; public class Main { public static void main(String[] args) throws Exception { TXDWWorkflowDocument txw = XDWFactory.eINSTANCE.createTXDWWorkflowDocument(); txw.setTitle(V3Factory.eINSTANCE.createST1()); txw.getTitle().setLanguage("langgg"); txw.setId(V3Factory.eINSTANCE.createII()); txw.getId().setRoot("rrrrrrrrhahahaha"); txw.setWorkflowInstanceID("ee"); txw.setWorkflowDocumentSequenceNumber(3333); txw.setPatient(XDWFactory.eINSTANCE.createTXDWpatient()); txw.getPatient().setBirthTime(V3Factory.eINSTANCE.createTS1()); txw.getPatient().getBirthTime().setValue("eeeeee"); txw.getAuthor().add(XDWFactory.eINSTANCE.createTXDWAuthor()); txw.getAuthor().get(0).setAssignedPerson(V3Factory.eINSTANCE.createPOCDMT000040Person()); txw.setTaskList(XDWFactory.eINSTANCE.createTaskListType()); txw.getTaskList().getXDWTask().add(XDWFactory.eINSTANCE.createTXDWTask()); txw.getTaskList().getXDWTask().get(0).setTaskData(OASISFactory.eINSTANCE.createTTaskInstanceData()); txw.getTaskList().getXDWTask().get(0).getTaskData().setComments(OASISFactory.eINSTANCE.createTComments()); System.err.println(txw.getAuthor().get(0).getAssignedPerson().getClassCode()); //txw. printDocRoot(txw); printDoc2(txw); } public static void printDocRoot(TXDWWorkflowDocument clinicalDocument){ XDWResource resource = (XDWResource) clinicalDocument.eResource(); if (resource == null) { resource = (XDWResource) XDWResource.Factory.INSTANCE.createResource(URI.createURI(XDWPackage.eNS_URI)); resource.getContents().add(clinicalDocument); } else { DocumentRoot root = (DocumentRoot) clinicalDocument.eContainer(); List keys = new ArrayList(); for (Map.Entry entry : root.getXMLNSPrefixMap().entrySet()) { if (EPackage.Registry.INSTANCE.keySet().contains(entry.getValue())) { keys.add(entry.getKey()); } } for (String key : keys) { root.getXMLNSPrefixMap().removeKey(key); } root.getXMLNSPrefixMap().put("", XDWPackage.eNS_URI); } try { resource.save(System.out, null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void printDoc2(TXDWWorkflowDocument clinicalDocument) throws IOException{ Resource rr = (new XDWResourceFactoryImpl()).createResource(URI.createFileURI("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/tt.xml")); rr.getContents().add(clinicalDocument); rr.save(Collections.EMPTY_MAP); } }