/******************************************************************************* * 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.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; 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.XDWResourceImpl; import net.ihe.gazelle.xdw.util.XDWValidator; import net.ihe.gazelle.xdw.validator.ValidationResult; import net.ihe.gazelle.xdw.validator.XDWUtil; import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.util.Diagnostician; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; import org.eclipse.xsd.ecore.XSDEcoreBuilder; import org.openhealthtools.uml.xdw.XDWResource; public class CopyOfMain { public static void main(String[] args) throws Exception { DocumentRoot dr = XDWFactory.eINSTANCE.createDocumentRoot(); TXDWWorkflowDocument txw = XDWFactory.eINSTANCE.createTXDWWorkflowDocument(); txw.setTitle(V3Factory.eINSTANCE.createST1()); txw.getTitle().setLanguage("langgg"); txw.setId(V3Factory.eINSTANCE.createII()); txw.getId().setRoot("rrrrrrrrhahahaha"); //txw.getId().setNullFlavor(NullFlavor.NA); 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()); //CDAUtil.init(dr); //CDAUtil.init(txw); //txw. // try{ // XDWUtil.save(txw, System.out); // } // catch(Exception e){ // e.printStackTrace(); // } // printDocRoot(txw); // loadDoc("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/example.xml"); // loadDoc(new FileInputStream("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/example.xml")); // load3(); // XDWUtil.load(new FileInputStream("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/example.xml")); // ValidationResult result = new ValidationResult(); // TXDWWorkflowDocument txdw = XDWUtil.load(new FileInputStream("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/example.xml"), result); // System.out.println("\n\n\nertertrth"); // printDocRoot(txdw); XDWUtil.validate(txw, new XDWUtil.ValidationHandler() { @Override public void handleWarning(Diagnostic diagnostic) { System.out.println("WARNING: " + diagnostic.getMessage()); // TODO Auto-generated method stub } @Override public void handleInfo(Diagnostic diagnostic) { System.out.println("INFO: " + diagnostic.getMessage()); // TODO Auto-generated method stub } @Override public void handleError(Diagnostic diagnostic) { System.out.println("ERROR: " + diagnostic.getMessage()); // TODO Auto-generated method stub } }); } public static void printDocRoot(TXDWWorkflowDocument clinicalDocument){ if (clinicalDocument == null) { System.err.println("nulllll"); return; } 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 load3(){ XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder(); Collection generatedPackages = xsdEcoreBuilder.generate(URI.createURI("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/gen/xdw.xsd")); // register the packages loaded from XSD for (EObject generatedEObject : generatedPackages) { if (generatedEObject instanceof EPackage) { EPackage generatedPackage = (EPackage) generatedEObject; EPackage.Registry.INSTANCE.put(generatedPackage.getNsURI(), generatedPackage); } } // add file extension to registry ResourceFactoryRegistryImpl.INSTANCE.getExtensionToFactoryMap() .put("xml", new GenericXMLResourceFactoryImpl()); Resource rr = (new XDWResourceImpl(URI.createURI("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/example.xml"))); try { rr.load(Collections.EMPTY_MAP); System.err.println(rr.getContents().get(0).getClass()); DocumentRoot dr = (DocumentRoot) rr.getContents().get(0); TXDWWorkflowDocument tt = dr.getXDWWorkflowDocument(); printDocRoot(tt); System.err.println(rr.getContents().size()); } catch (IOException e) { e.printStackTrace(); } // ResourceSet resourceSet = (new ResourceSetImpl()).createResourceSet(); // Resource resource = resourceSet.getResource(URI.createURI("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/example.xml"), true); // resource.load(Collections.EMPTY_MAP); // EObject root = resource.getContents().get(0); } // MyDocument clinicalDocument = ExampleFactory.eINSTANCE.createMyDocument().init(); // MySection section = ExampleFactory.eINSTANCE.createMySection().init(); // MyObservation obs = ExampleFactory.eINSTANCE.createMyObservation().init(); // // clinicalDocument.addSection(section); // section.addObservation(obs); // // save(clinicalDocument); // validate(clinicalDocument); // } // // private static void save(ClinicalDocument clinicalDocument) throws Exception { // CDAUtil.save(clinicalDocument, System.out); // } // private static void validate(ClinicalDocument clinicalDocument) throws Exception { // boolean valid = CDAUtil.validate(clinicalDocument, new BasicValidationHandler() { // @Override // public void handleError(Diagnostic diagnostic) { // System.out.println("ERROR: " + diagnostic.getMessage()); // } // // @Override // public void handleWarning(Diagnostic diagnostic) { // System.out.println("WARNING: " + diagnostic.getMessage()); // } // // @Override // public void handleInfo(Diagnostic diagnostic) { // System.out.println("INFO: " + diagnostic.getMessage()); // } // }); // // if (valid) { // System.out.println("Document is valid"); // } else { // System.out.println("Document is invalid"); // } // } }