| 1 |
|
|
| 2 |
|
|
| 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 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
0 |
public class Main { |
| 40 |
|
public static void main(String[] args) throws IOException { |
| 41 |
|
|
| 42 |
|
|
| 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 |
|
} |