src/share/jaxws_classes/com/sun/tools/internal/xjc/Driver.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.xjc;
  27 
  28 import java.io.File;
  29 import java.io.FileOutputStream;
  30 import java.io.IOException;
  31 import java.io.OutputStream;
  32 import java.io.OutputStreamWriter;
  33 import java.io.PrintStream;


  34 import java.util.Iterator;
  35 
  36 import com.sun.codemodel.internal.CodeWriter;
  37 import com.sun.codemodel.internal.JCodeModel;
  38 import com.sun.codemodel.internal.writer.ZipCodeWriter;
  39 import com.sun.istack.internal.NotNull;
  40 import com.sun.istack.internal.Nullable;
  41 import com.sun.istack.internal.tools.DefaultAuthenticator;
  42 import com.sun.tools.internal.xjc.generator.bean.BeanGenerator;
  43 import com.sun.tools.internal.xjc.model.Model;
  44 import com.sun.tools.internal.xjc.outline.Outline;
  45 import com.sun.tools.internal.xjc.reader.gbind.Expression;
  46 import com.sun.tools.internal.xjc.reader.gbind.Graph;
  47 import com.sun.tools.internal.xjc.reader.internalizer.DOMForest;
  48 import com.sun.tools.internal.xjc.reader.xmlschema.ExpressionBuilder;
  49 import com.sun.tools.internal.xjc.reader.xmlschema.parser.XMLSchemaInternalizationLogic;
  50 import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
  51 import com.sun.tools.internal.xjc.util.NullStream;
  52 import com.sun.tools.internal.xjc.util.Util;
  53 import com.sun.tools.internal.xjc.writer.SignatureWriter;
  54 import com.sun.xml.internal.xsom.XSComplexType;
  55 import com.sun.xml.internal.xsom.XSParticle;
  56 import com.sun.xml.internal.xsom.XSSchemaSet;
  57 
  58 import org.xml.sax.SAXException;
  59 import org.xml.sax.SAXParseException;
  60 
  61 
  62 /**
  63  * Command Line Interface of XJC.
  64  */
  65 public class Driver {
  66 


  67     public static void main(final String[] args) throws Exception {
  68         // use the platform default proxy if available.
  69         // see sun.net.spi.DefaultProxySelector for details.
  70         try {
  71             System.setProperty("java.net.useSystemProxies","true");
  72         } catch (SecurityException e) {
  73             // failing to set this property isn't fatal
  74         }
  75 
  76         if( Util.getSystemProperty(Driver.class,"noThreadSwap")!=null )
  77             _main(args);    // for the ease of debugging
  78 
  79         // run all the work in another thread so that the -Xss option
  80         // will take effect when compiling a large schema. See
  81         // http://developer.java.sun.com/developer/bugParade/bugs/4362291.html
  82         final Throwable[] ex = new Throwable[1];
  83 
  84         Thread th = new Thread() {
  85             @Override
  86             public void run() {
  87                 try {
  88                     _main(args);
  89                 } catch( Throwable e ) {
  90                     ex[0]=e;
  91                 }
  92             }
  93         };
  94         th.start();
  95         th.join();
  96 
  97         if(ex[0]!=null) {
  98             // re-throw
  99             if( ex[0] instanceof Exception )
 100                 throw (Exception)ex[0];
 101             else
 102                 throw (Error)ex[0];
 103         }
 104     }
 105 





















 106     private static void _main( String[] args ) throws Exception {
 107         try {
 108             System.exit(run( args, System.out, System.out ));
 109         } catch (BadCommandLineException e) {
 110             // there was an error in the command line.
 111             // print usage and abort.
 112             if(e.getMessage()!=null) {
 113                 System.out.println(e.getMessage());
 114                 System.out.println();
 115             }
 116 
 117             usage(e.getOptions(),false);
 118             System.exit(-1);
 119         }
 120     }
 121 
 122 
 123 
 124     /**
 125      * Performs schema compilation and prints the status/error into the


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.xjc;
  27 
  28 import java.io.File;
  29 import java.io.FileOutputStream;
  30 import java.io.IOException;
  31 import java.io.OutputStream;
  32 import java.io.OutputStreamWriter;
  33 import java.io.PrintStream;
  34 import java.security.AccessController;
  35 import java.security.PrivilegedAction;
  36 import java.util.Iterator;
  37 
  38 import com.sun.codemodel.internal.CodeWriter;
  39 import com.sun.codemodel.internal.JCodeModel;
  40 import com.sun.codemodel.internal.writer.ZipCodeWriter;
  41 import com.sun.istack.internal.NotNull;
  42 import com.sun.istack.internal.Nullable;
  43 import com.sun.istack.internal.tools.DefaultAuthenticator;
  44 import com.sun.tools.internal.xjc.generator.bean.BeanGenerator;
  45 import com.sun.tools.internal.xjc.model.Model;
  46 import com.sun.tools.internal.xjc.outline.Outline;
  47 import com.sun.tools.internal.xjc.reader.gbind.Expression;
  48 import com.sun.tools.internal.xjc.reader.gbind.Graph;
  49 import com.sun.tools.internal.xjc.reader.internalizer.DOMForest;
  50 import com.sun.tools.internal.xjc.reader.xmlschema.ExpressionBuilder;
  51 import com.sun.tools.internal.xjc.reader.xmlschema.parser.XMLSchemaInternalizationLogic;
  52 import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
  53 import com.sun.tools.internal.xjc.util.NullStream;
  54 import com.sun.tools.internal.xjc.util.Util;
  55 import com.sun.tools.internal.xjc.writer.SignatureWriter;
  56 import com.sun.xml.internal.xsom.XSComplexType;
  57 import com.sun.xml.internal.xsom.XSParticle;
  58 import com.sun.xml.internal.xsom.XSSchemaSet;
  59 
  60 import org.xml.sax.SAXException;
  61 import org.xml.sax.SAXParseException;
  62 
  63 
  64 /**
  65  * Command Line Interface of XJC.
  66  */
  67 public class Driver {
  68 
  69     private static final String SYSTEM_PROXY_PROPERTY = "java.net.useSystemProxies";
  70 
  71     public static void main(final String[] args) throws Exception {
  72         // use the platform default proxy if available.
  73         // see sun.net.spi.DefaultProxySelector for details.
  74         setupProxies();




  75 
  76         if( Util.getSystemProperty(Driver.class,"noThreadSwap")!=null )
  77             _main(args);    // for the ease of debugging
  78 
  79         // run all the work in another thread so that the -Xss option
  80         // will take effect when compiling a large schema. See
  81         // http://developer.java.sun.com/developer/bugParade/bugs/4362291.html
  82         final Throwable[] ex = new Throwable[1];
  83 
  84         Thread th = new Thread() {
  85             @Override
  86             public void run() {
  87                 try {
  88                     _main(args);
  89                 } catch( Throwable e ) {
  90                     ex[0]=e;
  91                 }
  92             }
  93         };
  94         th.start();
  95         th.join();
  96 
  97         if(ex[0]!=null) {
  98             // re-throw
  99             if( ex[0] instanceof Exception )
 100                 throw (Exception)ex[0];
 101             else
 102                 throw (Error)ex[0];
 103         }
 104     }
 105 
 106     /**
 107      * Set useSystemProxies if needed
 108      */
 109     private static void setupProxies() {
 110         Object setProperty = AccessController.doPrivileged(new PrivilegedAction<Object>() {
 111             @Override
 112             public Object run() {
 113                 return System.getProperty(SYSTEM_PROXY_PROPERTY);
 114             }
 115         });
 116         if (setProperty == null) {
 117             AccessController.doPrivileged(new PrivilegedAction<Void>() {
 118                 @Override
 119                 public Void run() {
 120                     System.setProperty(SYSTEM_PROXY_PROPERTY, "true");
 121                     return null;
 122                 }
 123             });
 124         }
 125     }
 126 
 127     private static void _main( String[] args ) throws Exception {
 128         try {
 129             System.exit(run( args, System.out, System.out ));
 130         } catch (BadCommandLineException e) {
 131             // there was an error in the command line.
 132             // print usage and abort.
 133             if(e.getMessage()!=null) {
 134                 System.out.println(e.getMessage());
 135                 System.out.println();
 136             }
 137 
 138             usage(e.getOptions(),false);
 139             System.exit(-1);
 140         }
 141     }
 142 
 143 
 144 
 145     /**
 146      * Performs schema compilation and prints the status/error into the