Created
April 25, 2014 17:16
-
-
Save vincent-zurczak/11296790 to your computer and use it in GitHub Desktop.
Convert a WSDL to its XMI Representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main( String[] args ) { | |
/* | |
* Manifest Dependencies used for this example. | |
* | |
* org.eclipse.emf, | |
* org.eclipse.emf.common, | |
* org.eclipse.emf.ecore, | |
* org.eclipse.emf.ecore.edit, | |
* org.eclipse.emf.ecore.xmi, | |
* org.eclipse.emf.edit, | |
* org.eclipse.wst.wsdl;bundle-version="1.2.201", | |
* org.eclipse.xsd;bundle-version="2.7.1", | |
* javax.wsdl;bundle-version="1.5.1" | |
*/ | |
// The file to convert | |
File f = new File( "D:/Workspaces/WSDLs/tuxDroid_test.wsdl" ); | |
// Register the basic elements of the specification | |
ResourceSet resourceSet = new ResourceSetImpl(); | |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( "xml", new XMLResourceFactoryImpl()); | |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( "xsd", new XSDResourceFactoryImpl()); | |
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( "wsdl", new WSDLResourceFactoryImpl()); | |
resourceSet.getPackageRegistry().put( XSDPackage.eNS_URI, XSDPackage.eINSTANCE ); | |
resourceSet.getPackageRegistry().put( WSDLPackage.eNS_URI, WSDLPackage.eINSTANCE ); | |
// Register the required extensions | |
// None here | |
// Load the main document | |
URI emfUri = URI.createFileURI( f.getAbsolutePath()); | |
Resource resource = resourceSet.getResource( emfUri, true ); | |
Definition def = (Definition) resource.getContents().iterator().next(); | |
// Write it in XMI | |
File targetFile = new File( f.getParent(), f.getName() + ".xmi" ); | |
emfUri = URI.createFileURI( targetFile.getAbsolutePath()); | |
Resource targetResource = new XMIResourceFactoryImpl().createResource( emfUri ); | |
targetResource.getContents().add( def ); | |
// See @link{org.eclipse.emf.ecore.xmi.XMIResource} for examples of SAVE options | |
Map<Object,Object> saveOptions = new HashMap<Object,Object> (); | |
try { | |
targetResource.save( saveOptions ); | |
} catch( IOException e ) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment