feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
284
jdkSrc/jdk8/com/sun/tools/internal/jxc/ConfigReader.java
Normal file
284
jdkSrc/jdk8/com/sun/tools/internal/jxc/ConfigReader.java
Normal file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc;
|
||||
|
||||
import com.sun.tools.internal.jxc.ap.Options;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.validation.ValidatorHandler;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import com.sun.tools.internal.jxc.gen.config.Config;
|
||||
import com.sun.tools.internal.jxc.gen.config.Schema;
|
||||
import com.sun.tools.internal.xjc.SchemaCache;
|
||||
import com.sun.tools.internal.xjc.api.Reference;
|
||||
import com.sun.tools.internal.xjc.util.ForkContentHandler;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.util.XmlFactory;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
|
||||
/**
|
||||
* This reads the config files passed by the user to annotation processing
|
||||
* and obtains a list of classes that need to be included
|
||||
* for a particular config from the set of classes passed
|
||||
* by the user to annotation processing.
|
||||
*
|
||||
* @author Bhakti Mehta (bhakti.mehta@sun.com)
|
||||
*/
|
||||
public final class ConfigReader {
|
||||
|
||||
/**
|
||||
* The set of classes to be passed to XJC
|
||||
*
|
||||
*/
|
||||
private final Set<Reference> classesToBeIncluded = new HashSet<Reference>();
|
||||
|
||||
|
||||
/**
|
||||
* The SchemaOutputResolver used to generate the schemas
|
||||
*/
|
||||
private final SchemaOutputResolver schemaOutputResolver;
|
||||
|
||||
private final ProcessingEnvironment env;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param classes
|
||||
* The set of classes passed to the AnnotationProcessor
|
||||
* @param xmlFile
|
||||
* The configuration file.
|
||||
* @throws SAXException
|
||||
* If this is thrown, the error has already been reported.
|
||||
* @throws IOException
|
||||
* If any IO errors occur.
|
||||
*/
|
||||
public ConfigReader(ProcessingEnvironment env, Collection<? extends TypeElement> classes, File xmlFile, ErrorHandler errorHandler) throws SAXException, IOException {
|
||||
this.env = env;
|
||||
Config config = parseAndGetConfig(xmlFile, errorHandler, env.getOptions().containsKey(Options.DISABLE_XML_SECURITY));
|
||||
checkAllClasses(config,classes);
|
||||
String path = xmlFile.getAbsolutePath();
|
||||
String xmlPath = path.substring(0,path.lastIndexOf(File.separatorChar));
|
||||
schemaOutputResolver = createSchemaOutputResolver(config,xmlPath);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This creates a regular expression
|
||||
* for the user pattern , matches the input classes
|
||||
* passed by the user and returns the final
|
||||
* list of classes that need to be included for a config file
|
||||
* after applying those patterns
|
||||
*
|
||||
*/
|
||||
public Collection<Reference> getClassesToBeIncluded() {
|
||||
return classesToBeIncluded;
|
||||
}
|
||||
|
||||
private void checkAllClasses(Config config, Collection<? extends TypeElement> rootClasses) {
|
||||
|
||||
List<Pattern> includeRegexList = config.getClasses().getIncludes();
|
||||
List<Pattern> excludeRegexList = config.getClasses().getExcludes();
|
||||
|
||||
OUTER:
|
||||
for (TypeElement typeDecl : rootClasses) {
|
||||
|
||||
String qualifiedName = typeDecl.getQualifiedName().toString();
|
||||
|
||||
for (Pattern pattern : excludeRegexList) {
|
||||
boolean match = checkPatternMatch(qualifiedName, pattern);
|
||||
if (match)
|
||||
continue OUTER; // excluded
|
||||
}
|
||||
|
||||
for (Pattern pattern : includeRegexList) {
|
||||
boolean match = checkPatternMatch(qualifiedName, pattern);
|
||||
if (match) {
|
||||
classesToBeIncluded.add(new Reference(typeDecl,env));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the SchemaOutputResolver to generate the schemas
|
||||
*/
|
||||
public SchemaOutputResolver getSchemaOutputResolver(){
|
||||
return schemaOutputResolver;
|
||||
}
|
||||
|
||||
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
|
||||
File baseDir = new File(xmlpath, config.getBaseDir().getPath());
|
||||
SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);
|
||||
|
||||
for( Schema schema : (List<Schema>)config.getSchema() ) {
|
||||
String namespace = schema.getNamespace();
|
||||
File location = schema.getLocation();
|
||||
outResolver.addSchemaInfo(namespace,location);
|
||||
}
|
||||
return outResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will check if the qualified name matches the pattern
|
||||
*
|
||||
* @param qualifiedName
|
||||
* The qualified name of the TypeDeclaration
|
||||
* @param pattern
|
||||
* The pattern obtained from the users input
|
||||
*
|
||||
*/
|
||||
private boolean checkPatternMatch(String qualifiedName, Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(qualifiedName);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Lazily parsed schema for the binding file.
|
||||
*/
|
||||
private static SchemaCache configSchema = new SchemaCache(Config.class.getResource("config.xsd"));
|
||||
|
||||
|
||||
/**
|
||||
* Parses an xml config file and returns a Config object.
|
||||
*
|
||||
* @param xmlFile
|
||||
* The xml config file which is passed by the user to annotation processing
|
||||
* @return
|
||||
* A non null Config object
|
||||
*/
|
||||
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
|
||||
XMLReader reader;
|
||||
try {
|
||||
SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
|
||||
reader = factory.newSAXParser().getXMLReader();
|
||||
} catch (ParserConfigurationException e) {
|
||||
// in practice this will never happen
|
||||
throw new Error(e);
|
||||
}
|
||||
NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
|
||||
|
||||
// set up validator
|
||||
ValidatorHandler validator = configSchema.newValidator();
|
||||
validator.setErrorHandler(errorHandler);
|
||||
|
||||
// the validator will receive events first, then the parser.
|
||||
reader.setContentHandler(new ForkContentHandler(validator,runtime));
|
||||
|
||||
reader.setErrorHandler(errorHandler);
|
||||
Config config = new Config(runtime);
|
||||
runtime.setRootHandler(config);
|
||||
reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
|
||||
runtime.reset();
|
||||
|
||||
return config;
|
||||
}
|
||||
/**
|
||||
* Controls where the JAXB RI puts the generates
|
||||
* schema files.
|
||||
* @author
|
||||
* Bhakti Mehta (bhakti.mehta@sun.com)
|
||||
*/
|
||||
private static final class SchemaOutputResolverImpl extends SchemaOutputResolver{
|
||||
|
||||
/**
|
||||
* Directory to which we put the rest of the files.
|
||||
* Never be null.
|
||||
*/
|
||||
private final File baseDir;
|
||||
|
||||
/**
|
||||
* Namespace URI to the location of the schema.
|
||||
* This captures what the user specifies.
|
||||
*/
|
||||
private final Map<String,File> schemas = new HashMap<String,File>();
|
||||
|
||||
|
||||
/**
|
||||
* Decides where the schema file (of the given namespace URI)
|
||||
* will be written, and return it as a {@link Result} object.
|
||||
*
|
||||
*/
|
||||
public Result createOutput( String namespaceUri, String suggestedFileName ) {
|
||||
|
||||
// the user's preference takes a precedence
|
||||
if(schemas.containsKey(namespaceUri)) {
|
||||
File loc = schemas.get(namespaceUri);
|
||||
if(loc==null) return null; // specifically not to generate a schema
|
||||
|
||||
// create directories if necessary. we've already checked that the baseDir
|
||||
// exists, so this should be no surprise to users.
|
||||
loc.getParentFile().mkdirs();
|
||||
|
||||
return new StreamResult(loc); // generate into a file the user specified.
|
||||
}
|
||||
|
||||
// if the user didn't say anything about this namespace,
|
||||
// generate it into the default directory with a default name.
|
||||
|
||||
File schemaFile = new File (baseDir, suggestedFileName);
|
||||
// The systemId for the result will be schemaFile
|
||||
return new StreamResult(schemaFile);
|
||||
}
|
||||
|
||||
|
||||
public SchemaOutputResolverImpl(File baseDir) {
|
||||
assert baseDir!=null;
|
||||
this.baseDir = baseDir;
|
||||
}
|
||||
|
||||
public void addSchemaInfo(String namespaceUri, File location) {
|
||||
if (namespaceUri == null )
|
||||
//generate elements in no namespace
|
||||
namespaceUri = "";
|
||||
schemas.put(namespaceUri, location);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
55
jdkSrc/jdk8/com/sun/tools/internal/jxc/Messages.java
Normal file
55
jdkSrc/jdk8/com/sun/tools/internal/jxc/Messages.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Message resources.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
enum Messages {
|
||||
// Accessor
|
||||
UNEXPECTED_NGCC_TOKEN, // 3 args
|
||||
BASEDIR_DOESNT_EXIST, // 1 arg
|
||||
USAGE, //0 args
|
||||
FULLVERSION, // 0 args
|
||||
VERSION, // 0 args
|
||||
;
|
||||
|
||||
private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getPackage().getName() +".MessageBundle");
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format();
|
||||
}
|
||||
|
||||
public String format( Object... args ) {
|
||||
return MessageFormat.format( rb.getString(name()), args );
|
||||
}
|
||||
}
|
||||
165
jdkSrc/jdk8/com/sun/tools/internal/jxc/NGCCRuntimeEx.java
Normal file
165
jdkSrc/jdk8/com/sun/tools/internal/jxc/NGCCRuntimeEx.java
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.sun.tools.internal.jxc.gen.config.NGCCRuntime;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
|
||||
/**
|
||||
* Controls the validating and converting of values obtained
|
||||
* from the config file.
|
||||
*
|
||||
* @author
|
||||
* Bhakti Mehta (bhakti.mehta@sun.com)
|
||||
*/
|
||||
public final class NGCCRuntimeEx extends NGCCRuntime {
|
||||
/**
|
||||
* All the errors shall be sent to this object.
|
||||
*/
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public NGCCRuntimeEx(ErrorHandler errorHandler) {
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will check if the baseDir provided by the user
|
||||
* in the config file exists. If not it throws an error
|
||||
* @param baseDir
|
||||
* The baseDir attribute passed by the user in the xml config file as a path
|
||||
* @return
|
||||
* The file representation of the path name
|
||||
*/
|
||||
public File getBaseDir(String baseDir) throws SAXException {
|
||||
File dir = new File(baseDir);
|
||||
if (dir.exists()) {
|
||||
return dir;
|
||||
} else {
|
||||
SAXParseException e = new SAXParseException(
|
||||
Messages.BASEDIR_DOESNT_EXIST.format(dir.getAbsolutePath()),
|
||||
getLocator());
|
||||
errorHandler.error(e);
|
||||
throw e; // we can't recover from this error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This takes the include list provided by the user in the config file
|
||||
* It converts the user values to {@link Pattern}
|
||||
* @param includeContent
|
||||
* The include list specified by the user
|
||||
* @return
|
||||
* A list of regular expression patterns {@link Pattern}
|
||||
*/
|
||||
public List<Pattern> getIncludePatterns(List<String> includeContent ) {
|
||||
List<Pattern> includeRegexList = new ArrayList<Pattern>();
|
||||
for (String includes : includeContent) {
|
||||
String regex = convertToRegex(includes);
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
includeRegexList.add(pattern);
|
||||
}
|
||||
return includeRegexList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This takes the exclude list provided by the user in the config file
|
||||
* It converts the user values to {@link Pattern}
|
||||
* @param excludeContent
|
||||
* The exclude list specified by the user
|
||||
* @return
|
||||
* A list of regular expression patterns {@link Pattern}
|
||||
*/
|
||||
public List getExcludePatterns(List<String> excludeContent ) {
|
||||
List<Pattern> excludeRegexList = new ArrayList<Pattern>();
|
||||
for (String excludes : excludeContent) {
|
||||
String regex = convertToRegex(excludes);
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
excludeRegexList.add(pattern);
|
||||
}
|
||||
return excludeRegexList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This will tokenize the pattern and convert it into a regular expression
|
||||
* @param pattern
|
||||
*/
|
||||
private String convertToRegex(String pattern) {
|
||||
StringBuilder regex = new StringBuilder();
|
||||
char nc = ' ';
|
||||
if (pattern.length() >0 ) {
|
||||
|
||||
for ( int i = 0 ; i < pattern.length(); i ++ ) {
|
||||
char c = pattern.charAt(i);
|
||||
nc = ' ';
|
||||
if ((i +1) != pattern.length()) {
|
||||
nc = pattern.charAt(i +1);
|
||||
}
|
||||
//escape single '.'
|
||||
if (c == '.' && nc != '.'){
|
||||
regex.append('\\');
|
||||
regex.append('.');
|
||||
//do not allow patterns like a..b
|
||||
} else if (c == '.'){
|
||||
continue;
|
||||
// "**" gets replaced by ".*"
|
||||
} else if ((c=='*') && (nc == '*')) {
|
||||
regex.append(".*");
|
||||
break;
|
||||
//'*' replaced by anything but '.' i.e [^\\.]+
|
||||
} else if (c=='*') {
|
||||
regex.append("[^\\.]+");
|
||||
continue;
|
||||
//'?' replaced by anything but '.' i.e [^\\.]
|
||||
} else if (c=='?') {
|
||||
regex.append("[^\\.]");
|
||||
//else leave the chars as they occur in the pattern
|
||||
} else
|
||||
regex.append(c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return regex.toString();
|
||||
}
|
||||
|
||||
protected void unexpectedX(String token) throws SAXException {
|
||||
errorHandler.error(
|
||||
new SAXParseException(Messages.UNEXPECTED_NGCC_TOKEN.format(
|
||||
token, getLocator().getLineNumber(), getLocator().getColumnNumber()),
|
||||
getLocator()));
|
||||
}
|
||||
}
|
||||
341
jdkSrc/jdk8/com/sun/tools/internal/jxc/SchemaGenerator.java
Normal file
341
jdkSrc/jdk8/com/sun/tools/internal/jxc/SchemaGenerator.java
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc;
|
||||
|
||||
import com.sun.tools.internal.jxc.ap.Options;
|
||||
import com.sun.tools.internal.xjc.BadCommandLineException;
|
||||
import com.sun.xml.internal.bind.util.Which;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.OptionChecker;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* CLI entry-point to the schema generator.
|
||||
*
|
||||
* @author Bhakti Mehta
|
||||
*/
|
||||
public class SchemaGenerator {
|
||||
/**
|
||||
* Runs the schema generator.
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.exit(run(args));
|
||||
}
|
||||
|
||||
public static int run(String[] args) throws Exception {
|
||||
try {
|
||||
ClassLoader cl = SecureLoader.getClassClassLoader(SchemaGenerator.class);
|
||||
if (cl==null) {
|
||||
cl = SecureLoader.getSystemClassLoader();
|
||||
}
|
||||
return run(args, cl);
|
||||
} catch(Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the schema generator.
|
||||
*
|
||||
* @param classLoader
|
||||
* the schema generator will run in this classLoader.
|
||||
* It needs to be able to load annotation processing and JAXB RI classes. Note that
|
||||
* JAXB RI classes refer to annotation processing classes. Must not be null.
|
||||
*
|
||||
* @return
|
||||
* exit code. 0 if success.
|
||||
*
|
||||
*/
|
||||
public static int run(String[] args, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
final Options options = new Options();
|
||||
if (args.length ==0) {
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
for (String arg : args) {
|
||||
if (arg.equals("-help")) {
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (arg.equals("-version")) {
|
||||
System.out.println(Messages.VERSION.format());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (arg.equals("-fullversion")) {
|
||||
System.out.println(Messages.FULLVERSION.format());
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
options.parseArguments(args);
|
||||
} catch (BadCommandLineException e) {
|
||||
// there was an error in the command line.
|
||||
// print usage and abort.
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println();
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
Class schemagenRunner = classLoader.loadClass(Runner.class.getName());
|
||||
Method compileMethod = schemagenRunner.getDeclaredMethod("compile",String[].class,File.class);
|
||||
|
||||
List<String> aptargs = new ArrayList<String>();
|
||||
|
||||
if (options.encoding != null) {
|
||||
aptargs.add("-encoding");
|
||||
aptargs.add(options.encoding);
|
||||
}
|
||||
|
||||
aptargs.add("-cp");
|
||||
aptargs.add(setClasspath(options.classpath)); // set original classpath + jaxb-api to be visible to annotation processor
|
||||
|
||||
if(options.targetDir!=null) {
|
||||
aptargs.add("-d");
|
||||
aptargs.add(options.targetDir.getPath());
|
||||
}
|
||||
|
||||
aptargs.addAll(options.arguments);
|
||||
|
||||
String[] argsarray = aptargs.toArray(new String[aptargs.size()]);
|
||||
return ((Boolean) compileMethod.invoke(null, argsarray, options.episodeFile)) ? 0 : 1;
|
||||
}
|
||||
|
||||
private static String setClasspath(String givenClasspath) {
|
||||
StringBuilder cp = new StringBuilder();
|
||||
appendPath(cp, givenClasspath);
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
while (cl != null) {
|
||||
if (cl instanceof URLClassLoader) {
|
||||
for (URL url : ((URLClassLoader) cl).getURLs()) {
|
||||
appendPath(cp, url.getPath());
|
||||
}
|
||||
}
|
||||
cl = cl.getParent();
|
||||
}
|
||||
|
||||
appendPath(cp, findJaxbApiJar());
|
||||
return cp.toString();
|
||||
}
|
||||
|
||||
private static void appendPath(StringBuilder cp, String url) {
|
||||
if (url == null || url.trim().isEmpty())
|
||||
return;
|
||||
if (cp.length() != 0)
|
||||
cp.append(File.pathSeparatorChar);
|
||||
cp.append(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the file system path of <tt>jaxb-api.jar</tt> so that
|
||||
* Annotation Processing will see them in the <tt>-cp</tt> option.
|
||||
*
|
||||
* <p>
|
||||
* In Java, you can't do this reliably (for that matter there's no guarantee
|
||||
* that such a jar file exists, such as in Glassfish), so we do the best we can.
|
||||
*
|
||||
* @return
|
||||
* null if failed to locate it.
|
||||
*/
|
||||
private static String findJaxbApiJar() {
|
||||
String url = Which.which(JAXBContext.class);
|
||||
if(url==null) return null; // impossible, but hey, let's be defensive
|
||||
|
||||
if(!url.startsWith("jar:") || url.lastIndexOf('!')==-1)
|
||||
// no jar file
|
||||
return null;
|
||||
|
||||
String jarFileUrl = url.substring(4,url.lastIndexOf('!'));
|
||||
if(!jarFileUrl.startsWith("file:"))
|
||||
return null; // not from file system
|
||||
|
||||
try {
|
||||
File f = new File(new URL(jarFileUrl).toURI());
|
||||
if (f.exists() && f.getName().endsWith(".jar")) { // see 6510966
|
||||
return f.getPath();
|
||||
}
|
||||
f = new File(new URL(jarFileUrl).getFile());
|
||||
if (f.exists() && f.getName().endsWith(".jar")) { // this is here for potential backw. compatibility issues
|
||||
return f.getPath();
|
||||
}
|
||||
} catch (URISyntaxException ex) {
|
||||
Logger.getLogger(SchemaGenerator.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (MalformedURLException ex) {
|
||||
Logger.getLogger(SchemaGenerator.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void usage( ) {
|
||||
System.out.println(Messages.USAGE.format());
|
||||
}
|
||||
|
||||
public static final class Runner {
|
||||
public static boolean compile(String[] args, File episode) throws Exception {
|
||||
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
|
||||
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
|
||||
JavacOptions options = JavacOptions.parse(compiler, fileManager, args);
|
||||
List<String> unrecognizedOptions = options.getUnrecognizedOptions();
|
||||
if (!unrecognizedOptions.isEmpty())
|
||||
Logger.getLogger(SchemaGenerator.class.getName()).log(Level.WARNING, "Unrecognized options found: {0}", unrecognizedOptions);
|
||||
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(options.getFiles());
|
||||
JavaCompiler.CompilationTask task = compiler.getTask(
|
||||
null,
|
||||
fileManager,
|
||||
diagnostics,
|
||||
options.getRecognizedOptions(),
|
||||
options.getClassNames(),
|
||||
compilationUnits);
|
||||
com.sun.tools.internal.jxc.ap.SchemaGenerator r = new com.sun.tools.internal.jxc.ap.SchemaGenerator();
|
||||
if (episode != null)
|
||||
r.setEpisodeFile(episode);
|
||||
task.setProcessors(Collections.singleton(r));
|
||||
boolean res = task.call();
|
||||
//Print messages generated by compiler
|
||||
for (Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics()) {
|
||||
System.err.println(d.toString());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Peter von der Ahe
|
||||
*/
|
||||
private static final class JavacOptions {
|
||||
private final List<String> recognizedOptions;
|
||||
private final List<String> classNames;
|
||||
private final List<File> files;
|
||||
private final List<String> unrecognizedOptions;
|
||||
|
||||
private JavacOptions(List<String> recognizedOptions, List<String> classNames, List<File> files,
|
||||
List<String> unrecognizedOptions) {
|
||||
this.recognizedOptions = recognizedOptions;
|
||||
this.classNames = classNames;
|
||||
this.files = files;
|
||||
this.unrecognizedOptions = unrecognizedOptions;
|
||||
}
|
||||
|
||||
public static JavacOptions parse(OptionChecker primary, OptionChecker secondary, String... arguments) {
|
||||
List<String> recognizedOptions = new ArrayList<String>();
|
||||
List<String> unrecognizedOptions = new ArrayList<String>();
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
List<File> files = new ArrayList<File>();
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
String argument = arguments[i];
|
||||
int optionCount = primary.isSupportedOption(argument);
|
||||
if (optionCount < 0) {
|
||||
optionCount = secondary.isSupportedOption(argument);
|
||||
}
|
||||
if (optionCount < 0) {
|
||||
File file = new File(argument);
|
||||
if (file.exists())
|
||||
files.add(file);
|
||||
else if (SourceVersion.isName(argument))
|
||||
classNames.add(argument);
|
||||
else
|
||||
unrecognizedOptions.add(argument);
|
||||
} else {
|
||||
for (int j = 0; j < optionCount + 1; j++) {
|
||||
int index = i + j;
|
||||
if (index == arguments.length) throw new IllegalArgumentException(argument);
|
||||
recognizedOptions.add(arguments[index]);
|
||||
}
|
||||
i += optionCount;
|
||||
}
|
||||
}
|
||||
return new JavacOptions(recognizedOptions, classNames, files, unrecognizedOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of recognized options and their arguments.
|
||||
*
|
||||
* @return a list of options
|
||||
*/
|
||||
public List<String> getRecognizedOptions() {
|
||||
return Collections.unmodifiableList(recognizedOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of file names.
|
||||
*
|
||||
* @return a list of file names
|
||||
*/
|
||||
public List<File> getFiles() {
|
||||
return Collections.unmodifiableList(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of class names.
|
||||
*
|
||||
* @return a list of class names
|
||||
*/
|
||||
public List<String> getClassNames() {
|
||||
return Collections.unmodifiableList(classNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of unrecognized options.
|
||||
*
|
||||
* @return a list of unrecognized options
|
||||
*/
|
||||
public List<String> getUnrecognizedOptions() {
|
||||
return Collections.unmodifiableList(unrecognizedOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("recognizedOptions = %s; classNames = %s; " + "files = %s; unrecognizedOptions = %s", recognizedOptions, classNames, files, unrecognizedOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* CLI entry point to schemagen that checks for JDK 5.0
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class SchemaGeneratorFacade {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
try {
|
||||
ClassLoader cl = SecureLoader.getClassClassLoader(SchemaGeneratorFacade.class);
|
||||
if(cl==null) cl = SecureLoader.getSystemClassLoader();
|
||||
|
||||
Class driver = cl.loadClass("com.sun.tools.internal.jxc.SchemaGenerator");
|
||||
Method mainMethod = driver.getDeclaredMethod("main", new Class[]{String[].class});
|
||||
try {
|
||||
mainMethod.invoke(null,new Object[]{args});
|
||||
} catch (IllegalAccessException e) {
|
||||
throw e;
|
||||
} catch (InvocationTargetException e) {
|
||||
if(e.getTargetException()!=null)
|
||||
throw e.getTargetException();
|
||||
}
|
||||
} catch (UnsupportedClassVersionError e) {
|
||||
System.err.println("schemagen requires JDK 6.0 or later. Please download it from http://www.oracle.com/technetwork/java/javase/downloads");
|
||||
}
|
||||
}
|
||||
}
|
||||
75
jdkSrc/jdk8/com/sun/tools/internal/jxc/SecureLoader.java
Normal file
75
jdkSrc/jdk8/com/sun/tools/internal/jxc/SecureLoader.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc;
|
||||
|
||||
/**
|
||||
* Class defined for safe calls of getClassLoader methods of any kind (context/system/class
|
||||
* classloader. This MUST be package private and defined in every package which
|
||||
* uses such invocations.
|
||||
* @author snajper
|
||||
*/
|
||||
class SecureLoader {
|
||||
|
||||
static ClassLoader getContextClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
} else {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getClassClassLoader(final Class c) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return c.getClassLoader();
|
||||
} else {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
return c.getClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getSystemClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
} else {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
145
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/AnnotationParser.java
Normal file
145
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/AnnotationParser.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
import com.sun.tools.internal.jxc.ConfigReader;
|
||||
import com.sun.tools.internal.jxc.api.JXC;
|
||||
import com.sun.tools.internal.xjc.ErrorReceiver;
|
||||
import com.sun.tools.internal.xjc.api.J2SJAXBModel;
|
||||
import com.sun.tools.internal.xjc.api.Reference;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
import javax.annotation.processing.SupportedOptions;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import javax.xml.namespace.QName;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* This class behaves as a JAXB Annotation Processor,
|
||||
* It reads the user specified typeDeclarations
|
||||
* and the config files
|
||||
* It also reads config files
|
||||
*
|
||||
* Used in unit tests
|
||||
*
|
||||
* @author Bhakti Mehta (bhakti.mehta@sun.com)
|
||||
*/
|
||||
@SupportedAnnotationTypes("javax.xml.bind.annotation.*")
|
||||
@SupportedOptions("jaxb.config")
|
||||
public final class AnnotationParser extends AbstractProcessor {
|
||||
|
||||
private ErrorReceiver errorListener;
|
||||
|
||||
@Override
|
||||
public void init(ProcessingEnvironment processingEnv) {
|
||||
super.init(processingEnv);
|
||||
this.processingEnv = processingEnv;
|
||||
errorListener = new ErrorReceiverImpl(
|
||||
processingEnv.getMessager(),
|
||||
processingEnv.getOptions().containsKey(Const.DEBUG_OPTION.getValue())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if (processingEnv.getOptions().containsKey(Const.CONFIG_FILE_OPTION.getValue())) {
|
||||
String value = processingEnv.getOptions().get(Const.CONFIG_FILE_OPTION.getValue());
|
||||
|
||||
// For multiple config files we are following the format
|
||||
// -Aconfig=foo.config:bar.config where : is the pathSeparatorChar
|
||||
StringTokenizer st = new StringTokenizer(value, File.pathSeparator);
|
||||
if (!st.hasMoreTokens()) {
|
||||
errorListener.error(null, Messages.OPERAND_MISSING.format(Const.CONFIG_FILE_OPTION.getValue()));
|
||||
return true;
|
||||
}
|
||||
|
||||
while (st.hasMoreTokens()) {
|
||||
File configFile = new File(st.nextToken());
|
||||
if (!configFile.exists()) {
|
||||
errorListener.error(null, Messages.NON_EXISTENT_FILE.format());
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Collection<TypeElement> rootElements = new ArrayList<TypeElement>();
|
||||
filterClass(rootElements, roundEnv.getRootElements());
|
||||
ConfigReader configReader = new ConfigReader(
|
||||
processingEnv,
|
||||
rootElements,
|
||||
configFile,
|
||||
errorListener
|
||||
);
|
||||
|
||||
Collection<Reference> classesToBeIncluded = configReader.getClassesToBeIncluded();
|
||||
J2SJAXBModel model = JXC.createJavaCompiler().bind(
|
||||
classesToBeIncluded, Collections.<QName, Reference>emptyMap(), null, processingEnv);
|
||||
|
||||
SchemaOutputResolver schemaOutputResolver = configReader.getSchemaOutputResolver();
|
||||
|
||||
model.generateSchema(schemaOutputResolver, errorListener);
|
||||
} catch (IOException e) {
|
||||
errorListener.error(e.getMessage(), e);
|
||||
} catch (SAXException e) {
|
||||
// the error should have already been reported
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void filterClass(Collection<TypeElement> rootElements, Collection<? extends Element> elements) {
|
||||
for (Element element : elements) {
|
||||
if (element.getKind().equals(ElementKind.CLASS) || element.getKind().equals(ElementKind.INTERFACE) ||
|
||||
element.getKind().equals(ElementKind.ENUM)) {
|
||||
rootElements.add((TypeElement) element);
|
||||
filterClass(rootElements, ElementFilter.typesIn(element.getEnclosedElements()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
if (SourceVersion.latest().compareTo(SourceVersion.RELEASE_6) > 0)
|
||||
return SourceVersion.valueOf("RELEASE_7");
|
||||
else
|
||||
return SourceVersion.RELEASE_6;
|
||||
}
|
||||
}
|
||||
56
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/Const.java
Normal file
56
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/Const.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Defines constants used in the Annotation Processing driver.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public enum Const {
|
||||
|
||||
/**
|
||||
* Name of the annotation processing command-line option to take user-specified config files.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* It can take multiple file names separately by {@link File#pathSeparator}.
|
||||
*/
|
||||
CONFIG_FILE_OPTION("jaxb.config"),
|
||||
|
||||
DEBUG_OPTION("jaxb.debug");
|
||||
|
||||
private String value;
|
||||
|
||||
private Const(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
import com.sun.tools.internal.xjc.ErrorReceiver;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ErrorReceiverImpl extends ErrorReceiver {
|
||||
private final Messager messager;
|
||||
private final boolean debug;
|
||||
|
||||
public ErrorReceiverImpl(Messager messager, boolean debug) {
|
||||
this.messager = messager;
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public ErrorReceiverImpl(Messager messager) {
|
||||
this(messager,false);
|
||||
}
|
||||
|
||||
public ErrorReceiverImpl(ProcessingEnvironment env) {
|
||||
this(env.getMessager());
|
||||
}
|
||||
|
||||
public void error(SAXParseException exception) {
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, exception.getMessage());
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, getLocation(exception));
|
||||
printDetail(exception);
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException exception) {
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, exception.getMessage());
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, getLocation(exception));
|
||||
printDetail(exception);
|
||||
}
|
||||
|
||||
public void warning(SAXParseException exception) {
|
||||
messager.printMessage(Diagnostic.Kind.WARNING, exception.getMessage());
|
||||
messager.printMessage(Diagnostic.Kind.WARNING, getLocation(exception));
|
||||
printDetail(exception);
|
||||
}
|
||||
|
||||
public void info(SAXParseException exception) {
|
||||
printDetail(exception);
|
||||
}
|
||||
|
||||
private String getLocation(SAXParseException e) {
|
||||
// TODO: format the location information for printing
|
||||
return "";
|
||||
}
|
||||
|
||||
private void printDetail(SAXParseException e) {
|
||||
if(debug) {
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.MirroredTypeException;
|
||||
import javax.lang.model.type.MirroredTypesException;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import com.sun.xml.internal.bind.v2.model.annotation.AbstractInlineAnnotationReaderImpl;
|
||||
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
|
||||
import com.sun.xml.internal.bind.v2.model.annotation.Locatable;
|
||||
import com.sun.xml.internal.bind.v2.model.annotation.LocatableAnnotation;
|
||||
|
||||
/**
|
||||
* {@link AnnotationReader} implementation that reads annotation inline from Annoation Processing.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public final class InlineAnnotationReaderImpl extends AbstractInlineAnnotationReaderImpl<TypeMirror, TypeElement, VariableElement, ExecutableElement> {
|
||||
|
||||
/** The singleton instance. */
|
||||
public static final InlineAnnotationReaderImpl theInstance = new InlineAnnotationReaderImpl();
|
||||
|
||||
private InlineAnnotationReaderImpl() {}
|
||||
|
||||
public <A extends Annotation> A getClassAnnotation(Class<A> a, TypeElement clazz, Locatable srcPos) {
|
||||
return LocatableAnnotation.create(clazz.getAnnotation(a),srcPos);
|
||||
}
|
||||
|
||||
public <A extends Annotation> A getFieldAnnotation(Class<A> a, VariableElement f, Locatable srcPos) {
|
||||
return LocatableAnnotation.create(f.getAnnotation(a),srcPos);
|
||||
}
|
||||
|
||||
public boolean hasFieldAnnotation(Class<? extends Annotation> annotationType, VariableElement f) {
|
||||
return f.getAnnotation(annotationType)!=null;
|
||||
}
|
||||
|
||||
public boolean hasClassAnnotation(TypeElement clazz, Class<? extends Annotation> annotationType) {
|
||||
return clazz.getAnnotation(annotationType)!=null;
|
||||
}
|
||||
|
||||
public Annotation[] getAllFieldAnnotations(VariableElement field, Locatable srcPos) {
|
||||
return getAllAnnotations(field,srcPos);
|
||||
}
|
||||
|
||||
public <A extends Annotation> A getMethodAnnotation(Class<A> a, ExecutableElement method, Locatable srcPos) {
|
||||
return LocatableAnnotation.create(method.getAnnotation(a),srcPos);
|
||||
}
|
||||
|
||||
public boolean hasMethodAnnotation(Class<? extends Annotation> a, ExecutableElement method) {
|
||||
return method.getAnnotation(a)!=null;
|
||||
}
|
||||
|
||||
public Annotation[] getAllMethodAnnotations(ExecutableElement method, Locatable srcPos) {
|
||||
return getAllAnnotations(method,srcPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the annotations on the given declaration.
|
||||
*/
|
||||
private Annotation[] getAllAnnotations(Element decl, Locatable srcPos) {
|
||||
List<Annotation> r = new ArrayList<Annotation>();
|
||||
|
||||
for( AnnotationMirror m : decl.getAnnotationMirrors() ) {
|
||||
try {
|
||||
String fullName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName().toString();
|
||||
Class<? extends Annotation> type =
|
||||
SecureLoader.getClassClassLoader(getClass()).loadClass(fullName).asSubclass(Annotation.class);
|
||||
Annotation annotation = decl.getAnnotation(type);
|
||||
if(annotation!=null)
|
||||
r.add( LocatableAnnotation.create(annotation,srcPos) );
|
||||
} catch (ClassNotFoundException e) {
|
||||
// just continue
|
||||
}
|
||||
}
|
||||
|
||||
return r.toArray(new Annotation[r.size()]);
|
||||
}
|
||||
|
||||
public <A extends Annotation> A getMethodParameterAnnotation(Class<A> a, ExecutableElement m, int paramIndex, Locatable srcPos) {
|
||||
VariableElement[] params = m.getParameters().toArray(new VariableElement[m.getParameters().size()]);
|
||||
return LocatableAnnotation.create(
|
||||
params[paramIndex].getAnnotation(a), srcPos );
|
||||
}
|
||||
|
||||
public <A extends Annotation> A getPackageAnnotation(Class<A> a, TypeElement clazz, Locatable srcPos) {
|
||||
return LocatableAnnotation.create(clazz.getEnclosingElement().getAnnotation(a), srcPos);
|
||||
}
|
||||
|
||||
public TypeMirror getClassValue(Annotation a, String name) {
|
||||
try {
|
||||
a.annotationType().getMethod(name).invoke(a);
|
||||
assert false;
|
||||
throw new IllegalStateException("should throw a MirroredTypeException");
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalAccessError(e.getMessage());
|
||||
} catch (InvocationTargetException e) {
|
||||
if( e.getCause() instanceof MirroredTypeException ) {
|
||||
MirroredTypeException me = (MirroredTypeException)e.getCause();
|
||||
return me.getTypeMirror();
|
||||
}
|
||||
// impossible
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new NoSuchMethodError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public TypeMirror[] getClassArrayValue(Annotation a, String name) {
|
||||
try {
|
||||
a.annotationType().getMethod(name).invoke(a);
|
||||
assert false;
|
||||
throw new IllegalStateException("should throw a MirroredTypesException");
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalAccessError(e.getMessage());
|
||||
} catch (InvocationTargetException e) {
|
||||
if( e.getCause() instanceof MirroredTypesException ) {
|
||||
MirroredTypesException me = (MirroredTypesException)e.getCause();
|
||||
Collection<? extends TypeMirror> r = me.getTypeMirrors();
|
||||
return r.toArray(new TypeMirror[r.size()]);
|
||||
}
|
||||
// *********************** TODO: jdk6 bug. Fixed in java7
|
||||
// According to the javadocs it should throw the MirroredTypesException
|
||||
if( e.getCause() instanceof MirroredTypeException ) {
|
||||
MirroredTypeException me = (MirroredTypeException)e.getCause();
|
||||
TypeMirror tr = me.getTypeMirror();
|
||||
TypeMirror[] trArr = new TypeMirror[1];
|
||||
trArr[0] = tr;
|
||||
return trArr;
|
||||
}
|
||||
// *******************************************
|
||||
// impossible
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new NoSuchMethodError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected String fullName(ExecutableElement m) {
|
||||
return ((TypeElement) m.getEnclosingElement()).getQualifiedName().toString()+'#'+m.getSimpleName();
|
||||
}
|
||||
}
|
||||
52
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/Messages.java
Normal file
52
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/Messages.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Message resources.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
enum Messages {
|
||||
// Accessor
|
||||
NON_EXISTENT_FILE, // 1 arg
|
||||
UNRECOGNIZED_PARAMETER, //1 arg
|
||||
OPERAND_MISSING, // 1 arg
|
||||
;
|
||||
|
||||
private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getPackage().getName() +".MessageBundle");
|
||||
|
||||
public String toString() {
|
||||
return format();
|
||||
}
|
||||
|
||||
public String format( Object... args ) {
|
||||
return MessageFormat.format( rb.getString(name()), args );
|
||||
}
|
||||
}
|
||||
130
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/Options.java
Normal file
130
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/Options.java
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.tools.internal.xjc.BadCommandLineException;
|
||||
|
||||
/**
|
||||
* This stores the invocation configuration for
|
||||
* SchemaGenerator
|
||||
*
|
||||
* @author Bhakti Mehta
|
||||
*/
|
||||
public class Options {
|
||||
|
||||
public static final String DISABLE_XML_SECURITY = "-disableXmlSecurity";
|
||||
|
||||
// honor CLASSPATH environment variable, but it will be overrided by -cp
|
||||
public String classpath = System.getenv("CLASSPATH");
|
||||
|
||||
public File targetDir = null;
|
||||
|
||||
public File episodeFile = null;
|
||||
|
||||
private boolean disableXmlSecurity = false;
|
||||
|
||||
// encoding is not required for JDK5, 6, but JDK 7 javac is much more strict - see issue 6859289
|
||||
public String encoding = null;
|
||||
|
||||
public final List<String> arguments = new ArrayList<String>();
|
||||
|
||||
public void parseArguments(String[] args) throws BadCommandLineException {
|
||||
for (int i = 0 ; i <args.length; i++) {
|
||||
if (args[i].charAt(0)== '-') {
|
||||
int j = parseArgument(args,i);
|
||||
if(j==0)
|
||||
throw new BadCommandLineException(
|
||||
Messages.UNRECOGNIZED_PARAMETER.format(args[i]));
|
||||
i += j;
|
||||
} else {
|
||||
arguments.add(args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int parseArgument( String[] args, int i ) throws BadCommandLineException {
|
||||
if (args[i].equals("-d")) {
|
||||
if (i == args.length - 1)
|
||||
throw new BadCommandLineException(
|
||||
(Messages.OPERAND_MISSING.format(args[i])));
|
||||
targetDir = new File(args[++i]);
|
||||
if( !targetDir.exists() )
|
||||
throw new BadCommandLineException(
|
||||
Messages.NON_EXISTENT_FILE.format(targetDir));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args[i].equals("-episode")) {
|
||||
if (i == args.length - 1)
|
||||
throw new BadCommandLineException(
|
||||
(Messages.OPERAND_MISSING.format(args[i])));
|
||||
episodeFile = new File(args[++i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args[i].equals(DISABLE_XML_SECURITY)) {
|
||||
if (i == args.length - 1)
|
||||
throw new BadCommandLineException(
|
||||
(Messages.OPERAND_MISSING.format(args[i])));
|
||||
disableXmlSecurity = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args[i].equals("-encoding")) {
|
||||
if (i == args.length - 1)
|
||||
throw new BadCommandLineException(
|
||||
(Messages.OPERAND_MISSING.format(args[i])));
|
||||
encoding = args[++i];
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args[i].equals("-cp") || args[i].equals("-classpath")) {
|
||||
if (i == args.length - 1)
|
||||
throw new BadCommandLineException(
|
||||
(Messages.OPERAND_MISSING.format(args[i])));
|
||||
classpath = args[++i];
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the disableXmlSecurity
|
||||
*/
|
||||
public boolean isDisableXmlSecurity() {
|
||||
return disableXmlSecurity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
152
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/SchemaGenerator.java
Normal file
152
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/SchemaGenerator.java
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
import com.sun.tools.internal.jxc.api.JXC;
|
||||
import com.sun.tools.internal.xjc.api.J2SJAXBModel;
|
||||
import com.sun.tools.internal.xjc.api.Reference;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.Processor;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.StandardLocation;
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* {@link Processor} that implements the schema generator
|
||||
* command line tool.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
@SupportedAnnotationTypes("*")
|
||||
public class SchemaGenerator extends AbstractProcessor {
|
||||
|
||||
/**
|
||||
* User-specified schema locations, if any.
|
||||
*/
|
||||
private final Map<String,File> schemaLocations = new HashMap<String, File>();
|
||||
|
||||
private File episodeFile;
|
||||
|
||||
public SchemaGenerator() {
|
||||
}
|
||||
|
||||
public SchemaGenerator( Map<String,File> m ) {
|
||||
schemaLocations.putAll(m);
|
||||
}
|
||||
|
||||
public void setEpisodeFile(File episodeFile) {
|
||||
this.episodeFile = episodeFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
final ErrorReceiverImpl errorListener = new ErrorReceiverImpl(processingEnv);
|
||||
|
||||
List<Reference> classes = new ArrayList<Reference>();
|
||||
// simply ignore all the interface definitions,
|
||||
// so that users won't have to manually exclude interfaces, which is silly.
|
||||
filterClass(classes, roundEnv.getRootElements());
|
||||
|
||||
J2SJAXBModel model = JXC.createJavaCompiler().bind(classes, Collections.<QName, Reference>emptyMap(), null, processingEnv);
|
||||
if (model == null)
|
||||
return false; // error
|
||||
|
||||
try {
|
||||
model.generateSchema(
|
||||
new SchemaOutputResolver() {
|
||||
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
|
||||
File file;
|
||||
OutputStream out;
|
||||
if (schemaLocations.containsKey(namespaceUri)) {
|
||||
file = schemaLocations.get(namespaceUri);
|
||||
if (file == null) return null; // don't generate
|
||||
out = new FileOutputStream(file);
|
||||
} else {
|
||||
// use the default
|
||||
file = new File(suggestedFileName);
|
||||
out = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", suggestedFileName)
|
||||
.openOutputStream();
|
||||
file = file.getAbsoluteFile();
|
||||
}
|
||||
|
||||
StreamResult ss = new StreamResult(out);
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Writing "+file);
|
||||
ss.setSystemId(file.toURL().toExternalForm());
|
||||
return ss;
|
||||
}
|
||||
}, errorListener);
|
||||
|
||||
if (episodeFile != null) {
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Writing "+episodeFile);
|
||||
model.generateEpisodeFile(new StreamResult(episodeFile));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
errorListener.error(e.getMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void filterClass(List<Reference> classes, Collection<? extends Element> elements) {
|
||||
for (Element element : elements) {
|
||||
if (element.getKind().equals(ElementKind.CLASS) || element.getKind().equals(ElementKind.ENUM)) {
|
||||
classes.add(new Reference((TypeElement) element, processingEnv));
|
||||
filterClass(classes, ElementFilter.typesIn(element.getEnclosedElements()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
if (SourceVersion.latest().compareTo(SourceVersion.RELEASE_6) > 0)
|
||||
return SourceVersion.valueOf("RELEASE_7");
|
||||
else
|
||||
return SourceVersion.RELEASE_6;
|
||||
}
|
||||
}
|
||||
75
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/SecureLoader.java
Normal file
75
jdkSrc/jdk8/com/sun/tools/internal/jxc/ap/SecureLoader.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.ap;
|
||||
|
||||
/**
|
||||
* Class defined for safe calls of getClassLoader methods of any kind (context/system/class
|
||||
* classloader. This MUST be package private and defined in every package which
|
||||
* uses such invocations.
|
||||
* @author snajper
|
||||
*/
|
||||
class SecureLoader {
|
||||
|
||||
static ClassLoader getContextClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
} else {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getClassClassLoader(final Class c) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return c.getClassLoader();
|
||||
} else {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
return c.getClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getSystemClassLoader() {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
} else {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
45
jdkSrc/jdk8/com/sun/tools/internal/jxc/api/JXC.java
Normal file
45
jdkSrc/jdk8/com/sun/tools/internal/jxc/api/JXC.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.api;
|
||||
|
||||
import com.sun.tools.internal.xjc.api.JavaCompiler;
|
||||
import com.sun.tools.internal.jxc.api.impl.j2s.JavaCompilerImpl;
|
||||
|
||||
/**
|
||||
* User: Iaroslav Savytskyi
|
||||
* Date: 25/05/12
|
||||
*/
|
||||
public class JXC {
|
||||
/**
|
||||
* Gets a fresh {@link JavaCompiler}.
|
||||
*
|
||||
* @return
|
||||
* always return non-null object.
|
||||
*/
|
||||
public static JavaCompiler createJavaCompiler() {
|
||||
return new JavaCompilerImpl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.api.impl.j2s;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import javax.xml.bind.annotation.XmlList;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import com.sun.tools.internal.xjc.api.ErrorListener;
|
||||
import com.sun.tools.internal.xjc.api.J2SJAXBModel;
|
||||
import com.sun.tools.internal.xjc.api.Reference;
|
||||
import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader;
|
||||
import com.sun.xml.internal.bind.v2.model.core.ArrayInfo;
|
||||
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
|
||||
import com.sun.xml.internal.bind.v2.model.core.Element;
|
||||
import com.sun.xml.internal.bind.v2.model.core.ElementInfo;
|
||||
import com.sun.xml.internal.bind.v2.model.core.EnumLeafInfo;
|
||||
import com.sun.xml.internal.bind.v2.model.core.NonElement;
|
||||
import com.sun.xml.internal.bind.v2.model.core.Ref;
|
||||
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
|
||||
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
|
||||
import com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator;
|
||||
import com.sun.xml.internal.txw2.output.ResultFactory;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
final class JAXBModelImpl implements J2SJAXBModel {
|
||||
|
||||
private final Map<QName,Reference> additionalElementDecls;
|
||||
|
||||
private final List<String> classList = new ArrayList<String>();
|
||||
|
||||
private final TypeInfoSet<TypeMirror, TypeElement, VariableElement, ExecutableElement> types;
|
||||
|
||||
private final AnnotationReader<TypeMirror, TypeElement, VariableElement, ExecutableElement> reader;
|
||||
|
||||
/**
|
||||
* Lazily created schema generator.
|
||||
*/
|
||||
private XmlSchemaGenerator<TypeMirror, TypeElement, VariableElement, ExecutableElement> xsdgen;
|
||||
|
||||
/**
|
||||
* Look up table from an externally visible {@link Reference} object
|
||||
* to our internal format.
|
||||
*/
|
||||
private final Map<Reference, NonElement<TypeMirror, TypeElement>> refMap = new HashMap<Reference, NonElement<TypeMirror, TypeElement>>();
|
||||
|
||||
public JAXBModelImpl(TypeInfoSet<TypeMirror, TypeElement, VariableElement, ExecutableElement> types,
|
||||
AnnotationReader<TypeMirror, TypeElement, VariableElement, ExecutableElement> reader,
|
||||
Collection<Reference> rootClasses,
|
||||
Map<QName, Reference> additionalElementDecls) {
|
||||
this.types = types;
|
||||
this.reader = reader;
|
||||
this.additionalElementDecls = additionalElementDecls;
|
||||
|
||||
Navigator<TypeMirror, TypeElement, VariableElement, ExecutableElement> navigator = types.getNavigator();
|
||||
|
||||
for (ClassInfo<TypeMirror, TypeElement> i : types.beans().values()) {
|
||||
classList.add(i.getName());
|
||||
}
|
||||
|
||||
for (ArrayInfo<TypeMirror, TypeElement> a : types.arrays().values()) {
|
||||
String javaName = navigator.getTypeName(a.getType());
|
||||
classList.add(javaName);
|
||||
}
|
||||
|
||||
for (EnumLeafInfo<TypeMirror, TypeElement> l : types.enums().values()) {
|
||||
QName tn = l.getTypeName();
|
||||
if(tn!=null) {
|
||||
String javaName = navigator.getTypeName(l.getType());
|
||||
classList.add(javaName);
|
||||
}
|
||||
}
|
||||
|
||||
for (Reference ref : rootClasses)
|
||||
refMap.put(ref,getXmlType(ref));
|
||||
|
||||
// check for collision between "additional" ones and the ones given to JAXB
|
||||
// and eliminate duplication
|
||||
Iterator<Map.Entry<QName, Reference>> itr = additionalElementDecls.entrySet().iterator();
|
||||
while(itr.hasNext()) {
|
||||
Map.Entry<QName, Reference> entry = itr.next();
|
||||
if(entry.getValue()==null) continue;
|
||||
|
||||
NonElement<TypeMirror, TypeElement> xt = getXmlType(entry.getValue());
|
||||
|
||||
assert xt!=null;
|
||||
refMap.put(entry.getValue(),xt);
|
||||
if(xt instanceof ClassInfo) {
|
||||
ClassInfo<TypeMirror, TypeElement> xct = (ClassInfo<TypeMirror, TypeElement>) xt;
|
||||
Element<TypeMirror, TypeElement> elem = xct.asElement();
|
||||
if(elem!=null && elem.getElementName().equals(entry.getKey())) {
|
||||
itr.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ElementInfo<TypeMirror, TypeElement> ei = types.getElementInfo(null, entry.getKey());
|
||||
if(ei!=null && ei.getContentType()==xt)
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getClassList() {
|
||||
return classList;
|
||||
}
|
||||
|
||||
public QName getXmlTypeName(Reference javaType) {
|
||||
NonElement<TypeMirror, TypeElement> ti = refMap.get(javaType);
|
||||
|
||||
if(ti!=null)
|
||||
return ti.getTypeName();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private NonElement<TypeMirror, TypeElement> getXmlType(Reference r) {
|
||||
if(r==null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
XmlJavaTypeAdapter xjta = r.annotations.getAnnotation(XmlJavaTypeAdapter.class);
|
||||
XmlList xl = r.annotations.getAnnotation(XmlList.class);
|
||||
|
||||
Ref<TypeMirror, TypeElement> ref = new Ref<TypeMirror, TypeElement>(
|
||||
reader,types.getNavigator(),r.type,xjta,xl);
|
||||
|
||||
return types.getTypeInfo(ref);
|
||||
}
|
||||
|
||||
public void generateSchema(SchemaOutputResolver outputResolver, ErrorListener errorListener) throws IOException {
|
||||
getSchemaGenerator().write(outputResolver,errorListener);
|
||||
}
|
||||
|
||||
public void generateEpisodeFile(Result output) {
|
||||
getSchemaGenerator().writeEpisodeFile(ResultFactory.createSerializer(output));
|
||||
}
|
||||
|
||||
private synchronized XmlSchemaGenerator<TypeMirror, TypeElement, VariableElement, ExecutableElement> getSchemaGenerator() {
|
||||
if(xsdgen==null) {
|
||||
xsdgen = new XmlSchemaGenerator<TypeMirror, TypeElement, VariableElement, ExecutableElement>(types.getNavigator(), types);
|
||||
|
||||
for (Map.Entry<QName, Reference> e : additionalElementDecls.entrySet()) {
|
||||
Reference value = e.getValue();
|
||||
if(value!=null) {
|
||||
NonElement<TypeMirror, TypeElement> typeInfo = refMap.get(value);
|
||||
if(typeInfo==null)
|
||||
throw new IllegalArgumentException(e.getValue()+" was not specified to JavaCompiler.bind");
|
||||
TypeMirror type = value.type;
|
||||
xsdgen.add(e.getKey(), !(type != null && type.getKind().isPrimitive()), typeInfo);
|
||||
} else {
|
||||
xsdgen.add(e.getKey(),false,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return xsdgen;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.api.impl.j2s;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlList;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic;
|
||||
import com.sun.tools.internal.jxc.ap.InlineAnnotationReaderImpl;
|
||||
import com.sun.tools.internal.jxc.model.nav.ApNavigator;
|
||||
import com.sun.tools.internal.xjc.api.J2SJAXBModel;
|
||||
import com.sun.tools.internal.xjc.api.JavaCompiler;
|
||||
import com.sun.tools.internal.xjc.api.Reference;
|
||||
import com.sun.xml.internal.bind.v2.model.core.ErrorHandler;
|
||||
import com.sun.xml.internal.bind.v2.model.core.Ref;
|
||||
import com.sun.xml.internal.bind.v2.model.core.TypeInfoSet;
|
||||
import com.sun.xml.internal.bind.v2.model.impl.ModelBuilder;
|
||||
import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class JavaCompilerImpl implements JavaCompiler {
|
||||
public J2SJAXBModel bind(
|
||||
Collection<Reference> rootClasses,
|
||||
Map<QName,Reference> additionalElementDecls,
|
||||
String defaultNamespaceRemap,
|
||||
ProcessingEnvironment env) {
|
||||
|
||||
ModelBuilder<TypeMirror, TypeElement, VariableElement, ExecutableElement> builder =
|
||||
new ModelBuilder<TypeMirror, TypeElement, VariableElement, ExecutableElement>(
|
||||
InlineAnnotationReaderImpl.theInstance,
|
||||
new ApNavigator(env),
|
||||
Collections.<TypeElement, TypeElement>emptyMap(),
|
||||
defaultNamespaceRemap );
|
||||
|
||||
builder.setErrorHandler(new ErrorHandlerImpl(env.getMessager()));
|
||||
|
||||
for ( Reference ref : rootClasses ) {
|
||||
TypeMirror t = ref.type;
|
||||
|
||||
XmlJavaTypeAdapter xjta = ref.annotations.getAnnotation(XmlJavaTypeAdapter.class);
|
||||
XmlList xl = ref.annotations.getAnnotation(XmlList.class);
|
||||
|
||||
builder.getTypeInfo(new Ref<TypeMirror, TypeElement>(builder, t, xjta, xl));
|
||||
}
|
||||
|
||||
TypeInfoSet<TypeMirror, TypeElement, VariableElement, ExecutableElement> r = builder.link();
|
||||
if(r==null) return null;
|
||||
|
||||
if(additionalElementDecls==null)
|
||||
additionalElementDecls = Collections.emptyMap();
|
||||
else {
|
||||
// fool proof check
|
||||
for (Map.Entry<QName, ? extends Reference> e : additionalElementDecls.entrySet()) {
|
||||
if(e.getKey()==null)
|
||||
throw new IllegalArgumentException("nulls in additionalElementDecls");
|
||||
}
|
||||
}
|
||||
return new JAXBModelImpl(r, builder.reader, rootClasses, new HashMap<QName, Reference>(additionalElementDecls));
|
||||
}
|
||||
|
||||
private static final class ErrorHandlerImpl implements ErrorHandler {
|
||||
private final Messager messager;
|
||||
|
||||
public ErrorHandlerImpl(Messager messager) {
|
||||
this.messager = messager;
|
||||
}
|
||||
|
||||
public void error(IllegalAnnotationException e) {
|
||||
String error = e.toString();
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, error);
|
||||
System.err.println(error); //TODO: temporary fix problem with no ouput from messager
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,629 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// AttributesImpl.java - default implementation of Attributes.
|
||||
// Written by David Megginson, sax@megginson.com
|
||||
// NO WARRANTY! This class is in the public domain.
|
||||
|
||||
// $Id: AttributesImpl.java,v 1.4 2002/09/29 02:55:48 okajima Exp $
|
||||
|
||||
//fixed bug at removeAttribute!! by Daisuke OKAJIMA 2002.4.21
|
||||
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of the Attributes interface.
|
||||
*
|
||||
* <blockquote>
|
||||
* <em>This module, both source code and documentation, is in the
|
||||
* Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
|
||||
* </blockquote>
|
||||
*
|
||||
* <p>This class provides a default implementation of the SAX2
|
||||
* {@link org.xml.sax.Attributes Attributes} interface, with the
|
||||
* addition of manipulators so that the list can be modified or
|
||||
* reused.</p>
|
||||
*
|
||||
* <p>There are two typical uses of this class:</p>
|
||||
*
|
||||
* <ol>
|
||||
* <li>to take a persistent snapshot of an Attributes object
|
||||
* in a {@link org.xml.sax.ContentHandler#startElement startElement} event; or</li>
|
||||
* <li>to construct or modify an Attributes object in a SAX2 driver or filter.</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>This class replaces the now-deprecated SAX1 {@link
|
||||
* org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
|
||||
* class; in addition to supporting the updated Attributes
|
||||
* interface rather than the deprecated {@link org.xml.sax.AttributeList
|
||||
* AttributeList} interface, it also includes a much more efficient
|
||||
* implementation using a single array rather than a set of Vectors.</p>
|
||||
*
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
* @since SAX 2.0
|
||||
* @author David Megginson,
|
||||
* <a href="mailto:sax@megginson.com">sax@megginson.com</a>
|
||||
* @version 2.0
|
||||
*/
|
||||
public class AttributesImpl implements Attributes
|
||||
{
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Constructors.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new, empty AttributesImpl object.
|
||||
*/
|
||||
public AttributesImpl ()
|
||||
{
|
||||
length = 0;
|
||||
data = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy an existing Attributes object.
|
||||
*
|
||||
* <p>This constructor is especially useful inside a
|
||||
* {@link org.xml.sax.ContentHandler#startElement startElement} event.</p>
|
||||
*
|
||||
* @param atts The existing Attributes object.
|
||||
*/
|
||||
public AttributesImpl (Attributes atts)
|
||||
{
|
||||
setAttributes(atts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Implementation of org.xml.sax.Attributes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of attributes in the list.
|
||||
*
|
||||
* @return The number of attributes in the list.
|
||||
* @see org.xml.sax.Attributes#getLength
|
||||
*/
|
||||
public int getLength ()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an attribute's Namespace URI.
|
||||
*
|
||||
* @param index The attribute's index (zero-based).
|
||||
* @return The Namespace URI, the empty string if none is
|
||||
* available, or null if the index is out of range.
|
||||
* @see org.xml.sax.Attributes#getURI
|
||||
*/
|
||||
public String getURI (int index)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
return data[index*5];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an attribute's local name.
|
||||
*
|
||||
* @param index The attribute's index (zero-based).
|
||||
* @return The attribute's local name, the empty string if
|
||||
* none is available, or null if the index if out of range.
|
||||
* @see org.xml.sax.Attributes#getLocalName
|
||||
*/
|
||||
public String getLocalName (int index)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
return data[index*5+1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an attribute's qualified (prefixed) name.
|
||||
*
|
||||
* @param index The attribute's index (zero-based).
|
||||
* @return The attribute's qualified name, the empty string if
|
||||
* none is available, or null if the index is out of bounds.
|
||||
* @see org.xml.sax.Attributes#getQName
|
||||
*/
|
||||
public String getQName (int index)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
return data[index*5+2];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an attribute's type by index.
|
||||
*
|
||||
* @param index The attribute's index (zero-based).
|
||||
* @return The attribute's type, "CDATA" if the type is unknown, or null
|
||||
* if the index is out of bounds.
|
||||
* @see org.xml.sax.Attributes#getType(int)
|
||||
*/
|
||||
public String getType (int index)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
return data[index*5+3];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an attribute's value by index.
|
||||
*
|
||||
* @param index The attribute's index (zero-based).
|
||||
* @return The attribute's value or null if the index is out of bounds.
|
||||
* @see org.xml.sax.Attributes#getValue(int)
|
||||
*/
|
||||
public String getValue (int index)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
return data[index*5+4];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look up an attribute's index by Namespace name.
|
||||
*
|
||||
* <p>In many cases, it will be more efficient to look up the name once and
|
||||
* use the index query methods rather than using the name query methods
|
||||
* repeatedly.</p>
|
||||
*
|
||||
* @param uri The attribute's Namespace URI, or the empty
|
||||
* string if none is available.
|
||||
* @param localName The attribute's local name.
|
||||
* @return The attribute's index, or -1 if none matches.
|
||||
* @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String)
|
||||
*/
|
||||
public int getIndex (String uri, String localName)
|
||||
{
|
||||
int max = length * 5;
|
||||
for (int i = 0; i < max; i += 5) {
|
||||
if (data[i].equals(uri) && data[i+1].equals(localName)) {
|
||||
return i / 5;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look up an attribute's index by qualified (prefixed) name.
|
||||
*
|
||||
* @param qName The qualified name.
|
||||
* @return The attribute's index, or -1 if none matches.
|
||||
* @see org.xml.sax.Attributes#getIndex(java.lang.String)
|
||||
*/
|
||||
public int getIndex (String qName)
|
||||
{
|
||||
int max = length * 5;
|
||||
for (int i = 0; i < max; i += 5) {
|
||||
if (data[i+2].equals(qName)) {
|
||||
return i / 5;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look up an attribute's type by Namespace-qualified name.
|
||||
*
|
||||
* @param uri The Namespace URI, or the empty string for a name
|
||||
* with no explicit Namespace URI.
|
||||
* @param localName The local name.
|
||||
* @return The attribute's type, or null if there is no
|
||||
* matching attribute.
|
||||
* @see org.xml.sax.Attributes#getType(java.lang.String,java.lang.String)
|
||||
*/
|
||||
public String getType (String uri, String localName)
|
||||
{
|
||||
int max = length * 5;
|
||||
for (int i = 0; i < max; i += 5) {
|
||||
if (data[i].equals(uri) && data[i+1].equals(localName)) {
|
||||
return data[i+3];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look up an attribute's type by qualified (prefixed) name.
|
||||
*
|
||||
* @param qName The qualified name.
|
||||
* @return The attribute's type, or null if there is no
|
||||
* matching attribute.
|
||||
* @see org.xml.sax.Attributes#getType(java.lang.String)
|
||||
*/
|
||||
public String getType (String qName)
|
||||
{
|
||||
int max = length * 5;
|
||||
for (int i = 0; i < max; i += 5) {
|
||||
if (data[i+2].equals(qName)) {
|
||||
return data[i+3];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look up an attribute's value by Namespace-qualified name.
|
||||
*
|
||||
* @param uri The Namespace URI, or the empty string for a name
|
||||
* with no explicit Namespace URI.
|
||||
* @param localName The local name.
|
||||
* @return The attribute's value, or null if there is no
|
||||
* matching attribute.
|
||||
* @see org.xml.sax.Attributes#getValue(java.lang.String,java.lang.String)
|
||||
*/
|
||||
public String getValue (String uri, String localName)
|
||||
{
|
||||
int max = length * 5;
|
||||
for (int i = 0; i < max; i += 5) {
|
||||
if (data[i].equals(uri) && data[i+1].equals(localName)) {
|
||||
return data[i+4];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look up an attribute's value by qualified (prefixed) name.
|
||||
*
|
||||
* @param qName The qualified name.
|
||||
* @return The attribute's value, or null if there is no
|
||||
* matching attribute.
|
||||
* @see org.xml.sax.Attributes#getValue(java.lang.String)
|
||||
*/
|
||||
public String getValue (String qName)
|
||||
{
|
||||
int max = length * 5;
|
||||
for (int i = 0; i < max; i += 5) {
|
||||
if (data[i+2].equals(qName)) {
|
||||
return data[i+4];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Manipulators.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Clear the attribute list for reuse.
|
||||
*
|
||||
* <p>Note that no memory is actually freed by this call:
|
||||
* the current arrays are kept so that they can be
|
||||
* reused.</p>
|
||||
*/
|
||||
public void clear ()
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy an entire Attributes object.
|
||||
*
|
||||
* <p>It may be more efficient to reuse an existing object
|
||||
* rather than constantly allocating new ones.</p>
|
||||
*
|
||||
* @param atts The attributes to copy.
|
||||
*/
|
||||
public void setAttributes (Attributes atts)
|
||||
{
|
||||
clear();
|
||||
length = atts.getLength();
|
||||
data = new String[length*5];
|
||||
for (int i = 0; i < length; i++) {
|
||||
data[i*5] = atts.getURI(i);
|
||||
data[i*5+1] = atts.getLocalName(i);
|
||||
data[i*5+2] = atts.getQName(i);
|
||||
data[i*5+3] = atts.getType(i);
|
||||
data[i*5+4] = atts.getValue(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an attribute to the end of the list.
|
||||
*
|
||||
* <p>For the sake of speed, this method does no checking
|
||||
* to see if the attribute is already in the list: that is
|
||||
* the responsibility of the application.</p>
|
||||
*
|
||||
* @param uri The Namespace URI, or the empty string if
|
||||
* none is available or Namespace processing is not
|
||||
* being performed.
|
||||
* @param localName The local name, or the empty string if
|
||||
* Namespace processing is not being performed.
|
||||
* @param qName The qualified (prefixed) name, or the empty string
|
||||
* if qualified names are not available.
|
||||
* @param type The attribute type as a string.
|
||||
* @param value The attribute value.
|
||||
*/
|
||||
public void addAttribute (String uri, String localName, String qName,
|
||||
String type, String value)
|
||||
{
|
||||
ensureCapacity(length+1);
|
||||
data[length*5] = uri;
|
||||
data[length*5+1] = localName;
|
||||
data[length*5+2] = qName;
|
||||
data[length*5+3] = type;
|
||||
data[length*5+4] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an attribute in the list.
|
||||
*
|
||||
* <p>For the sake of speed, this method does no checking
|
||||
* for name conflicts or well-formedness: such checks are the
|
||||
* responsibility of the application.</p>
|
||||
*
|
||||
* @param index The index of the attribute (zero-based).
|
||||
* @param uri The Namespace URI, or the empty string if
|
||||
* none is available or Namespace processing is not
|
||||
* being performed.
|
||||
* @param localName The local name, or the empty string if
|
||||
* Namespace processing is not being performed.
|
||||
* @param qName The qualified name, or the empty string
|
||||
* if qualified names are not available.
|
||||
* @param type The attribute type as a string.
|
||||
* @param value The attribute value.
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException When the
|
||||
* supplied index does not point to an attribute
|
||||
* in the list.
|
||||
*/
|
||||
public void setAttribute (int index, String uri, String localName,
|
||||
String qName, String type, String value)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
data[index*5] = uri;
|
||||
data[index*5+1] = localName;
|
||||
data[index*5+2] = qName;
|
||||
data[index*5+3] = type;
|
||||
data[index*5+4] = value;
|
||||
} else {
|
||||
badIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an attribute from the list.
|
||||
*
|
||||
* @param index The index of the attribute (zero-based).
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException When the
|
||||
* supplied index does not point to an attribute
|
||||
* in the list.
|
||||
*/
|
||||
public void removeAttribute (int index)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
if (index < length - 1) {
|
||||
System.arraycopy(data, (index+1)*5, data, index*5,
|
||||
(length-index-1)*5);
|
||||
}
|
||||
length--;
|
||||
} else {
|
||||
badIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Namespace URI of a specific attribute.
|
||||
*
|
||||
* @param index The index of the attribute (zero-based).
|
||||
* @param uri The attribute's Namespace URI, or the empty
|
||||
* string for none.
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException When the
|
||||
* supplied index does not point to an attribute
|
||||
* in the list.
|
||||
*/
|
||||
public void setURI (int index, String uri)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
data[index*5] = uri;
|
||||
} else {
|
||||
badIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the local name of a specific attribute.
|
||||
*
|
||||
* @param index The index of the attribute (zero-based).
|
||||
* @param localName The attribute's local name, or the empty
|
||||
* string for none.
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException When the
|
||||
* supplied index does not point to an attribute
|
||||
* in the list.
|
||||
*/
|
||||
public void setLocalName (int index, String localName)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
data[index*5+1] = localName;
|
||||
} else {
|
||||
badIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the qualified name of a specific attribute.
|
||||
*
|
||||
* @param index The index of the attribute (zero-based).
|
||||
* @param qName The attribute's qualified name, or the empty
|
||||
* string for none.
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException When the
|
||||
* supplied index does not point to an attribute
|
||||
* in the list.
|
||||
*/
|
||||
public void setQName (int index, String qName)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
data[index*5+2] = qName;
|
||||
} else {
|
||||
badIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the type of a specific attribute.
|
||||
*
|
||||
* @param index The index of the attribute (zero-based).
|
||||
* @param type The attribute's type.
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException When the
|
||||
* supplied index does not point to an attribute
|
||||
* in the list.
|
||||
*/
|
||||
public void setType (int index, String type)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
data[index*5+3] = type;
|
||||
} else {
|
||||
badIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of a specific attribute.
|
||||
*
|
||||
* @param index The index of the attribute (zero-based).
|
||||
* @param value The attribute's value.
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException When the
|
||||
* supplied index does not point to an attribute
|
||||
* in the list.
|
||||
*/
|
||||
public void setValue (int index, String value)
|
||||
{
|
||||
if (index >= 0 && index < length) {
|
||||
data[index*5+4] = value;
|
||||
} else {
|
||||
badIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Internal methods.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Ensure the internal array's capacity.
|
||||
*
|
||||
* @param n The minimum number of attributes that the array must
|
||||
* be able to hold.
|
||||
*/
|
||||
private void ensureCapacity (int n)
|
||||
{
|
||||
if (n > 0 && (data == null || data.length==0)) {
|
||||
data = new String[25];
|
||||
}
|
||||
|
||||
int max = data.length;
|
||||
if (max >= n * 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
while (max < n * 5) {
|
||||
max *= 2;
|
||||
}
|
||||
String newData[] = new String[max];
|
||||
System.arraycopy(data, 0, newData, 0, length*5);
|
||||
data = newData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Report a bad array index in a manipulator.
|
||||
*
|
||||
* @param index The index to report.
|
||||
* @exception java.lang.ArrayIndexOutOfBoundsException Always.
|
||||
*/
|
||||
private void badIndex (int index)
|
||||
throws ArrayIndexOutOfBoundsException
|
||||
{
|
||||
String msg =
|
||||
"Attempt to modify attribute at illegal index: " + index;
|
||||
throw new ArrayIndexOutOfBoundsException(msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Internal state.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
int length;
|
||||
String data [];
|
||||
|
||||
}
|
||||
|
||||
// end of AttributesImpl.java
|
||||
338
jdkSrc/jdk8/com/sun/tools/internal/jxc/gen/config/Classes.java
Normal file
338
jdkSrc/jdk8/com/sun/tools/internal/jxc/gen/config/Classes.java
Normal file
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* this file is generated by RelaxNGCC */
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.Attributes;
|
||||
import com.sun.tools.internal.jxc.NGCCRuntimeEx;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public class Classes extends NGCCHandler {
|
||||
private String __text;
|
||||
private String exclude_content;
|
||||
private String include_content;
|
||||
protected final NGCCRuntimeEx $runtime;
|
||||
private int $_ngcc_current_state;
|
||||
protected String $uri;
|
||||
protected String $localName;
|
||||
protected String $qname;
|
||||
|
||||
public final NGCCRuntime getRuntime() {
|
||||
return($runtime);
|
||||
}
|
||||
|
||||
public Classes(NGCCHandler parent, NGCCEventSource source, NGCCRuntimeEx runtime, int cookie) {
|
||||
super(source, parent, cookie);
|
||||
$runtime = runtime;
|
||||
$_ngcc_current_state = 12;
|
||||
}
|
||||
|
||||
public Classes(NGCCRuntimeEx runtime) {
|
||||
this(null, runtime, runtime, -1);
|
||||
}
|
||||
|
||||
private void action0()throws SAXException {
|
||||
this.excludes.add(exclude_content);
|
||||
}
|
||||
|
||||
private void action1()throws SAXException {
|
||||
$runtime.processList(__text);}
|
||||
|
||||
private void action2()throws SAXException {
|
||||
this.includes.add(include_content);
|
||||
}
|
||||
|
||||
private void action3()throws SAXException {
|
||||
$runtime.processList(__text);}
|
||||
|
||||
public void enterElement(String $__uri, String $__local, String $__qname, Attributes $attrs) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 12:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("classes"))) {
|
||||
$runtime.onEnterElementConsumed($__uri, $__local, $__qname, $attrs);
|
||||
$_ngcc_current_state = 11;
|
||||
}
|
||||
else {
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("excludes"))) {
|
||||
$runtime.onEnterElementConsumed($__uri, $__local, $__qname, $attrs);
|
||||
$_ngcc_current_state = 6;
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
$_ngcc_current_state = 3;
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("includes"))) {
|
||||
$runtime.onEnterElementConsumed($__uri, $__local, $__qname, $attrs);
|
||||
$_ngcc_current_state = 10;
|
||||
}
|
||||
else {
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromEnterElement(this, super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void leaveElement(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
$_ngcc_current_state = 3;
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("classes"))) {
|
||||
$runtime.onLeaveElementConsumed($__uri, $__local, $__qname);
|
||||
$_ngcc_current_state = 0;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("excludes"))) {
|
||||
$runtime.onLeaveElementConsumed($__uri, $__local, $__qname);
|
||||
$_ngcc_current_state = 1;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromLeaveElement(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("includes"))) {
|
||||
$runtime.onLeaveElementConsumed($__uri, $__local, $__qname);
|
||||
$_ngcc_current_state = 2;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void enterAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
$_ngcc_current_state = 3;
|
||||
$runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromEnterAttribute(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedEnterAttribute($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void leaveAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
$_ngcc_current_state = 3;
|
||||
$runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromLeaveAttribute(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedLeaveAttribute($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void text(String $value) throws SAXException {
|
||||
int $ai;
|
||||
switch($_ngcc_current_state) {
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendText(super._cookie, $value);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
exclude_content = $value;
|
||||
$_ngcc_current_state = 3;
|
||||
action0();
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
{
|
||||
__text = $value;
|
||||
$_ngcc_current_state = 9;
|
||||
action3();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
exclude_content = $value;
|
||||
$_ngcc_current_state = 3;
|
||||
action0();
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
__text = $value;
|
||||
$_ngcc_current_state = 4;
|
||||
action1();
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromText(this, super._cookie, $value);
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
{
|
||||
include_content = $value;
|
||||
$_ngcc_current_state = 8;
|
||||
action2();
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
{
|
||||
include_content = $value;
|
||||
$_ngcc_current_state = 8;
|
||||
action2();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onChildCompleted(Object result, int cookie, boolean needAttCheck)throws SAXException {
|
||||
switch(cookie) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean accepted() {
|
||||
return(($_ngcc_current_state == 0));
|
||||
}
|
||||
|
||||
|
||||
private List includes = new ArrayList();
|
||||
public List getIncludes() { return $runtime.getIncludePatterns(this.includes);}
|
||||
private List excludes = new ArrayList();
|
||||
public List getExcludes() { return $runtime.getExcludePatterns(this.excludes);}
|
||||
|
||||
}
|
||||
336
jdkSrc/jdk8/com/sun/tools/internal/jxc/gen/config/Config.java
Normal file
336
jdkSrc/jdk8/com/sun/tools/internal/jxc/gen/config/Config.java
Normal file
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* this file is generated by RelaxNGCC */
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.Attributes;
|
||||
import com.sun.tools.internal.jxc.NGCCRuntimeEx;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public class Config extends NGCCHandler {
|
||||
private String bd;
|
||||
private Schema _schema;
|
||||
protected final NGCCRuntimeEx $runtime;
|
||||
private int $_ngcc_current_state;
|
||||
protected String $uri;
|
||||
protected String $localName;
|
||||
protected String $qname;
|
||||
|
||||
public final NGCCRuntime getRuntime() {
|
||||
return($runtime);
|
||||
}
|
||||
|
||||
public Config(NGCCHandler parent, NGCCEventSource source, NGCCRuntimeEx runtime, int cookie) {
|
||||
super(source, parent, cookie);
|
||||
$runtime = runtime;
|
||||
$_ngcc_current_state = 8;
|
||||
}
|
||||
|
||||
public Config(NGCCRuntimeEx runtime) {
|
||||
this(null, runtime, runtime, -1);
|
||||
}
|
||||
|
||||
private void action0()throws SAXException {
|
||||
this.schema.add (_schema);
|
||||
}
|
||||
|
||||
private void action1()throws SAXException {
|
||||
baseDir = $runtime.getBaseDir(bd);
|
||||
}
|
||||
|
||||
public void enterElement(String $__uri, String $__local, String $__qname, Attributes $attrs) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromEnterElement(this, super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("schema"))) {
|
||||
NGCCHandler h = new Schema(this, super._source, $runtime, 19, baseDir);
|
||||
spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
else {
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("config"))) {
|
||||
$runtime.onEnterElementConsumed($__uri, $__local, $__qname, $attrs);
|
||||
$_ngcc_current_state = 7;
|
||||
}
|
||||
else {
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("classes"))) {
|
||||
NGCCHandler h = new Classes(this, super._source, $runtime, 22);
|
||||
spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
else {
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("schema"))) {
|
||||
NGCCHandler h = new Schema(this, super._source, $runtime, 20, baseDir);
|
||||
spawnChildFromEnterElement(h, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","baseDir"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
else {
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void leaveElement(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromLeaveElement(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("config"))) {
|
||||
$runtime.onLeaveElementConsumed($__uri, $__local, $__qname);
|
||||
$_ngcc_current_state = 0;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","baseDir"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void enterAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromEnterAttribute(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("baseDir"))) {
|
||||
$_ngcc_current_state = 6;
|
||||
}
|
||||
else {
|
||||
unexpectedEnterAttribute($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedEnterAttribute($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void leaveAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromLeaveAttribute(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("baseDir"))) {
|
||||
$_ngcc_current_state = 4;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveAttribute($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedLeaveAttribute($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void text(String $value) throws SAXException {
|
||||
int $ai;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromText(this, super._cookie, $value);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
bd = $value;
|
||||
$_ngcc_current_state = 5;
|
||||
action1();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendText(super._cookie, $value);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","baseDir"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendText(super._cookie, $value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onChildCompleted(Object result, int cookie, boolean needAttCheck)throws SAXException {
|
||||
switch(cookie) {
|
||||
case 19:
|
||||
{
|
||||
this._schema = ((Schema)result);
|
||||
action0();
|
||||
$_ngcc_current_state = 1;
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
{
|
||||
this.classes = ((Classes)result);
|
||||
$_ngcc_current_state = 2;
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
{
|
||||
this._schema = ((Schema)result);
|
||||
action0();
|
||||
$_ngcc_current_state = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean accepted() {
|
||||
return(($_ngcc_current_state == 0));
|
||||
}
|
||||
|
||||
|
||||
private File baseDir;
|
||||
private Classes classes;
|
||||
private List schema = new ArrayList();
|
||||
public Classes getClasses() { return this.classes;}
|
||||
public File getBaseDir() { return baseDir;}
|
||||
public List getSchema() { return this.schema;}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public interface NGCCEventReceiver {
|
||||
void enterElement(String uri, String localName, String qname,Attributes atts) throws SAXException;
|
||||
void leaveElement(String uri, String localName, String qname) throws SAXException;
|
||||
void text(String value) throws SAXException;
|
||||
void enterAttribute(String uri, String localName, String qname) throws SAXException;
|
||||
void leaveAttribute(String uri, String localName, String qname) throws SAXException;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public interface NGCCEventSource {
|
||||
/**
|
||||
* Replaces an old handler with a new handler, and returns
|
||||
* ID of the EventReceiver thread.
|
||||
*/
|
||||
int replace( NGCCEventReceiver _old, NGCCEventReceiver _new );
|
||||
|
||||
/** Sends an enter element event to the specified EventReceiver thread. */
|
||||
void sendEnterElement( int receiverThreadId, String uri, String local, String qname, Attributes atts ) throws SAXException;
|
||||
|
||||
void sendLeaveElement( int receiverThreadId, String uri, String local, String qname ) throws SAXException;
|
||||
void sendEnterAttribute( int receiverThreadId, String uri, String local, String qname ) throws SAXException;
|
||||
void sendLeaveAttribute( int receiverThreadId, String uri, String local, String qname ) throws SAXException;
|
||||
void sendText( int receiverThreadId, String value ) throws SAXException;
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*
|
||||
* @version $Id: NGCCHandler.java,v 1.9 2002/09/29 02:55:48 okajima Exp $
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public abstract class NGCCHandler implements NGCCEventReceiver {
|
||||
protected NGCCHandler( NGCCEventSource source, NGCCHandler parent, int parentCookie ) {
|
||||
|
||||
_parent = parent;
|
||||
_source = source;
|
||||
_cookie = parentCookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parent NGCCHandler, if any.
|
||||
* If this is the root handler, this field will be null.
|
||||
*/
|
||||
protected final NGCCHandler _parent;
|
||||
|
||||
/**
|
||||
* Event source.
|
||||
*/
|
||||
protected final NGCCEventSource _source;
|
||||
|
||||
/**
|
||||
* This method will be implemented by the generated code
|
||||
* and returns a reference to the current runtime.
|
||||
*/
|
||||
protected abstract NGCCRuntime getRuntime();
|
||||
|
||||
/**
|
||||
* Cookie assigned by the parent.
|
||||
*
|
||||
* This value will be passed to the onChildCompleted handler
|
||||
* of the parent.
|
||||
*/
|
||||
protected final int _cookie;
|
||||
|
||||
// used to copy parameters to (enter|leave)(Element|Attribute) events.
|
||||
//protected String localName,uri,qname;
|
||||
|
||||
|
||||
/**
|
||||
* Notifies the completion of a child object.
|
||||
*
|
||||
* @param result
|
||||
* The parsing result of the child state.
|
||||
* @param cookie
|
||||
* The cookie value passed to the child object
|
||||
* when it is created.
|
||||
* @param needAttCheck
|
||||
* This flag is true when the callee needs to call the
|
||||
* processAttribute method to check attribute transitions.
|
||||
* This flag is set to false when this method is triggered by
|
||||
* attribute transition.
|
||||
*/
|
||||
protected abstract void onChildCompleted( Object result, int cookie, boolean needAttCheck ) throws SAXException;
|
||||
|
||||
//
|
||||
//
|
||||
// spawns a new child object from event handlers.
|
||||
//
|
||||
//
|
||||
public void spawnChildFromEnterElement( NGCCEventReceiver child,
|
||||
String uri, String localname, String qname, Attributes atts) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,child);
|
||||
_source.sendEnterElement(id,uri,localname,qname,atts);
|
||||
}
|
||||
public void spawnChildFromEnterAttribute( NGCCEventReceiver child,
|
||||
String uri, String localname, String qname) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,child);
|
||||
_source.sendEnterAttribute(id,uri,localname,qname);
|
||||
}
|
||||
public void spawnChildFromLeaveElement( NGCCEventReceiver child,
|
||||
String uri, String localname, String qname) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,child);
|
||||
_source.sendLeaveElement(id,uri,localname,qname);
|
||||
}
|
||||
public void spawnChildFromLeaveAttribute( NGCCEventReceiver child,
|
||||
String uri, String localname, String qname) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,child);
|
||||
_source.sendLeaveAttribute(id,uri,localname,qname);
|
||||
}
|
||||
public void spawnChildFromText( NGCCEventReceiver child,
|
||||
String value) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,child);
|
||||
_source.sendText(id,value);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// reverts to the parent object from the child handler
|
||||
//
|
||||
//
|
||||
public void revertToParentFromEnterElement( Object result, int cookie,
|
||||
String uri,String local,String qname, Attributes atts ) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,_parent);
|
||||
_parent.onChildCompleted(result,cookie,true);
|
||||
_source.sendEnterElement(id,uri,local,qname,atts);
|
||||
}
|
||||
public void revertToParentFromLeaveElement( Object result, int cookie,
|
||||
String uri,String local,String qname ) throws SAXException {
|
||||
|
||||
if(uri==NGCCRuntime.IMPOSSIBLE && uri==local && uri==qname && _parent==null )
|
||||
// all the handlers are properly finalized.
|
||||
// quit now, because we don't have any more NGCCHandler.
|
||||
// see the endDocument handler for detail
|
||||
return;
|
||||
|
||||
int id = _source.replace(this,_parent);
|
||||
_parent.onChildCompleted(result,cookie,true);
|
||||
_source.sendLeaveElement(id,uri,local,qname);
|
||||
}
|
||||
public void revertToParentFromEnterAttribute( Object result, int cookie,
|
||||
String uri,String local,String qname ) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,_parent);
|
||||
_parent.onChildCompleted(result,cookie,true);
|
||||
_source.sendEnterAttribute(id,uri,local,qname);
|
||||
}
|
||||
public void revertToParentFromLeaveAttribute( Object result, int cookie,
|
||||
String uri,String local,String qname ) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,_parent);
|
||||
_parent.onChildCompleted(result,cookie,true);
|
||||
_source.sendLeaveAttribute(id,uri,local,qname);
|
||||
}
|
||||
public void revertToParentFromText( Object result, int cookie,
|
||||
String text ) throws SAXException {
|
||||
|
||||
int id = _source.replace(this,_parent);
|
||||
_parent.onChildCompleted(result,cookie,true);
|
||||
_source.sendText(id,text);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// error handler
|
||||
//
|
||||
//
|
||||
public void unexpectedEnterElement(String qname) throws SAXException {
|
||||
getRuntime().unexpectedX('<'+qname+'>');
|
||||
}
|
||||
public void unexpectedLeaveElement(String qname) throws SAXException {
|
||||
getRuntime().unexpectedX("</"+qname+'>');
|
||||
}
|
||||
public void unexpectedEnterAttribute(String qname) throws SAXException {
|
||||
getRuntime().unexpectedX('@'+qname);
|
||||
}
|
||||
public void unexpectedLeaveAttribute(String qname) throws SAXException {
|
||||
getRuntime().unexpectedX("/@"+qname);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Dispatches incoming events into sub handlers appropriately
|
||||
* so that the interleaving semantics will be correctly realized.
|
||||
*
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public abstract class NGCCInterleaveFilter implements NGCCEventSource, NGCCEventReceiver {
|
||||
protected NGCCInterleaveFilter( NGCCHandler parent, int cookie ) {
|
||||
this._parent = parent;
|
||||
this._cookie = cookie;
|
||||
}
|
||||
|
||||
protected void setHandlers( NGCCEventReceiver[] receivers ) {
|
||||
this._receivers = receivers;
|
||||
}
|
||||
|
||||
/** event receiverse. */
|
||||
protected NGCCEventReceiver[] _receivers;
|
||||
|
||||
public int replace(NGCCEventReceiver oldHandler, NGCCEventReceiver newHandler) {
|
||||
for( int i=0; i<_receivers.length; i++ )
|
||||
if( _receivers[i]==oldHandler ) {
|
||||
_receivers[i]=newHandler;
|
||||
return i;
|
||||
}
|
||||
throw new InternalError(); // a bug in RelaxNGCC.
|
||||
}
|
||||
|
||||
|
||||
/** Parent handler. */
|
||||
private final NGCCHandler _parent;
|
||||
/** Cookie given by the parent. */
|
||||
private final int _cookie;
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// event handler
|
||||
//
|
||||
//
|
||||
/**
|
||||
* Receiver that is being locked and therefore receives all the events.
|
||||
* <pre><xmp>
|
||||
* <interleave>
|
||||
* <element name="foo"/>
|
||||
* <element name="bar">
|
||||
* <element name="foo"/>
|
||||
* </element>
|
||||
* </interlaeve>
|
||||
* </xmp></pre>
|
||||
* When processing inside the bar element, this receiver is
|
||||
* "locked" so that it can correctly receive its child foo element.
|
||||
*/
|
||||
private int lockedReceiver;
|
||||
/**
|
||||
* Nest level. Lock will be release when the lockCount becomes 0.
|
||||
*/
|
||||
private int lockCount=0;
|
||||
|
||||
public void enterElement(
|
||||
String uri, String localName, String qname,Attributes atts) throws SAXException {
|
||||
|
||||
if(isJoining) return; // ignore any token if we are joining. See joinByXXXX.
|
||||
|
||||
if(lockCount++==0) {
|
||||
lockedReceiver = findReceiverOfElement(uri,localName);
|
||||
if(lockedReceiver==-1) {
|
||||
// we can't process this token. join.
|
||||
joinByEnterElement(null,uri,localName,qname,atts);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_receivers[lockedReceiver].enterElement(uri,localName,qname,atts);
|
||||
}
|
||||
public void leaveElement(String uri, String localName, String qname) throws SAXException {
|
||||
if(isJoining) return; // ignore any token if we are joining. See joinByXXXX.
|
||||
|
||||
if( lockCount-- == 0 )
|
||||
joinByLeaveElement(null,uri,localName,qname);
|
||||
else
|
||||
_receivers[lockedReceiver].leaveElement(uri,localName,qname);
|
||||
}
|
||||
public void enterAttribute(String uri, String localName, String qname) throws SAXException {
|
||||
if(isJoining) return; // ignore any token if we are joining. See joinByXXXX.
|
||||
|
||||
if(lockCount++==0) {
|
||||
lockedReceiver = findReceiverOfAttribute(uri,localName);
|
||||
if(lockedReceiver==-1) {
|
||||
// we can't process this token. join.
|
||||
joinByEnterAttribute(null,uri,localName,qname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_receivers[lockedReceiver].enterAttribute(uri,localName,qname);
|
||||
}
|
||||
public void leaveAttribute(String uri, String localName, String qname) throws SAXException {
|
||||
if(isJoining) return; // ignore any token if we are joining. See joinByXXXX.
|
||||
|
||||
if( lockCount-- == 0 )
|
||||
joinByLeaveAttribute(null,uri,localName,qname);
|
||||
else
|
||||
_receivers[lockedReceiver].leaveAttribute(uri,localName,qname);
|
||||
}
|
||||
public void text(String value) throws SAXException {
|
||||
if(isJoining) return; // ignore any token if we are joining. See joinByXXXX.
|
||||
|
||||
if(lockCount!=0)
|
||||
_receivers[lockedReceiver].text(value);
|
||||
else {
|
||||
int receiver = findReceiverOfText();
|
||||
if(receiver!=-1) _receivers[receiver].text(value);
|
||||
else joinByText(null,value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implemented by the generated code to determine the handler
|
||||
* that can receive the given element.
|
||||
*
|
||||
* @return
|
||||
* Thread ID of the receiver that can handle this event,
|
||||
* or -1 if none.
|
||||
*/
|
||||
protected abstract int findReceiverOfElement( String uri, String local );
|
||||
|
||||
/**
|
||||
* Returns the handler that can receive the given attribute, or null.
|
||||
*/
|
||||
protected abstract int findReceiverOfAttribute( String uri, String local );
|
||||
|
||||
/**
|
||||
* Returns the handler that can receive text events, or null.
|
||||
*/
|
||||
protected abstract int findReceiverOfText();
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// join method
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Set to true when this handler is in the process of
|
||||
* joining all branches.
|
||||
*/
|
||||
private boolean isJoining = false;
|
||||
|
||||
/**
|
||||
* Joins all the child receivers.
|
||||
*
|
||||
* <p>
|
||||
* This method is called by a child receiver when it sees
|
||||
* something that it cannot handle, or by this object itself
|
||||
* when it sees an event that it can't process.
|
||||
*
|
||||
* <p>
|
||||
* This method forces children to move to its final state,
|
||||
* then revert to the parent.
|
||||
*
|
||||
* @param source
|
||||
* If this method is called by one of the child receivers,
|
||||
* the receiver object. If this method is called by itself,
|
||||
* null.
|
||||
*/
|
||||
public void joinByEnterElement( NGCCEventReceiver source,
|
||||
String uri, String local, String qname, Attributes atts ) throws SAXException {
|
||||
|
||||
if(isJoining) return; // we are already in the process of joining. ignore.
|
||||
isJoining = true;
|
||||
|
||||
// send special token to the rest of the branches.
|
||||
// these branches don't understand this token, so they will
|
||||
// try to move to a final state and send the token back to us,
|
||||
// which this object will ignore (because isJoining==true)
|
||||
// Otherwise branches will find an error.
|
||||
for( int i=0; i<_receivers.length; i++ )
|
||||
if( _receivers[i]!=source )
|
||||
_receivers[i].enterElement(uri,local,qname,atts);
|
||||
|
||||
// revert to the parent
|
||||
_parent._source.replace(this,_parent);
|
||||
_parent.onChildCompleted(null,_cookie,true);
|
||||
// send this event to the parent
|
||||
_parent.enterElement(uri,local,qname,atts);
|
||||
}
|
||||
|
||||
public void joinByLeaveElement( NGCCEventReceiver source,
|
||||
String uri, String local, String qname ) throws SAXException {
|
||||
|
||||
if(isJoining) return; // we are already in the process of joining. ignore.
|
||||
isJoining = true;
|
||||
|
||||
// send special token to the rest of the branches.
|
||||
// these branches don't understand this token, so they will
|
||||
// try to move to a final state and send the token back to us,
|
||||
// which this object will ignore (because isJoining==true)
|
||||
// Otherwise branches will find an error.
|
||||
for( int i=0; i<_receivers.length; i++ )
|
||||
if( _receivers[i]!=source )
|
||||
_receivers[i].leaveElement(uri,local,qname);
|
||||
|
||||
// revert to the parent
|
||||
_parent._source.replace(this,_parent);
|
||||
_parent.onChildCompleted(null,_cookie,true);
|
||||
// send this event to the parent
|
||||
_parent.leaveElement(uri,local,qname);
|
||||
}
|
||||
|
||||
public void joinByEnterAttribute( NGCCEventReceiver source,
|
||||
String uri, String local, String qname ) throws SAXException {
|
||||
|
||||
if(isJoining) return; // we are already in the process of joining. ignore.
|
||||
isJoining = true;
|
||||
|
||||
// send special token to the rest of the branches.
|
||||
// these branches don't understand this token, so they will
|
||||
// try to move to a final state and send the token back to us,
|
||||
// which this object will ignore (because isJoining==true)
|
||||
// Otherwise branches will find an error.
|
||||
for( int i=0; i<_receivers.length; i++ )
|
||||
if( _receivers[i]!=source )
|
||||
_receivers[i].enterAttribute(uri,local,qname);
|
||||
|
||||
// revert to the parent
|
||||
_parent._source.replace(this,_parent);
|
||||
_parent.onChildCompleted(null,_cookie,true);
|
||||
// send this event to the parent
|
||||
_parent.enterAttribute(uri,local,qname);
|
||||
}
|
||||
|
||||
public void joinByLeaveAttribute( NGCCEventReceiver source,
|
||||
String uri, String local, String qname ) throws SAXException {
|
||||
|
||||
if(isJoining) return; // we are already in the process of joining. ignore.
|
||||
isJoining = true;
|
||||
|
||||
// send special token to the rest of the branches.
|
||||
// these branches don't understand this token, so they will
|
||||
// try to move to a final state and send the token back to us,
|
||||
// which this object will ignore (because isJoining==true)
|
||||
// Otherwise branches will find an error.
|
||||
for( int i=0; i<_receivers.length; i++ )
|
||||
if( _receivers[i]!=source )
|
||||
_receivers[i].leaveAttribute(uri,local,qname);
|
||||
|
||||
// revert to the parent
|
||||
_parent._source.replace(this,_parent);
|
||||
_parent.onChildCompleted(null,_cookie,true);
|
||||
// send this event to the parent
|
||||
_parent.leaveAttribute(uri,local,qname);
|
||||
}
|
||||
|
||||
public void joinByText( NGCCEventReceiver source,
|
||||
String value ) throws SAXException {
|
||||
|
||||
if(isJoining) return; // we are already in the process of joining. ignore.
|
||||
isJoining = true;
|
||||
|
||||
// send special token to the rest of the branches.
|
||||
// these branches don't understand this token, so they will
|
||||
// try to move to a final state and send the token back to us,
|
||||
// which this object will ignore (because isJoining==true)
|
||||
// Otherwise branches will find an error.
|
||||
for( int i=0; i<_receivers.length; i++ )
|
||||
if( _receivers[i]!=source )
|
||||
_receivers[i].text(value);
|
||||
|
||||
// revert to the parent
|
||||
_parent._source.replace(this,_parent);
|
||||
_parent.onChildCompleted(null,_cookie,true);
|
||||
// send this event to the parent
|
||||
_parent.text(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// event dispatching methods
|
||||
//
|
||||
//
|
||||
|
||||
public void sendEnterAttribute( int threadId,
|
||||
String uri, String local, String qname) throws SAXException {
|
||||
|
||||
_receivers[threadId].enterAttribute(uri,local,qname);
|
||||
}
|
||||
|
||||
public void sendEnterElement( int threadId,
|
||||
String uri, String local, String qname, Attributes atts) throws SAXException {
|
||||
|
||||
_receivers[threadId].enterElement(uri,local,qname,atts);
|
||||
}
|
||||
|
||||
public void sendLeaveAttribute( int threadId,
|
||||
String uri, String local, String qname) throws SAXException {
|
||||
|
||||
_receivers[threadId].leaveAttribute(uri,local,qname);
|
||||
}
|
||||
|
||||
public void sendLeaveElement( int threadId,
|
||||
String uri, String local, String qname) throws SAXException {
|
||||
|
||||
_receivers[threadId].leaveElement(uri,local,qname);
|
||||
}
|
||||
|
||||
public void sendText(int threadId, String value) throws SAXException {
|
||||
_receivers[threadId].text(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,557 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* Runtime Engine for RELAXNGCC execution.
|
||||
*
|
||||
* This class has the following functionalities:
|
||||
*
|
||||
* <ol>
|
||||
* <li>Managing a stack of NGCCHandler objects and
|
||||
* switching between them appropriately.
|
||||
*
|
||||
* <li>Keep track of all Attributes.
|
||||
*
|
||||
* <li>manage mapping between namespace URIs and prefixes.
|
||||
*
|
||||
* <li>TODO: provide support for interleaving.
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
* @version $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public class NGCCRuntime implements ContentHandler, NGCCEventSource {
|
||||
|
||||
public NGCCRuntime() {
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the root handler, which will be used to parse the
|
||||
* root element.
|
||||
* <p>
|
||||
* This method can be called right after the object is created
|
||||
* or the reset method is called. You can't replace the root
|
||||
* handler while parsing is in progress.
|
||||
* <p>
|
||||
* Usually a generated class that corresponds to the <start>
|
||||
* pattern will be used as the root handler, but any NGCCHandler
|
||||
* can be a root handler.
|
||||
*
|
||||
* @exception IllegalStateException
|
||||
* If this method is called but it doesn't satisfy the
|
||||
* pre-condition stated above.
|
||||
*/
|
||||
public void setRootHandler( NGCCHandler rootHandler ) {
|
||||
if(currentHandler!=null)
|
||||
throw new IllegalStateException();
|
||||
currentHandler = rootHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up all the data structure so that the object can be reused later.
|
||||
* Normally, applications do not need to call this method directly,
|
||||
*
|
||||
* as the runtime resets itself after the endDocument method.
|
||||
*/
|
||||
public void reset() {
|
||||
attStack.clear();
|
||||
currentAtts = null;
|
||||
currentHandler = null;
|
||||
indent=0;
|
||||
locator = null;
|
||||
namespaces.clear();
|
||||
needIndent = true;
|
||||
redirect = null;
|
||||
redirectionDepth = 0;
|
||||
text = new StringBuffer();
|
||||
|
||||
// add a dummy attributes at the bottom as a "centinel."
|
||||
attStack.push(new AttributesImpl());
|
||||
}
|
||||
|
||||
// current content handler can be acccessed via set/getContentHandler.
|
||||
|
||||
private Locator locator;
|
||||
public void setDocumentLocator( Locator _loc ) { this.locator=_loc; }
|
||||
/**
|
||||
* Gets the source location of the current event.
|
||||
*
|
||||
* <p>
|
||||
* One can call this method from RelaxNGCC handlers to access
|
||||
* the line number information. Note that to
|
||||
*/
|
||||
public Locator getLocator() { return locator; }
|
||||
|
||||
|
||||
/** stack of {@link Attributes}. */
|
||||
private final Stack attStack = new Stack();
|
||||
/** current attributes set. always equal to attStack.peek() */
|
||||
private AttributesImpl currentAtts;
|
||||
|
||||
/**
|
||||
* Attributes that belong to the current element.
|
||||
* <p>
|
||||
* It's generally not recommended for applications to use
|
||||
* this method. RelaxNGCC internally removes processed attributes,
|
||||
* so this doesn't correctly reflect all the attributes an element
|
||||
* carries.
|
||||
*/
|
||||
public Attributes getCurrentAttributes() {
|
||||
return currentAtts;
|
||||
}
|
||||
|
||||
/** accumulated text. */
|
||||
private StringBuffer text = new StringBuffer();
|
||||
|
||||
|
||||
|
||||
|
||||
/** The current NGCCHandler. Always equals to handlerStack.peek() */
|
||||
private NGCCEventReceiver currentHandler;
|
||||
|
||||
public int replace( NGCCEventReceiver o, NGCCEventReceiver n ) {
|
||||
if(o!=currentHandler)
|
||||
throw new IllegalStateException(); // bug of RelaxNGCC
|
||||
currentHandler = n;
|
||||
|
||||
return 0; // we only have one thread.
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes buffered text.
|
||||
*
|
||||
* This method will be called by the start/endElement event to process
|
||||
* buffered text as a text event.
|
||||
*
|
||||
* <p>
|
||||
* Whitespace handling is a tricky business. Consider the following
|
||||
* schema fragment:
|
||||
*
|
||||
* <xmp>
|
||||
* <element name="foo">
|
||||
* <choice>
|
||||
* <element name="bar"><empty/></element>
|
||||
* <text/>
|
||||
* </choice>
|
||||
* </element>
|
||||
* </xmp>
|
||||
*
|
||||
* Assume we hit the following instance:
|
||||
* <xmp>
|
||||
* <foo> <bar/></foo>
|
||||
* </xmp>
|
||||
*
|
||||
* Then this first space needs to be ignored (for otherwise, we will
|
||||
* end up treating this space as the match to <text/> and won't
|
||||
* be able to process <bar>.)
|
||||
*
|
||||
* Now assume the following instance:
|
||||
* <xmp>
|
||||
* <foo/>
|
||||
* </xmp>
|
||||
*
|
||||
* This time, we need to treat this empty string as a text, for
|
||||
* otherwise we won't be able to accept this instance.
|
||||
*
|
||||
* <p>
|
||||
* This is very difficult to solve in general, but one seemingly
|
||||
* easy solution is to use the type of next event. If a text is
|
||||
* followed by a start tag, it follows from the constraint on
|
||||
* RELAX NG that that text must be either whitespaces or a match
|
||||
* to <text/>.
|
||||
*
|
||||
* <p>
|
||||
* On the contrary, if a text is followed by a end tag, then it
|
||||
* cannot be whitespace unless the content model can accept empty,
|
||||
* in which case sending a text event will be harmlessly ignored
|
||||
* by the NGCCHandler.
|
||||
*
|
||||
* <p>
|
||||
* Thus this method take one parameter, which controls the
|
||||
* behavior of this method.
|
||||
*
|
||||
* <p>
|
||||
* TODO: according to the constraint of RELAX NG, if characters
|
||||
* follow an end tag, then they must be either whitespaces or
|
||||
* must match to <text/>.
|
||||
*
|
||||
* @param possiblyWhitespace
|
||||
* True if the buffered character can be ignorabale. False if
|
||||
* it needs to be consumed.
|
||||
*/
|
||||
private void processPendingText(boolean ignorable) throws SAXException {
|
||||
if(ignorable && text.toString().trim().length()==0)
|
||||
; // ignore. See the above javadoc comment for the description
|
||||
else
|
||||
currentHandler.text(text.toString()); // otherwise consume this token
|
||||
|
||||
// truncate StringBuffer, but avoid excessive allocation.
|
||||
if(text.length()>1024) text = new StringBuffer();
|
||||
else text.setLength(0);
|
||||
}
|
||||
|
||||
public void processList( String str ) throws SAXException {
|
||||
StringTokenizer t = new StringTokenizer(str, " \t\r\n");
|
||||
while(t.hasMoreTokens())
|
||||
currentHandler.text(t.nextToken());
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localname, String qname, Attributes atts)
|
||||
throws SAXException {
|
||||
|
||||
if(redirect!=null) {
|
||||
redirect.startElement(uri,localname,qname,atts);
|
||||
redirectionDepth++;
|
||||
} else {
|
||||
processPendingText(true);
|
||||
// System.out.println("startElement:"+localname+"->"+_attrStack.size());
|
||||
currentHandler.enterElement(uri, localname, qname, atts);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the generated handler code when an enter element
|
||||
* event is consumed.
|
||||
*
|
||||
* <p>
|
||||
* Pushes a new attribute set.
|
||||
*
|
||||
* <p>
|
||||
* Note that attributes are NOT pushed at the startElement method,
|
||||
* because the processing of the enterElement event can trigger
|
||||
* other attribute events and etc.
|
||||
* <p>
|
||||
* This method will be called from one of handlers when it truely
|
||||
* consumes the enterElement event.
|
||||
*/
|
||||
public void onEnterElementConsumed(
|
||||
String uri, String localName, String qname,Attributes atts) throws SAXException {
|
||||
attStack.push(currentAtts=new AttributesImpl(atts));
|
||||
nsEffectiveStack.push( new Integer(nsEffectivePtr) );
|
||||
nsEffectivePtr = namespaces.size();
|
||||
}
|
||||
|
||||
public void onLeaveElementConsumed(String uri, String localName, String qname) throws SAXException {
|
||||
attStack.pop();
|
||||
if(attStack.isEmpty())
|
||||
currentAtts = null;
|
||||
else
|
||||
currentAtts = (AttributesImpl)attStack.peek();
|
||||
nsEffectivePtr = ((Integer)nsEffectiveStack.pop()).intValue();
|
||||
}
|
||||
|
||||
public void endElement(String uri, String localname, String qname)
|
||||
throws SAXException {
|
||||
|
||||
if(redirect!=null) {
|
||||
redirect.endElement(uri,localname,qname);
|
||||
redirectionDepth--;
|
||||
|
||||
if(redirectionDepth!=0)
|
||||
return;
|
||||
|
||||
// finished redirection.
|
||||
for( int i=0; i<namespaces.size(); i+=2 )
|
||||
redirect.endPrefixMapping((String)namespaces.get(i));
|
||||
redirect.endDocument();
|
||||
|
||||
redirect = null;
|
||||
// then process this element normally
|
||||
}
|
||||
|
||||
processPendingText(false);
|
||||
|
||||
currentHandler.leaveElement(uri, localname, qname);
|
||||
// System.out.println("endElement:"+localname);
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if(redirect!=null)
|
||||
redirect.characters(ch,start,length);
|
||||
else
|
||||
text.append(ch,start,length);
|
||||
}
|
||||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
||||
if(redirect!=null)
|
||||
redirect.ignorableWhitespace(ch,start,length);
|
||||
else
|
||||
text.append(ch,start,length);
|
||||
}
|
||||
|
||||
public int getAttributeIndex(String uri, String localname) {
|
||||
return currentAtts.getIndex(uri, localname);
|
||||
}
|
||||
public void consumeAttribute(int index) throws SAXException {
|
||||
final String uri = currentAtts.getURI(index);
|
||||
final String local = currentAtts.getLocalName(index);
|
||||
final String qname = currentAtts.getQName(index);
|
||||
final String value = currentAtts.getValue(index);
|
||||
currentAtts.removeAttribute(index);
|
||||
|
||||
currentHandler.enterAttribute(uri,local,qname);
|
||||
currentHandler.text(value);
|
||||
currentHandler.leaveAttribute(uri,local,qname);
|
||||
}
|
||||
|
||||
|
||||
public void startPrefixMapping( String prefix, String uri ) throws SAXException {
|
||||
if(redirect!=null)
|
||||
redirect.startPrefixMapping(prefix,uri);
|
||||
else {
|
||||
namespaces.add(prefix);
|
||||
namespaces.add(uri);
|
||||
}
|
||||
}
|
||||
|
||||
public void endPrefixMapping( String prefix ) throws SAXException {
|
||||
if(redirect!=null)
|
||||
redirect.endPrefixMapping(prefix);
|
||||
else {
|
||||
namespaces.remove(namespaces.size()-1);
|
||||
namespaces.remove(namespaces.size()-1);
|
||||
}
|
||||
}
|
||||
|
||||
public void skippedEntity( String name ) throws SAXException {
|
||||
if(redirect!=null)
|
||||
redirect.skippedEntity(name);
|
||||
}
|
||||
|
||||
public void processingInstruction( String target, String data ) throws SAXException {
|
||||
if(redirect!=null)
|
||||
redirect.processingInstruction(target,data);
|
||||
}
|
||||
|
||||
/** Impossible token. This value can never be a valid XML name. */
|
||||
static final String IMPOSSIBLE = "\u0000";
|
||||
|
||||
public void endDocument() throws SAXException {
|
||||
// consume the special "end document" token so that all the handlers
|
||||
// currently at the stack will revert to their respective parents.
|
||||
//
|
||||
// this is necessary to handle a grammar like
|
||||
// <start><ref name="X"/></start>
|
||||
// <define name="X">
|
||||
// <element name="root"><empty/></element>
|
||||
// </define>
|
||||
//
|
||||
// With this grammar, when the endElement event is consumed, two handlers
|
||||
// are on the stack (because a child object won't revert to its parent
|
||||
// unless it sees a next event.)
|
||||
|
||||
// pass around an "impossible" token.
|
||||
currentHandler.leaveElement(IMPOSSIBLE,IMPOSSIBLE,IMPOSSIBLE);
|
||||
|
||||
reset();
|
||||
}
|
||||
public void startDocument() {}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// event dispatching methods
|
||||
//
|
||||
//
|
||||
|
||||
public void sendEnterAttribute( int threadId,
|
||||
String uri, String local, String qname) throws SAXException {
|
||||
|
||||
currentHandler.enterAttribute(uri,local,qname);
|
||||
}
|
||||
|
||||
public void sendEnterElement( int threadId,
|
||||
String uri, String local, String qname, Attributes atts) throws SAXException {
|
||||
|
||||
currentHandler.enterElement(uri,local,qname,atts);
|
||||
}
|
||||
|
||||
public void sendLeaveAttribute( int threadId,
|
||||
String uri, String local, String qname) throws SAXException {
|
||||
|
||||
currentHandler.leaveAttribute(uri,local,qname);
|
||||
}
|
||||
|
||||
public void sendLeaveElement( int threadId,
|
||||
String uri, String local, String qname) throws SAXException {
|
||||
|
||||
currentHandler.leaveElement(uri,local,qname);
|
||||
}
|
||||
|
||||
public void sendText(int threadId, String value) throws SAXException {
|
||||
currentHandler.text(value);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// redirection of SAX2 events.
|
||||
//
|
||||
//
|
||||
/** When redirecting a sub-tree, this value will be non-null. */
|
||||
private ContentHandler redirect = null;
|
||||
|
||||
/**
|
||||
* Counts the depth of the elements when we are re-directing
|
||||
* a sub-tree to another ContentHandler.
|
||||
*/
|
||||
private int redirectionDepth = 0;
|
||||
|
||||
/**
|
||||
* This method can be called only from the enterElement handler.
|
||||
* The sub-tree rooted at the new element will be redirected
|
||||
* to the specified ContentHandler.
|
||||
*
|
||||
* <p>
|
||||
* Currently active NGCCHandler will only receive the leaveElement
|
||||
* event of the newly started element.
|
||||
*
|
||||
* @param uri,local,qname
|
||||
* Parameters passed to the enter element event. Used to
|
||||
* simulate the startElement event for the new ContentHandler.
|
||||
*/
|
||||
public void redirectSubtree( ContentHandler child,
|
||||
String uri, String local, String qname ) throws SAXException {
|
||||
|
||||
redirect = child;
|
||||
redirect.setDocumentLocator(locator);
|
||||
redirect.startDocument();
|
||||
|
||||
// TODO: when a prefix is re-bound to something else,
|
||||
// the following code is potentially dangerous. It should be
|
||||
// modified to report active bindings only.
|
||||
for( int i=0; i<namespaces.size(); i+=2 )
|
||||
redirect.startPrefixMapping(
|
||||
(String)namespaces.get(i),
|
||||
(String)namespaces.get(i+1)
|
||||
);
|
||||
|
||||
redirect.startElement(uri,local,qname,currentAtts);
|
||||
redirectionDepth=1;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// validation context implementation
|
||||
//
|
||||
//
|
||||
/** in-scope namespace mapping.
|
||||
* namespaces[2n ] := prefix
|
||||
* namespaces[2n+1] := namespace URI */
|
||||
private final ArrayList namespaces = new ArrayList();
|
||||
/**
|
||||
* Index on the namespaces array, which points to
|
||||
* the top of the effective bindings. Because of the
|
||||
* timing difference between the startPrefixMapping method
|
||||
* and the execution of the corresponding actions,
|
||||
* this value can be different from <code>namespaces.size()</code>.
|
||||
* <p>
|
||||
* For example, consider the following schema:
|
||||
* <pre><xmp>
|
||||
* <oneOrMore>
|
||||
* <element name="foo"><empty/></element>
|
||||
* </oneOrMore>
|
||||
* code fragment X
|
||||
* <element name="bob"/>
|
||||
* </xmp></pre>
|
||||
* Code fragment X is executed after we see a startElement event,
|
||||
* but at this time the namespaces variable already include new
|
||||
* namespace bindings declared on "bob".
|
||||
*/
|
||||
private int nsEffectivePtr=0;
|
||||
|
||||
/**
|
||||
* Stack to preserve old nsEffectivePtr values.
|
||||
*/
|
||||
private final Stack nsEffectiveStack = new Stack();
|
||||
|
||||
public String resolveNamespacePrefix( String prefix ) {
|
||||
for( int i = nsEffectivePtr-2; i>=0; i-=2 )
|
||||
if( namespaces.get(i).equals(prefix) )
|
||||
return (String)namespaces.get(i+1);
|
||||
|
||||
// no binding was found.
|
||||
if(prefix.equals("")) return ""; // return the default no-namespace
|
||||
if(prefix.equals("xml")) // pre-defined xml prefix
|
||||
return "http://www.w3.org/XML/1998/namespace";
|
||||
else return null; // prefix undefined
|
||||
}
|
||||
|
||||
|
||||
// error reporting
|
||||
protected void unexpectedX(String token) throws SAXException {
|
||||
throw new SAXParseException(MessageFormat.format(
|
||||
"Unexpected {0} appears at line {1} column {2}",
|
||||
new Object[]{
|
||||
token,
|
||||
new Integer(getLocator().getLineNumber()),
|
||||
new Integer(getLocator().getColumnNumber()) }),
|
||||
getLocator());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// trace functions
|
||||
//
|
||||
//
|
||||
private int indent=0;
|
||||
private boolean needIndent=true;
|
||||
private void printIndent() {
|
||||
for( int i=0; i<indent; i++ )
|
||||
System.out.print(" ");
|
||||
}
|
||||
public void trace( String s ) {
|
||||
if(needIndent) {
|
||||
needIndent=false;
|
||||
printIndent();
|
||||
}
|
||||
System.out.print(s);
|
||||
}
|
||||
public void traceln( String s ) {
|
||||
trace(s);
|
||||
trace("\n");
|
||||
needIndent=true;
|
||||
}
|
||||
}
|
||||
331
jdkSrc/jdk8/com/sun/tools/internal/jxc/gen/config/Schema.java
Normal file
331
jdkSrc/jdk8/com/sun/tools/internal/jxc/gen/config/Schema.java
Normal file
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* this file is generated by RelaxNGCC */
|
||||
package com.sun.tools.internal.jxc.gen.config;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.Attributes;
|
||||
import com.sun.tools.internal.jxc.NGCCRuntimeEx;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public class Schema extends NGCCHandler {
|
||||
private File baseDir;
|
||||
private String loc;
|
||||
protected final NGCCRuntimeEx $runtime;
|
||||
private int $_ngcc_current_state;
|
||||
protected String $uri;
|
||||
protected String $localName;
|
||||
protected String $qname;
|
||||
|
||||
public final NGCCRuntime getRuntime() {
|
||||
return($runtime);
|
||||
}
|
||||
|
||||
public Schema(NGCCHandler parent, NGCCEventSource source, NGCCRuntimeEx runtime, int cookie, File _baseDir) {
|
||||
super(source, parent, cookie);
|
||||
$runtime = runtime;
|
||||
this.baseDir = _baseDir;
|
||||
$_ngcc_current_state = 10;
|
||||
}
|
||||
|
||||
public Schema(NGCCRuntimeEx runtime, File _baseDir) {
|
||||
this(null, runtime, runtime, -1, _baseDir);
|
||||
}
|
||||
|
||||
private void action0()throws SAXException {
|
||||
location = new File(baseDir,loc);
|
||||
}
|
||||
|
||||
public void enterElement(String $__uri, String $__local, String $__qname, Attributes $attrs) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromEnterElement(this, super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","location"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","namespace"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 2;
|
||||
$runtime.sendEnterElement(super._cookie, $__uri, $__local, $__qname, $attrs);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("schema"))) {
|
||||
$runtime.onEnterElementConsumed($__uri, $__local, $__qname, $attrs);
|
||||
$_ngcc_current_state = 6;
|
||||
}
|
||||
else {
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedEnterElement($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void leaveElement(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 1:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("schema"))) {
|
||||
$runtime.onLeaveElementConsumed($__uri, $__local, $__qname);
|
||||
$_ngcc_current_state = 0;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromLeaveElement(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","location"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","namespace"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 2;
|
||||
$runtime.sendLeaveElement(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedLeaveElement($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void enterAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromEnterAttribute(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("location"))) {
|
||||
$_ngcc_current_state = 4;
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("namespace"))) {
|
||||
$_ngcc_current_state = 8;
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 2;
|
||||
$runtime.sendEnterAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedEnterAttribute($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void leaveAttribute(String $__uri, String $__local, String $__qname) throws SAXException {
|
||||
int $ai;
|
||||
$uri = $__uri;
|
||||
$localName = $__local;
|
||||
$qname = $__qname;
|
||||
switch($_ngcc_current_state) {
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromLeaveAttribute(this, super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("location"))) {
|
||||
$_ngcc_current_state = 1;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveAttribute($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
if(($__uri.equals("") && $__local.equals("namespace"))) {
|
||||
$_ngcc_current_state = 2;
|
||||
}
|
||||
else {
|
||||
unexpectedLeaveAttribute($__qname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
$_ngcc_current_state = 2;
|
||||
$runtime.sendLeaveAttribute(super._cookie, $__uri, $__local, $__qname);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
unexpectedLeaveAttribute($__qname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void text(String $value) throws SAXException {
|
||||
int $ai;
|
||||
switch($_ngcc_current_state) {
|
||||
case 8:
|
||||
{
|
||||
namespace = $value;
|
||||
$_ngcc_current_state = 7;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
loc = $value;
|
||||
$_ngcc_current_state = 3;
|
||||
action0();
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
revertToParentFromText(this, super._cookie, $value);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","location"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendText(super._cookie, $value);
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 1;
|
||||
$runtime.sendText(super._cookie, $value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
{
|
||||
if(($ai = $runtime.getAttributeIndex("","namespace"))>=0) {
|
||||
$runtime.consumeAttribute($ai);
|
||||
$runtime.sendText(super._cookie, $value);
|
||||
}
|
||||
else {
|
||||
$_ngcc_current_state = 2;
|
||||
$runtime.sendText(super._cookie, $value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onChildCompleted(Object result, int cookie, boolean needAttCheck)throws SAXException {
|
||||
switch(cookie) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean accepted() {
|
||||
return(($_ngcc_current_state == 0));
|
||||
}
|
||||
|
||||
|
||||
private File location;
|
||||
private String namespace;
|
||||
public String getNamespace() { return this.namespace;}
|
||||
public File getLocation() { return this.location;}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,517 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.jxc.model.nav;
|
||||
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.TreePath;
|
||||
import com.sun.source.util.Trees;
|
||||
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
|
||||
import com.sun.xml.internal.bind.v2.runtime.Location;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.TypeParameterElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.PrimitiveType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeVariable;
|
||||
import javax.lang.model.type.TypeVisitor;
|
||||
import javax.lang.model.type.WildcardType;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
import javax.lang.model.util.Types;
|
||||
|
||||
/**
|
||||
* {@link Navigator} implementation for annotation processing.
|
||||
* TODO: check the spec on how generics are supposed to be handled
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kk@kohsuke.org)
|
||||
*/
|
||||
public final class ApNavigator implements Navigator<TypeMirror, TypeElement, VariableElement, ExecutableElement> {
|
||||
|
||||
private final ProcessingEnvironment env;
|
||||
|
||||
private final PrimitiveType primitiveByte;
|
||||
|
||||
public ApNavigator(ProcessingEnvironment env) {
|
||||
this.env = env;
|
||||
this.primitiveByte = env.getTypeUtils().getPrimitiveType(TypeKind.BYTE);
|
||||
}
|
||||
|
||||
public TypeElement getSuperClass(TypeElement typeElement) {
|
||||
if (typeElement.getKind().equals(ElementKind.CLASS)) {
|
||||
TypeMirror sup = typeElement.getSuperclass();
|
||||
if (!sup.getKind().equals(TypeKind.NONE))
|
||||
return (TypeElement) ((DeclaredType) sup).asElement();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
return env.getElementUtils().getTypeElement(Object.class.getName());
|
||||
}
|
||||
|
||||
public TypeMirror getBaseClass(TypeMirror type, TypeElement sup) {
|
||||
return baseClassFinder.visit(type, sup);
|
||||
}
|
||||
|
||||
public String getClassName(TypeElement t) {
|
||||
return t.getQualifiedName().toString();
|
||||
}
|
||||
|
||||
public String getTypeName(TypeMirror typeMirror) {
|
||||
return typeMirror.toString();
|
||||
}
|
||||
|
||||
public String getClassShortName(TypeElement t) {
|
||||
return t.getSimpleName().toString();
|
||||
}
|
||||
|
||||
public Collection<VariableElement> getDeclaredFields(TypeElement typeElement) {
|
||||
return ElementFilter.fieldsIn(typeElement.getEnclosedElements());
|
||||
}
|
||||
|
||||
public VariableElement getDeclaredField(TypeElement clazz, String fieldName) {
|
||||
for (VariableElement fd : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
|
||||
if (fd.getSimpleName().toString().equals(fieldName))
|
||||
return fd;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<ExecutableElement> getDeclaredMethods(TypeElement typeElement) {
|
||||
return ElementFilter.methodsIn(typeElement.getEnclosedElements());
|
||||
}
|
||||
|
||||
public TypeElement getDeclaringClassForField(VariableElement f) {
|
||||
return (TypeElement) f.getEnclosingElement();
|
||||
}
|
||||
|
||||
public TypeElement getDeclaringClassForMethod(ExecutableElement m) {
|
||||
return (TypeElement) m.getEnclosingElement();
|
||||
}
|
||||
|
||||
public TypeMirror getFieldType(VariableElement f) {
|
||||
return f.asType();
|
||||
}
|
||||
|
||||
public String getFieldName(VariableElement f) {
|
||||
return f.getSimpleName().toString();
|
||||
}
|
||||
|
||||
public String getMethodName(ExecutableElement m) {
|
||||
return m.getSimpleName().toString();
|
||||
}
|
||||
|
||||
public TypeMirror getReturnType(ExecutableElement m) {
|
||||
return m.getReturnType();
|
||||
}
|
||||
|
||||
public TypeMirror[] getMethodParameters(ExecutableElement m) {
|
||||
Collection<? extends VariableElement> ps = m.getParameters();
|
||||
TypeMirror[] r = new TypeMirror[ps.size()];
|
||||
int i=0;
|
||||
for (VariableElement p : ps)
|
||||
r[i++] = p.asType();
|
||||
return r;
|
||||
}
|
||||
|
||||
public boolean isStaticMethod(ExecutableElement m) {
|
||||
return hasModifier(m, Modifier.STATIC);
|
||||
}
|
||||
|
||||
public boolean isFinalMethod(ExecutableElement m) {
|
||||
return hasModifier(m, Modifier.FINAL);
|
||||
}
|
||||
|
||||
private boolean hasModifier(Element d, Modifier mod) {
|
||||
return d.getModifiers().contains(mod);
|
||||
}
|
||||
|
||||
public boolean isSubClassOf(TypeMirror sub, TypeMirror sup) {
|
||||
if(sup==DUMMY)
|
||||
// see ref(). if the sub type is known to Annotation Processing,
|
||||
// its base class must be known. Thus if the sup is DUMMY,
|
||||
// it cannot possibly be the super type.
|
||||
return false;
|
||||
return env.getTypeUtils().isSubtype(sub,sup);
|
||||
}
|
||||
|
||||
private String getSourceClassName(Class clazz) {
|
||||
Class<?> d = clazz.getDeclaringClass();
|
||||
if(d==null)
|
||||
return clazz.getName();
|
||||
else {
|
||||
String shortName = clazz.getName().substring(d.getName().length()+1/*for $*/);
|
||||
return getSourceClassName(d)+'.'+shortName;
|
||||
}
|
||||
}
|
||||
|
||||
public TypeMirror ref(Class c) {
|
||||
if(c.isArray())
|
||||
return env.getTypeUtils().getArrayType( ref(c.getComponentType()) );
|
||||
if(c.isPrimitive())
|
||||
return getPrimitive(c);
|
||||
TypeElement t = env.getElementUtils().getTypeElement(getSourceClassName(c));
|
||||
// Annotation Processing only operates on a set of classes used in the compilation,
|
||||
// and it won't recognize additional classes (even if they are visible from javac)
|
||||
// and return null.
|
||||
//
|
||||
// this is causing a problem where we check if a type is collection.
|
||||
// so until the problem is fixed in Annotation Processing, work around the issue
|
||||
// by returning a dummy token
|
||||
// TODO: check if this is still valid
|
||||
if(t==null)
|
||||
return DUMMY;
|
||||
return env.getTypeUtils().getDeclaredType(t);
|
||||
}
|
||||
|
||||
public TypeMirror use(TypeElement t) {
|
||||
assert t != null;
|
||||
return env.getTypeUtils().getDeclaredType(t);
|
||||
}
|
||||
|
||||
public TypeElement asDecl(TypeMirror m) {
|
||||
m = env.getTypeUtils().erasure(m);
|
||||
if (m.getKind().equals(TypeKind.DECLARED)) {
|
||||
DeclaredType d = (DeclaredType) m;
|
||||
return (TypeElement) d.asElement();
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
public TypeElement asDecl(Class c) {
|
||||
return env.getElementUtils().getTypeElement(getSourceClassName(c));
|
||||
}
|
||||
|
||||
public TypeMirror erasure(TypeMirror t) {
|
||||
Types tu = env.getTypeUtils();
|
||||
t = tu.erasure(t);
|
||||
if (t.getKind().equals(TypeKind.DECLARED)) {
|
||||
DeclaredType dt = (DeclaredType)t;
|
||||
if (!dt.getTypeArguments().isEmpty())
|
||||
return tu.getDeclaredType((TypeElement) dt.asElement());
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public boolean isAbstract(TypeElement clazz) {
|
||||
return hasModifier(clazz,Modifier.ABSTRACT);
|
||||
}
|
||||
|
||||
public boolean isFinal(TypeElement clazz) {
|
||||
return hasModifier(clazz, Modifier.FINAL);
|
||||
}
|
||||
|
||||
public VariableElement[] getEnumConstants(TypeElement clazz) {
|
||||
List<? extends Element> elements = env.getElementUtils().getAllMembers(clazz);
|
||||
Collection<VariableElement> constants = new ArrayList<VariableElement>();
|
||||
for (Element element : elements) {
|
||||
if (element.getKind().equals(ElementKind.ENUM_CONSTANT)) {
|
||||
constants.add((VariableElement) element);
|
||||
}
|
||||
}
|
||||
return constants.toArray(new VariableElement[constants.size()]);
|
||||
}
|
||||
|
||||
public TypeMirror getVoidType() {
|
||||
return env.getTypeUtils().getNoType(TypeKind.VOID);
|
||||
}
|
||||
|
||||
public String getPackageName(TypeElement clazz) {
|
||||
return env.getElementUtils().getPackageOf(clazz).getQualifiedName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeElement loadObjectFactory(TypeElement referencePoint, String packageName) {
|
||||
return env.getElementUtils().getTypeElement(packageName + ".ObjectFactory");
|
||||
}
|
||||
|
||||
public boolean isBridgeMethod(ExecutableElement method) {
|
||||
return method.getModifiers().contains(Modifier.VOLATILE);
|
||||
}
|
||||
|
||||
public boolean isOverriding(ExecutableElement method, TypeElement base) {
|
||||
Elements elements = env.getElementUtils();
|
||||
|
||||
while (true) {
|
||||
for (ExecutableElement m : ElementFilter.methodsIn(elements.getAllMembers(base))) {
|
||||
if (elements.overrides(method, m, base))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.getSuperclass().getKind().equals(TypeKind.NONE))
|
||||
return false;
|
||||
base = (TypeElement) env.getTypeUtils().asElement(base.getSuperclass());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInterface(TypeElement clazz) {
|
||||
return clazz.getKind().isInterface();
|
||||
}
|
||||
|
||||
public boolean isTransient(VariableElement f) {
|
||||
return f.getModifiers().contains(Modifier.TRANSIENT);
|
||||
}
|
||||
|
||||
public boolean isInnerClass(TypeElement clazz) {
|
||||
return clazz.getEnclosingElement() != null && !clazz.getModifiers().contains(Modifier.STATIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(TypeMirror t1, TypeMirror t2) {
|
||||
return env.getTypeUtils().isSameType(t1, t2);
|
||||
}
|
||||
|
||||
public boolean isArray(TypeMirror type) {
|
||||
return type != null && type.getKind().equals(TypeKind.ARRAY);
|
||||
}
|
||||
|
||||
public boolean isArrayButNotByteArray(TypeMirror t) {
|
||||
if(!isArray(t))
|
||||
return false;
|
||||
|
||||
ArrayType at = (ArrayType) t;
|
||||
TypeMirror ct = at.getComponentType();
|
||||
|
||||
return !ct.equals(primitiveByte);
|
||||
}
|
||||
|
||||
public TypeMirror getComponentType(TypeMirror t) {
|
||||
if (isArray(t)) {
|
||||
ArrayType at = (ArrayType) t;
|
||||
return at.getComponentType();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public TypeMirror getTypeArgument(TypeMirror typeMirror, int i) {
|
||||
if (typeMirror != null && typeMirror.getKind().equals(TypeKind.DECLARED)) {
|
||||
DeclaredType declaredType = (DeclaredType) typeMirror;
|
||||
TypeMirror[] args = declaredType.getTypeArguments().toArray(new TypeMirror[declaredType.getTypeArguments().size()]);
|
||||
return args[i];
|
||||
} else throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public boolean isParameterizedType(TypeMirror typeMirror) {
|
||||
if (typeMirror != null && typeMirror.getKind().equals(TypeKind.DECLARED)) {
|
||||
DeclaredType d = (DeclaredType) typeMirror;
|
||||
return !d.getTypeArguments().isEmpty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPrimitive(TypeMirror t) {
|
||||
return t.getKind().isPrimitive();
|
||||
}
|
||||
|
||||
private static final Map<Class, TypeKind> primitives = new HashMap<Class, TypeKind>();
|
||||
|
||||
static {
|
||||
primitives.put(Integer.TYPE, TypeKind.INT);
|
||||
primitives.put(Byte.TYPE, TypeKind.BYTE);
|
||||
primitives.put(Float.TYPE, TypeKind.FLOAT);
|
||||
primitives.put(Boolean.TYPE, TypeKind.BOOLEAN);
|
||||
primitives.put(Short.TYPE, TypeKind.SHORT);
|
||||
primitives.put(Long.TYPE, TypeKind.LONG);
|
||||
primitives.put(Double.TYPE, TypeKind.DOUBLE);
|
||||
primitives.put(Character.TYPE, TypeKind.CHAR);
|
||||
}
|
||||
|
||||
public TypeMirror getPrimitive(Class primitiveType) {
|
||||
assert primitiveType.isPrimitive();
|
||||
if(primitiveType==void.class)
|
||||
return getVoidType();
|
||||
return env.getTypeUtils().getPrimitiveType(primitives.get(primitiveType));
|
||||
}
|
||||
|
||||
/**
|
||||
* see {@link #ref(Class)}.
|
||||
*/
|
||||
private static final TypeMirror DUMMY = new TypeMirror() {
|
||||
@Override
|
||||
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKind getKind() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public List<? extends AnnotationMirror> getAnnotationMirrors() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
};
|
||||
|
||||
public Location getClassLocation(TypeElement typeElement) {
|
||||
Trees trees = Trees.instance(env);
|
||||
return getLocation(typeElement.getQualifiedName().toString(), trees.getPath(typeElement));
|
||||
}
|
||||
|
||||
public Location getFieldLocation(VariableElement variableElement) {
|
||||
return getLocation(variableElement);
|
||||
}
|
||||
|
||||
public Location getMethodLocation(ExecutableElement executableElement) {
|
||||
return getLocation(executableElement);
|
||||
}
|
||||
|
||||
public boolean hasDefaultConstructor(TypeElement t) {
|
||||
if (t == null || !t.getKind().equals(ElementKind.CLASS))
|
||||
return false;
|
||||
|
||||
for (ExecutableElement init : ElementFilter.constructorsIn(env.getElementUtils().getAllMembers(t))) {
|
||||
if (init.getParameters().isEmpty())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStaticField(VariableElement f) {
|
||||
return hasModifier(f,Modifier.STATIC);
|
||||
}
|
||||
|
||||
public boolean isPublicMethod(ExecutableElement m) {
|
||||
return hasModifier(m,Modifier.PUBLIC);
|
||||
}
|
||||
|
||||
public boolean isPublicField(VariableElement f) {
|
||||
return hasModifier(f,Modifier.PUBLIC);
|
||||
}
|
||||
|
||||
public boolean isEnum(TypeElement t) {
|
||||
return t != null && t.getKind().equals(ElementKind.ENUM);
|
||||
}
|
||||
|
||||
private Location getLocation(Element element) {
|
||||
Trees trees = Trees.instance(env);
|
||||
return getLocation(
|
||||
((TypeElement) element.getEnclosingElement()).getQualifiedName() + "." + element.getSimpleName(),
|
||||
trees.getPath(element)
|
||||
);
|
||||
}
|
||||
|
||||
private Location getLocation(final String name, final TreePath treePath) {
|
||||
return new Location() {
|
||||
public String toString() {
|
||||
if (treePath == null)
|
||||
return name + " (Unknown Source)";
|
||||
// just like stack trace, we just print the file name and
|
||||
// not the whole path. The idea is that the package name should
|
||||
// provide enough clue on which directory it lives.
|
||||
CompilationUnitTree compilationUnit = treePath.getCompilationUnit();
|
||||
Trees trees = Trees.instance(env);
|
||||
long startPosition = trees.getSourcePositions().getStartPosition(compilationUnit, treePath.getLeaf());
|
||||
return name + "(" +
|
||||
compilationUnit.getSourceFile().getName() + ":" + compilationUnit.getLineMap().getLineNumber(startPosition) +
|
||||
")";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements {@link #getBaseClass}.
|
||||
*/
|
||||
private final SimpleTypeVisitor6<TypeMirror, TypeElement> baseClassFinder = new SimpleTypeVisitor6<TypeMirror, TypeElement>() {
|
||||
@Override
|
||||
public TypeMirror visitDeclared(DeclaredType t, TypeElement sup) {
|
||||
if (t.asElement().equals(sup))
|
||||
return t;
|
||||
|
||||
for (TypeMirror i : env.getTypeUtils().directSupertypes(t)) {
|
||||
TypeMirror r = visitDeclared((DeclaredType) i, sup);
|
||||
if (r != null)
|
||||
return r;
|
||||
}
|
||||
|
||||
// otherwise recursively apply super class and base types
|
||||
TypeMirror superclass = ((TypeElement) t.asElement()).getSuperclass();
|
||||
if (!superclass.getKind().equals(TypeKind.NONE)) {
|
||||
TypeMirror r = visitDeclared((DeclaredType) superclass, sup);
|
||||
if (r != null)
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeMirror visitTypeVariable(TypeVariable t, TypeElement typeElement) {
|
||||
// we are checking if T (declared as T extends A&B&C) is assignable to sup.
|
||||
// so apply bounds recursively.
|
||||
for (TypeMirror typeMirror : ((TypeParameterElement) t.asElement()).getBounds()) {
|
||||
TypeMirror m = visit(typeMirror, typeElement);
|
||||
if (m != null)
|
||||
return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeMirror visitArray(ArrayType t, TypeElement typeElement) {
|
||||
// we are checking if t=T[] is assignable to sup.
|
||||
// the only case this is allowed is sup=Object,
|
||||
// and Object isn't parameterized.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeMirror visitWildcard(WildcardType t, TypeElement typeElement) {
|
||||
// we are checking if T (= ? extends A&B&C) is assignable to sup.
|
||||
// so apply bounds recursively.
|
||||
return visit(t.getExtendsBound(), typeElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeMirror defaultAction(TypeMirror e, TypeElement typeElement) {
|
||||
return e;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user