--- a/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/Options.java Fri Feb 10 00:39:51 2017 -0800
+++ b/jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/Options.java Thu Feb 16 13:14:39 2017 +0300
@@ -25,6 +25,27 @@
package com.sun.tools.internal.xjc;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.Set;
+
import com.sun.codemodel.internal.CodeWriter;
import com.sun.codemodel.internal.JPackage;
import com.sun.codemodel.internal.JResourceFile;
@@ -37,40 +58,16 @@
import com.sun.tools.internal.xjc.model.Model;
import com.sun.tools.internal.xjc.reader.Util;
import com.sun.xml.internal.bind.api.impl.NameConverter;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
import java.util.Locale;
-import java.util.ServiceLoader;
-import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.xml.catalog.CatalogFeatures;
-import javax.xml.catalog.CatalogFeatures.Feature;
-import javax.xml.catalog.CatalogManager;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
/**
* Global options.
@@ -181,7 +178,7 @@
public File targetDir = new File(".");
/**
- * Actually stores {@link CatalogResolver}, but the field
+ * On JDK 8 an odler stores {@code 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.
*/
@@ -208,9 +205,9 @@
/**
* Input schema files as a list of {@link InputSource}s.
*/
- private final List<InputSource> grammars = new ArrayList<InputSource>();
+ private final List<InputSource> grammars = new ArrayList<>();
- private final List<InputSource> bindFiles = new ArrayList<InputSource>();
+ private final List<InputSource> bindFiles = new ArrayList<>();
// Proxy setting.
private String proxyHost = null;
@@ -220,7 +217,7 @@
/**
* {@link Plugin}s that are enabled in this compilation.
*/
- public final List<Plugin> activePlugins = new ArrayList<Plugin>();
+ public final List<Plugin> activePlugins = new ArrayList<>();
/**
* All discovered {@link Plugin}s.
@@ -233,7 +230,7 @@
/**
* Set of URIs that plug-ins recognize as extension bindings.
*/
- public final Set<String> pluginURIs = new HashSet<String>();
+ public final Set<String> pluginURIs = new HashSet<>();
/**
* This allocator has the final say on deciding the class name.
@@ -357,6 +354,7 @@
* 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.
+ * @return
*/
public List<Plugin> getAllPlugins() {
if(allPlugins==null) {
@@ -375,13 +373,15 @@
this.schemaLanguage = _schemaLanguage;
}
- /** Input schema files. */
+ /** Input schema files.
+ * @return */
public InputSource[] getGrammars() {
return grammars.toArray(new InputSource[grammars.size()]);
}
/**
* Adds a new input schema.
+ * @param is
*/
public void addGrammar( InputSource is ) {
grammars.add(absolutize(is));
@@ -402,6 +402,7 @@
/**
* Recursively scan directories and add all XSD files in it.
+ * @param dir
*/
public void addGrammarRecursive( File dir ) {
addRecursive(dir,".xsd",grammars);
@@ -432,13 +433,15 @@
return is;
}
- /** Input external binding files. */
+ /** Input external binding files.
+ * @return */
public InputSource[] getBindFiles() {
return bindFiles.toArray(new InputSource[bindFiles.size()]);
}
/**
* Adds a new binding file.
+ * @param is
*/
public void addBindFile( InputSource is ) {
bindFiles.add(absolutize(is));
@@ -446,6 +449,7 @@
/**
* Adds a new binding file.
+ * @param bindFile
*/
public void addBindFile( File bindFile ) {
bindFiles.add(fileToInputSource(bindFile));
@@ -453,15 +457,18 @@
/**
* Recursively scan directories and add all ".xjb" files in it.
+ * @param dir
*/
public void addBindFileRecursive( File dir ) {
addRecursive(dir,".xjb",bindFiles);
}
- public final List<URL> classpaths = new ArrayList<URL>();
+ public final List<URL> classpaths = new ArrayList<>();
/**
* Gets a classLoader that can load classes specified via the
* -classpath option.
+ * @param parent
+ * @return
*/
public ClassLoader getUserClassLoader( ClassLoader parent ) {
if (classpaths.isEmpty())
@@ -482,6 +489,8 @@
* Parses an option {@code args[i]} and return
* the number of tokens consumed.
*
+ * @param args
+ * @param i
* @return
* 0 if the argument is not understood. Returning 0
* will let the caller report an error.
@@ -610,10 +619,8 @@
Messages.format(Messages.NO_SUCH_FILE,file));
}
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"))) {
parseProxy(in.readLine());
- in.close();
} catch (IOException e) {
throw new BadCommandLineException(
Messages.format(Messages.FAILED_TO_PARSE,file,e.getMessage()),e);
@@ -639,7 +646,9 @@
return 2;
}
if( args[i].equals("-catalog") ) {
- // use javax.xml.catalog to resolve external entities.
+ // use Sun's "XML Entity and URI Resolvers" by Norman Walsh
+ // to resolve external entities.
+ // https://xerces.apache.org/xml-commons/components/resolver/resolver-article.html
File catalogFile = new File(requireArgument("-catalog",args,++i));
try {
@@ -652,6 +661,7 @@
}
if( args[i].equals("-Xtest-class-name-allocator") ) {
classNameAllocator = new ClassNameAllocator() {
+ @Override
public String assignClassName(String packageName, String className) {
System.out.printf("assignClassName(%s,%s)\n",packageName,className);
return className+"_Type";
@@ -736,6 +746,11 @@
/**
* Obtains an operand and reports an error if it's not there.
+ * @param optionName
+ * @param args
+ * @param i
+ * @return
+ * @throws com.sun.tools.internal.xjc.BadCommandLineException
*/
public String requireArgument(String optionName, String[] args, int i) throws BadCommandLineException {
if (i == args.length || args[i].startsWith("-")) {
@@ -773,34 +788,27 @@
}
}
- /**
- * Adds a new catalog file.
- */
- public void addCatalog(File catalogFile) throws IOException {
- URI newUrl = catalogFile.toURI();
- if (!catalogUrls.contains(newUrl)) {
- catalogUrls.add(newUrl);
- }
- try {
- entityResolver = CatalogManager.catalogResolver(catalogFeatures,
- catalogUrls.stream().toArray(URI[]::new));
- } catch (Exception ex) {
- entityResolver = null;
- }
- }
-
// Since javax.xml.catalog is unmodifiable we need to track catalog
// URLs added and create new catalog each time addCatalog is called
private final ArrayList<URI> catalogUrls = new ArrayList<>();
- // Cache CatalogFeatures instance for future usages.
- // Resolve feature is set to "continue" value for backward compatibility.
- private static CatalogFeatures catalogFeatures = CatalogFeatures.builder()
- .with(Feature.RESOLVE, "continue")
- .build();
+ /**
+ * Adds a new catalog file.Use created or existed resolver to parse new catalog file.
+ * @param catalogFile
+ * @throws java.io.IOException
+ */
+ public void addCatalog(File catalogFile) throws IOException {
+ URI newUri = catalogFile.toURI();
+ if (!catalogUrls.contains(newUri)) {
+ catalogUrls.add(newUri);
+ }
+ entityResolver = CatalogUtil.getCatalog(entityResolver, catalogFile, catalogUrls);
+ }
+
/**
* Parses arguments and fill fields of this object.
*
+ * @param args
* @exception BadCommandLineException
* thrown when there's a problem in the command-line arguments
*/
@@ -861,6 +869,8 @@
/**
* Finds the {@code META-INF/sun-jaxb.episode} file to add as a binding customization.
+ * @param jar
+ * @throws com.sun.tools.internal.xjc.BadCommandLineException
*/
public void scanEpisodeFile(File jar) throws BadCommandLineException {
try {
@@ -879,6 +889,7 @@
/**
* Guesses the schema language.
+ * @return
*/
public Language guessSchemaLanguage() {
@@ -899,6 +910,8 @@
/**
* Creates a configured CodeWriter that produces files into the specified directory.
+ * @return
+ * @throws java.io.IOException
*/
public CodeWriter createCodeWriter() throws IOException {
return createCodeWriter(new FileCodeWriter( targetDir, readOnly, encoding ));
@@ -906,6 +919,8 @@
/**
* Creates a configured CodeWriter that produces files into the specified directory.
+ * @param core
+ * @return
*/
public CodeWriter createCodeWriter( CodeWriter core ) {
if(noFileHeader)
@@ -915,8 +930,8 @@
}
/**
- * Gets the string suitable to be used as the prolog comment baked into artifacts.
- * This is the string like "This file was generated by the JAXB RI on YYYY/mm/dd..."
+ * Gets the string suitable to be used as the prolog comment baked into artifacts.This is the string like "This file was generated by the JAXB RI on YYYY/mm/dd..."
+ * @return
*/
public String getPrologComment() {
// generate format syntax: <date> 'at' <time>
@@ -943,7 +958,7 @@
* create one instance for each class name found inside this file.
*/
private <T> List<T> findServices( Class<T> clazz) {
- final List<T> result = new ArrayList<T>();
+ final List<T> result = new ArrayList<>();
final boolean debug = getDebugPropertyValue();
try {
// TCCL allows user plugins to be loaded even if xjc is in jdk