/******************************************************************************* * 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.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; import net.ihe.gazelle.oasis.OASISPackage; import net.ihe.gazelle.oasis.impl.OASISPackageImpl; import net.ihe.gazelle.v3.V3Package; import net.ihe.gazelle.v3.impl.V3PackageImpl; import net.ihe.gazelle.xdw.DocumentRoot; import net.ihe.gazelle.xdw.TXDWWorkflowDocument; import net.ihe.gazelle.xdw.XDWPackage; import net.ihe.gazelle.xdw.impl.XDWPackageImpl; import net.ihe.gazelle.xdw.util.XDWResourceFactoryImpl; import org.eclipse.emf.common.util.EList; 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.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl; import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl; import org.openhealthtools.uml.xdw.XDWResource; import org.openhealthtools.uml.xdw.XDWResourceImpl; public class Load { public static void main(String[] args) throws Exception { // loadDoc4("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/tt.xml"); // lastone(); laod5(); } public static void loadDoc2(String file) throws IOException{ XDWPackageImpl.init(); V3PackageImpl.init(); Map loadOptions = new HashMap(); loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); loadOptions.put(XMLResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE); Resource rr = (new XDWResourceFactoryImpl()).createResource(URI.createFileURI(file)); rr.load(loadOptions); } public static void loadDoc3(String file) throws IOException{ XDWPackageImpl.init(); V3PackageImpl.init(); Map loadOptions = new HashMap(); loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); loadOptions.put(XMLResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl()); resourceSet.getPackageRegistry().put(XDWPackage.eNS_URI, XDWPackage.eINSTANCE); XMLResource resource = (XMLResource) (new XMLResourceFactoryImpl()).createResource(URI.createFileURI(file)); resource.load(loadOptions); } public static void loadDoc4(String file) throws IOException{ Map loadOptions = new HashMap(); loadOptions.put(XMLResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE); loadOptions.put(XMLResource.OPTION_DISABLE_NOTIFY, Boolean.TRUE); loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); XDWPackageImpl.init(); V3PackageImpl.init(); OASISPackageImpl.init(); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl()); resourceSet.getPackageRegistry().put(XDWPackage.eNS_URI, XDWPackage.eINSTANCE); resourceSet.getPackageRegistry().put(V3Package.eNS_URI, V3Package.eINSTANCE); resourceSet.getPackageRegistry().put(OASISPackage.eNS_URI, OASISPackage.eINSTANCE); Resource resource = resourceSet.createResource(URI.createFileURI(file)); resource.load(loadOptions); } public static void lastone() throws Exception{ XDWResourceFactoryImpl xr = new XDWResourceFactoryImpl(); XDWPackageImpl.init(); Resource resource = xr.createResource(URI.createURI("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/tt.xml")); XDWPackageImpl.init(); V3PackageImpl.init(); OASISPackageImpl.init(); Set ss = EPackage.Registry.INSTANCE.keySet(); for (String string : ss) { System.out.println("ss = " + string); if (string == "urn:ihe:iti:2011:xdw"){ EPackage ep = EPackage.Registry.INSTANCE.getEPackage(string); System.out.println("\t" + ep.getName()); EList el = ep.eContents(); for (EObject eAnnotation : el) { System.out.println("\t\t" + eAnnotation.toString()); } } } resource.load(Collections.EMPTY_MAP); DocumentRoot root = (DocumentRoot) resource.getContents().get(0); TXDWWorkflowDocument clinicalDocument = root.getXDWWorkflowDocument(); System.out.println(root.getXMLNSPrefixMap()); System.out.println(root.getXSISchemaLocation()); Main.printDocRoot(clinicalDocument); } public static void laod5() throws IOException{ XDWResource resource = new XDWResourceImpl(URI.createURI("/Users/aboufahj/Documents/eclipse-mdht/workspace/net.ihe.gazelle.xdw/sample/tt.xml")); XDWPackageImpl.init(); V3PackageImpl.init(); resource.load(Collections.EMPTY_MAP); DocumentRoot root = (DocumentRoot) resource.getContents().get(0); TXDWWorkflowDocument clinicalDocument = root.getXDWWorkflowDocument(); System.out.println(root.getXMLNSPrefixMap()); System.out.println(root.getXSISchemaLocation()); Main.printDocRoot(clinicalDocument); } }