/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Global options.
*
* <p>
* This class stores invocation configuration for XJC.
* The configuration in this class should be abstract enough so that
* it could be parsed from both command-line or Ant.
*/
public class Options
{
/** If "-debug" is specified. */
public boolean debugMode;
/** If the "-verbose" option is specified. */
public boolean verbose;
/** If the "-quiet" option is specified. */
public boolean quiet;
/** If the -readOnly option is specified. */
public boolean readOnly;
/** No file header comment (to be more friendly with diff.) */
public boolean noFileHeader;
public boolean enableIntrospection;
/** When on, generates content property for types with multiple xs:any derived elements (which is supposed to be correct behaviour) */
public boolean contentForWildcard;
/** Encoding to be used by generated java sources, null for platform default. */
/**
* Check the source schemas with extra scrutiny.
* The exact meaning depends on the schema language.
*/
public boolean strictCheck =true;
/**
* If -explicit-annotation option is specified.
* <p>
* This generates code that works around issues specific to 1.4 runtime.
*/
public boolean runtime14 = false;
/**
* If true, try to resolve name conflicts automatically by assigning mechanical numbers.
*/
public boolean automaticNameConflictResolution = false;
/**
* strictly follow the compatibility rules and reject schemas that
* contain features from App. E.2, use vendor binding extensions
*/
/**
* loosely follow the compatibility rules and allow the use of vendor
* binding extensions
*/
/**
* this switch determines how carefully the compiler will follow
* the compatibility rules in the spec. Either <code>STRICT</code>
* or <code>EXTENSION</code>.
*/
public boolean isExtensionMode() {
return compatibilityMode==EXTENSION;
}
/**
* Generates output for the specified version of the runtime.
*/
private boolean is2_2 = true;
public Options() {
if (is2_2) {
try {
} catch (ClassNotFoundException cnfe) {
is2_2 = false;
}
if (!is2_2) {
} else {
}
}
}
/**
* Target directory when producing files.
* <p>
* This field is not used when XJC is driven through the XJC API.
* Plugins that need to generate extra files should do so by using
* {@link JPackage#addResourceFile(JResourceFile)}.
*/
/**
* Actually stores {@link CatalogResolver}, but the field
* type is made to {@link EntityResolver} so that XJC can be
* used even if resolver.jar is not available in the classpath.
*/
/**
* Type of input schema language. One of the <code>SCHEMA_XXX</code>
* constants.
*/
/**
* The -p option that should control the default Java package that
* will contain the generated code. Null if unspecified.
*/
/**
* Similar to the -p option, but this one works with a lower priority,
* and customizations overrides this. Used by JAX-RPC.
*/
/**
* Input schema files as a list of {@link InputSource}s.
*/
// Proxy setting.
/**
* {@link Plugin}s that are enabled in this compilation.
*/
/**
* All discovered {@link Plugin}s.
* This is lazily parsed, so that we can take '-cp' option into account.
*
* @see #getAllPlugins()
*/
/**
* Set of URIs that plug-ins recognize as extension bindings.
*/
/**
* This allocator has the final say on deciding the class name.
*/
/**
* This switch controls whether or not xjc will generate package level annotations
*/
public boolean packageLevelAnnotations = true;
/**
* This {@link FieldRendererFactory} determines how the fields are generated.
*/
/**
* Used to detect if two {@link Plugin}s try to overwrite {@link #fieldRendererFactory}.
*/
/**
* If this is non-null, we use this {@link NameConverter} over the one
*/
/**
* Used to detect if two {@link Plugin}s try to overwrite {@link #nameConverter}.
*/
/**
* Gets the active {@link FieldRendererFactory} that shall be used to build {@link Model}.
*
* @return always non-null.
*/
return fieldRendererFactory;
}
/**
* Sets the {@link FieldRendererFactory}.
*
* <p>
* This method is for plugins to call to set a custom {@link FieldRendererFactory}.
*
* @param frf
* The {@link FieldRendererFactory} to be installed. Must not be null.
* @param owner
* Identifies the plugin that owns this {@link FieldRendererFactory}.
* When two {@link Plugin}s try to call this method, this allows XJC
* to report it as a user-friendly error message.
*
* @throws BadCommandLineException
* If a conflit happens, this exception carries a user-friendly error
* message, indicating a conflict.
*/
public void setFieldRendererFactory(FieldRendererFactory frf, Plugin owner) throws BadCommandLineException {
// since this method is for plugins, make it bit more fool-proof than usual
throw new IllegalArgumentException();
if(fieldRendererFactoryOwner!=null) {
throw new BadCommandLineException(
owner.getOptionName() ));
}
this.fieldRendererFactoryOwner = owner;
this.fieldRendererFactory = frf;
}
/**
* Gets the active {@link NameConverter} that shall be used to build {@link Model}.
*
* @return can be null, in which case it's up to the binding.
*/
return nameConverter;
}
/**
* Sets the {@link NameConverter}.
*
* <p>
* This method is for plugins to call to set a custom {@link NameConverter}.
*
* @param nc
* The {@link NameConverter} to be installed. Must not be null.
* @param owner
* Identifies the plugin that owns this {@link NameConverter}.
* When two {@link Plugin}s try to call this method, this allows XJC
* to report it as a user-friendly error message.
*
* @throws BadCommandLineException
* If a conflit happens, this exception carries a user-friendly error
* message, indicating a conflict.
*/
// since this method is for plugins, make it bit more fool-proof than usual
throw new IllegalArgumentException();
if(nameConverter!=null) {
throw new BadCommandLineException(
owner.getOptionName() ));
}
this.nameConverterOwner = owner;
this.nameConverter = nc;
}
/**
* Gets all the {@link Plugin}s discovered so far.
*
* <p>
* A plugins are enumerated when this method is called for the first time,
* by taking {@link #classpaths} into account. That means
* "-cp plugin.jar" has to come before you specify options to enable it.
*/
if(allPlugins==null) {
}
return allPlugins;
}
if( schemaLanguage==null)
return schemaLanguage;
}
this.schemaLanguage = _schemaLanguage;
}
/** Input schema files. */
}
/**
* Adds a new input schema.
*/
}
try {
} catch (MalformedURLException e) {
}
}
}
/**
* Recursively scan directories and add all XSD files in it.
*/
}
if(f.isDirectory())
else
}
}
// absolutize all the system IDs in the input, so that we can map system IDs to DOM trees.
try {
} catch( IOException e ) {
}
return is;
}
/** Input external binding files. */
}
/**
* Adds a new binding file.
*/
}
/**
* Adds a new binding file.
*/
}
/**
* Recursively scan directories and add all ".xjb" files in it.
*/
}
/**
* Gets a classLoader that can load classes specified via the
* -classpath option.
*/
return new URLClassLoader(
}
/**
* Parses an option <code>args[i]</code> and return
* the number of tokens consumed.
*
* @return
* 0 if the argument is not understood. Returning 0
* will let the caller report an error.
* @exception BadCommandLineException
* If the callee wants to provide a custom message for an error.
*/
try {
} catch (MalformedURLException e) {
throw new BadCommandLineException(
}
}
return 2;
}
throw new BadCommandLineException(
return 2;
}
readOnly = true;
return 1;
}
// there won't be any package to annotate, so disable them
// automatically as a usability feature
packageLevelAnnotations = false;
}
return 2;
}
debugMode = true;
verbose = true;
return 1;
}
strictCheck = false;
return 1;
}
packageLevelAnnotations = false;
return 1;
}
noFileHeader = true;
return 1;
}
verbose = true;
return 1;
}
quiet = true;
return 1;
}
runtime14 = true;
return 1;
}
enableIntrospection = true;
return 1;
}
contentForWildcard = true;
return 1;
}
automaticNameConflictResolution = true;
return 1;
}
return 2;
}
return 1;
}
return 1;
}
return 1;
}
return 1;
}
return 1;
}
return 1;
}
return 2;
}
throw new BadCommandLineException(
}
throw new BadCommandLineException(
}
try {
} catch (IOException e) {
throw new BadCommandLineException(
}
return 2;
}
throw new BadCommandLineException(
}
parseProxy(args[++i]);
return 2;
}
return 2;
}
return 2;
}
// use Sun's "XML Entity and URI Resolvers" by Norman Walsh
// to resolve external entities.
try {
} catch (IOException e) {
throw new BadCommandLineException(
}
return 2;
}
//For source 1.0 the 1.0 Driver is loaded
//Hence anything other than 2.0 is defaulted to
//2.0
throw new BadCommandLineException(
return 2;
}
classNameAllocator = new ClassNameAllocator() {
return className+"_Type";
}
};
return 1;
}
try {
throw new BadCommandLineException(
}
} catch (IllegalCharsetNameException icne) {
throw new BadCommandLineException(
}
return 2;
}
// see if this is one of the extensions
try {
plugin.onActivated(this);
// give the plugin a chance to parse arguments to this option.
// this is new in 2.1, and due to the backward compatibility reason,
// if plugin didn't understand it, we still return 1 to indicate
// that this option is consumed.
if(r!=0)
return r;
else
return 1;
}
if(r!=0) return r;
} catch (IOException e) {
throw new BadCommandLineException(e.getMessage(),e);
}
}
return 0; // unrecognized
}
// syntax is [user[:password]@]proxyHost:proxyPort
try {
} catch (NumberFormatException e) {
}
}
/**
* Obtains an operand and reports an error if it's not there.
*/
public String requireArgument(String optionName, String[] args, int i) throws BadCommandLineException {
throw new BadCommandLineException(
}
return args[i];
}
/**
* Parses a token to a file (or a set of files)
* and add them as {@link InputSource} to the specified list.
*
* @param suffix
* If the given token is a directory name, we do a recusive search
* and find all files that have the given suffix.
*/
private void addFile(String name, List<InputSource> target, String suffix) throws BadCommandLineException {
try {
} catch (IOException e) {
throw new BadCommandLineException(
}
} else {
if(fsrc.isDirectory()) {
} else {
}
}
}
/**
* Adds a new catalog file.
*/
if(entityResolver==null) {
entityResolver = new CatalogResolver(true);
}
}
/**
* Parses arguments and fill fields of this object.
*
* @exception BadCommandLineException
* thrown when there's a problem in the command-line arguments
*/
throw new BadCommandLineException();
int j = parseArgument(args,i);
if(j==0)
throw new BadCommandLineException(
i += (j-1);
} else {
else
}
}
// configure proxy
throw new BadCommandLineException(
} else {
throw new BadCommandLineException(
}
if(proxyPassword!=null)
}
throw new BadCommandLineException(
if( schemaLanguage==null )
// if(target==SpecVersion.V2_2 && !isExtensionMode())
// throw new BadCommandLineException(
// "Currently 2.2 is still not finalized yet, so using it requires the -extension switch." +
// "NOTE THAT 2.2 SPEC MAY CHANGE BEFORE IT BECOMES FINAL.");
if(pluginLoadFailure!=null)
throw new BadCommandLineException(
}
/**
* Finds the <tt>META-INF/sun-jaxb.episode</tt> file to add as a binding customization.
*/
try {
while (resources.hasMoreElements()) {
}
} catch (IOException e) {
throw new BadCommandLineException(
}
}
/**
* Guesses the schema language.
*/
// otherwise, use the file extension.
// not a good solution, but very easy.
return Language.RELAXNG_COMPACT;
}
// by default, assume XML Schema
}
/**
* Creates a configured CodeWriter that produces files into the specified directory.
*/
}
/**
* Creates a configured CodeWriter that produces files into the specified directory.
*/
if(noFileHeader)
return core;
}
/**
* Gets the string suitable to be used as the prolog comment baked into artifacts.
*/
// generate format syntax: <date> 'at' <time>
+ " '"
+ "' "
}
/**
* If a plugin failed to load, report.
*/
/**
* create one instance for each class name found inside this file.
*/
// if true, print debug output
final boolean debug = com.sun.tools.internal.xjc.util.Util.getSystemProperty(Options.class,"findServices")!=null;
// if we are running on Mustang or Dolphin, use ServiceLoader
// so that we can take advantage of JSR-277 module system.
try {
if(debug)
Iterable<T> itr = (Iterable<T>)serviceLoader.getMethod("load",Class.class,ClassLoader.class).invoke(null,clazz,classLoader);
for (T t : itr)
r.add(t);
} catch (ClassNotFoundException e) {
// fall through
} catch (IllegalAccessException e) {
Error x = new IllegalAccessError();
x.initCause(e);
throw x;
} catch (InvocationTargetException e) {
Throwable x = e.getTargetException();
if (x instanceof RuntimeException)
throw (RuntimeException) x;
if (x instanceof Error)
throw (Error) x;
throw new Error(x);
} catch (NoSuchMethodException e) {
Error x = new NoSuchMethodError();
x.initCause(e);
throw x;
}
// used to avoid creating the same instance twice
if(debug) {
}
// try to find services in CLASSPATH
try {
while(e.hasMoreElements()) {
if(debug) {
}
try {
// try to instanciate the object
if(debug)
continue;
}
if(debug) {
}
}
}
// let it go.
StringWriter w = new StringWriter();
pluginLoadFailure = w.toString();
if(debug) {
}
try {
} catch( IOException ex2 ) {
// ignore
}
}
}
}
} catch( Throwable e ) {
// ignore any error
StringWriter w = new StringWriter();
e.printStackTrace(new PrintWriter(w));
pluginLoadFailure = w.toString();
if(debug) {
}
}
}
// this is a convenient place to expose the build version to xjc plugins
}
}