/** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.airavata.workflow.model.graph.dynamic; import java.io.File; import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException; import org.apache.xmlbeans.SchemaCodePrinter; import org.apache.xmlbeans.impl.common.IOUtil; import org.apache.xmlbeans.impl.common.XmlErrorPrinter; import org.apache.xmlbeans.impl.tool.CodeGenUtil; import org.apache.xmlbeans.impl.tool.CommandLine; import org.apache.xmlbeans.impl.tool.SchemaCompiler; import org.apache.xmlbeans.impl.values.XmlListImpl; public class SchemaCompilerUtil extends SchemaCompiler { public static void compile(String[] args) { if (args.length == 0) { return; } Set flags = new HashSet(); flags.add("h"); flags.add("help"); flags.add("usage"); flags.add("license"); flags.add("quiet"); flags.add("verbose"); flags.add("version"); flags.add("dl"); flags.add("noupa"); flags.add("nopvr"); flags.add("noann"); flags.add("novdoc"); flags.add("noext"); flags.add("srconly"); flags.add("debug"); Set opts = new HashSet(); opts.add("out"); opts.add("name"); opts.add("src"); opts.add("d"); opts.add("cp"); opts.add("compiler"); opts.add("javasource"); opts.add("jar"); // deprecated opts.add("ms"); opts.add("mx"); opts.add("repackage"); opts.add("schemaCodePrinter"); opts.add("extension"); opts.add("extensionParms"); opts.add("allowmdef"); opts.add("catalog"); CommandLine cl = new CommandLine(args, flags, opts); String[] badopts = cl.getBadOpts(); if (badopts.length > 0) { for (int i = 0; i < badopts.length; i++) System.out.println("Unrecognized option: " + badopts[i]); return; } boolean verbose = (cl.getOpt("verbose") != null); boolean quiet = (cl.getOpt("quiet") != null); if (verbose) quiet = false; String outputfilename = cl.getOpt("out"); String repackage = cl.getOpt("repackage"); cl.getOpt("schemaCodePrinter"); SchemaCodePrinter codePrinter = null; String name = cl.getOpt("name"); boolean download = (cl.getOpt("dl") != null); boolean noUpa = (cl.getOpt("noupa") != null); boolean noPvr = (cl.getOpt("nopvr") != null); boolean noAnn = (cl.getOpt("noann") != null); boolean noVDoc = (cl.getOpt("novdoc") != null); boolean noExt = (cl.getOpt("noext") != null); boolean nojavac = (cl.getOpt("srconly") != null); boolean debug = (cl.getOpt("debug") != null); String allowmdef = cl.getOpt("allowmdef"); Set mdefNamespaces = (allowmdef == null ? Collections.EMPTY_SET : new HashSet(Arrays.asList(XmlListImpl .split_list(allowmdef)))); List extensions = new ArrayList(); String classesdir = cl.getOpt("d"); File classes = null; if (classesdir != null) classes = new File(classesdir); String srcdir = cl.getOpt("src"); File src = null; if (srcdir != null) src = new File(srcdir); if (nojavac && srcdir == null && classes != null) src = classes; // create temp directory File tempdir = null; if (src == null || classes == null) { throw new WorkflowRuntimeException("Code gen src directory or classes directory is null"); } File jarfile = null; if (outputfilename == null && classes == null && !nojavac) outputfilename = "xmltypes.jar"; if (outputfilename != null) jarfile = new File(outputfilename); if (src == null) src = IOUtil.createDir(tempdir, "src"); if (classes == null) classes = IOUtil.createDir(tempdir, "classes"); File[] classpath = null; String cpString = cl.getOpt("cp"); if (cpString != null) { String[] cpparts = cpString.split(File.pathSeparator); List cpList = new ArrayList(); for (int i = 0; i < cpparts.length; i++) cpList.add(new File(cpparts[i])); classpath = (File[]) cpList.toArray(new File[cpList.size()]); } else { classpath = CodeGenUtil.systemClasspath(); } String javasource = cl.getOpt("javasource"); String compiler = cl.getOpt("compiler"); String jar = cl.getOpt("jar"); if (verbose && jar != null) System.out.println("The 'jar' option is no longer supported."); String memoryInitialSize = cl.getOpt("ms"); String memoryMaximumSize = cl.getOpt("mx"); File[] xsdFiles = cl.filesEndingWith(".xsd"); File[] wsdlFiles = cl.filesEndingWith(".wsdl"); File[] javaFiles = cl.filesEndingWith(".java"); File[] configFiles = cl.filesEndingWith(".xsdconfig"); URL[] urlFiles = cl.getURLs(); if (xsdFiles.length + wsdlFiles.length + urlFiles.length == 0) { System.out.println("Could not find any xsd or wsdl files to process."); return; } File baseDir = cl.getBaseDir(); URI baseURI = baseDir == null ? null : baseDir.toURI(); XmlErrorPrinter err = new XmlErrorPrinter(verbose, baseURI); String catString = cl.getOpt("catalog"); Parameters params = new Parameters(); params.setBaseDir(baseDir); params.setXsdFiles(xsdFiles); params.setWsdlFiles(wsdlFiles); params.setJavaFiles(javaFiles); params.setConfigFiles(configFiles); params.setUrlFiles(urlFiles); params.setClasspath(classpath); params.setOutputJar(jarfile); params.setName(name); params.setSrcDir(src); params.setClassesDir(classes); params.setCompiler(compiler); params.setJavaSource(javasource); params.setMemoryInitialSize(memoryInitialSize); params.setMemoryMaximumSize(memoryMaximumSize); params.setNojavac(nojavac); params.setQuiet(quiet); params.setVerbose(verbose); params.setDownload(download); params.setNoUpa(noUpa); params.setNoPvr(noPvr); params.setNoAnn(noAnn); params.setNoVDoc(noVDoc); params.setNoExt(noExt); params.setDebug(debug); params.setErrorListener(err); params.setRepackage(repackage); params.setExtensions(extensions); params.setMdefNamespaces(mdefNamespaces); params.setCatalogFile(catString); params.setSchemaCodePrinter(codePrinter); compile(params); } }