< prev index next >

src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/Options.java

Print this page




 128     public boolean runtime14 = false;
 129 
 130     /**
 131      * If true, try to resolve name conflicts automatically by assigning mechanical numbers.
 132      */
 133     public boolean automaticNameConflictResolution = false;
 134 
 135     /**
 136      * strictly follow the compatibility rules and reject schemas that
 137      * contain features from App. E.2, use vendor binding extensions
 138      */
 139     public static final int STRICT = 1;
 140     /**
 141      * loosely follow the compatibility rules and allow the use of vendor
 142      * binding extensions
 143      */
 144     public static final int EXTENSION = 2;
 145 
 146     /**
 147      * this switch determines how carefully the compiler will follow
 148      * the compatibility rules in the spec. Either <code>STRICT</code>
 149      * or <code>EXTENSION</code>.
 150      */
 151     public int compatibilityMode = STRICT;
 152 
 153     public boolean isExtensionMode() {
 154         return compatibilityMode==EXTENSION;
 155     }
 156 
 157     private static final Logger logger = com.sun.xml.internal.bind.Util.getClassLogger();
 158 
 159     /**
 160      * Generates output for the specified version of the runtime.
 161      */
 162     public SpecVersion target = SpecVersion.LATEST;
 163 
 164 
 165     public Options() {
 166         try {
 167             Class.forName("javax.xml.bind.JAXBPermission");
 168         } catch (ClassNotFoundException cnfe) {
 169             target = SpecVersion.V2_1;
 170         }
 171     }
 172 
 173     /**
 174      * Target directory when producing files.
 175      * <p>
 176      * This field is not used when XJC is driven through the XJC API.
 177      * Plugins that need to generate extra files should do so by using
 178      * {@link JPackage#addResourceFile(JResourceFile)}.
 179      */
 180     public File targetDir = new File(".");
 181 
 182     /**
 183      * Actually stores {@link CatalogResolver}, but the field
 184      * type is made to {@link EntityResolver} so that XJC can be
 185      * used even if resolver.jar is not available in the classpath.
 186      */
 187     public EntityResolver entityResolver = null;
 188 
 189     /**
 190      * Type of input schema language. One of the <code>SCHEMA_XXX</code>
 191      * constants.
 192      */
 193     private Language schemaLanguage = null;
 194 
 195     /**
 196      * The -p option that should control the default Java package that
 197      * will contain the generated code. Null if unspecified.
 198      */
 199     public String defaultPackage = null;
 200 
 201     /**
 202      * Similar to the -p option, but this one works with a lower priority,
 203      * and customizations overrides this. Used by JAX-RPC.
 204      */
 205     public String defaultPackage2 = null;
 206 
 207     /**
 208      * Input schema files as a list of {@link InputSource}s.
 209      */
 210     private final List<InputSource> grammars = new ArrayList<InputSource>();


 449      * Recursively scan directories and add all ".xjb" files in it.
 450      */
 451     public void addBindFileRecursive( File dir ) {
 452         addRecursive(dir,".xjb",bindFiles);
 453     }
 454 
 455     public final List<URL> classpaths = new ArrayList<URL>();
 456     /**
 457      * Gets a classLoader that can load classes specified via the
 458      * -classpath option.
 459      */
 460     public ClassLoader getUserClassLoader( ClassLoader parent ) {
 461         if (classpaths.isEmpty())
 462             return parent;
 463         return new URLClassLoader(
 464                 classpaths.toArray(new URL[classpaths.size()]),parent);
 465     }
 466 
 467 
 468     /**
 469      * Parses an option <code>args[i]</code> and return
 470      * the number of tokens consumed.
 471      *
 472      * @return
 473      *      0 if the argument is not understood. Returning 0
 474      *      will let the caller report an error.
 475      * @exception BadCommandLineException
 476      *      If the callee wants to provide a custom message for an error.
 477      */
 478     public int parseArgument( String[] args, int i ) throws BadCommandLineException {
 479         if (args[i].equals("-classpath") || args[i].equals("-cp")) {
 480             String a = requireArgument(args[i], args, ++i);
 481             for (String p : a.split(File.pathSeparator)) {
 482                 File file = new File(p);
 483                 try {
 484                     classpaths.add(file.toURL());
 485                 } catch (MalformedURLException e) {
 486                     throw new BadCommandLineException(
 487                         Messages.format(Messages.NOT_A_VALID_FILENAME,file),e);
 488                 }
 489             }


 825         }
 826 
 827         if (grammars.isEmpty())
 828             throw new BadCommandLineException(
 829                 Messages.format(Messages.MISSING_GRAMMAR));
 830 
 831         if( schemaLanguage==null )
 832             schemaLanguage = guessSchemaLanguage();
 833 
 834 //        if(target==SpecVersion.V2_2 && !isExtensionMode())
 835 //            throw new BadCommandLineException(
 836 //                "Currently 2.2 is still not finalized yet, so using it requires the -extension switch." +
 837 //                "NOTE THAT 2.2 SPEC MAY CHANGE BEFORE IT BECOMES FINAL.");
 838 
 839         if(pluginLoadFailure!=null)
 840             throw new BadCommandLineException(
 841                 Messages.format(Messages.PLUGIN_LOAD_FAILURE,pluginLoadFailure));
 842     }
 843 
 844     /**
 845      * Finds the <tt>META-INF/sun-jaxb.episode</tt> file to add as a binding customization.
 846      */
 847     public void scanEpisodeFile(File jar) throws BadCommandLineException {
 848         try {
 849             URLClassLoader ucl = new URLClassLoader(new URL[]{jar.toURL()});
 850             Enumeration<URL> resources = ucl.findResources("META-INF/sun-jaxb.episode");
 851             while (resources.hasMoreElements()) {
 852                 URL url = resources.nextElement();
 853                 addBindFile(new InputSource(url.toExternalForm()));
 854             }
 855         } catch (IOException e) {
 856             throw new BadCommandLineException(
 857                     Messages.format(Messages.FAILED_TO_LOAD,jar,e.getMessage()), e);
 858         }
 859     }
 860 
 861 
 862     /**
 863      * Guesses the schema language.
 864      */
 865     public Language guessSchemaLanguage() {




 128     public boolean runtime14 = false;
 129 
 130     /**
 131      * If true, try to resolve name conflicts automatically by assigning mechanical numbers.
 132      */
 133     public boolean automaticNameConflictResolution = false;
 134 
 135     /**
 136      * strictly follow the compatibility rules and reject schemas that
 137      * contain features from App. E.2, use vendor binding extensions
 138      */
 139     public static final int STRICT = 1;
 140     /**
 141      * loosely follow the compatibility rules and allow the use of vendor
 142      * binding extensions
 143      */
 144     public static final int EXTENSION = 2;
 145 
 146     /**
 147      * this switch determines how carefully the compiler will follow
 148      * the compatibility rules in the spec. Either {@code STRICT}
 149      * or {@code EXTENSION}.
 150      */
 151     public int compatibilityMode = STRICT;
 152 
 153     public boolean isExtensionMode() {
 154         return compatibilityMode==EXTENSION;
 155     }
 156 
 157     private static final Logger logger = com.sun.xml.internal.bind.Util.getClassLogger();
 158 
 159     /**
 160      * Generates output for the specified version of the runtime.
 161      */
 162     public SpecVersion target = SpecVersion.LATEST;
 163 
 164 
 165     public Options() {
 166         try {
 167             Class.forName("javax.xml.bind.JAXBPermission");
 168         } catch (ClassNotFoundException cnfe) {
 169             target = SpecVersion.V2_1;
 170         }
 171     }
 172 
 173     /**
 174      * Target directory when producing files.
 175      * <p>
 176      * This field is not used when XJC is driven through the XJC API.
 177      * Plugins that need to generate extra files should do so by using
 178      * {@link JPackage#addResourceFile(JResourceFile)}.
 179      */
 180     public File targetDir = new File(".");
 181 
 182     /**
 183      * Actually stores {@link CatalogResolver}, but the field
 184      * type is made to {@link EntityResolver} so that XJC can be
 185      * used even if resolver.jar is not available in the classpath.
 186      */
 187     public EntityResolver entityResolver = null;
 188 
 189     /**
 190      * Type of input schema language. One of the {@code SCHEMA_XXX}
 191      * constants.
 192      */
 193     private Language schemaLanguage = null;
 194 
 195     /**
 196      * The -p option that should control the default Java package that
 197      * will contain the generated code. Null if unspecified.
 198      */
 199     public String defaultPackage = null;
 200 
 201     /**
 202      * Similar to the -p option, but this one works with a lower priority,
 203      * and customizations overrides this. Used by JAX-RPC.
 204      */
 205     public String defaultPackage2 = null;
 206 
 207     /**
 208      * Input schema files as a list of {@link InputSource}s.
 209      */
 210     private final List<InputSource> grammars = new ArrayList<InputSource>();


 449      * Recursively scan directories and add all ".xjb" files in it.
 450      */
 451     public void addBindFileRecursive( File dir ) {
 452         addRecursive(dir,".xjb",bindFiles);
 453     }
 454 
 455     public final List<URL> classpaths = new ArrayList<URL>();
 456     /**
 457      * Gets a classLoader that can load classes specified via the
 458      * -classpath option.
 459      */
 460     public ClassLoader getUserClassLoader( ClassLoader parent ) {
 461         if (classpaths.isEmpty())
 462             return parent;
 463         return new URLClassLoader(
 464                 classpaths.toArray(new URL[classpaths.size()]),parent);
 465     }
 466 
 467 
 468     /**
 469      * Parses an option {@code args[i]} and return
 470      * the number of tokens consumed.
 471      *
 472      * @return
 473      *      0 if the argument is not understood. Returning 0
 474      *      will let the caller report an error.
 475      * @exception BadCommandLineException
 476      *      If the callee wants to provide a custom message for an error.
 477      */
 478     public int parseArgument( String[] args, int i ) throws BadCommandLineException {
 479         if (args[i].equals("-classpath") || args[i].equals("-cp")) {
 480             String a = requireArgument(args[i], args, ++i);
 481             for (String p : a.split(File.pathSeparator)) {
 482                 File file = new File(p);
 483                 try {
 484                     classpaths.add(file.toURL());
 485                 } catch (MalformedURLException e) {
 486                     throw new BadCommandLineException(
 487                         Messages.format(Messages.NOT_A_VALID_FILENAME,file),e);
 488                 }
 489             }


 825         }
 826 
 827         if (grammars.isEmpty())
 828             throw new BadCommandLineException(
 829                 Messages.format(Messages.MISSING_GRAMMAR));
 830 
 831         if( schemaLanguage==null )
 832             schemaLanguage = guessSchemaLanguage();
 833 
 834 //        if(target==SpecVersion.V2_2 && !isExtensionMode())
 835 //            throw new BadCommandLineException(
 836 //                "Currently 2.2 is still not finalized yet, so using it requires the -extension switch." +
 837 //                "NOTE THAT 2.2 SPEC MAY CHANGE BEFORE IT BECOMES FINAL.");
 838 
 839         if(pluginLoadFailure!=null)
 840             throw new BadCommandLineException(
 841                 Messages.format(Messages.PLUGIN_LOAD_FAILURE,pluginLoadFailure));
 842     }
 843 
 844     /**
 845      * Finds the {@code META-INF/sun-jaxb.episode} file to add as a binding customization.
 846      */
 847     public void scanEpisodeFile(File jar) throws BadCommandLineException {
 848         try {
 849             URLClassLoader ucl = new URLClassLoader(new URL[]{jar.toURL()});
 850             Enumeration<URL> resources = ucl.findResources("META-INF/sun-jaxb.episode");
 851             while (resources.hasMoreElements()) {
 852                 URL url = resources.nextElement();
 853                 addBindFile(new InputSource(url.toExternalForm()));
 854             }
 855         } catch (IOException e) {
 856             throw new BadCommandLineException(
 857                     Messages.format(Messages.FAILED_TO_LOAD,jar,e.getMessage()), e);
 858         }
 859     }
 860 
 861 
 862     /**
 863      * Guesses the schema language.
 864      */
 865     public Language guessSchemaLanguage() {


< prev index next >