Coverage Report - uk.co.badgersinfoil.asxsd.Main
 
Classes in this File Line Coverage Branch Coverage Complexity
Main
0% 
0% 
1.5
 
 1  
 /*
 2  
  * Copyright (c) 2006 David Holroyd
 3  
  */
 4  
 
 5  
 package uk.co.badgersinfoil.asxsd;
 6  
 
 7  
 
 8  
 import java.io.IOException;
 9  
 import org.eclipse.emf.common.util.URI;
 10  
 import org.eclipse.emf.ecore.resource.Resource;
 11  
 import org.eclipse.emf.ecore.resource.ResourceSet;
 12  
 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
 13  
 import org.eclipse.xsd.XSDSchema;
 14  
 import org.eclipse.xsd.util.XSDResourceFactoryImpl;
 15  
 import org.eclipse.xsd.util.XSDResourceImpl;
 16  
 import uk.co.badgersinfoil.metaas.ActionScriptProject;
 17  
 import uk.co.badgersinfoil.metaas.ActionScriptFactory;
 18  
 
 19  
 
 20  
 /*
 21  
  * To use this class, you will need both metaas, and the Eclpise XSD infoset
 22  
  * model, and supporting packages.  I used emf-sdo-xsd-Standalone-2.2.0,
 23  
  * available at,
 24  
  * 
 25  
  * http://www.eclipse.org/downloads/download.php?file=/tools/emf/downloads/drops/2.2.0/R200606271057/emf-sdo-xsd-Standalone-2.2.0.zip
 26  
  * 
 27  
  * After unpacking the contents of this archive, the emf_common, emf_ecore and
 28  
  * xsd jars (from the archive's 'emf/bin' directory) must be added to your
 29  
  * classpath.
 30  
  */
 31  
 
 32  
 
 33  
 /*
 34  
  * TODOs:
 35  
  * - WSDL?  [ http://dev.eclipse.org/newslists/news.eclipse.technology.xsd/msg00401.html ]
 36  
  */
 37  
 
 38  
 
 39  0
 public class Main {
 40  
         public static void main(String[] args) throws IOException {
 41  
                 // need to do this in order to have Eclipse's XSD 'resource'
 42  
                 // support work,
 43  0
                 Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xsd", new XSDResourceFactoryImpl());
 44  
 
 45  0
                 String filename = args[0];
 46  
                 String destDir;
 47  0
                 if (args.length > 1) {
 48  0
                         destDir = args[1];
 49  
                 } else {
 50  0
                         destDir = ".";
 51  
                 }
 52  0
                 XSDSchema mainSchema = loadSchema(filename);
 53  0
                 ActionScriptFactory fact = new ActionScriptFactory();
 54  0
                 ActionScriptProject project = fact.newEmptyASProject(destDir);
 55  0
                 MappingCodeGenerator generator  = new MappingCodeGenerator(fact, project);
 56  0
                 generator.processSchema(mainSchema);
 57  0
                 project.performAutoImport();
 58  0
                 project.writeAll();
 59  0
         }
 60  
 
 61  
         private static XSDSchema loadSchema(String filename) throws IOException {
 62  0
                 ResourceSet resourceSet = new ResourceSetImpl();
 63  0
                 XSDResourceImpl resource = (XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd"));
 64  0
                 resource.setURI(URI.createFileURI(filename));
 65  0
                 resource.load(resourceSet.getLoadOptions());
 66  0
                 XSDSchema mainSchema = resource.getSchema();
 67  0
                 return mainSchema;
 68  
         }
 69  
 }