feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View 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);
}
}
}

View 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 );
}
}

View 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()));
}
}

View 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);
}
}
}

View 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;
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");
}
}
}

View 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();
}
});
}
}
}

View 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;
}
}

View 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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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();
}
}

View 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 );
}
}

View 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;
}
}

View 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;
}
}

View 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();
}
});
}
}
}

View 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();
}
}

View File

@@ -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;
}
}

View File

@@ -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
}
}
}

View File

@@ -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

View 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);}
}

View 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;}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 &lt;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 &lt;text/> and won't
* be able to process &lt;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 &lt;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 &lt;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;
}
}

View 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;}
}

View File

@@ -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;
}
};
}

View File

@@ -0,0 +1,277 @@
/*
* 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.ws;
import com.sun.istack.internal.tools.MaskingClassLoader;
import com.sun.istack.internal.tools.ParallelWorldClassLoader;
import com.sun.tools.internal.ws.resources.WscompileMessages;
import com.sun.tools.internal.ws.wscompile.Options;
import com.sun.tools.internal.xjc.api.util.ToolsJarNotFoundException;
import com.sun.xml.internal.bind.util.Which;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceFeature;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.OutputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Invokes JAX-WS tools in a special class loader that can pick up annotation processing classes,
* even if it's not available in the tool launcher classpath.
*
* @author Kohsuke Kawaguchi
*/
public final class Invoker {
/**
* The list of package prefixes we want the
* {@link MaskingClassLoader} to prevent the parent
* classLoader from loading
*/
static final String[] maskedPackages = new String[]{
"com.sun.istack.internal.tools.",
"com.sun.tools.internal.jxc.",
"com.sun.tools.internal.xjc.",
"com.sun.tools.internal.ws.",
"com.sun.codemodel.internal.",
"com.sun.relaxng.",
"com.sun.xml.internal.xsom.",
"com.sun.xml.internal.bind.",
"com.ctc.wstx.", //wsimport, wsgen ant task
"org.codehaus.stax2.", //wsimport, wsgen ant task
"com.sun.xml.internal.messaging.saaj.", //wsgen ant task
"com.sun.xml.internal.ws.",
"com.oracle.webservices.internal.api." //wsgen
};
/**
* Escape hatch to work around IBM JDK problem.
* See http://www-128.ibm.com/developerworks/forums/dw_thread.jsp?nav=false&forum=367&thread=164718&cat=10
*/
public static final boolean noSystemProxies;
static {
boolean noSysProxiesProperty = false;
try {
noSysProxiesProperty = Boolean.getBoolean(Invoker.class.getName()+".noSystemProxies");
} catch(SecurityException e) {
// ignore
} finally {
noSystemProxies = noSysProxiesProperty;
}
}
static int invoke(String mainClass, String[] args) throws Throwable {
// use the platform default proxy if available.
// see sun.net.spi.DefaultProxySelector for details.
if(!noSystemProxies) {
try {
System.setProperty("java.net.useSystemProxies","true");
} catch (SecurityException e) {
// failing to set this property isn't fatal
}
}
ClassLoader oldcc = Thread.currentThread().getContextClassLoader();
try {
ClassLoader cl = Invoker.class.getClassLoader();
if(Arrays.asList(args).contains("-Xendorsed"))
cl = createClassLoader(cl); // perform JDK6 workaround hack
else {
int targetArgIndex = Arrays.asList(args).indexOf("-target");
Options.Target targetVersion;
if (targetArgIndex != -1) {
targetVersion = Options.Target.parse(args[targetArgIndex+1]);
} else {
targetVersion = Options.Target.getDefault();
}
Options.Target loadedVersion = Options.Target.getLoadedAPIVersion();
//Check if the target version is supported by the loaded API version
if (!loadedVersion.isLaterThan(targetVersion)) {
if (Service.class.getClassLoader() == null)
System.err.println(WscompileMessages.INVOKER_NEED_ENDORSED(loadedVersion.getVersion(), targetVersion.getVersion()));
else {
System.err.println(WscompileMessages.WRAPPER_TASK_LOADING_INCORRECT_API(loadedVersion.getVersion(), Which.which(Service.class), targetVersion.getVersion()));
}
return -1;
}
//find and load tools.jar
List<URL> urls = new ArrayList<URL>();
findToolsJar(cl, urls);
if(urls.size() > 0){
List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages));
// first create a protected area so that we load JAXB/WS 2.1 API
// and everything that depends on them inside
cl = new MaskingClassLoader(cl,mask);
// then this classloader loads the API and tools.jar
cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), cl);
// finally load the rest of the RI. The actual class files are loaded from ancestors
cl = new ParallelWorldClassLoader(cl,"");
}
}
Thread.currentThread().setContextClassLoader(cl);
Class compileTool = cl.loadClass(mainClass);
Constructor ctor = compileTool.getConstructor(OutputStream.class);
Object tool = ctor.newInstance(System.out);
Method runMethod = compileTool.getMethod("run",String[].class);
boolean r = (Boolean)runMethod.invoke(tool,new Object[]{args});
return r ? 0 : 1;
} catch (ToolsJarNotFoundException e) {
System.err.println(e.getMessage());
} catch (InvocationTargetException e) {
throw e.getCause();
} catch(ClassNotFoundException e){
throw e;
}finally {
Thread.currentThread().setContextClassLoader(oldcc);
}
return -1;
}
/**
* Returns true if the RI appears to be loading the JAX-WS 2.1 API.
*/
public static boolean checkIfLoading21API() {
try {
Service.class.getMethod("getPort",Class.class, WebServiceFeature[].class);
// yup. things look good.
return true;
} catch (NoSuchMethodException e) {
} catch (LinkageError e) {
}
// nope
return false;
}
/**
* Returns true if the RI appears to be loading the JAX-WS 2.2 API.
*/
public static boolean checkIfLoading22API() {
try {
Service.class.getMethod("create",java.net.URL.class, QName.class, WebServiceFeature[].class);
// yup. things look good.
return true;
} catch (NoSuchMethodException e) {
} catch (LinkageError e) {
}
// nope
return false;
}
/**
* Creates a classloader that can load JAXB/WS 2.2 API and tools.jar,
* and then return a classloader that can RI classes, which can see all those APIs and tools.jar.
*/
public static ClassLoader createClassLoader(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException {
URL[] urls = findIstack22APIs(cl);
if(urls.length==0)
return cl; // we seem to be able to load everything already. no need for the hack
List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages));
if(urls.length>1) {
// we need to load 2.1 API from side. so add them to the mask
mask.add("javax.xml.bind.");
mask.add("javax.xml.ws.");
}
// first create a protected area so that we load JAXB/WS 2.1 API
// and everything that depends on them inside
cl = new MaskingClassLoader(cl,mask);
// then this classloader loads the API and tools.jar
cl = new URLClassLoader(urls, cl);
// finally load the rest of the RI. The actual class files are loaded from ancestors
cl = new ParallelWorldClassLoader(cl,"");
return cl;
}
/**
* Creates a classloader for loading JAXB/WS 2.2 jar and tools.jar
*/
private static URL[] findIstack22APIs(ClassLoader cl) throws ClassNotFoundException, IOException, ToolsJarNotFoundException {
List<URL> urls = new ArrayList<URL>();
if(Service.class.getClassLoader()==null) {
// JAX-WS API is loaded from bootstrap classloader
URL res = cl.getResource("javax/xml/ws/EndpointContext.class");
if(res==null)
throw new ClassNotFoundException("There's no JAX-WS 2.2 API in the classpath");
urls.add(ParallelWorldClassLoader.toJarUrl(res));
res = cl.getResource("javax/xml/bind/JAXBPermission.class");
if(res==null)
throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath");
urls.add(ParallelWorldClassLoader.toJarUrl(res));
}
findToolsJar(cl, urls);
return urls.toArray(new URL[urls.size()]);
}
private static void findToolsJar(ClassLoader cl, List<URL> urls) throws ToolsJarNotFoundException, MalformedURLException {
try {
Class.forName("com.sun.tools.javac.Main",false,cl);
// we can already load them in the parent class loader.
// so no need to look for tools.jar.
// this happens when we are run inside IDE/Ant, or
// in Mac OS.
} catch (ClassNotFoundException e) {
// otherwise try to find tools.jar
File jreHome = new File(System.getProperty("java.home"));
File toolsJar = new File( jreHome.getParent(), "lib/tools.jar" );
if (!toolsJar.exists()) {
throw new ToolsJarNotFoundException(toolsJar);
}
urls.add(toolsJar.toURL());
}
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.ws;
import com.sun.xml.internal.ws.util.Version;
/**
* Obtains the version number of the JAX-WS tools.
* @author Kohsuke Kawaguchi
*/
public abstract class ToolVersion {
private ToolVersion() {} // no instanciation please
public static final Version VERSION = Version.create(ToolVersion.class.getResourceAsStream("version.properties"));
}

View File

@@ -0,0 +1,61 @@
/*
* 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.ws;
import com.sun.tools.internal.ws.wscompile.WsgenTool;
/**
* WsGen tool entry point.
*
* @author Vivek Pandey
* @author Kohsuke Kawaguchi
*/
public class WsGen {
/**
* CLI entry point. Use {@link Invoker} to
* load tools.jar
*/
public static void main(String[] args) throws Throwable {
System.exit(Invoker.invoke("com.sun.tools.internal.ws.wscompile.WsgenTool", args));
}
/**
* Entry point for tool integration.
*
* <p>
* This does the same as {@link #main(String[])} except
* it doesn't invoke {@link System#exit(int)}. This method
* also doesn't play with classloaders. It's the caller's
* responsibility to set up the classloader to load all jars
* needed to run the tool, including <tt>$JAVA_HOME/lib/tools.jar</tt>
*
* @return
* 0 if the tool runs successfully.
*/
public static int doMain(String[] args) throws Throwable {
return new WsgenTool(System.out).run(args) ? 0 : 1;
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.ws;
import com.sun.tools.internal.ws.wscompile.WsimportTool;
/**
* WsImport tool entry point.
*
* @author Vivek Pandey
* @author Kohsuke Kawaguchi
*/
public class WsImport {
/**
* CLI entry point. Use {@link Invoker} to
* load tools.jar
*/
public static void main(String[] args) throws Throwable {
System.exit(Invoker.invoke("com.sun.tools.internal.ws.wscompile.WsimportTool", args));
}
/**
* Entry point for tool integration.
*
* <p>
* This does the same as {@link #main(String[])} except
* it doesn't invoke {@link System#exit(int)}. This method
* also doesn't play with classloaders. It's the caller's
* responsibility to set up the classloader to load all jars
* needed to run the tool, including <tt>$JAVA_HOME/lib/tools.jar</tt>
*
* @return
* 0 if the tool runs successfully.
*/
public static int doMain(String[] args) throws Throwable {
return new WsimportTool(System.out).run(args) ? 0 : 1;
}
}

View File

@@ -0,0 +1,47 @@
/*
* 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.ws.api;
import com.sun.codemodel.internal.JMethod;
import com.sun.tools.internal.ws.api.wsdl.TWSDLOperation;
import com.sun.tools.internal.ws.processor.generator.JavaGeneratorExtensionFacade;
/**
* Provides Java SEI Code generation Extensiblity mechanism.
*
* @see JavaGeneratorExtensionFacade
* @author Vivek Pandey
* @deprecated This class is deprecated, will be removed in JAX-WS 2.2 RI.
*/
public abstract class TJavaGeneratorExtension {
/**
* This method should be used to write annotations on {@link JMethod}.
*
* @param wsdlOperation non-null wsdl extensiblity element - wsdl:portType/wsdl:operation.
* @param jMethod non-null {@link JMethod}
*/
public abstract void writeMethodAnnotations(TWSDLOperation wsdlOperation, JMethod jMethod);
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2009, 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.ws.api;
/**
* Allows to customize wsgen behaviour using this extension.
* The extension implementations are found using service
* discovery mechanism i.e. JAX-WS tooltime locates
* {@link WsgenExtension}s through the
* <tt>META-INF/services/com.sun.tools.internal.ws.api.WsgenExtension</tt>
* files.
*
* {@link WsgenProtocol} annotation can be specified on the
* extensions to extend -wsdl[:protocol] behaviour.
*
* @author Jitendra Kotamraju
* @since JAX-WS RI 2.1.6
* @see WsgenProtocol
*/
public abstract class WsgenExtension {
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2009, 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.ws.api;
import java.lang.annotation.*;
/**
* Allows to extend protocol for wsgen's wsdl[:protocol] switch.
* This annotation must be specified on {@link WsgenExtension}
* implementations.
*
* @author Jitendra Kotamraju
* @since JAX-WS RI 2.1.6
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface WsgenProtocol {
/**
* Token for wsgen -wsdl[:protocol]
* @return Token for wsgen -wsdl[:protocol]
*/
String token();
/**
* The corresponding lexical string used to create BindingID
* @return lexical string used to create BindingID
*/
String lexical();
}

View File

@@ -0,0 +1,80 @@
/*
* 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.ws.api.wsdl;
import javax.xml.namespace.QName;
/**
* A WSDL element or attribute that can be extended.
*
* @author Vivek Pandey
* @deprecated This interface is deprecated, will be removed in JAX-WS 2.2 RI.
*
*/
public interface TWSDLExtensible {
/**
* Gives the wsdl extensiblity element's name attribute value. It can be null as @name on some of the wsdl
* extensibility elements are optinal such as wsdl:input
*/
String getNameValue();
/**
* Gives namespace URI of a wsdl extensibility element.
*/
String getNamespaceURI();
/**
* Gives the WSDL element or WSDL extensibility element name
*/
QName getWSDLElementName();
/**
* An {@link TWSDLExtensionHandler} will call this method to add an {@link TWSDLExtension} object
*
* @param e non-null extension object
*/
void addExtension(TWSDLExtension e);
/**
* Gives iterator over {@link TWSDLExtension}s
*/
Iterable<? extends TWSDLExtension> extensions();
/**
* Gives the parent of a wsdl extensibility element.
* <pre>
* For example,
*
* <wsdl:portType>
* <wsdl:operation>
* ...
* Here, the {@link TWSDLExtensible}representing wsdl:operation's parent would be wsdl:portType
*
* @return null if the {@link TWSDLExtensible} has no parent, root of wsdl document - wsdl:definition.
*/
TWSDLExtensible getParent();
}

View File

@@ -0,0 +1,39 @@
/*
* 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.ws.api.wsdl;
/**
* A WSDL extension
*
* @author Vivek Pandey
* @deprecated This interface is deprecated, will be removed in JAX-WS 2.2 RI.
*/
public interface TWSDLExtension {
/**
* Gives Parent {@link TWSDLExtensible} element
*/
TWSDLExtensible getParent();
}

View File

@@ -0,0 +1,216 @@
/*
* 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.ws.api.wsdl;
import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
import org.w3c.dom.Element;
/**
* JAXWS WSDL parser {@link com.sun.tools.internal.ws.wsdl.parser.WSDLParser} will call an {@link TWSDLExtensionHandler} registered
* with it for the WSDL extensibility elements thats not already defined in the WSDL 1.1 spec, such as SOAP or MIME.
*
* @author Vivek Pandey
* @deprecated This class is deprecated, will be removed in JAX-WS 2.2 RI.
*/
public abstract class TWSDLExtensionHandler {
/**
* Gives the namespace of an extensibility element.
* <p/>
* For example a soap 1.1 XXExtensionHandler would return <code>""http://schemas.xmlsoap.org/wsdl/soap/"</code>
*/
public String getNamespaceURI() {
return null;
}
/**
* This interface is called during WSDL parsing on detecting any wsdl extension.
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean doHandleExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_DEFINITIONS)) {
return handleDefinitionsExtension(context, parent, e);
} else if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_TYPES)) {
return handleTypesExtension(context, parent, e);
} else if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_PORT_TYPE)) {
return handlePortTypeExtension(context, parent, e);
} else if (
parent.getWSDLElementName().equals(WSDLConstants.QNAME_BINDING)) {
return handleBindingExtension(context, parent, e);
} else if (
parent.getWSDLElementName().equals(WSDLConstants.QNAME_OPERATION)) {
return handleOperationExtension(context, parent, e);
} else if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_INPUT)) {
return handleInputExtension(context, parent, e);
} else if (
parent.getWSDLElementName().equals(WSDLConstants.QNAME_OUTPUT)) {
return handleOutputExtension(context, parent, e);
} else if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_FAULT)) {
return handleFaultExtension(context, parent, e);
} else if (
parent.getWSDLElementName().equals(WSDLConstants.QNAME_SERVICE)) {
return handleServiceExtension(context, parent, e);
} else if (parent.getWSDLElementName().equals(WSDLConstants.QNAME_PORT)) {
return handlePortExtension(context, parent, e);
} else {
return false;
}
}
/**
* Callback for <code>wsdl:portType</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:definitions</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleDefinitionsExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:type</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleTypesExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:binding</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleBindingExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:portType/wsdl:operation</code>.
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleOperationExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:input</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleInputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:output</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleOutputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:fault</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleFaultExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:service</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handleServiceExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
/**
* Callback for <code>wsdl:port</code>
*
* @param context Parser context that will be passed on by the wsdl parser
* @param parent The Parent element within which the extensibility element is defined
* @param e The extensibility elemenet
* @return false if there was some error during the extension handling otherwise returns true. If returned false
* then the WSDL parser can abort if the wsdl extensibility element had <code>required</code> attribute set to true
*/
public boolean handlePortExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
return false;
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.ws.api.wsdl;
import com.sun.codemodel.internal.JClass;
import java.util.Map;
/**
* Abstracts wsdl:portType/wsdl:operation
*
* @author Vivek Pandey
* @deprecated This interface is deprecated, will be removed in JAX-WS 2.2 RI.
*/
public interface TWSDLOperation extends TWSDLExtensible{
/**
* Gives a Map of fault name attribute value to the {@link JClass}
*/
Map<String, JClass> getFaults();
}

View File

@@ -0,0 +1,82 @@
/*
* 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.ws.api.wsdl;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
/**
* Provides WSDL parsing context. It should be used by the WSDL extension handlers to register their namespaces so that
* it can be latter used by other extensions to resolve the namespaces.
*
* @author Vivek Pandey
* @deprecated This interface is deprecated, will be removed in JAX-WS 2.2 RI.
*/
public interface TWSDLParserContext {
/**
* Pushes the parsing context
*/
void push();
/**
* pops the parsing context
*/
void pop();
/**
* Gives the namespace URI for a given prefix
*
* @param prefix non-null prefix
* @return null of the prefix is not found
*/
String getNamespaceURI(String prefix);
/**
* Gives the prefixes in the current context
*/
Iterable<String> getPrefixes();
/**
* Gives default namespace
*
* @return null if there is no default namespace declaration found
*/
String getDefaultNamespaceURI();
/**
* Registers naemespace declarations of a given {@link Element} found in the WSDL
*
* @param e {@link Element} whose namespace declarations need to be registered
*/
void registerNamespaces(Element e);
/**
* gives the location information for the given Element.
*/
Locator getLocation(Element e);
}

View File

@@ -0,0 +1,121 @@
/*
* 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.
*/
/**
* <h1>JAX-WS 2.1 Tools</h1>
* This document describes the tools included with JAX-WS 2.0.1.
*
* {@DotDiagram digraph G {
// external tools
AP;
// ANT tasks
node [style=filled,color=lightyellow];
"WsGen ANT Task"; "WsImport ANT Task";
// commandline
node [style=filled,color=lightpink];
wsgen; wsimport;
// libraries
node [style=filled,color=lightblue];
WsimportTool; WsgenTool;"WSAP"; WebServiceAp; WSDLModeler;WSDLParser;SeiGenerator;ServiceGenerator;ExceptionGenerator;"JAXB XJC APIs";CodeModel;
// aps
# node [style=filled,color=lightpink];
# "JAX-WS"; tools; runtime; SPI; "Annotation Processor";
"WsGen ANT Task" -> wsgen -> WsgenTool;
"WsImport ANT Task" -> wsimport -> WsimportTool;
WsgenTool -> Annotation Processing -> WSAP -> WebServiceAp;
WsimportTool -> WSDLModeler;
WSDLModeler->WSDLParser;
WSDLModeler->"JAXB XJC APIs"
WsimportTool->SeiGenerator->CodeModel;
WsimportTool->ServiceGenerator->CodeModel;
WsimportTool->ExceptionGenerator->CodeModel;
WebServiceAp->CodeModel
}
* }
* <div align=right>
* <b>Legend:</b> blue: implementation classes, pink: command-line toosl, white: external tool, yellow: ANT tasks
* </div>
*
* <h2>ANT Tasks</h2>
<d1>
* <dt>{@link com.sun.tools.internal.ws.ant.AnnotationProcessingTask AnnotationProcessing}
* <dd>An ANT task to invoke <a href="http://download.oracle.com/javase/6/docs/api/javax/annotation/processing/package-summary.html">Annotation Processing</a>.
* <dt>{@link com.sun.tools.internal.ws.ant.WsGen2 WsGen}
* <dd>
* An ANT task to invoke {@link com.sun.tools.internal.ws.WsGen WsGen}
* <dt>{@link com.sun.tools.internal.ws.ant.WsImport2 WsImport}
* <dd>
* An ANT task to invoke {@link com.sun.tools.internal.ws.WsImport WsImport}
*
* </d1>
* <h2>Command-line Tools</h2>
<d1>
* <dt><a href="http://download.oracle.com/javase/6/docs/api/javax/annotation/processing/package-summary.html">AP</a>
<dd>A Java SE tool and framework for processing annotations. Annotation processing will invoke a JAX-WS AnnotationProcossor for
* processing Java source files with javax.jws.* annotations and making them web services.
* Annotation processing will compile the Java source files and generate any additional classes needed to make an javax.jws.WebService
* annotated class a Web service.
*
* <dt>{@link com.sun.tools.internal.ws.WsGen WsGen}
* <dd>Tool to process a compiled javax.jws.WebService annotated class and to generate the necessary classes to make
* it a Web service.
* <dt>{@link com.sun.tools.internal.ws.ant.WsImport2 WsImport}
* <dd>
* Tool to import a WSDL and to generate an SEI (a javax.jws.WebService) interface that can be either implemented
* on the server to build a web service, or can be used on the client to invoke the web service.
* </d1>
* <h2>Implementation Classes</h2>
* <d1>
* <dt>{@link com.sun.tools.internal.ws.processor.model.Model Model}
* <dd>The model is used to represent the entire Web Service. The JAX-WS ProcessorActions can process
* this Model to generate Java artifacts such as the service interface.
*
*
* <dt>{@link com.sun.tools.internal.ws.processor.modeler.Modeler Modeler}
* <dd>A Modeler is used to create a Model of a Web Service from a particular Web
* Web Service description such as a WSDL
* file.
*
* <dt>{@link com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler WSDLModeler}
* <dd>The WSDLModeler processes a WSDL to create a Model.
*
* <dt>{@link com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAp WebServiceAp}
* <dd>WebServiceAp is a AnnotationProcessor for processing javax.jws.* and
* javax.xml.ws.* annotations. This class is used either by the WsGen (CompileTool) tool or
* idirectly via the {@link com.sun.istack.internal.ws.WSAP WSAP} when invoked by Annotation Processing.
* </d1>
*
* @ArchitectureDocument
**/
package com.sun.tools.internal.ws;

View File

@@ -0,0 +1,55 @@
/*
* 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.ws.processor;
import com.sun.xml.internal.ws.util.exception.JAXWSExceptionBase;
/**
* ProcessorException represents an exception that occurred while processing
* a web service.
*
* @see JAXWSExceptionBase
*
* @author WS Development Team
*/
public class ProcessorException extends JAXWSExceptionBase {
public ProcessorException(String key, Object... args) {
super(key, args);
}
public ProcessorException(String msg){
super(msg);
}
public ProcessorException(Throwable throwable) {
super(throwable);
}
public String getDefaultResourceBundleName() {
return "com.sun.tools.internal.ws.resources.processor";
}
}

View File

@@ -0,0 +1,160 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.ClassType;
import com.sun.codemodel.internal.JAnnotationUse;
import com.sun.codemodel.internal.JBlock;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JClassAlreadyExistsException;
import com.sun.codemodel.internal.JDefinedClass;
import com.sun.codemodel.internal.JDocComment;
import com.sun.codemodel.internal.JExpr;
import com.sun.codemodel.internal.JFieldRef;
import com.sun.codemodel.internal.JFieldVar;
import com.sun.codemodel.internal.JMethod;
import com.sun.codemodel.internal.JMod;
import com.sun.codemodel.internal.JType;
import com.sun.codemodel.internal.JVar;
import com.sun.tools.internal.ws.processor.model.Fault;
import com.sun.tools.internal.ws.processor.model.Model;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import javax.xml.ws.WebFault;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author WS Development Team
*/
public class CustomExceptionGenerator extends GeneratorBase {
private Map<String, JClass> faults = new HashMap<String, JClass>();
public static void generate(Model model,
WsimportOptions options,
ErrorReceiver receiver){
CustomExceptionGenerator exceptionGen = new CustomExceptionGenerator();
exceptionGen.init(model, options, receiver);
exceptionGen.doGeneration();
}
public GeneratorBase getGenerator(Model model, WsimportOptions options, ErrorReceiver receiver) {
GeneratorBase g = new CustomExceptionGenerator();
g.init(model, options, receiver);
return g;
}
@Override
public void visit(Fault fault) throws Exception {
if (isRegistered(fault))
return;
registerFault(fault);
}
private boolean isRegistered(Fault fault) {
if(faults.keySet().contains(fault.getJavaException().getName())){
fault.setExceptionClass(faults.get(fault.getJavaException().getName()));
return true;
}
return false;
}
private void registerFault(Fault fault) {
try {
write(fault);
faults.put(fault.getJavaException().getName(), fault.getExceptionClass());
} catch (JClassAlreadyExistsException e) {
throw new GeneratorException("generator.nestedGeneratorError",e);
}
}
private void write(Fault fault) throws JClassAlreadyExistsException {
String className = Names.customExceptionClassName(fault);
JDefinedClass cls = cm._class(className, ClassType.CLASS);
JDocComment comment = cls.javadoc();
if(fault.getJavaDoc() != null){
comment.add(fault.getJavaDoc());
comment.add("\n\n");
}
for (String doc : getJAXWSClassComment()) {
comment.add(doc);
}
cls._extends(java.lang.Exception.class);
//@WebFault
JAnnotationUse faultAnn = cls.annotate(WebFault.class);
faultAnn.param("name", fault.getBlock().getName().getLocalPart());
faultAnn.param("targetNamespace", fault.getBlock().getName().getNamespaceURI());
JType faultBean = fault.getBlock().getType().getJavaType().getType().getType();
//faultInfo filed
JFieldVar fi = cls.field(JMod.PRIVATE, faultBean, "faultInfo");
//add jaxb annotations
fault.getBlock().getType().getJavaType().getType().annotate(fi);
fi.javadoc().add("Java type that goes as soapenv:Fault detail element.");
JFieldRef fr = JExpr.ref(JExpr._this(), fi);
//Constructor
JMethod constrc1 = cls.constructor(JMod.PUBLIC);
JVar var1 = constrc1.param(String.class, "message");
JVar var2 = constrc1.param(faultBean, "faultInfo");
constrc1.javadoc().addParam(var1);
constrc1.javadoc().addParam(var2);
JBlock cb1 = constrc1.body();
cb1.invoke("super").arg(var1);
cb1.assign(fr, var2);
//constructor with Throwable
JMethod constrc2 = cls.constructor(JMod.PUBLIC);
var1 = constrc2.param(String.class, "message");
var2 = constrc2.param(faultBean, "faultInfo");
JVar var3 = constrc2.param(Throwable.class, "cause");
constrc2.javadoc().addParam(var1);
constrc2.javadoc().addParam(var2);
constrc2.javadoc().addParam(var3);
JBlock cb2 = constrc2.body();
cb2.invoke("super").arg(var1).arg(var3);
cb2.assign(fr, var2);
//getFaultInfo() method
JMethod fim = cls.method(JMod.PUBLIC, faultBean, "getFaultInfo");
fim.javadoc().addReturn().add("returns fault bean: "+faultBean.fullName());
JBlock fib = fim.body();
fib._return(fi);
fault.setExceptionClass(cls);
}
}

View File

@@ -0,0 +1,244 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.ClassType;
import com.sun.codemodel.internal.JAnnotationUse;
import com.sun.codemodel.internal.JClassAlreadyExistsException;
import com.sun.codemodel.internal.JCodeModel;
import com.sun.codemodel.internal.JDefinedClass;
import com.sun.tools.internal.ws.ToolVersion;
import com.sun.tools.internal.ws.processor.model.Block;
import com.sun.tools.internal.ws.processor.model.Fault;
import com.sun.tools.internal.ws.processor.model.Model;
import com.sun.tools.internal.ws.processor.model.ModelVisitor;
import com.sun.tools.internal.ws.processor.model.Operation;
import com.sun.tools.internal.ws.processor.model.Parameter;
import com.sun.tools.internal.ws.processor.model.Port;
import com.sun.tools.internal.ws.processor.model.Request;
import com.sun.tools.internal.ws.processor.model.Response;
import com.sun.tools.internal.ws.processor.model.Service;
import com.sun.tools.internal.ws.processor.util.DirectoryUtil;
import com.sun.tools.internal.ws.processor.util.IndentingWriter;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.xml.internal.ws.util.xml.XmlUtil;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.jws.HandlerChain;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.annotation.processing.Filer;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
public abstract class GeneratorBase implements ModelVisitor {
private File destDir;
private String targetVersion;
protected boolean donotOverride;
protected JCodeModel cm;
protected Model model;
protected String wsdlLocation;
protected ErrorReceiver receiver;
protected WsimportOptions options;
protected GeneratorBase() {
}
public void init(Model model, WsimportOptions options, ErrorReceiver receiver){
this.model = model;
this.options = options;
this.destDir = options.destDir;
this.receiver = receiver;
this.wsdlLocation = options.wsdlLocation;
this.targetVersion = options.target.getVersion();
this.cm = options.getCodeModel();
}
public void doGeneration() {
try {
model.accept(this);
} catch (Exception e) {
receiver.error(e);
}
}
@Override
public void visit(Model model) throws Exception {
for (Service service : model.getServices()) {
service.accept(this);
}
}
@Override
public void visit(Service service) throws Exception {
for (Port port : service.getPorts()) {
port.accept(this);
}
}
@Override
public void visit(Port port) throws Exception {
for (Operation operation : port.getOperations()) {
operation.accept(this);
}
}
@Override
public void visit(Operation operation) throws Exception {
operation.getRequest().accept(this);
if (operation.getResponse() != null) {
operation.getResponse().accept(this);
}
Iterator faults = operation.getFaultsSet().iterator();
if (faults != null) {
Fault fault;
while (faults.hasNext()) {
fault = (Fault) faults.next();
fault.accept(this);
}
}
}
@Override
public void visit(Parameter param) throws Exception {}
@Override
public void visit(Block block) throws Exception {}
@Override
public void visit(Response response) throws Exception {}
@Override
public void visit(Request request) throws Exception {}
@Override
public void visit(Fault fault) throws Exception {}
public List<String> getJAXWSClassComment(){
return getJAXWSClassComment(targetVersion);
}
public static List<String> getJAXWSClassComment(String targetVersion) {
List<String> comments = new ArrayList<String>();
comments.add("This class was generated by the JAX-WS RI.\n");
comments.add(ToolVersion.VERSION.BUILD_VERSION+"\n");
comments.add("Generated source version: " + targetVersion);
return comments;
}
protected JDefinedClass getClass(String className, ClassType type) throws JClassAlreadyExistsException {
JDefinedClass cls;
try {
cls = cm._class(className, type);
} catch (JClassAlreadyExistsException e){
cls = cm._getClass(className);
if (cls == null) {
throw e;
}
}
return cls;
}
protected void log(String msg) {
if (options.verbose) {
System.out.println(
"["
+ Names.stripQualifier(this.getClass().getName())
+ ": "
+ msg
+ "]");
}
}
protected void writeHandlerConfig(String className, JDefinedClass cls, WsimportOptions options) {
Element e = options.getHandlerChainConfiguration();
if (e == null) {
return;
}
JAnnotationUse handlerChainAnn = cls.annotate(cm.ref(HandlerChain.class));
NodeList nl = e.getElementsByTagNameNS(
"http://java.sun.com/xml/ns/javaee", "handler-chain");
if(nl.getLength() > 0){
String fName = getHandlerConfigFileName(className);
handlerChainAnn.param("file", fName);
generateHandlerChainFile(e, className);
}
}
private String getHandlerConfigFileName(String fullName){
String name = Names.stripQualifier(fullName);
return name+"_handler.xml";
}
private void generateHandlerChainFile(Element hChains, String name) {
Filer filer = options.filer;
try {
IndentingWriter p;
FileObject jfo;
if (filer != null) {
jfo = filer.createResource(StandardLocation.SOURCE_OUTPUT,
Names.getPackageName(name), getHandlerConfigFileName(name));
options.addGeneratedFile(new File(jfo.toUri()));
p = new IndentingWriter(new OutputStreamWriter(jfo.openOutputStream()));
} else { // leave for backw. compatibility now
String hcName = getHandlerConfigFileName(name);
File packageDir = DirectoryUtil.getOutputDirectoryFor(name, destDir);
File hcFile = new File(packageDir, hcName);
options.addGeneratedFile(hcFile);
p = new IndentingWriter(new OutputStreamWriter(new FileOutputStream(hcFile)));
}
Transformer it = XmlUtil.newTransformer();
it.setOutputProperty(OutputKeys.METHOD, "xml");
it.setOutputProperty(OutputKeys.INDENT, "yes");
it.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount",
"2");
it.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
it.transform( new DOMSource(hChains), new StreamResult(p) );
p.close();
} catch (Exception e) {
throw new GeneratorException(
"generator.nestedGeneratorError",
e);
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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.ws.processor.generator;
/**
* @author WS Development Team
*/
public enum GeneratorConstants {
DOTC("."),
SIG_INNERCLASS("$"),
JAVA_SRC_SUFFIX(".java"),
QNAME_SUFFIX("_QNAME"),
GET("get"),
IS("is"),
RESPONSE("Response"),
FAULT_CLASS_MEMBER_NAME("faultInfo");
private String value;
private GeneratorConstants(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@@ -0,0 +1,47 @@
/*
* 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.ws.processor.generator;
import com.sun.tools.internal.ws.processor.ProcessorException;
/**
*
* @author WS Development Team
*/
public class GeneratorException extends ProcessorException {
public GeneratorException(String key, Object... args) {
super(key, args);
}
public GeneratorException(Throwable throwable) {
super(throwable);
}
public String getDefaultResourceBundleName() {
return "com.sun.tools.internal.ws.resources.generator";
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.JCodeModel;
import com.sun.codemodel.internal.JDefinedClass;
import com.sun.tools.internal.ws.processor.model.Model;
import com.sun.tools.internal.ws.processor.model.Port;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.xml.internal.ws.api.SOAPVersion;
/**
* Service Generator Extension for Custom Binding and Transport
*
* @since 2.2.6
* @see JwsImplGenerator
*/
public abstract class GeneratorExtension {
/**
* Derive Binding ID based on transport and SOAP version
* @param transport
* @param soapVersion
* @return BindingID
*/
public String getBindingValue(String transport, SOAPVersion soapVersion) {
return null;
}
/**
* Create annotations in service JWS generated
* @param model
* @param cm
* @param cls
* @param port
*/
public void writeWebServiceAnnotation(Model model, JCodeModel cm, JDefinedClass cls, Port port) {
}
/**
* Allow additional wsimport options
* @param name for instance, "-neoption"
* @return whether the name specifies an option recognized by the extension
*/
public boolean validateOption(String name) {
return false;
}
/**
* Create annotations in service client generated
* @param options
* @param cm
* @param cls
*/
public void writeWebServiceClientAnnotation(WsimportOptions options, JCodeModel cm, JDefinedClass cls) {
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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.ws.processor.generator;
import com.sun.tools.internal.ws.wscompile.Options;
/**
*
* @author WS Development Team
*/
public class GeneratorUtil {
public static boolean classExists(
Options options,
String className) {
try {
// Takes care of inner classes.
getLoadableClassName(className, options.getClassLoader());
return true;
} catch(ClassNotFoundException ce) {
return false;
}
}
private static String getLoadableClassName(
String className,
ClassLoader classLoader)
throws ClassNotFoundException {
try {
Class.forName(className, true, classLoader);
} catch (ClassNotFoundException e) {
int idx = className.lastIndexOf(GeneratorConstants.DOTC.getValue());
if (idx > -1) {
String tmp = className.substring(0, idx) + GeneratorConstants.SIG_INNERCLASS.getValue();
tmp += className.substring(idx + 1);
return getLoadableClassName(tmp, classLoader);
}
throw e;
}
return className;
}
}

View File

@@ -0,0 +1,48 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.JMethod;
import com.sun.tools.internal.ws.api.TJavaGeneratorExtension;
import com.sun.tools.internal.ws.api.wsdl.TWSDLOperation;
/**
* @author Arun Gupta
*/
public final class JavaGeneratorExtensionFacade extends TJavaGeneratorExtension {
private final TJavaGeneratorExtension[] extensions;
JavaGeneratorExtensionFacade(TJavaGeneratorExtension... extensions) {
assert extensions != null;
this.extensions = extensions;
}
public void writeMethodAnnotations(TWSDLOperation wsdlOperation, JMethod jMethod) {
for (TJavaGeneratorExtension e : extensions) {
e.writeMethodAnnotations(wsdlOperation, jMethod);
}
}
}

View File

@@ -0,0 +1,582 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.*;
import com.sun.tools.internal.ws.processor.model.*;
import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
import com.sun.tools.internal.ws.processor.model.java.JavaMethod;
import com.sun.tools.internal.ws.processor.model.java.JavaParameter;
import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
import com.sun.tools.internal.ws.wsdl.document.Definitions;
import com.sun.tools.internal.ws.wsdl.document.Binding;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAP12Binding;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPBinding;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPConstants;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.processor.model.ModelProperties;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.codemodel.internal.JClassAlreadyExistsException;
import com.sun.xml.internal.ws.api.SOAPVersion;
import com.sun.xml.internal.ws.util.ServiceFinder;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
/**
* Generator for placeholder JWS implementations
*
* @since 2.2.6
*/
public final class JwsImplGenerator extends GeneratorBase {
private static final Map<String, String> TRANSLATION_MAP = new HashMap<String, String>(
1);
static
{
TRANSLATION_MAP.put(SOAPConstants.URI_SOAP_TRANSPORT_HTTP,
javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING);
}
// save the generated impl files' info
private final List<String> implFiles = new ArrayList<String>();
public static List<String> generate(Model model, WsimportOptions options,
ErrorReceiver receiver) {
// options check
// Generate it according the implDestDir option
if (options.implDestDir == null)
return null;
JwsImplGenerator jwsImplGenerator = new JwsImplGenerator();
jwsImplGenerator.init(model, options, receiver);
jwsImplGenerator.doGeneration();
// print a warning message while implFiles.size() is zero
if (jwsImplGenerator.implFiles.isEmpty()) {
StringBuilder msg = new StringBuilder();
if (options.implServiceName != null)
msg.append("serviceName=[").append(options.implServiceName).append("] ");
if (options.implPortName != null)
msg.append("portName=[").append(options.implPortName).append("] ");
if (msg.length() > 0)
msg.append(", Not found in wsdl file.\n");
msg.append("No impl files generated!");
receiver.warning(null, msg.toString());
}
return jwsImplGenerator.implFiles;
}
/**
* Move impl files to implDestDir
*/
public static boolean moveToImplDestDir(List<String> gImplFiles,
WsimportOptions options, ErrorReceiver receiver) {
if (options.implDestDir == null || gImplFiles == null
|| gImplFiles.isEmpty())
return true;
List<ImplFile> generatedImplFiles = ImplFile.toImplFiles(gImplFiles);
try {
File implDestDir = makePackageDir(options);
File movedF;
File f;
for (ImplFile implF : generatedImplFiles) {
movedF = findFile(options, implF.qualifiedName);
if (movedF == null) {
// should never happen
receiver.warning(null, "Class " + implF.qualifiedName
+ " is not generated. Not moving.");
return false;
}
f = new File(implDestDir, implF.name);
if (!movedF.equals(f)) { //bug 10102169
if (f.exists())
{
if (!f.delete()){
receiver.error("Class " + implF.qualifiedName
+ " has existed in destImplDir, and it "
+ "can not be written!", null);
}
}
if(!movedF.renameTo(f))
{
throw new Exception();
}
}
}
} catch (Exception e) {
receiver.error("Moving WebService Impl files failed!", e);
return false;
}
return true;
}
private JwsImplGenerator() {
donotOverride = true;
}
@Override
public void visit(Service service) {
QName serviceName = service.getName();
// process the ordered service only if it is defined
if (options.implServiceName != null
&& !equalsNSOptional(options.implServiceName, serviceName))
return;
for (Port port : service.getPorts()) {
if (port.isProvider()) {
continue; // Not generating for Provider based endpoint
}
// Generate the impl class name according to
// Xpath(/definitions/service/port[@name]);
QName portName = port.getName();
// process the ordered port only if it is defined
if (options.implPortName != null
&& !equalsNSOptional(options.implPortName, portName))
continue;
String simpleClassName = serviceName.getLocalPart() + "_"
+ portName.getLocalPart() + "Impl";
String className = makePackageQualified(simpleClassName);
implFiles.add(className);
if (donotOverride && GeneratorUtil.classExists(options, className)) {
log("Class " + className + " exists. Not overriding.");
return;
}
JDefinedClass cls = null;
try {
cls = getClass(className, ClassType.CLASS);
} catch (JClassAlreadyExistsException e) {
log("Class " + className
+ " generates failed. JClassAlreadyExistsException[" + className
+ "].");
return;
}
// Each serviceImpl will implements one port interface
JavaInterface portIntf = port.getJavaInterface();
String portClassName = Names.customJavaTypeClassName(portIntf);
JDefinedClass portCls = null;
try {
portCls = getClass(portClassName, ClassType.INTERFACE);
} catch (JClassAlreadyExistsException e) {
log("Class " + className
+ " generates failed. JClassAlreadyExistsException["
+ portClassName + "].");
return;
}
cls._implements(portCls);
// create a default constructor
cls.constructor(JMod.PUBLIC);
// write class comment - JAXWS warning
JDocComment comment = cls.javadoc();
if (service.getJavaDoc() != null) {
comment.add(service.getJavaDoc());
comment.add("\n\n");
}
for (String doc : getJAXWSClassComment()) {
comment.add(doc);
}
// @WebService
JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
writeWebServiceAnnotation(service, port, webServiceAnn);
// @BindingType
JAnnotationUse bindingTypeAnn = cls.annotate(cm.ref(BindingType.class));
writeBindingTypeAnnotation(port, bindingTypeAnn);
// extra annotation
for( GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
f.writeWebServiceAnnotation(model, cm, cls, port);
}
// WebMethods
for (Operation operation : port.getOperations()) {
JavaMethod method = operation.getJavaMethod();
// @WebMethod
JMethod m;
JDocComment methodDoc;
String methodJavaDoc = operation.getJavaDoc();
if (method.getReturnType().getName().equals("void")) {
m = cls.method(JMod.PUBLIC, void.class, method.getName());
methodDoc = m.javadoc();
} else {
JAXBTypeAndAnnotation retType = method.getReturnType().getType();
m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
retType.annotate(m);
methodDoc = m.javadoc();
JCommentPart ret = methodDoc.addReturn();
ret.add("returns " + retType.getName());
}
if (methodJavaDoc != null)
methodDoc.add(methodJavaDoc);
JClass holder = cm.ref(Holder.class);
for (JavaParameter parameter : method.getParametersList()) {
JVar var;
JAXBTypeAndAnnotation paramType = parameter.getType().getType();
if (parameter.isHolder()) {
var = m.param(holder.narrow(paramType.getType().boxify()),
parameter.getName());
} else {
var = m.param(paramType.getType(), parameter.getName());
}
methodDoc.addParam(var);
}
com.sun.tools.internal.ws.wsdl.document.Operation wsdlOp = operation
.getWSDLPortTypeOperation();
for (Fault fault : operation.getFaultsSet()) {
m._throws(fault.getExceptionClass());
methodDoc.addThrows(fault.getExceptionClass());
wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
}
m.body().block().directStatement("//replace with your impl here");
m.body().block().directStatement(
getReturnString(method.getReturnType().getName()));
}
}
}
/**
* Generate return statement according to return type.
*
* @param type
* The method's return type
* @return The whole return statement
*/
private String getReturnString(String type) {
final String nullReturnStr = "return null;";
// complex type or array
if (type.indexOf('.') > -1 || type.indexOf('[') > -1) {
return nullReturnStr;
}
// primitive type
if (type.equals("void")) {
return "return;";
}
if (type.equals("boolean")) {
return "return false;";
}
if (type.equals("int") || type.equals("byte") || type.equals("short")
|| type.equals("long") || type.equals("double") || type.equals("float")) {
return "return 0;";
}
if (type.equals("char")) {
return "return '0';";
}
return nullReturnStr;
}
/**
*
* @param service
* @param port
* @param webServiceAnn
* @param options
*/
private void writeWebServiceAnnotation(Service service, Port port,
JAnnotationUse webServiceAnn) {
webServiceAnn.param("portName", port.getName().getLocalPart());
webServiceAnn.param("serviceName", service.getName().getLocalPart());
webServiceAnn.param("targetNamespace", service.getName().getNamespaceURI());
webServiceAnn.param("wsdlLocation", wsdlLocation);
webServiceAnn.param("endpointInterface", port.getJavaInterface().getName());
}
//CR373098 To transform the java class name as validate.
private String transToValidJavaIdentifier(String s) {
if (s == null) {
return null;
}
final int len = s.length();
StringBuilder retSB = new StringBuilder();
if (len == 0 || !Character.isJavaIdentifierStart(s.charAt(0))) {
retSB.append("J"); //update to a default start char
} else {
retSB.append(s.charAt(0));
}
for (int i = 1; i < len; i++) {
if (!Character.isJavaIdentifierPart(s.charAt(i)))
; //delete it if it is illegal //TODO: It might conflict "a-b" vs. "ab"
else {
retSB.append(s.charAt(i));
}
}
return retSB.toString();
}
private String makePackageQualified(String s) {
s = transToValidJavaIdentifier(s);
if (options.defaultPackage != null && !options.defaultPackage.equals("")) {
return options.defaultPackage + "." + s;
} else {
return s;
}
}
/**
* TODO
*
* @param port
* @param bindingTypeAnn
*/
private void writeBindingTypeAnnotation(Port port,
JAnnotationUse bindingTypeAnn) {
QName bName = (QName) port
.getProperty(ModelProperties.PROPERTY_WSDL_BINDING_NAME);
if (bName == null)
return;
String v = getBindingType(bName);
// TODO: How to decide if it is a mtom?
if (v != null) {
// transport = translate(transport);
bindingTypeAnn.param("value", v);
}
}
private String resolveBindingValue(TWSDLExtension wsdlext) {
if (wsdlext.getClass().equals(SOAPBinding.class)) {
SOAPBinding sb = (SOAPBinding) wsdlext;
if(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(sb.getTransport()))
return javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING;
else {
for(GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
String bindingValue = f.getBindingValue(sb.getTransport(), SOAPVersion.SOAP_11);
if(bindingValue!=null) {
return bindingValue;
}
}
return javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
}
}
if (wsdlext.getClass().equals(SOAP12Binding.class)) {
SOAP12Binding sb = (SOAP12Binding) wsdlext;
if(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(sb.getTransport()))
return javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING;
else {
for(GeneratorExtension f : ServiceFinder.find(GeneratorExtension.class) ) {
String bindingValue = f.getBindingValue(sb.getTransport(), SOAPVersion.SOAP_12);
if(bindingValue!=null) {
return bindingValue;
}
}
return javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING;
}
}
return null;
}
private String getBindingType(QName bName) {
String value = null;
// process the bindings in definitions of model.entity
if (model.getEntity() instanceof Definitions) {
Definitions definitions = (Definitions) model.getEntity();
if (definitions != null) {
Iterator bindings = definitions.bindings();
if (bindings != null) {
while (bindings.hasNext()) {
Binding binding = (Binding) bindings.next();
if (bName.getLocalPart().equals(binding.getName())
&& bName.getNamespaceURI().equals(binding.getNamespaceURI())) {
List<TWSDLExtension> bindextends = (List<TWSDLExtension>) binding
.extensions();
for (TWSDLExtension wsdlext : bindextends) {
value = resolveBindingValue(wsdlext);
if (value != null)
break;
}
break;
}
}
}
}
}
// process the bindings in whole document
if (value == null) {
if (model.getEntity() instanceof Definitions) {
Definitions definitions = (Definitions) model.getEntity();
Binding b = (Binding) definitions.resolveBindings().get(bName);
if (b != null) {
List<TWSDLExtension> bindextends = (List<TWSDLExtension>) b
.extensions();
for (TWSDLExtension wsdlext : bindextends) {
value = resolveBindingValue(wsdlext);
if (value != null)
break;
}
}
}
}
return value;
}
/**
* Since the SOAP 1.1 binding transport URI defined in WSDL 1.1 specification
* is different with the SOAPBinding URI defined by JAX-WS 2.0 specification.
* We must translate the wsdl version into JAX-WS version. If the given
* transport URI is NOT one of the predefined transport URIs, it is returned
* as is.
*
* @param transportURI
* retrieved from WSDL
* @return Standard BindingType URI defined by JAX-WS 2.0 specification.
*/
// private String translate(String transportURI)
// {
// String translatedBindingId = TRANSLATION_MAP.get(transportURI);
// if (translatedBindingId == null)
// translatedBindingId = transportURI;
//
// return translatedBindingId;
// }
/*****************************************************************************
* Inner classes definition
*/
static final class ImplFile {
public String qualifiedName; // package+"."+simpleClassName + ".java"
public String name; // simpleClassName + ".java"
private ImplFile(String qualifiedClassName) {
this.qualifiedName = qualifiedClassName + ".java";
String simpleClassName = qualifiedClassName;
int i = qualifiedClassName.lastIndexOf(".");
if (i != -1)
simpleClassName = qualifiedClassName.substring(i + 1);
this.name = simpleClassName + ".java";
}
public static List<ImplFile> toImplFiles(List<String> qualifiedClassNames) {
List<ImplFile> ret = new ArrayList<ImplFile>();
for (String qualifiedClassName : qualifiedClassNames)
ret.add(new ImplFile(qualifiedClassName));
return ret;
}
}
/*****************************************************************************
* Other utility methods
*/
private static File makePackageDir(WsimportOptions options) {
File ret = null;
if (options.defaultPackage != null && !options.defaultPackage.equals("")) {
String subDir = options.defaultPackage.replace('.', '/');
ret = new File(options.implDestDir, subDir);
} else {
ret = options.implDestDir;
}
boolean created = ret.mkdirs();
if (options.verbose && !created) {
System.out.println(MessageFormat.format("Directory not created: {0}", ret));
}
return ret;
}
private static String getQualifiedFileName(String canonicalBaseDir, File f)
throws java.io.IOException {
String fp = f.getCanonicalPath();
if (fp == null)
return null;
fp = fp.replace(canonicalBaseDir, "");
fp = fp.replace('\\', '.');
fp = fp.replace('/', '.');
if (fp.startsWith("."))
fp = fp.substring(1);
return fp;
}
private static File findFile(WsimportOptions options, String qualifiedFileName)
throws java.io.IOException {
String baseDir = options.sourceDir.getCanonicalPath();
String fp = null;
for (File f : options.getGeneratedFiles()) {
fp = getQualifiedFileName(baseDir, f);
if (qualifiedFileName.equals(fp))
return f;
}
return null;
}
private static boolean equalsNSOptional(String strQName, QName checkQN) {
if (strQName == null)
return false;
strQName = strQName.trim();
QName reqQN = QName.valueOf(strQName);
if (reqQN.getNamespaceURI() == null || reqQN.getNamespaceURI().equals(""))
return reqQN.getLocalPart().equals(checkQN.getLocalPart());
return reqQN.equals(checkQN);
}
}

View File

@@ -0,0 +1,180 @@
/*
* 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.ws.processor.generator;
import com.sun.istack.internal.NotNull;
import com.sun.tools.internal.ws.processor.model.Fault;
import com.sun.tools.internal.ws.processor.model.ModelProperties;
import com.sun.tools.internal.ws.processor.model.Port;
import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
import com.sun.tools.internal.ws.processor.model.java.JavaStructureMember;
import com.sun.tools.internal.ws.processor.modeler.ModelerConstants;
import com.sun.tools.internal.ws.util.ClassNameInfo;
import com.sun.xml.internal.ws.util.StringUtils;
import javax.xml.namespace.QName;
import java.util.HashMap;
import java.util.Map;
/**
* Names provides utility methods used by other wscompile classes
* for dealing with identifiers.
*
* @author WS Development Team
*/
public final class Names {
private Names() {
}
public static String getPortName(Port port) {
String javaPortName =
(String) port.getProperty(ModelProperties.PROPERTY_JAVA_PORT_NAME);
if (javaPortName != null) {
return javaPortName;
} else {
QName portName =
(QName) port.getProperty(
ModelProperties.PROPERTY_WSDL_PORT_NAME);
if (portName != null) {
return portName.getLocalPart();
} else {
String name = stripQualifier(port.getJavaInterface().getName());
return ClassNameInfo.replaceInnerClassSym(name);
}
}
}
public static String stripQualifier(String name) {
return ClassNameInfo.getName(name);
}
public static String getPackageName(String className) {
String packageName = ClassNameInfo.getQualifier(className);
return packageName != null ? packageName : "";
}
public static String customJavaTypeClassName(JavaInterface intf) {
return intf.getName();
}
public static String customExceptionClassName(Fault fault) {
return fault.getJavaException().getName();
}
public static String getExceptionClassMemberName(){
return GeneratorConstants.FAULT_CLASS_MEMBER_NAME.getValue();
}
public static boolean isJavaReservedWord(String name) {
return RESERVED_WORDS.get(name) != null;
}
/**
* See if its a java keyword name, if so then mangle the name
*/
public static @NotNull String getJavaReserverVarialbeName(@NotNull String name){
return (RESERVED_WORDS.get(name) == null) ? name : RESERVED_WORDS.get(name);
}
/* here we check on wether return values datatype is
boolean. If its boolean, instead of a get method
its set a is<MethodName> to comply with JavaBeans
Pattern spec */
public static String getJavaMemberReadMethod(JavaStructureMember member) {
String return_value;
if (member.getType().getRealName().equals(ModelerConstants.BOOLEAN_CLASSNAME.getValue())) {
return_value = GeneratorConstants.IS.getValue() + StringUtils.capitalize(member.getName());
} else {
return_value = GeneratorConstants.GET.getValue() + StringUtils.capitalize(member.getName());
}
return (return_value);
}
public static String getResponseName(String messageName) {
return messageName + GeneratorConstants.RESPONSE.getValue();
}
private static final Map<String, String> RESERVED_WORDS = new HashMap<String, String>(53);
static {
RESERVED_WORDS.put("abstract", "_abstract");
RESERVED_WORDS.put("assert", "_assert");
RESERVED_WORDS.put("boolean", "_boolean");
RESERVED_WORDS.put("break", "_break");
RESERVED_WORDS.put("byte", "_byte");
RESERVED_WORDS.put("case", "_case");
RESERVED_WORDS.put("catch", "_catch");
RESERVED_WORDS.put("char", "_char");
RESERVED_WORDS.put("class", "_class");
RESERVED_WORDS.put("const", "_const");
RESERVED_WORDS.put("continue", "_continue");
RESERVED_WORDS.put("default", "_default");
RESERVED_WORDS.put("do", "_do");
RESERVED_WORDS.put("double", "_double");
RESERVED_WORDS.put("else", "_else");
RESERVED_WORDS.put("extends", "_extends");
RESERVED_WORDS.put("false", "_false");
RESERVED_WORDS.put("final", "_final");
RESERVED_WORDS.put("finally", "_finally");
RESERVED_WORDS.put("float", "_float");
RESERVED_WORDS.put("for", "_for");
RESERVED_WORDS.put("goto", "_goto");
RESERVED_WORDS.put("if", "_if");
RESERVED_WORDS.put("implements", "_implements");
RESERVED_WORDS.put("import", "_import");
RESERVED_WORDS.put("instanceof", "_instanceof");
RESERVED_WORDS.put("int", "_int");
RESERVED_WORDS.put("interface", "_interface");
RESERVED_WORDS.put("long", "_long");
RESERVED_WORDS.put("native", "_native");
RESERVED_WORDS.put("new", "_new");
RESERVED_WORDS.put("null", "_null");
RESERVED_WORDS.put("package", "_package");
RESERVED_WORDS.put("private", "_private");
RESERVED_WORDS.put("protected", "_protected");
RESERVED_WORDS.put("public", "_public");
RESERVED_WORDS.put("return", "_return");
RESERVED_WORDS.put("short", "_short");
RESERVED_WORDS.put("static", "_static");
RESERVED_WORDS.put("strictfp", "_strictfp");
RESERVED_WORDS.put("super", "_super");
RESERVED_WORDS.put("switch", "_switch");
RESERVED_WORDS.put("synchronized", "_synchronized");
RESERVED_WORDS.put("this", "_this");
RESERVED_WORDS.put("throw", "_throw");
RESERVED_WORDS.put("throws", "_throws");
RESERVED_WORDS.put("transient", "_transient");
RESERVED_WORDS.put("true", "_true");
RESERVED_WORDS.put("try", "_try");
RESERVED_WORDS.put("void", "_void");
RESERVED_WORDS.put("volatile", "_volatile");
RESERVED_WORDS.put("while", "_while");
RESERVED_WORDS.put("enum", "_enum");
}
}

View File

@@ -0,0 +1,491 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.*;
import com.sun.tools.internal.ws.api.TJavaGeneratorExtension;
import com.sun.tools.internal.ws.processor.model.*;
import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
import com.sun.tools.internal.ws.processor.model.java.JavaMethod;
import com.sun.tools.internal.ws.processor.model.java.JavaParameter;
import com.sun.tools.internal.ws.processor.model.jaxb.JAXBType;
import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.Options;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
import com.sun.tools.internal.ws.wsdl.document.PortType;
import com.sun.tools.internal.ws.resources.GeneratorMessages;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.namespace.QName;
import javax.xml.ws.Holder;
import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Locator;
public class SeiGenerator extends GeneratorBase {
private TJavaGeneratorExtension extension;
private List<TJavaGeneratorExtension> extensionHandlers;
public static void generate(Model model, WsimportOptions options, ErrorReceiver receiver, TJavaGeneratorExtension... extensions){
SeiGenerator seiGenerator = new SeiGenerator();
seiGenerator.init(model, options, receiver, extensions);
seiGenerator.doGeneration();
}
public void init(Model model, WsimportOptions options, ErrorReceiver receiver, TJavaGeneratorExtension... extensions) {
init(model, options, receiver);
extensionHandlers = new ArrayList<TJavaGeneratorExtension>();
// register handlers for default extensions
// 2.2 Spec requires generation of @Action when wsam:Action is explicitly stated in wsdl
if (options.target.isLaterThan(Options.Target.V2_2)) {
register(new W3CAddressingJavaGeneratorExtension());
}
for (TJavaGeneratorExtension j : extensions) {
register(j);
}
this.extension = new JavaGeneratorExtensionFacade(extensionHandlers.toArray(new TJavaGeneratorExtension[extensionHandlers.size()]));
}
private void write(Port port) {
JavaInterface intf = port.getJavaInterface();
String className = Names.customJavaTypeClassName(intf);
if (donotOverride && GeneratorUtil.classExists(options, className)) {
log("Class " + className + " exists. Not overriding.");
return;
}
JDefinedClass cls;
try {
cls = getClass(className, ClassType.INTERFACE);
} catch (JClassAlreadyExistsException e) {
QName portTypeName =
(QName) port.getProperty(
ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
Locator loc = null;
if(portTypeName != null){
PortType pt = port.portTypes.get(portTypeName);
if (pt!=null) {
loc = pt.getLocator();
}
}
receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName));
return;
}
// If the class has methods it has already been defined
// so skip it.
if (!cls.methods().isEmpty()) {
return;
}
//write class comment - JAXWS warning
JDocComment comment = cls.javadoc();
String ptDoc = intf.getJavaDoc();
if(ptDoc != null){
comment.add(ptDoc);
comment.add("\n\n");
}
for(String doc:getJAXWSClassComment()){
comment.add(doc);
}
//@WebService
JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
writeWebServiceAnnotation(port, webServiceAnn);
//@HandlerChain
writeHandlerConfig(Names.customJavaTypeClassName(port.getJavaInterface()), cls, options);
//@SOAPBinding
writeSOAPBinding(port, cls);
//@XmlSeeAlso
if (options.target.isLaterThan(Options.Target.V2_1)) {
writeXmlSeeAlso(cls);
}
for (Operation operation: port.getOperations()) {
JavaMethod method = operation.getJavaMethod();
//@WebMethod
JMethod m;
JDocComment methodDoc;
String methodJavaDoc = operation.getJavaDoc();
if(method.getReturnType().getName().equals("void")){
m = cls.method(JMod.PUBLIC, void.class, method.getName());
methodDoc = m.javadoc();
}else {
JAXBTypeAndAnnotation retType = method.getReturnType().getType();
m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
retType.annotate(m);
methodDoc = m.javadoc();
JCommentPart ret = methodDoc.addReturn();
ret.add("returns "+retType.getName());
}
if (methodJavaDoc != null) {
methodDoc.add(methodJavaDoc);
}
writeWebMethod(operation, m);
JClass holder = cm.ref(Holder.class);
for (JavaParameter parameter: method.getParametersList()) {
JVar var;
JAXBTypeAndAnnotation paramType = parameter.getType().getType();
if (parameter.isHolder()) {
var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName());
}else{
var = m.param(paramType.getType(), parameter.getName());
}
//annotate parameter with JAXB annotations
paramType.annotate(var);
methodDoc.addParam(var);
JAnnotationUse paramAnn = var.annotate(cm.ref(WebParam.class));
writeWebParam(operation, parameter, paramAnn);
}
com.sun.tools.internal.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation();
for(Fault fault:operation.getFaultsSet()){
m._throws(fault.getExceptionClass());
methodDoc.addThrows(fault.getExceptionClass());
wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
}
//It should be the last thing to invoke after JMethod is built completely
extension.writeMethodAnnotations(wsdlOp, m);
}
}
private void writeXmlSeeAlso(JDefinedClass cls) {
if (model.getJAXBModel().getS2JJAXBModel() != null) {
List<JClass> objectFactories = model.getJAXBModel().getS2JJAXBModel().getAllObjectFactories();
//if there are no object facotires, dont generate @XmlSeeAlso
if (objectFactories.isEmpty()) {
return;
}
JAnnotationUse xmlSeeAlso = cls.annotate(cm.ref(XmlSeeAlso.class));
JAnnotationArrayMember paramArray = xmlSeeAlso.paramArray("value");
for (JClass of : objectFactories) {
paramArray = paramArray.param(of);
}
}
}
private void writeWebMethod(Operation operation, JMethod m) {
Response response = operation.getResponse();
JAnnotationUse webMethodAnn = m.annotate(cm.ref(WebMethod.class));
String operationName = (operation instanceof AsyncOperation)?
((AsyncOperation)operation).getNormalOperation().getName().getLocalPart():
operation.getName().getLocalPart();
if(!m.name().equals(operationName)){
webMethodAnn.param("operationName", operationName);
}
if (operation.getSOAPAction() != null && operation.getSOAPAction().length() > 0){
webMethodAnn.param("action", operation.getSOAPAction());
}
if (operation.getResponse() == null){
m.annotate(javax.jws.Oneway.class);
}else if (!operation.getJavaMethod().getReturnType().getName().equals("void") &&
operation.getResponse().getParametersList().size() > 0){
Block block;
String resultName = null;
String nsURI = null;
if (operation.getResponse().getBodyBlocks().hasNext()) {
block = operation.getResponse().getBodyBlocks().next();
resultName = block.getName().getLocalPart();
if(isDocStyle || block.getLocation() == Block.HEADER){
nsURI = block.getName().getNamespaceURI();
}
}
for (Parameter parameter : operation.getResponse().getParametersList()) {
if (parameter.getParameterIndex() == -1) {
if(operation.isWrapped()||!isDocStyle){
if(parameter.getBlock().getLocation() == Block.HEADER){
resultName = parameter.getBlock().getName().getLocalPart();
}else{
resultName = parameter.getName();
}
if (isDocStyle || (parameter.getBlock().getLocation() == Block.HEADER)) {
nsURI = parameter.getType().getName().getNamespaceURI();
}
}else if(isDocStyle){
JAXBType t = (JAXBType)parameter.getType();
resultName = t.getName().getLocalPart();
nsURI = t.getName().getNamespaceURI();
}
if(!(operation instanceof AsyncOperation)){
JAnnotationUse wr = null;
if(!resultName.equals("return")){
wr = m.annotate(javax.jws.WebResult.class);
wr.param("name", resultName);
}
if (nsURI != null || (isDocStyle && operation.isWrapped())) {
if(wr == null) {
wr = m.annotate(javax.jws.WebResult.class);
}
wr.param("targetNamespace", nsURI);
}
//doclit wrapped could have additional headers
if(!(isDocStyle && operation.isWrapped()) ||
(parameter.getBlock().getLocation() == Block.HEADER)){
if (wr == null) {
wr = m.annotate(javax.jws.WebResult.class);
}
wr.param("partName", parameter.getName());
}
if(parameter.getBlock().getLocation() == Block.HEADER){
if (wr == null) {
wr = m.annotate(javax.jws.WebResult.class);
}
wr.param("header",true);
}
}
}
}
}
//DOC/BARE
if (!sameParamStyle) {
if(!operation.isWrapped()) {
JAnnotationUse sb = m.annotate(SOAPBinding.class);
sb.param("parameterStyle", SOAPBinding.ParameterStyle.BARE);
}
}
if (operation.isWrapped() && operation.getStyle().equals(SOAPStyle.DOCUMENT)) {
Block reqBlock = operation.getRequest().getBodyBlocks().next();
JAnnotationUse reqW = m.annotate(javax.xml.ws.RequestWrapper.class);
reqW.param("localName", reqBlock.getName().getLocalPart());
reqW.param("targetNamespace", reqBlock.getName().getNamespaceURI());
reqW.param("className", reqBlock.getType().getJavaType().getName());
if (response != null) {
JAnnotationUse resW = m.annotate(javax.xml.ws.ResponseWrapper.class);
Block resBlock = response.getBodyBlocks().next();
resW.param("localName", resBlock.getName().getLocalPart());
resW.param("targetNamespace", resBlock.getName().getNamespaceURI());
resW.param("className", resBlock.getType().getJavaType().getName());
}
}
}
private boolean isMessageParam(Parameter param, Message message) {
Block block = param.getBlock();
return (message.getBodyBlockCount() > 0 && block.equals(message.getBodyBlocks().next())) ||
(message.getHeaderBlockCount() > 0 &&
block.equals(message.getHeaderBlocks().next()));
}
private boolean isHeaderParam(Parameter param, Message message) {
if (message.getHeaderBlockCount() == 0) {
return false;
}
for (Block headerBlock : message.getHeaderBlocksMap().values()) {
if (param.getBlock().equals(headerBlock)) {
return true;
}
}
return false;
}
private boolean isAttachmentParam(Parameter param, Message message){
if (message.getAttachmentBlockCount() == 0) {
return false;
}
for (Block attBlock : message.getAttachmentBlocksMap().values()) {
if (param.getBlock().equals(attBlock)) {
return true;
}
}
return false;
}
private boolean isUnboundParam(Parameter param, Message message){
if (message.getUnboundBlocksCount() == 0) {
return false;
}
for (Block unboundBlock : message.getUnboundBlocksMap().values()) {
if (param.getBlock().equals(unboundBlock)) {
return true;
}
}
return false;
}
private void writeWebParam(Operation operation, JavaParameter javaParameter, JAnnotationUse paramAnno) {
Parameter param = javaParameter.getParameter();
Request req = operation.getRequest();
Response res = operation.getResponse();
boolean header = isHeaderParam(param, req) ||
(res != null && isHeaderParam(param, res));
String name;
boolean isWrapped = operation.isWrapped();
if ((param.getBlock().getLocation() == Block.HEADER) || (isDocStyle && !isWrapped)) {
name = param.getBlock().getName().getLocalPart();
} else {
name = param.getName();
}
paramAnno.param("name", name);
String ns= null;
if (isDocStyle) {
ns = param.getBlock().getName().getNamespaceURI(); // its bare nsuri
if(isWrapped){
ns = param.getType().getName().getNamespaceURI();
}
}else if(header){
ns = param.getBlock().getName().getNamespaceURI();
}
if (ns != null || (isDocStyle && isWrapped)) {
paramAnno.param("targetNamespace", ns);
}
if (header) {
paramAnno.param("header", true);
}
if (param.isINOUT()){
paramAnno.param("mode", javax.jws.WebParam.Mode.INOUT);
}else if ((res != null) && (isMessageParam(param, res) || isHeaderParam(param, res) || isAttachmentParam(param, res) ||
isUnboundParam(param,res) || param.isOUT())){
paramAnno.param("mode", javax.jws.WebParam.Mode.OUT);
}
//doclit wrapped could have additional headers
if (!(isDocStyle && isWrapped) || header) {
paramAnno.param("partName", javaParameter.getParameter().getName());
}
}
private boolean isDocStyle = true;
private boolean sameParamStyle = true;
private void writeSOAPBinding(Port port, JDefinedClass cls) {
JAnnotationUse soapBindingAnn = null;
isDocStyle = port.getStyle() == null || port.getStyle().equals(SOAPStyle.DOCUMENT);
if(!isDocStyle){
soapBindingAnn = cls.annotate(SOAPBinding.class);
soapBindingAnn.param("style", SOAPBinding.Style.RPC);
port.setWrapped(true);
}
if(isDocStyle){
boolean first = true;
boolean isWrapper = true;
for(Operation operation:port.getOperations()){
if(first){
isWrapper = operation.isWrapped();
first = false;
continue;
}
sameParamStyle = (isWrapper == operation.isWrapped());
if (!sameParamStyle) {
break;
}
}
if (sameParamStyle) {
port.setWrapped(isWrapper);
}
}
if(sameParamStyle && !port.isWrapped()){
if (soapBindingAnn == null) {
soapBindingAnn = cls.annotate(SOAPBinding.class);
}
soapBindingAnn.param("parameterStyle", SOAPBinding.ParameterStyle.BARE);
}
}
private void writeWebServiceAnnotation(Port port, JAnnotationUse wsa) {
QName name = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
wsa.param("name", name.getLocalPart());
wsa.param("targetNamespace", name.getNamespaceURI());
}
@Override
public void visit(Model model) throws Exception {
for(Service s:model.getServices()){
s.accept(this);
}
}
@Override
public void visit(Service service) throws Exception {
String jd = model.getJavaDoc();
if(jd != null){
JPackage pkg = cm._package(options.defaultPackage);
pkg.javadoc().add(jd);
}
for(Port p:service.getPorts()){
visitPort(service, p);
}
}
private void visitPort(Service service, Port port) {
if (port.isProvider()) {
return; // Not generating for Provider based endpoint
}
write(port);
}
private void register(TJavaGeneratorExtension h) {
extensionHandlers.add(h);
}
}

View File

@@ -0,0 +1,422 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.ClassType;
import com.sun.codemodel.internal.JAnnotationUse;
import com.sun.codemodel.internal.JBlock;
import com.sun.codemodel.internal.JCatchBlock;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JClassAlreadyExistsException;
import com.sun.codemodel.internal.JCommentPart;
import com.sun.codemodel.internal.JConditional;
import com.sun.codemodel.internal.JDefinedClass;
import com.sun.codemodel.internal.JDocComment;
import com.sun.codemodel.internal.JExpr;
import com.sun.codemodel.internal.JFieldVar;
import com.sun.codemodel.internal.JInvocation;
import com.sun.codemodel.internal.JMethod;
import com.sun.codemodel.internal.JMod;
import com.sun.codemodel.internal.JTryBlock;
import com.sun.codemodel.internal.JType;
import com.sun.codemodel.internal.JVar;
import com.sun.tools.internal.ws.processor.model.Model;
import com.sun.tools.internal.ws.processor.model.ModelProperties;
import com.sun.tools.internal.ws.processor.model.Port;
import com.sun.tools.internal.ws.processor.model.Service;
import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
import com.sun.tools.internal.ws.resources.GeneratorMessages;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.Options;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.wsdl.document.PortType;
import com.sun.xml.internal.ws.spi.db.BindingHelper;
import org.xml.sax.Locator;
import javax.xml.namespace.QName;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.WebServiceException;
import java.net.MalformedURLException;
import java.net.URL;
import com.sun.xml.internal.ws.util.ServiceFinder;
import java.util.Locale;
/**
* @author WS Development Team
* @author Jitendra Kotamraju
*/
public class ServiceGenerator extends GeneratorBase {
public static void generate(Model model, WsimportOptions options, ErrorReceiver receiver) {
ServiceGenerator serviceGenerator = new ServiceGenerator(model, options, receiver);
serviceGenerator.doGeneration();
}
private ServiceGenerator(Model model, WsimportOptions options, ErrorReceiver receiver) {
init(model, options, receiver);
}
@Override
public void visit(Service service) {
JavaInterface intf = service.getJavaInterface();
String className = Names.customJavaTypeClassName(intf);
if (donotOverride && GeneratorUtil.classExists(options, className)) {
log("Class " + className + " exists. Not overriding.");
return;
}
JDefinedClass cls;
try {
cls = getClass(className, ClassType.CLASS);
} catch (JClassAlreadyExistsException e) {
receiver.error(service.getLocator(), GeneratorMessages.GENERATOR_SERVICE_CLASS_ALREADY_EXIST(className, service.getName()));
return;
}
cls._extends(javax.xml.ws.Service.class);
String serviceFieldName = BindingHelper.mangleNameToClassName(service.getName().getLocalPart()).toUpperCase(Locale.ENGLISH);
String wsdlLocationName = serviceFieldName + "_WSDL_LOCATION";
JFieldVar urlField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, URL.class, wsdlLocationName);
JFieldVar exField = cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, WebServiceException.class, serviceFieldName+"_EXCEPTION");
String serviceName = serviceFieldName + "_QNAME";
cls.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, QName.class, serviceName,
JExpr._new(cm.ref(QName.class)).arg(service.getName().getNamespaceURI()).arg(service.getName().getLocalPart()));
JClass qNameCls = cm.ref(QName.class);
JInvocation inv;
inv = JExpr._new(qNameCls);
inv.arg("namespace");
inv.arg("localpart");
if (options.useBaseResourceAndURLToLoadWSDL) {
writeClassLoaderBaseResourceWSDLLocation(className, cls, urlField, exField);
} else if (wsdlLocation.startsWith("http://") || wsdlLocation.startsWith("https://") || wsdlLocation.startsWith("file:/")) {
writeAbsWSDLLocation(cls, urlField, exField);
} else if (wsdlLocation.startsWith("META-INF/")) {
writeClassLoaderResourceWSDLLocation(className, cls, urlField, exField);
} else {
writeResourceWSDLLocation(className, cls, urlField, exField);
}
//write class comment - JAXWS warning
JDocComment comment = cls.javadoc();
if (service.getJavaDoc() != null) {
comment.add(service.getJavaDoc());
comment.add("\n\n");
}
for (String doc : getJAXWSClassComment()) {
comment.add(doc);
}
// Generating constructor
// for e.g: public ExampleService()
JMethod constructor1 = cls.constructor(JMod.PUBLIC);
String constructor1Str = String.format("super(__getWsdlLocation(), %s);", serviceName);
constructor1.body().directStatement(constructor1Str);
// Generating constructor
// for e.g: public ExampleService(WebServiceFeature ... features)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor2 = cls.constructor(JMod.PUBLIC);
constructor2.varParam(WebServiceFeature.class, "features");
String constructor2Str = String.format("super(__getWsdlLocation(), %s, features);", serviceName);
constructor2.body().directStatement(constructor2Str);
}
// Generating constructor
// for e.g: public ExampleService(URL wsdlLocation)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor3 = cls.constructor(JMod.PUBLIC);
constructor3.param(URL.class, "wsdlLocation");
String constructor3Str = String.format("super(wsdlLocation, %s);", serviceName);
constructor3.body().directStatement(constructor3Str);
}
// Generating constructor
// for e.g: public ExampleService(URL wsdlLocation, WebServiceFeature ... features)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor4 = cls.constructor(JMod.PUBLIC);
constructor4.param(URL.class, "wsdlLocation");
constructor4.varParam(WebServiceFeature.class, "features");
String constructor4Str = String.format("super(wsdlLocation, %s, features);", serviceName);
constructor4.body().directStatement(constructor4Str);
}
// Generating constructor
// for e.g: public ExampleService(URL wsdlLocation, QName serviceName)
JMethod constructor5 = cls.constructor(JMod.PUBLIC);
constructor5.param(URL.class, "wsdlLocation");
constructor5.param(QName.class, "serviceName");
constructor5.body().directStatement("super(wsdlLocation, serviceName);");
// Generating constructor
// for e.g: public ExampleService(URL, QName, WebServiceFeature ...)
if (options.target.isLaterThan(Options.Target.V2_2)) {
JMethod constructor6 = cls.constructor(JMod.PUBLIC);
constructor6.param(URL.class, "wsdlLocation");
constructor6.param(QName.class, "serviceName");
constructor6.varParam(WebServiceFeature.class, "features");
constructor6.body().directStatement("super(wsdlLocation, serviceName, features);");
}
//@WebService
JAnnotationUse webServiceClientAnn = cls.annotate(cm.ref(WebServiceClient.class));
writeWebServiceClientAnnotation(service, webServiceClientAnn);
// additional annotations
for (GeneratorExtension f:ServiceFinder.find(GeneratorExtension.class)) {
f.writeWebServiceClientAnnotation(options, cm, cls);
}
//@HandlerChain
writeHandlerConfig(Names.customJavaTypeClassName(service.getJavaInterface()), cls, options);
for (Port port : service.getPorts()) {
if (port.isProvider()) {
continue; // No getXYZPort() for porvider based endpoint
}
//Get the SEI class
JType retType;
try {
retType = getClass(port.getJavaInterface().getName(), ClassType.INTERFACE);
} catch (JClassAlreadyExistsException e) {
QName portTypeName =
(QName) port.getProperty(
ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
Locator loc = null;
if (portTypeName != null) {
PortType pt = port.portTypes.get(portTypeName);
if (pt != null) {
loc = pt.getLocator();
}
}
receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(port.getJavaInterface().getName(), portTypeName));
return;
}
//write getXyzPort()
writeDefaultGetPort(port, retType, cls);
//write getXyzPort(WebServicesFeature...)
if (options.target.isLaterThan(Options.Target.V2_1)) {
writeGetPort(port, retType, cls);
}
}
writeGetWsdlLocation(cm.ref(URL.class), cls, urlField, exField);
}
private void writeGetPort(Port port, JType retType, JDefinedClass cls) {
JMethod m = cls.method(JMod.PUBLIC, retType, port.getPortGetter());
JDocComment methodDoc = m.javadoc();
if (port.getJavaDoc() != null) {
methodDoc.add(port.getJavaDoc());
}
JCommentPart ret = methodDoc.addReturn();
JCommentPart paramDoc = methodDoc.addParam("features");
paramDoc.append("A list of ");
paramDoc.append("{@link " + WebServiceFeature.class.getName() + "}");
paramDoc.append("to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.");
ret.add("returns " + retType.name());
m.varParam(WebServiceFeature.class, "features");
JBlock body = m.body();
StringBuilder statement = new StringBuilder("return ");
statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), ");
statement.append(retType.name());
statement.append(".class, features);");
body.directStatement(statement.toString());
writeWebEndpoint(port, m);
}
/*
Generates the code to create URL for absolute WSDL location
for e.g.:
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://ExampleService.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
EXAMPLESERVICE_WSDL_LOCATION = url;
EXAMPLESERVICE_EXCEPTION = e;
}
*/
private void writeAbsWSDLLocation(JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JTryBlock tryBlock = staticBlock._try();
tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(wsdlLocation));
JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
catchBlock.param("ex");
catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(JExpr.ref("ex")));
staticBlock.assign(urlField, urlVar);
staticBlock.assign(exField, exVar);
}
/*
Generates the code to create URL for WSDL location as resource
for e.g.:
static {
EXAMPLESERVICE_WSDL_LOCATION = ExampleService.class.getResource(...);
Exception e = null;
if (EXAMPLESERVICE_WSDL_LOCATION == null) {
e = new WebServiceException("...");
}
EXAMPLESERVICE_EXCEPTION = e;
}
*/
private void writeResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(wsdlLocation));
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
"Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
staticBlock.assign(exField, exVar);
}
/*
Generates the code to create URL for WSDL location as classloader resource
for e.g.:
static {
EXAMPLESERVICE_WSDL_LOCATION = ExampleService.class.getClassLoader().getResource(...);
Exception e = null;
if (EXAMPLESERVICE_WSDL_LOCATION == null) {
e = new WebServiceException("...");
}
EXAMPLESERVICE_EXCEPTION = e;
}
*/
private void writeClassLoaderResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
staticBlock.assign(urlField, JExpr.dotclass(cm.ref(className)).invoke("getClassLoader").invoke("getResource").arg(wsdlLocation));
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JConditional ifBlock = staticBlock._if(urlField.eq(JExpr._null()));
ifBlock._then().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(
"Cannot find "+JExpr.quotify('\'', wsdlLocation)+" wsdl. Place the resource correctly in the classpath."));
staticBlock.assign(exField, exVar);
}
/*
Generates the code to create URL for WSDL location from classloader base resource
for e.g.:
static {
Exception e = null;
URL url = null;
try {
url = new URL(ExampleService.class.getClassLoader().getResource("."), ...);
} catch (MalformedURLException murl) {
e = new WebServiceException(murl);
}
EXAMPLESERVICE_WSDL_LOCATION = url;
EXAMPLESERVICE_EXCEPTION = e;
}
*/
private void writeClassLoaderBaseResourceWSDLLocation(String className, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JBlock staticBlock = cls.init();
JVar exVar = staticBlock.decl(cm.ref(WebServiceException.class), "e", JExpr._null());
JVar urlVar = staticBlock.decl(cm.ref(URL.class), "url", JExpr._null());
JTryBlock tryBlock = staticBlock._try();
tryBlock.body().assign(urlVar, JExpr._new(cm.ref(URL.class)).arg(JExpr.dotclass(cm.ref(className)).invoke("getResource").arg(".")).arg(wsdlLocation));
JCatchBlock catchBlock = tryBlock._catch(cm.ref(MalformedURLException.class));
JVar murlVar = catchBlock.param("murl");
catchBlock.body().assign(exVar, JExpr._new(cm.ref(WebServiceException.class)).arg(murlVar));
staticBlock.assign(urlField, urlVar);
staticBlock.assign(exField, exVar);
}
/*
Generates code that gives wsdl URL. If there is an exception in
creating the URL, it throws an exception.
for example:
private URL __getWsdlLocation() {
if (EXAMPLESERVICE_EXCEPTION != null) {
throw EXAMPLESERVICE_EXCEPTION;
}
return EXAMPLESERVICE_WSDL_LOCATION;
}
*/
private void writeGetWsdlLocation(JType retType, JDefinedClass cls, JFieldVar urlField, JFieldVar exField) {
JMethod m = cls.method(JMod.PRIVATE|JMod.STATIC , retType, "__getWsdlLocation");
JConditional ifBlock = m.body()._if(exField.ne(JExpr._null()));
ifBlock._then()._throw(exField);
m.body()._return(urlField);
}
private void writeDefaultGetPort(Port port, JType retType, JDefinedClass cls) {
String portGetter = port.getPortGetter();
JMethod m = cls.method(JMod.PUBLIC, retType, portGetter);
JDocComment methodDoc = m.javadoc();
if (port.getJavaDoc() != null) {
methodDoc.add(port.getJavaDoc());
}
JCommentPart ret = methodDoc.addReturn();
ret.add("returns " + retType.name());
JBlock body = m.body();
StringBuilder statement = new StringBuilder("return ");
statement.append("super.getPort(new QName(\"").append(port.getName().getNamespaceURI()).append("\", \"").append(port.getName().getLocalPart()).append("\"), ");
statement.append(retType.name());
statement.append(".class);");
body.directStatement(statement.toString());
writeWebEndpoint(port, m);
}
private void writeWebServiceClientAnnotation(Service service, JAnnotationUse wsa) {
String serviceName = service.getName().getLocalPart();
String serviceNS = service.getName().getNamespaceURI();
wsa.param("name", serviceName);
wsa.param("targetNamespace", serviceNS);
wsa.param("wsdlLocation", wsdlLocation);
}
private void writeWebEndpoint(Port port, JMethod m) {
JAnnotationUse webEndpointAnn = m.annotate(cm.ref(WebEndpoint.class));
webEndpointAnn.param("name", port.getName().getLocalPart());
}
}

View File

@@ -0,0 +1,97 @@
/*
* 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.ws.processor.generator;
import com.sun.codemodel.internal.JAnnotationArrayMember;
import com.sun.codemodel.internal.JAnnotationUse;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JMethod;
import com.sun.tools.internal.ws.api.TJavaGeneratorExtension;
import com.sun.tools.internal.ws.api.wsdl.TWSDLOperation;
import com.sun.tools.internal.ws.wsdl.document.Fault;
import com.sun.tools.internal.ws.wsdl.document.Operation;
import javax.xml.ws.Action;
import javax.xml.ws.FaultAction;
import java.util.Map;
/**
* This Java Generator extension generates @Action annotation on web methods if an explicit wsam:Action value is specified
* in the wsdl definitions.
*
* @author Arun Gupta
*/
public class W3CAddressingJavaGeneratorExtension extends TJavaGeneratorExtension {
@Override
public void writeMethodAnnotations(TWSDLOperation two, JMethod jMethod) {
JAnnotationUse actionAnn = null;
if (!(two instanceof Operation))
return;
Operation o = ((Operation)two);
// explicit input action
if (o.getInput().getAction() != null && !o.getInput().getAction().equals("")) {
// explicitly specified
actionAnn = jMethod.annotate(Action.class);
actionAnn.param("input", o.getInput().getAction());
}
// explicit output action
if (o.getOutput() != null && o.getOutput().getAction() != null && !o.getOutput().getAction().equals("")) {
// explicitly specified
if (actionAnn == null)
actionAnn = jMethod.annotate(Action.class);
actionAnn.param("output", o.getOutput().getAction());
}
// explicit fault action
if (o.getFaults() != null && o.getFaults().size() > 0) {
Map<String, JClass> map = o.getFaults();
JAnnotationArrayMember jam = null;
for (Fault f : o.faults()) {
if (f.getAction() == null)
continue;
if (f.getAction().equals(""))
continue;
if (actionAnn == null) {
actionAnn = jMethod.annotate(Action.class);
}
if (jam == null) {
jam = actionAnn.paramArray("fault");
}
final JAnnotationUse faAnn = jam.annotate(FaultAction.class);
faAnn.param("className", map.get(f.getName()));
faAnn.param("value", f.getAction());
}
}
}
}

View 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.ws.processor.model;
import com.sun.tools.internal.ws.processor.model.java.JavaType;
import javax.xml.namespace.QName;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
*
* @author WS Development Team
*/
public abstract class AbstractType {
protected AbstractType() {}
protected AbstractType(QName name) {
this(name, null, null);
}
protected AbstractType(QName name, String version) {
this(name, null, version);
}
protected AbstractType(QName name, JavaType javaType) {
this(name, javaType, null);
}
protected AbstractType(QName name, JavaType javaType, String version) {
this.name = name;
this.javaType = javaType;
this.version = version;
}
public QName getName() {
return name;
}
public void setName(QName name) {
this.name = name;
}
public JavaType getJavaType() {
return javaType;
}
public void setJavaType(JavaType javaType) {
this.javaType = javaType;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public boolean isNillable() {
return false;
}
public boolean isSOAPType() {
return false;
}
public boolean isLiteralType() {
return false;
}
public Object getProperty(String key) {
if (properties == null) {
return null;
}
return properties.get(key);
}
public void setProperty(String key, Object value) {
if (value == null) {
removeProperty(key);
return;
}
if (properties == null) {
properties = new HashMap();
}
properties.put(key, value);
}
public void removeProperty(String key) {
if (properties != null) {
properties.remove(key);
}
}
public Iterator getProperties() {
if (properties == null) {
return Collections.emptyList().iterator();
} else {
return properties.keySet().iterator();
}
}
/* serialization */
public Map getPropertiesMap() {
return properties;
}
/* serialization */
public void setPropertiesMap(Map m) {
properties = m;
}
private QName name;
private JavaType javaType;
private String version = null;
private Map properties;
}

View File

@@ -0,0 +1,133 @@
/*
* 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.ws.processor.model;
import com.sun.codemodel.internal.JClass;
import com.sun.codemodel.internal.JCodeModel;
import com.sun.tools.internal.ws.processor.model.java.JavaSimpleType;
import com.sun.tools.internal.ws.processor.model.java.JavaType;
import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import javax.xml.namespace.QName;
/**
* @author Vivek Pandey
*
*
*/
public class AsyncOperation extends Operation {
/**
*
*/
public AsyncOperation(Entity entity) {
super(entity);
// TODO Auto-generated constructor stub
}
/**
* @param operation
*/
public AsyncOperation(Operation operation, Entity entity) {
super(operation, entity);
this.operation = operation;
}
/**
* @param name
*/
public AsyncOperation(QName name, Entity entity) {
super(name, entity);
// TODO Auto-generated constructor stub
}
/**
* @return Returns the async.
*/
public boolean isAsync() {
return _async;
}
public void setAsyncType(AsyncOperationType type) {
this._asyncOpType = type;
_async = true;
}
public AsyncOperationType getAsyncType(){
return _asyncOpType;
}
public void setResponseBean(AbstractType type){
_responseBean = type;
}
public AbstractType getResponseBeanType(){
return _responseBean;
}
public JavaType getResponseBeanJavaType(){
JCodeModel cm = _responseBean.getJavaType().getType().getType().owner();
if(_asyncOpType.equals(AsyncOperationType.CALLBACK)){
JClass future = cm.ref(java.util.concurrent.Future.class).narrow(cm.ref(Object.class).wildcard());
return new JavaSimpleType(new JAXBTypeAndAnnotation(future));
}else if(_asyncOpType.equals(AsyncOperationType.POLLING)){
JClass polling = cm.ref(javax.xml.ws.Response.class).narrow(_responseBean.getJavaType().getType().getType().boxify());
return new JavaSimpleType(new JAXBTypeAndAnnotation(polling));
}
return null;
}
public JavaType getCallBackType(){
if(_asyncOpType.equals(AsyncOperationType.CALLBACK)){
JCodeModel cm = _responseBean.getJavaType().getType().getType().owner();
JClass cb = cm.ref(javax.xml.ws.AsyncHandler.class).narrow(_responseBean.getJavaType().getType().getType().boxify());
return new JavaSimpleType(new JAXBTypeAndAnnotation(cb));
}
return null;
}
public Operation getNormalOperation(){
return operation;
}
public void setNormalOperation(Operation operation){
this.operation = operation;
}
@Override public String getJavaMethodName() {
return super.getJavaMethodName() + "Async";
}
//Normal operation
private Operation operation;
private boolean _async;
private AsyncOperationType _asyncOpType;
private AbstractType _responseBean;
}

View File

@@ -0,0 +1,43 @@
/*
* 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.ws.processor.model;
/**
* @author Vivek Pandey
*
* Async WSDLOperation type
*/
public final class AsyncOperationType {
public static final AsyncOperationType POLLING = new AsyncOperationType();
public static final AsyncOperationType CALLBACK = new AsyncOperationType();
private AsyncOperationType() {
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import com.sun.tools.internal.ws.wsdl.document.*;
import javax.xml.namespace.QName;
/**
*
* @author WS Development Team
*/
public class Block extends ModelObject {
public static final int UNBOUND = 0;
public static final int BODY = 1;
public static final int HEADER = 2;
public static final int ATTACHMENT = 3;
public Block(QName name, AbstractType type, Entity entity) {
super(entity);
this.name = name;
this.type = type;
}
public QName getName() {
return name;
}
public AbstractType getType() {
return type;
}
public void setType(AbstractType type) {
this.type = type;
}
public int getLocation() {
return location;
}
public void setLocation(int i) {
location = i;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
private final QName name;
private AbstractType type;
private int location;
}

View File

@@ -0,0 +1,138 @@
/*
* 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.ws.processor.model;
import java.util.Iterator;
/**
*
* A model visitor incorporating all the logic required to walk through the model.
*
* @author WS Development Team
*/
public class ExtendedModelVisitor {
public ExtendedModelVisitor() {}
public void visit(Model model) throws Exception {
preVisit(model);
for (Service service : model.getServices()) {
preVisit(service);
for (Port port : service.getPorts()) {
preVisit(port);
if (shouldVisit(port)) {
for (Operation operation : port.getOperations()) {
preVisit(operation);
Request request = operation.getRequest();
if (request != null) {
preVisit(request);
for (Iterator iter4 = request.getHeaderBlocks();
iter4.hasNext();) {
Block block = (Block) iter4.next();
visitHeaderBlock(block);
}
for (Iterator iter4 = request.getBodyBlocks();
iter4.hasNext();) {
Block block = (Block) iter4.next();
visitBodyBlock(block);
}
for (Iterator iter4 = request.getParameters();
iter4.hasNext();) {
Parameter parameter = (Parameter) iter4.next();
visit(parameter);
}
postVisit(request);
}
Response response = operation.getResponse();
if (response != null) {
preVisit(response);
for (Iterator iter4 = response.getHeaderBlocks();
iter4.hasNext();) {
Block block = (Block) iter4.next();
visitHeaderBlock(block);
}
for (Iterator iter4 = response.getBodyBlocks();
iter4.hasNext();) {
Block block = (Block) iter4.next();
visitBodyBlock(block);
}
for (Iterator iter4 = response.getParameters();
iter4.hasNext();) {
Parameter parameter = (Parameter) iter4.next();
visit(parameter);
}
postVisit(response);
}
for (Iterator iter4 = operation.getFaults();
iter4.hasNext();) {
Fault fault = (Fault) iter4.next();
preVisit(fault);
visitFaultBlock(fault.getBlock());
postVisit(fault);
}
postVisit(operation);
}
}
postVisit(port);
}
postVisit(service);
}
postVisit(model);
}
protected boolean shouldVisit(Port port) {
return true;
}
// these methods are intended for subclasses
protected void preVisit(Model model) throws Exception {}
protected void postVisit(Model model) throws Exception {}
protected void preVisit(Service service) throws Exception {}
protected void postVisit(Service service) throws Exception {}
protected void preVisit(Port port) throws Exception {}
protected void postVisit(Port port) throws Exception {}
protected void preVisit(Operation operation) throws Exception {}
protected void postVisit(Operation operation) throws Exception {}
protected void preVisit(Request request) throws Exception {}
protected void postVisit(Request request) throws Exception {}
protected void preVisit(Response response) throws Exception {}
protected void postVisit(Response response) throws Exception {}
protected void preVisit(Fault fault) throws Exception {}
protected void postVisit(Fault fault) throws Exception {}
protected void visitBodyBlock(Block block) throws Exception {}
protected void visitHeaderBlock(Block block) throws Exception {}
protected void visitFaultBlock(Block block) throws Exception {}
protected void visit(Parameter parameter) throws Exception {}
}

View File

@@ -0,0 +1,170 @@
/*
* 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.ws.processor.model;
import com.sun.codemodel.internal.JClass;
import com.sun.tools.internal.ws.processor.model.java.JavaException;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import javax.xml.namespace.QName;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
*
* @author WS Development Team
*/
public class Fault extends ModelObject {
public Fault(Entity entity) {
super(entity);
}
public Fault(String name, Entity entity) {
super(entity);
this.name = name;
}
public String getName() {
return name;
}
public void setName(String s) {
name = s;
}
public Block getBlock() {
return block;
}
public void setBlock(Block b) {
block = b;
}
public JavaException getJavaException() {
return javaException;
}
public void setJavaException(JavaException e) {
javaException = e;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
public Iterator getSubfaults() {
if (subfaults.isEmpty()) {
return null;
}
return subfaults.iterator();
}
/* serialization */
public Set getSubfaultsSet() {
return subfaults;
}
/* serialization */
public void setSubfaultsSet(Set s) {
subfaults = s;
}
public Iterator getAllFaults() {
Set allFaults = getAllFaultsSet();
if (allFaults.isEmpty()) {
return null;
}
return allFaults.iterator();
}
public Set getAllFaultsSet() {
Set transSet = new HashSet();
Iterator iter = subfaults.iterator();
while (iter.hasNext()) {
transSet.addAll(((Fault)iter.next()).getAllFaultsSet());
}
transSet.addAll(subfaults);
return transSet;
}
public QName getElementName() {
return elementName;
}
public void setElementName(QName elementName) {
this.elementName = elementName;
}
public String getJavaMemberName() {
return javaMemberName;
}
public void setJavaMemberName(String javaMemberName) {
this.javaMemberName = javaMemberName;
}
/**
* @return Returns the wsdlFault.
*/
public boolean isWsdlException() {
return wsdlException;
}
/**
* @param wsdlFault The wsdlFault to set.
*/
public void setWsdlException(boolean wsdlFault) {
this.wsdlException = wsdlFault;
}
public void setExceptionClass(JClass ex){
exceptionClass = ex;
}
public JClass getExceptionClass(){
return exceptionClass;
}
private boolean wsdlException = true;
private String name;
private Block block;
private JavaException javaException;
private Set subfaults = new HashSet();
private QName elementName = null;
private String javaMemberName = null;
private JClass exceptionClass;
public String getWsdlFaultName() {
return wsdlFaultName;
}
public void setWsdlFaultName(String wsdlFaultName) {
this.wsdlFaultName = wsdlFaultName;
}
private String wsdlFaultName;
}

View File

@@ -0,0 +1,60 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import javax.xml.namespace.QName;
public class HeaderFault extends Fault {
public HeaderFault(Entity entity) {
super(entity);
}
public HeaderFault(String name, Entity entity) {
super(name, entity);
}
public QName getMessage() {
return _message;
}
public void setMessage(QName message) {
_message = message;
}
public String getPart() {
return _part;
}
public void setPart(String part) {
_part = part;
}
private QName _message;
private String _part;
}

View File

@@ -0,0 +1,234 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.AbortException;
import com.sun.tools.internal.ws.resources.ModelMessages;
import javax.xml.namespace.QName;
import java.util.*;
/**
*
* @author WS Development Team
*/
public abstract class Message extends ModelObject {
protected Message(com.sun.tools.internal.ws.wsdl.document.Message entity, ErrorReceiver receiver) {
super(entity);
setErrorReceiver(receiver);
}
public void addBodyBlock(Block b) {
if (_bodyBlocks.containsKey(b.getName())) {
errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PART_NOT_UNIQUE(((com.sun.tools.internal.ws.wsdl.document.Message)getEntity()).getName(), b.getName()));
throw new AbortException();
}
_bodyBlocks.put(b.getName(), b);
b.setLocation(Block.BODY);
}
public Iterator<Block> getBodyBlocks() {
return _bodyBlocks.values().iterator();
}
public int getBodyBlockCount() {
return _bodyBlocks.size();
}
/* serialization */
public Map<QName, Block> getBodyBlocksMap() {
return _bodyBlocks;
}
/* serialization */
public void setBodyBlocksMap(Map<QName, Block> m) {
_bodyBlocks = m;
}
public boolean isBodyEmpty() {
return getBodyBlocks().hasNext();
}
public boolean isBodyEncoded() {
boolean isEncoded = false;
for (Iterator iter = getBodyBlocks(); iter.hasNext();) {
Block bodyBlock = (Block) iter.next();
if (bodyBlock.getType().isSOAPType()) {
isEncoded = true;
}
}
return isEncoded;
}
public void addHeaderBlock(Block b) {
if (_headerBlocks.containsKey(b.getName())) {
errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PART_NOT_UNIQUE(((com.sun.tools.internal.ws.wsdl.document.Message)getEntity()).getName(), b.getName()));
throw new AbortException();
}
_headerBlocks.put(b.getName(), b);
b.setLocation(Block.HEADER);
}
public Iterator<Block> getHeaderBlocks() {
return _headerBlocks.values().iterator();
}
public Collection<Block> getHeaderBlockCollection() {
return _headerBlocks.values();
}
public int getHeaderBlockCount() {
return _headerBlocks.size();
}
/* serialization */
public Map<QName, Block> getHeaderBlocksMap() {
return _headerBlocks;
}
/* serialization */
public void setHeaderBlocksMap(Map<QName, Block> m) {
_headerBlocks = m;
}
/** attachment block */
public void addAttachmentBlock(Block b) {
if (_attachmentBlocks.containsKey(b.getName())) {
errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PART_NOT_UNIQUE(((com.sun.tools.internal.ws.wsdl.document.Message)getEntity()).getName(), b.getName()));
throw new AbortException();
}
_attachmentBlocks.put(b.getName(), b);
b.setLocation(Block.ATTACHMENT);
}
public void addUnboundBlock(Block b) {
if (_unboundBlocks.containsKey(b.getName())) {
return;
}
_unboundBlocks.put(b.getName(), b);
b.setLocation(Block.UNBOUND);
}
public Iterator<Block> getUnboundBlocks() {
return _unboundBlocks.values().iterator();
}
/* serialization */
public Map<QName, Block> getUnboundBlocksMap() {
return _unboundBlocks;
}
public int getUnboundBlocksCount() {
return _unboundBlocks.size();
}
/* serialization */
public void setUnboundBlocksMap(Map<QName, Block> m) {
_unboundBlocks = m;
}
public Iterator<Block> getAttachmentBlocks() {
return _attachmentBlocks.values().iterator();
}
public int getAttachmentBlockCount () {
return _attachmentBlocks.size();
}
/* serialization */
public Map<QName, Block> getAttachmentBlocksMap() {
return _attachmentBlocks;
}
/* serialization */
public void setAttachmentBlocksMap(Map<QName, Block> m) {
_attachmentBlocks = m;
}
public void addParameter(Parameter p) {
if (_parametersByName.containsKey(p.getName())) {
errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE(p.getName(), p.getName()));
throw new AbortException();
}
_parameters.add(p);
String name = p.getCustomName() != null ? p.getCustomName() : p.getName();
_parametersByName.put(name, p);
}
public Parameter getParameterByName(String name) {
if (_parametersByName.size() != _parameters.size()) {
initializeParametersByName();
}
return _parametersByName.get(name);
}
public Iterator<Parameter> getParameters() {
return _parameters.iterator();
}
/* serialization */
public List<Parameter> getParametersList() {
return _parameters;
}
/* serialization */
public void setParametersList(List<Parameter> l) {
_parameters = l;
}
private void initializeParametersByName() {
_parametersByName = new HashMap();
if (_parameters != null) {
for (Iterator iter = _parameters.iterator(); iter.hasNext();) {
Parameter param = (Parameter) iter.next();
if (param.getName() != null &&
_parametersByName.containsKey(param.getName())) {
errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE(param.getName(), param.getName()));
throw new AbortException();
}
_parametersByName.put(param.getName(), param);
}
}
}
public Set<Block> getAllBlocks(){
Set<Block> blocks = new HashSet<Block>();
blocks.addAll(_bodyBlocks.values());
blocks.addAll(_headerBlocks.values());
blocks.addAll(_attachmentBlocks.values());
return blocks;
}
private Map<QName, Block> _attachmentBlocks = new HashMap<QName, Block>();
private Map<QName, Block> _bodyBlocks = new HashMap<QName, Block>();
private Map<QName, Block> _headerBlocks = new HashMap<QName, Block>();
private Map<QName, Block> _unboundBlocks = new HashMap<QName, Block>();
private List<Parameter> _parameters = new ArrayList<Parameter>();
private Map<String, Parameter> _parametersByName = new HashMap<String, Parameter>();
}

View File

@@ -0,0 +1,158 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.processor.model.jaxb.JAXBModel;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import javax.xml.namespace.QName;
import java.util.*;
/**
* The model is used to represent the entire Web Service. The JAX-WS ProcessorActions can process
* this Model to generate Java artifacts such as the service interface.
*
* @author WS Development Team
*/
public class Model extends ModelObject {
public Model(Entity entity) {
super(entity);
}
public Model(QName name, Entity entity) {
super(entity);
this.name = name;
}
public QName getName() {
return name;
}
public void setName(QName n) {
name = n;
}
public String getTargetNamespaceURI() {
return targetNamespace;
}
public void setTargetNamespaceURI(String s) {
targetNamespace = s;
}
public void addService(Service service) {
if (servicesByName.containsKey(service.getName())) {
throw new ModelException("model.uniqueness");
}
services.add(service);
servicesByName.put(service.getName(), service);
}
public Service getServiceByName(QName name) {
if (servicesByName.size() != services.size()) {
initializeServicesByName();
}
return (Service)servicesByName.get(name);
}
/* serialization */
public List<Service> getServices() {
return services;
}
/* serialization */
public void setServices(List<Service> l) {
services = l;
}
private void initializeServicesByName() {
servicesByName = new HashMap();
if (services != null) {
for (Service service : services) {
if (service.getName() != null &&
servicesByName.containsKey(service.getName())) {
throw new ModelException("model.uniqueness");
}
servicesByName.put(service.getName(), service);
}
}
}
public void addExtraType(AbstractType type) {
extraTypes.add(type);
}
public Iterator getExtraTypes() {
return extraTypes.iterator();
}
/* serialization */
public Set<AbstractType> getExtraTypesSet() {
return extraTypes;
}
/* serialization */
public void setExtraTypesSet(Set<AbstractType> s) {
extraTypes = s;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
/**
* @return the source version
*/
public String getSource() {
return source;
}
/**
* @param string
*/
public void setSource(String string) {
source = string;
}
public void setJAXBModel(JAXBModel jaxBModel) {
this.jaxBModel = jaxBModel;
}
public JAXBModel getJAXBModel() {
return jaxBModel;
}
private QName name;
private String targetNamespace;
private List<Service> services = new ArrayList<Service>();
private Map<QName, Service> servicesByName = new HashMap<QName, Service>();
private Set<AbstractType> extraTypes = new HashSet<AbstractType>();
private String source;
private JAXBModel jaxBModel = null;
}

View File

@@ -0,0 +1,56 @@
/*
* 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.ws.processor.model;
import com.sun.istack.internal.localization.Localizable;
import com.sun.tools.internal.ws.processor.ProcessorException;
/**
* ModelException represents an exception that occurred while
* visiting service model.
*
* @see ProcessorException
*
* @author WS Development Team
*/
public class ModelException extends ProcessorException {
public ModelException(String key, Object... args) {
super(key, args);
}
public ModelException(Throwable throwable) {
super(throwable);
}
public ModelException(Localizable arg) {
super("model.nestedModelError", arg);
}
public String getDefaultResourceBundleName() {
return "com.sun.tools.internal.ws.resources.model";
}
}

View File

@@ -0,0 +1,115 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.xml.sax.Locator;
/**
*
* @author WS Development Team
*/
public abstract class ModelObject {
public abstract void accept(ModelVisitor visitor) throws Exception;
private final Entity entity;
protected ErrorReceiver errorReceiver;
protected ModelObject(Entity entity) {
this.entity = entity;
}
public void setErrorReceiver(ErrorReceiver errorReceiver) {
this.errorReceiver = errorReceiver;
}
public Entity getEntity() {
return entity;
}
public Object getProperty(String key) {
if (_properties == null) {
return null;
}
return _properties.get(key);
}
public void setProperty(String key, Object value) {
if (value == null) {
removeProperty(key);
return;
}
if (_properties == null) {
_properties = new HashMap();
}
_properties.put(key, value);
}
public void removeProperty(String key) {
if (_properties != null) {
_properties.remove(key);
}
}
public Iterator getProperties() {
if (_properties == null) {
return Collections.emptyList().iterator();
} else {
return _properties.keySet().iterator();
}
}
public Locator getLocator(){
return entity.getLocator();
}
public Map getPropertiesMap() {
return _properties;
}
public void setPropertiesMap(Map m) {
_properties = m;
}
public String getJavaDoc() {
return javaDoc;
}
public void setJavaDoc(String javaDoc) {
this.javaDoc = javaDoc;
}
private String javaDoc;
private Map _properties;
}

View File

@@ -0,0 +1,76 @@
/*
* 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.ws.processor.model;
/**
*
* @author WS Development Team
*/
public interface ModelProperties {
//to set WSDL_MODELER_NAME from inside WSDLModeler
public static final String WSDL_MODELER_NAME =
"com.sun.xml.internal.ws.processor.modeler.wsdl.WSDLModeler";
public static final String PROPERTY_PARAM_MESSAGE_PART_NAME =
"com.sun.xml.internal.ws.processor.model.ParamMessagePartName";
public static final String PROPERTY_ANONYMOUS_TYPE_NAME =
"com.sun.xml.internal.ws.processor.model.AnonymousTypeName";
public static final String PROPERTY_ANONYMOUS_ARRAY_TYPE_NAME =
"com.sun.xml.internal.ws.processor.model.AnonymousArrayTypeName";
public static final String PROPERTY_ANONYMOUS_ARRAY_JAVA_TYPE =
"com.sun.xml.internal.ws.processor.model.AnonymousArrayJavaType";
public static final String PROPERTY_PTIE_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.PtieClassName";
public static final String PROPERTY_EPTFF_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.EPTFFClassName";
public static final String PROPERTY_SED_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.SEDClassName";
public static final String PROPERTY_WSDL_PORT_NAME =
"com.sun.xml.internal.ws.processor.model.WSDLPortName";
public static final String PROPERTY_WSDL_PORT_TYPE_NAME =
"com.sun.xml.internal.ws.processor.model.WSDLPortTypeName";
public static final String PROPERTY_WSDL_BINDING_NAME =
"com.sun.xml.internal.ws.processor.model.WSDLBindingName";
public static final String PROPERTY_WSDL_MESSAGE_NAME =
"com.sun.xml.internal.ws.processor.model.WSDLMessageName";
public static final String PROPERTY_MODELER_NAME =
"com.sun.xml.internal.ws.processor.model.ModelerName";
public static final String PROPERTY_STUB_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.StubClassName";
public static final String PROPERTY_STUB_OLD_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.StubOldClassName";
public static final String PROPERTY_DELEGATE_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.DelegateClassName";
public static final String PROPERTY_CLIENT_ENCODER_DECODER_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.ClientEncoderClassName";
public static final String PROPERTY_CLIENT_CONTACTINFOLIST_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.ClientContactInfoListClassName";
public static final String PROPERTY_TIE_CLASS_NAME =
"com.sun.xml.internal.ws.processor.model.TieClassName";
public static final String PROPERTY_JAVA_PORT_NAME =
"com.sun.xml.internal.ws.processor.model.JavaPortName";
}

View File

@@ -0,0 +1,42 @@
/*
* 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.ws.processor.model;
/**
*
* @author WS Development Team
*/
public interface ModelVisitor {
public void visit(Model model) throws Exception;
public void visit(Service service) throws Exception;
public void visit(Port port) throws Exception;
public void visit(Operation operation) throws Exception;
public void visit(Request request) throws Exception;
public void visit(Response response) throws Exception;
public void visit(Fault fault) throws Exception;
public void visit(Block block) throws Exception;
public void visit(Parameter parameter) throws Exception;
}

View File

@@ -0,0 +1,257 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.processor.model.java.JavaMethod;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPUse;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import com.sun.xml.internal.ws.spi.db.BindingHelper;
import javax.xml.namespace.QName;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
*
* @author WS Development Team
*/
public class Operation extends ModelObject {
public Operation(Entity entity) {
super(entity);
}
public Operation(Operation operation, Entity entity){
this(operation._name, entity);
this._style = operation._style;
this._use = operation._use;
this.customizedName = operation.customizedName;
}
public Operation(QName name, Entity entity) {
super(entity);
_name = name;
_uniqueName = name.getLocalPart();
_faultNames = new HashSet<String>();
_faults = new HashSet<Fault>();
}
public QName getName() {
return _name;
}
public void setName(QName n) {
_name = n;
}
public String getUniqueName() {
return _uniqueName;
}
public void setUniqueName(String s) {
_uniqueName = s;
}
public Request getRequest() {
return _request;
}
public void setRequest(Request r) {
_request = r;
}
public Response getResponse() {
return _response;
}
public void setResponse(Response r) {
_response = r;
}
public boolean isOverloaded() {
return !_name.getLocalPart().equals(_uniqueName);
}
public void addFault(Fault f) {
if (_faultNames.contains(f.getName())) {
throw new ModelException("model.uniqueness");
}
_faultNames.add(f.getName());
_faults.add(f);
}
public Iterator<Fault> getFaults() {
return _faults.iterator();
}
public Set<Fault> getFaultsSet() {
return _faults;
}
/* serialization */
public void setFaultsSet(Set<Fault> s) {
_faults = s;
initializeFaultNames();
}
private void initializeFaultNames() {
_faultNames = new HashSet<String>();
if (_faults != null) {
for (Iterator iter = _faults.iterator(); iter.hasNext();) {
Fault f = (Fault) iter.next();
if (f.getName() != null && _faultNames.contains(f.getName())) {
throw new ModelException("model.uniqueness");
}
_faultNames.add(f.getName());
}
}
}
public Iterator<Fault> getAllFaults() {
Set<Fault> allFaults = getAllFaultsSet();
return allFaults.iterator();
}
public Set<Fault> getAllFaultsSet() {
Set transSet = new HashSet();
transSet.addAll(_faults);
Iterator iter = _faults.iterator();
Fault fault;
Set tmpSet;
while (iter.hasNext()) {
tmpSet = ((Fault)iter.next()).getAllFaultsSet();
transSet.addAll(tmpSet);
}
return transSet;
}
public int getFaultCount() {
return _faults.size();
}
public Set<Block> getAllFaultBlocks(){
Set<Block> blocks = new HashSet<Block>();
Iterator faults = _faults.iterator();
while(faults.hasNext()){
Fault f = (Fault)faults.next();
blocks.add(f.getBlock());
}
return blocks;
}
public JavaMethod getJavaMethod() {
return _javaMethod;
}
public void setJavaMethod(JavaMethod i) {
_javaMethod = i;
}
public String getSOAPAction() {
return _soapAction;
}
public void setSOAPAction(String s) {
_soapAction = s;
}
public SOAPStyle getStyle() {
return _style;
}
public void setStyle(SOAPStyle s) {
_style = s;
}
public SOAPUse getUse() {
return _use;
}
public void setUse(SOAPUse u) {
_use = u;
}
public boolean isWrapped() {
return _isWrapped;
}
public void setWrapped(boolean isWrapped) {
_isWrapped = isWrapped;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
public void setCustomizedName(String name){
this.customizedName = name;
}
public String getCustomizedName(){
return customizedName;
}
public String getJavaMethodName(){
//if JavaMethod is created return the name
if(_javaMethod != null){
return _javaMethod.getName();
}
//return the customized operation name if any without mangling
if(customizedName != null){
return customizedName;
}
return BindingHelper.mangleNameToVariableName(_name.getLocalPart());
}
public com.sun.tools.internal.ws.wsdl.document.Operation getWSDLPortTypeOperation(){
return wsdlOperation;
}
public void setWSDLPortTypeOperation(com.sun.tools.internal.ws.wsdl.document.Operation wsdlOperation){
this.wsdlOperation = wsdlOperation;
}
private String customizedName;
private boolean _isWrapped = true;
private QName _name;
private String _uniqueName;
private Request _request;
private Response _response;
private JavaMethod _javaMethod;
private String _soapAction;
private SOAPStyle _style = SOAPStyle.DOCUMENT;
private SOAPUse _use = SOAPUse.LITERAL;
private Set<String> _faultNames;
private Set<Fault> _faults;
private com.sun.tools.internal.ws.wsdl.document.Operation wsdlOperation;
}

View File

@@ -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.ws.processor.model;
import com.sun.tools.internal.ws.processor.model.java.JavaParameter;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import com.sun.tools.internal.ws.wsdl.document.MessagePart;
import javax.jws.WebParam.Mode;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author WS Development Team
*/
public class Parameter extends ModelObject {
private final String entityName;
public Parameter(String name, Entity entity) {
super(entity);
this.name = name;
if(entity instanceof com.sun.tools.internal.ws.wsdl.document.Message){
this.entityName = ((com.sun.tools.internal.ws.wsdl.document.Message)entity).getName();
}else if(entity instanceof MessagePart){
this.entityName = ((MessagePart)entity).getName();
}else{
this.entityName = name;
}
}
public String getEntityName() {
return entityName;
}
public String getName() {
return name;
}
public void setName(String s) {
name = s;
}
public JavaParameter getJavaParameter() {
return javaParameter;
}
public void setJavaParameter(JavaParameter p) {
javaParameter = p;
}
public AbstractType getType() {
return type;
}
public void setType(AbstractType t) {
type = t;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String t) {
typeName = t;
}
public Block getBlock() {
return block;
}
public void setBlock(Block d) {
block = d;
}
public Parameter getLinkedParameter() {
return link;
}
public void setLinkedParameter(Parameter p) {
link = p;
}
public boolean isEmbedded() {
return embedded;
}
public void setEmbedded(boolean b) {
embedded = b;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
private String name;
private JavaParameter javaParameter;
private AbstractType type;
private Block block;
private Parameter link;
private boolean embedded;
private String typeName;
private String customName;
private Mode mode;
public int getParameterIndex() {
return parameterOrderPosition;
}
public void setParameterIndex(int parameterOrderPosition) {
this.parameterOrderPosition = parameterOrderPosition;
}
public boolean isReturn(){
return (parameterOrderPosition == -1);
}
// 0 is the first parameter, -1 is the return type
private int parameterOrderPosition;
/**
* @return Returns the customName.
*/
public String getCustomName() {
return customName;
}
/**
* @param customName The customName to set.
*/
public void setCustomName(String customName) {
this.customName = customName;
}
private List<String> annotations = new ArrayList<String>();
/**
* @return Returns the annotations.
*/
public List<String> getAnnotations() {
return annotations;
}
/**
* @param annotations The annotations to set.
*/
public void setAnnotations(List<String> annotations) {
this.annotations = annotations;
}
public void setMode(Mode mode){
this.mode = mode;
}
public boolean isIN(){
return (mode == Mode.IN);
}
public boolean isOUT(){
return (mode == Mode.OUT);
}
public boolean isINOUT(){
return (mode == Mode.INOUT);
}
}

View File

@@ -0,0 +1,179 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
import com.sun.tools.internal.ws.wsdl.document.PortType;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPStyle;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author WS Development Team
*/
public class Port extends ModelObject {
public Port(Entity entity) {
super(entity);
}
public Port(QName name, Entity entity) {
super(entity);
_name = name;
}
public QName getName() {
return _name;
}
public void setName(QName n) {
_name = n;
}
public void addOperation(Operation operation) {
_operations.add(operation);
operationsByName.put(operation.getUniqueName(), operation);
}
public Operation getOperationByUniqueName(String name) {
if (operationsByName.size() != _operations.size()) {
initializeOperationsByName();
}
return operationsByName.get(name);
}
private void initializeOperationsByName() {
operationsByName = new HashMap<String, Operation>();
if (_operations != null) {
for (Operation operation : _operations) {
if (operation.getUniqueName() != null &&
operationsByName.containsKey(operation.getUniqueName())) {
throw new ModelException("model.uniqueness");
}
operationsByName.put(operation.getUniqueName(), operation);
}
}
}
/* serialization */
public List<Operation> getOperations() {
return _operations;
}
/* serialization */
public void setOperations(List<Operation> l) {
_operations = l;
}
public JavaInterface getJavaInterface() {
return _javaInterface;
}
public void setJavaInterface(JavaInterface i) {
_javaInterface = i;
}
public String getAddress() {
return _address;
}
public void setAddress(String s) {
_address = s;
}
public String getServiceImplName() {
return _serviceImplName;
}
public void setServiceImplName(String name) {
_serviceImplName = name;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
public boolean isProvider() {
JavaInterface intf = getJavaInterface();
if (intf != null) {
String sei = intf.getName();
if (sei.equals(javax.xml.ws.Provider.class.getName())) {
return true;
}
}
return false;
}
/**
* XYZ_Service.getABC() method name
*
* @return Returns the portGetterName.
*/
public String getPortGetter() {
return portGetter;
}
/**
* @param portGetterName The portGetterName to set.
*/
public void setPortGetter(String portGetterName) {
this.portGetter = portGetterName;
}
public SOAPStyle getStyle() {
return _style;
}
public void setStyle(SOAPStyle s) {
_style = s;
}
public boolean isWrapped() {
return _isWrapped;
}
public void setWrapped(boolean isWrapped) {
_isWrapped = isWrapped;
}
private SOAPStyle _style = null;
private boolean _isWrapped = true;
private String portGetter;
private QName _name;
private List<Operation> _operations = new ArrayList<Operation>();
private JavaInterface _javaInterface;
private String _address;
private String _serviceImplName;
private Map<String, Operation> operationsByName = new HashMap<String, Operation>();
public Map<QName, PortType> portTypes = new HashMap<QName, PortType>();
}

View File

@@ -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.ws.processor.model;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
/**
*
* @author WS Development Team
*/
public class Request extends Message {
public Request(com.sun.tools.internal.ws.wsdl.document.Message entity, ErrorReceiver receiver) {
super(entity, receiver);
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
}

View File

@@ -0,0 +1,74 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
*
* @author WS Development Team
*/
public class Response extends Message {
public Response(com.sun.tools.internal.ws.wsdl.document.Message entity, ErrorReceiver receiver) {
super(entity, receiver);
}
public void addFaultBlock(Block b) {
if (_faultBlocks.containsKey(b.getName())) {
throw new ModelException("model.uniqueness");
}
_faultBlocks.put(b.getName(), b);
}
public Iterator getFaultBlocks() {
return _faultBlocks.values().iterator();
}
public int getFaultBlockCount () {
return _faultBlocks.size();
}
/* serialization */
public Map getFaultBlocksMap() {
return _faultBlocks;
}
public void setFaultBlocksMap(Map m) {
_faultBlocks = m;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
private Map _faultBlocks = new HashMap();
}

View File

@@ -0,0 +1,120 @@
/*
* 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.ws.processor.model;
import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
import com.sun.tools.internal.ws.wsdl.framework.Entity;
import javax.xml.namespace.QName;
import java.util.*;
/**
*
* @author WS Development Team
*/
public class Service extends ModelObject {
public Service(Entity entity) {
super(entity);
}
public Service(QName name, JavaInterface javaInterface, Entity entity) {
super(entity);
this.name = name;
this.javaInterface = javaInterface;
}
public QName getName() {
return name;
}
public void setName(QName n) {
name = n;
}
public void addPort(Port port) {
if (portsByName.containsKey(port.getName())) {
throw new ModelException("model.uniqueness");
}
ports.add(port);
portsByName.put(port.getName(), port);
}
public Port getPortByName(QName n) {
if (portsByName.size() != ports.size()) {
initializePortsByName();
}
return (Port) portsByName.get(n);
}
/* serialization */
public List<Port> getPorts() {
return ports;
}
/* serialization */
public void setPorts(List<Port> m) {
ports = m;
// initializePortsByName();
}
private void initializePortsByName() {
portsByName = new HashMap();
if (ports != null) {
for (Iterator iter = ports.iterator(); iter.hasNext();) {
Port port = (Port) iter.next();
if (port.getName() != null &&
portsByName.containsKey(port.getName())) {
throw new ModelException("model.uniqueness");
}
portsByName.put(port.getName(), port);
}
}
}
public JavaInterface getJavaIntf() {
return getJavaInterface();
}
public JavaInterface getJavaInterface() {
return javaInterface;
}
public void setJavaInterface(JavaInterface i) {
javaInterface = i;
}
public void accept(ModelVisitor visitor) throws Exception {
visitor.visit(this);
}
private QName name;
private List<Port> ports = new ArrayList();
private Map<QName, Port> portsByName = new HashMap<QName, Port>();
private JavaInterface javaInterface;
}

View File

@@ -0,0 +1,48 @@
/*
* 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.ws.processor.model.exporter;
import org.xml.sax.ContentHandler;
/**
* "Opaque" object in the object graph that knows how
* to persist itself to XML.
*
* TODO: ExternalObjectReader
*
*/
public interface ExternalObject {
/**
* Type name of this object. This will be used
* when loading the object back from XML.
*/
String getType();
/**
* Saves the object into XML.
*/
void saveTo(ContentHandler receiver);
}

View File

@@ -0,0 +1,77 @@
/*
* 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.ws.processor.model.java;
/**
*
* @author WS Development Team
*/
public class JavaArrayType extends JavaType {
public JavaArrayType() {
}
public JavaArrayType(String name) {
super(name, true, "null");
}
public JavaArrayType(String name, String elementName,
JavaType elementType) {
super(name, true, "null");
this.elementName = elementName;
this.elementType = elementType;
}
public String getElementName() {
return elementName;
}
public void setElementName(String name) {
elementName = name;
}
public JavaType getElementType() {
return elementType;
}
public void setElementType(JavaType type) {
elementType = type;
}
// bug fix:4904604
public String getSOAPArrayHolderName() {
return soapArrayHolderName;
}
public void setSOAPArrayHolderName(String holderName) {
this.soapArrayHolderName = holderName;
}
private String elementName;
private JavaType elementType;
private String soapArrayHolderName;
}

View File

@@ -0,0 +1,39 @@
/*
* 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.ws.processor.model.java;
/**
*
* @author WS Development Team
*/
public class JavaException extends JavaStructureType {
public JavaException() {}
public JavaException(String name, boolean present, Object owner) {
super(name, present, owner);
}
}

View File

@@ -0,0 +1,166 @@
/*
* 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.ws.processor.model.java;
import com.sun.tools.internal.ws.processor.model.ModelException;
import com.sun.tools.internal.ws.util.ClassNameInfo;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @author WS Development Team
*/
public class JavaInterface {
public JavaInterface() {}
public JavaInterface(String name) {
this(name, null);
}
public JavaInterface(String name, String impl) {
this.realName = name;
this.name = name.replace('$', '.');
this.impl = impl;
}
public String getName() {
return name;
}
public String getFormalName() {
return name;
}
public void setFormalName(String s) {
name = s;
}
public String getRealName() {
return realName;
}
public void setRealName(String s) {
realName = s;
}
public String getImpl() {
return impl;
}
public void setImpl(String s) {
impl = s;
}
public Iterator getMethods() {
return methods.iterator();
}
public boolean hasMethod(JavaMethod method) {
for (int i=0; i<methods.size();i++) {
if (method.equals(((JavaMethod)methods.get(i)))) {
return true;
}
}
return false;
}
public void addMethod(JavaMethod method) {
if (hasMethod(method)) {
throw new ModelException("model.uniqueness");
}
methods.add(method);
}
/* serialization */
public List getMethodsList() {
return methods;
}
/* serialization */
public void setMethodsList(List l) {
methods = l;
}
public boolean hasInterface(String interfaceName) {
for (int i=0; i<interfaces.size();i++) {
if (interfaceName.equals((String)interfaces.get(i))) {
return true;
}
}
return false;
}
public void addInterface(String interfaceName) {
// verify that an exception with this name does not already exist
if (hasInterface(interfaceName)) {
return;
}
interfaces.add(interfaceName);
}
public Iterator getInterfaces() {
return interfaces.iterator();
}
/* serialization */
public List getInterfacesList() {
return interfaces;
}
/* serialization */
public void setInterfacesList(List l) {
interfaces = l;
}
public String getSimpleName() {
return ClassNameInfo.getName(name);
}
/* NOTE - all these fields (except "interfaces") were final, but had to
* remove this modifier to enable serialization
*/
private String javadoc;
public String getJavaDoc() {
return javadoc;
}
public void setJavaDoc(String javadoc) {
this.javadoc = javadoc;
}
private String name;
private String realName;
private String impl;
private List methods = new ArrayList();
private List interfaces = new ArrayList();
}

View File

@@ -0,0 +1,129 @@
/*
* 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.ws.processor.model.java;
import com.sun.tools.internal.ws.resources.ModelMessages;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.processor.model.Parameter;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
/**
* @author WS Development Team
*/
public class JavaMethod {
private final ErrorReceiver errorReceiver;
private final String name;
private final List<JavaParameter> parameters = new ArrayList<JavaParameter>();
private final List<String> exceptions = new ArrayList<String>();
private final WsimportOptions options;
private JavaType returnType;
public JavaMethod(String name, WsimportOptions options, ErrorReceiver receiver) {
this.name = name;
this.returnType = null;
this.errorReceiver = receiver;
this.options = options;
}
public String getName() {
return name;
}
public JavaType getReturnType() {
return returnType;
}
public void setReturnType(JavaType returnType) {
this.returnType = returnType;
}
private boolean hasParameter(String paramName) {
for (JavaParameter parameter : parameters) {
if (paramName.equals(parameter.getName())) {
return true;
}
}
return false;
}
private Parameter getParameter(String paramName){
for (JavaParameter parameter : parameters) {
if (paramName.equals(parameter.getName())) {
return parameter.getParameter();
}
}
return null;
}
public void addParameter(JavaParameter param) {
// verify that this member does not already exist
if (hasParameter(param.getName())) {
if (options.isExtensionMode()) {
param.setName(getUniqueName(param.getName()));
} else {
Parameter duplicParam = getParameter(param.getName());
if(param.getParameter().isEmbedded()){
errorReceiver.error(param.getParameter().getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE_WRAPPER(param.getName(), param.getParameter().getEntityName()));
errorReceiver.error(duplicParam.getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE_WRAPPER(param.getName(), duplicParam.getEntityName()));
} else {
errorReceiver.error(param.getParameter().getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE(param.getName(), param.getParameter().getEntityName()));
errorReceiver.error(duplicParam.getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE(param.getName(), duplicParam.getEntityName()));
}
return;
}
}
parameters.add(param);
}
public List<JavaParameter> getParametersList() {
return parameters;
}
public void addException(String exception) {
// verify that this exception does not already exist
if (!exceptions.contains(exception)) {
exceptions.add(exception);
}
}
/** TODO: NB uses it, remove it once we expose it thru some API **/
public Iterator<String> getExceptions() {
return exceptions.iterator();
}
private String getUniqueName(String param){
int parmNum = 0;
while (hasParameter(param)) {
param = param + Integer.toString(parmNum++);
}
return param;
}
}

View File

@@ -0,0 +1,96 @@
/*
* 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.ws.processor.model.java;
import com.sun.tools.internal.ws.processor.model.Parameter;
/**
*
* @author WS Development Team
*/
public class JavaParameter {
public JavaParameter() {}
public JavaParameter(String name, JavaType type, Parameter parameter) {
this(name, type, parameter, false);
}
public JavaParameter(String name, JavaType type, Parameter parameter,
boolean holder) {
this.name = name;
this.type = type;
this.parameter = parameter;
this.holder = holder;
}
public String getName() {
return name;
}
public void setName(String s) {
name = s;
}
public JavaType getType() {
return type;
}
public void setType(JavaType t) {
type = t;
}
public Parameter getParameter() {
return parameter;
}
public void setParameter(Parameter p) {
parameter = p;
}
public boolean isHolder() {
return holder;
}
public void setHolder(boolean b) {
holder = b;
}
public String getHolderName() {
return holderName;
}
public void setHolderName(String holderName) {
this.holderName = holderName;
}
private String name;
private JavaType type;
private Parameter parameter;
private boolean holder;
private String holderName;
}

View File

@@ -0,0 +1,46 @@
/*
* 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.ws.processor.model.java;
import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
/**
*
* @author WS Development Team
*/
public class JavaSimpleType extends JavaType {
public JavaSimpleType() {}
public JavaSimpleType(String name, String initString) {
super(name, true, initString);
}
public JavaSimpleType(JAXBTypeAndAnnotation jtype) {
super(jtype);
}
}

View File

@@ -0,0 +1,129 @@
/*
* 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.ws.processor.model.java;
/**
*
* @author WS Development Team
*/
public class JavaStructureMember {
public JavaStructureMember() {}
public JavaStructureMember(String name, JavaType type, Object owner) {
this(name, type, owner, false);
}
public JavaStructureMember(String name, JavaType type,
Object owner, boolean isPublic) {
this.name = name;
this.type = type;
this.owner = owner;
this.isPublic = isPublic;
constructorPos = -1;
}
public String getName() {
return name;
}
public void setName(String s) {
name = s;
}
public JavaType getType() {
return type;
}
public void setType(JavaType t) {
type = t;
}
public boolean isPublic() {
return isPublic;
}
public void setPublic(boolean b) {
isPublic = b;
}
public boolean isInherited() {
return isInherited;
}
public void setInherited(boolean b) {
isInherited = b;
}
public String getReadMethod() {
return readMethod;
}
public void setReadMethod(String readMethod) {
this.readMethod = readMethod;
}
public String getWriteMethod() {
return writeMethod;
}
public void setWriteMethod(String writeMethod) {
this.writeMethod = writeMethod;
}
public String getDeclaringClass() {
return declaringClass;
}
public void setDeclaringClass(String declaringClass) {
this.declaringClass = declaringClass;
}
public Object getOwner() {
return owner;
}
public void setOwner(Object owner) {
this.owner = owner;
}
public int getConstructorPos() {
return constructorPos;
}
public void setConstructorPos(int idx) {
constructorPos = idx;
}
private String name;
private JavaType type;
private boolean isPublic = false;
private boolean isInherited = false;
private String readMethod;
private String writeMethod;
private String declaringClass;
private Object owner;
private int constructorPos;
}

View File

@@ -0,0 +1,175 @@
/*
* 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.ws.processor.model.java;
import com.sun.tools.internal.ws.processor.model.ModelException;
import java.util.*;
/**
*
* @author WS Development Team
*/
public class JavaStructureType extends JavaType {
public JavaStructureType() {}
public JavaStructureType(String name, boolean present, Object owner) {
super(name, present, "null");
this.owner = owner;
}
public void add(JavaStructureMember m) {
if (membersByName.containsKey(m.getName())) {
throw new ModelException("model.uniqueness.javastructuretype",
new Object[] {m.getName(), getRealName()});
}
members.add(m);
membersByName.put(m.getName(), m);
}
public JavaStructureMember getMemberByName(String name) {
if (membersByName.size() != members.size()) {
initializeMembersByName();
}
return membersByName.get(name);
}
public Iterator getMembers() {
return members.iterator();
}
public int getMembersCount() {
return members.size();
}
/* serialization */
public List<JavaStructureMember> getMembersList() {
return members;
}
/* serialization */
public void setMembersList(List<JavaStructureMember> l) {
members = l;
}
private void initializeMembersByName() {
membersByName = new HashMap<String, JavaStructureMember>();
if (members != null) {
for (JavaStructureMember m : members) {
if (m.getName() != null &&
membersByName.containsKey(m.getName())) {
throw new ModelException("model.uniqueness");
}
membersByName.put(m.getName(), m);
}
}
}
public boolean isAbstract() {
return isAbstract;
}
public void setAbstract(boolean isAbstract) {
this.isAbstract = isAbstract;
}
public JavaStructureType getSuperclass() {
return superclass;
}
public void setSuperclass(JavaStructureType superclassType) {
superclass = superclassType;
}
public void addSubclass(JavaStructureType subclassType) {
subclasses.add(subclassType);
subclassType.setSuperclass(this);
}
public Iterator getSubclasses() {
if (subclasses == null || subclasses.size() == 0) {
return null;
}
return subclasses.iterator();
}
public Set getSubclassesSet() {
return subclasses;
}
/* serialization */
public void setSubclassesSet(Set s) {
subclasses = s;
for (Iterator iter = s.iterator(); iter.hasNext();) {
((JavaStructureType) iter.next()).setSuperclass(this);
}
}
public Iterator getAllSubclasses() {
Set subs = getAllSubclassesSet();
if (subs.size() == 0) {
return null;
}
return subs.iterator();
}
public Set getAllSubclassesSet() {
Set transitiveSet = new HashSet();
Iterator subs = subclasses.iterator();
while (subs.hasNext()) {
transitiveSet.addAll(
((JavaStructureType)subs.next()).getAllSubclassesSet());
}
transitiveSet.addAll(subclasses);
return transitiveSet;
}
public Object getOwner() {
// usually a SOAPStructureType
return owner;
}
public void setOwner(Object owner) {
// usually a SOAPStructureType
this.owner = owner;
}
private List<JavaStructureMember> members = new ArrayList();
private Map<String, JavaStructureMember> membersByName = new HashMap();
// known subclasses of this type
private Set subclasses = new HashSet();
private JavaStructureType superclass;
// usually a SOAPStructureType
private Object owner;
private boolean isAbstract = false;
}

View 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.ws.processor.model.java;
import com.sun.tools.internal.ws.processor.model.jaxb.JAXBTypeAndAnnotation;
/**
*
* @author WS Development Team
*/
public abstract class JavaType {
private String name;
private String realName;
private boolean present;
private boolean holder;
private boolean holderPresent;
private String initString;
private String holderName;
private JAXBTypeAndAnnotation type;
public JavaType() {}
public JavaType(JAXBTypeAndAnnotation type){
this.type = type;
init(type.getName(), false, null, null);
}
public JavaType(String name, boolean present, String initString) {
init(name, present, initString, null);
}
public JavaType(String name, boolean present, String initString,
String holderName) {
init(name, present, initString, holderName);
}
public JAXBTypeAndAnnotation getType(){
return type;
}
private void init(String name, boolean present, String initString,
String holderName) {
this.realName = name;
this.name = name.replace('$', '.');
this.present = present;
this.initString = initString;
this.holderName = holderName;
holder = holderName != null;
}
public String getName() {
return name;
}
public void doSetName(String name) {
// renamed to avoid creating a "name" property with broken semantics
this.realName = name;
this.name = name.replace('$', '.');
}
public String getRealName() {
return realName;
}
/* serialization */
public void setRealName(String s) {
realName = s;
}
public String getFormalName() {
return name;
}
public void setFormalName(String s) {
name = s;
}
public boolean isPresent() {
return present;
}
/* serialization */
public void setPresent(boolean b) {
present = b;
}
public boolean isHolder() {
return holder;
}
public void setHolder(boolean holder) {
this.holder = holder;
}
public boolean isHolderPresent() {
return holderPresent;
}
public void setHolderPresent(boolean holderPresent) {
this.holderPresent = holderPresent;
}
public String getInitString() {
return initString;
}
/* serialization */
public void setInitString(String s) {
initString = s;
}
public String getHolderName() {
return holderName;
}
public void setHolderName(String holderName) {
this.holderName = holderName;
}
}

View File

@@ -0,0 +1,100 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.ws.processor.model.java.JavaStructureMember;
import javax.xml.namespace.QName;
/**
* @author Kathy Walsh, Vivek Pandey
*
*
*/
public class JAXBElementMember {
public JAXBElementMember() {
}
public JAXBElementMember(QName name, JAXBType type) {
this(name, type, null);
}
public JAXBElementMember(QName name, JAXBType type,
JavaStructureMember javaStructureMember) {
_name = name;
_type = type;
_javaStructureMember = javaStructureMember;
}
public QName getName() {
return _name;
}
public void setName(QName n) {
_name = n;
}
public JAXBType getType() {
return _type;
}
public void setType(JAXBType t) {
_type = t;
}
public boolean isRepeated() {
return _repeated;
}
public void setRepeated(boolean b) {
_repeated = b;
}
public JavaStructureMember getJavaStructureMember() {
return _javaStructureMember;
}
public void setJavaStructureMember(JavaStructureMember javaStructureMember) {
_javaStructureMember = javaStructureMember;
}
public boolean isInherited() {
return isInherited;
}
public void setInherited(boolean b) {
isInherited = b;
}
public JAXBProperty getProperty() {
if(_prop == null && _type != null) {
for (JAXBProperty prop: _type.getWrapperChildren()){
if(prop.getElementName().equals(_name))
setProperty(prop);
}
}
return _prop;
}
public void setProperty(JAXBProperty prop) {
_prop = prop;
}
private QName _name;
private JAXBType _type;
private JavaStructureMember _javaStructureMember;
private boolean _repeated;
private boolean isInherited = false;
private JAXBProperty _prop;
private static final String JAXB_UNIQUE_PARRAM = "__jaxbUniqueParam_";
}

View File

@@ -0,0 +1,101 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.xjc.api.Mapping;
import com.sun.tools.internal.xjc.api.Property;
import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* @author Kohsuke Kawaguchi, Vivek Pandey
*/
public class JAXBMapping {
/**
* @see Mapping#getElement()
*/
private QName elementName;
/**
*
*/
private JAXBTypeAndAnnotation type;
/**
* @see Mapping#getWrapperStyleDrilldown()
*/
private List<JAXBProperty> wrapperStyleDrilldown;
/**
* Default constructor for the persistence.
*/
public JAXBMapping() {}
/**
* Constructor that fills in the values from the given raw model
*/
JAXBMapping( com.sun.tools.internal.xjc.api.Mapping rawModel ) {
elementName = rawModel.getElement();
TypeAndAnnotation typeAndAnno = rawModel.getType();
type = new JAXBTypeAndAnnotation(typeAndAnno);
List<? extends Property> list = rawModel.getWrapperStyleDrilldown();
if(list==null)
wrapperStyleDrilldown = null;
else {
wrapperStyleDrilldown = new ArrayList<JAXBProperty>(list.size());
for( Property p : list )
wrapperStyleDrilldown.add(new JAXBProperty(p));
}
}
/**
* @see Mapping#getElement()
*/
public QName getElementName() {
return elementName;
}
public void setElementName(QName elementName) {
this.elementName = elementName;
}
public JAXBTypeAndAnnotation getType() {
return type;
}
/**
* @see Mapping#getWrapperStyleDrilldown()
*/
public List<JAXBProperty> getWrapperStyleDrilldown() {
return wrapperStyleDrilldown;
}
}

View File

@@ -0,0 +1,141 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.xjc.api.J2SJAXBModel;
import com.sun.tools.internal.xjc.api.Mapping;
import com.sun.tools.internal.xjc.api.S2JJAXBModel;
import javax.xml.namespace.QName;
import java.util.*;
/**
* Root of the JAXB Model.
*
* <p>
* This is just a wrapper around a list of {@link JAXBMapping}s.
*
* @author Kohsuke Kawaguchi, Vivek Pandey
*/
public class JAXBModel {
/**
* All the mappings known to this model.
*/
private List<JAXBMapping> mappings;
// index for faster access.
private final Map<QName,JAXBMapping> byQName = new HashMap<QName,JAXBMapping>();
private final Map<String,JAXBMapping> byClassName = new HashMap<String,JAXBMapping>();
private com.sun.tools.internal.xjc.api.JAXBModel rawJAXBModel;
public com.sun.tools.internal.xjc.api.JAXBModel getRawJAXBModel() {
return rawJAXBModel;
}
/**
* @return Schema to Java model
*/
public S2JJAXBModel getS2JJAXBModel(){
if(rawJAXBModel instanceof S2JJAXBModel)
return (S2JJAXBModel)rawJAXBModel;
return null;
}
/**
* @return Java to Schema JAXBModel
*/
public J2SJAXBModel getJ2SJAXBModel(){
if(rawJAXBModel instanceof J2SJAXBModel)
return (J2SJAXBModel)rawJAXBModel;
return null;
}
/**
* Default constructor for the persistence.
*/
public JAXBModel() {}
/**
* Constructor that fills in the values from the given raw model
*/
public JAXBModel( com.sun.tools.internal.xjc.api.JAXBModel rawModel ) {
this.rawJAXBModel = rawModel;
if(rawModel instanceof S2JJAXBModel){
S2JJAXBModel model = (S2JJAXBModel)rawModel;
List<JAXBMapping> ms = new ArrayList<JAXBMapping>(model.getMappings().size());
for( Mapping m : model.getMappings())
ms.add(new JAXBMapping(m));
setMappings(ms);
}
}
/**
*/
public List<JAXBMapping> getMappings() {
return mappings;
}
//public void setMappings(List<JAXBMapping> mappings) {
public void setMappings(List<JAXBMapping> mappings) {
this.mappings = mappings;
byQName.clear();
byClassName.clear();
for( JAXBMapping m : mappings ) {
byQName.put(m.getElementName(),m);
byClassName.put(m.getType().getName(),m);
}
}
/**
*/
public JAXBMapping get( QName elementName ) {
return byQName.get(elementName);
}
/**
*/
public JAXBMapping get( String className ) {
return byClassName.get(className);
}
/**
*
* @return set of full qualified class names that jaxb will generate
*/
public Set<String> getGeneratedClassNames() {
return generatedClassNames;
}
public void setGeneratedClassNames(Set<String> generatedClassNames) {
this.generatedClassNames = generatedClassNames;
}
private Set<String> generatedClassNames;
}

View File

@@ -0,0 +1,93 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.xjc.api.Property;
import javax.xml.namespace.QName;
/**
* @author Kohsuke Kawaguchi
*/
public class JAXBProperty {
/**
* @see Property#name()
*/
private String name;
private JAXBTypeAndAnnotation type;
/**
* @see Property#elementName()
*/
private QName elementName;
/**
* @see Property#rawName()
*/
private QName rawTypeName;
/**
* Default constructor for the persistence.
*/
public JAXBProperty() {}
/**
* Constructor that fills in the values from the given raw model
*/
JAXBProperty( Property prop ) {
this.name = prop.name();
this.type = new JAXBTypeAndAnnotation(prop.type());
this.elementName = prop.elementName();
this.rawTypeName = prop.rawName();
}
/**
* @see Property#name()
*/
public String getName() {
return name;
}
public QName getRawTypeName() {
return rawTypeName;
}
public void setName(String name) {
this.name = name;
}
public JAXBTypeAndAnnotation getType() {
return type;
}
/**
* @see Property#elementName()
*/
public QName getElementName() {
return elementName;
}
}

View File

@@ -0,0 +1,138 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.ws.processor.model.ModelException;
import com.sun.tools.internal.ws.processor.model.java.JavaStructureType;
import javax.xml.namespace.QName;
import java.util.*;
/**
* Top-level binding between JAXB generated Java type
* and XML Schema element declaration.
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public class JAXBStructuredType extends JAXBType {
public JAXBStructuredType(JAXBType jaxbType){
super(jaxbType);
}
public JAXBStructuredType() {}
public JAXBStructuredType(QName name) {
this(name, null);
}
public JAXBStructuredType(QName name, JavaStructureType javaType) {
super(name, javaType);
}
public void add(JAXBElementMember m) {
if (_elementMembersByName.containsKey(m.getName())) {
throw new ModelException("model.uniqueness");
}
_elementMembers.add(m);
if (m.getName() != null) {
_elementMembersByName.put(m.getName().getLocalPart(), m);
}
}
public Iterator getElementMembers() {
return _elementMembers.iterator();
}
public int getElementMembersCount() {
return _elementMembers.size();
}
/* serialization */
public List getElementMembersList() {
return _elementMembers;
}
/* serialization */
public void setElementMembersList(List l) {
_elementMembers = l;
}
public void addSubtype(JAXBStructuredType type) {
if (_subtypes == null) {
_subtypes = new HashSet();
}
_subtypes.add(type);
type.setParentType(this);
}
public Iterator getSubtypes() {
if (_subtypes != null) {
return _subtypes.iterator();
}
return null;
}
/* (non-Javadoc)
* @see JAXBType#isUnwrapped()
*/
public boolean isUnwrapped() {
return true;
}
/* serialization */
public Set getSubtypesSet() {
return _subtypes;
}
/* serialization */
public void setSubtypesSet(Set s) {
_subtypes = s;
}
public void setParentType(JAXBStructuredType parent) {
if (_parentType != null &&
parent != null &&
!_parentType.equals(parent)) {
throw new ModelException("model.parent.type.already.set",
new Object[] { getName().toString(),
_parentType.getName().toString(),
parent.getName().toString()});
}
this._parentType = parent;
}
public JAXBStructuredType getParentType() {
return _parentType;
}
private List _elementMembers = new ArrayList();
private Map _elementMembersByName = new HashMap();
private Set _subtypes = null;
private JAXBStructuredType _parentType = null;
}

View File

@@ -0,0 +1,124 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.ws.processor.model.AbstractType;
import com.sun.tools.internal.ws.processor.model.java.JavaType;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* Top-level binding between JAXB generated Java type
* and XML Schema element declaration.
*
* @author
* Vivek Pandey
*/
public class JAXBType extends AbstractType{
public JAXBType(JAXBType jaxbType){
setName(jaxbType.getName());
this.jaxbMapping = jaxbType.getJaxbMapping();
this.jaxbModel = jaxbType.getJaxbModel();
init();
}
public JAXBType(){}
public JAXBType(QName name, JavaType type){
super(name, type);
}
public JAXBType(QName name, JavaType type, JAXBMapping jaxbMapping, JAXBModel jaxbModel){
super(name, type);
this.jaxbMapping = jaxbMapping;
this.jaxbModel = jaxbModel;
init();
}
public void accept(JAXBTypeVisitor visitor) throws Exception {
visitor.visit(this);
}
private void init() {
if (jaxbMapping != null)
wrapperChildren = jaxbMapping.getWrapperStyleDrilldown();
else
wrapperChildren = new ArrayList<JAXBProperty>();
}
public boolean isUnwrappable(){
return jaxbMapping != null && jaxbMapping.getWrapperStyleDrilldown() != null;
}
public boolean hasWrapperChildren(){
return wrapperChildren.size() > 0;
}
public boolean isLiteralType() {
return true;
}
public List<JAXBProperty> getWrapperChildren(){
return wrapperChildren;
}
public void setWrapperChildren(List<JAXBProperty> children) {
wrapperChildren = children;
}
public JAXBMapping getJaxbMapping() {
return jaxbMapping;
}
public void setJaxbMapping(JAXBMapping jaxbMapping) {
this.jaxbMapping = jaxbMapping;
init();
}
public void setUnwrapped(boolean unwrapped) {
this.unwrapped = unwrapped;
}
public boolean isUnwrapped() {
return unwrapped;
}
private JAXBMapping jaxbMapping;
public JAXBModel getJaxbModel() {
return jaxbModel;
}
public void setJaxbModel(JAXBModel jaxbModel) {
this.jaxbModel = jaxbModel;
}
private JAXBModel jaxbModel;
private boolean unwrapped = false;
private List<JAXBProperty> wrapperChildren;
}

View File

@@ -0,0 +1,78 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.codemodel.internal.JAnnotatable;
import com.sun.codemodel.internal.JType;
import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
/**
* Holds JAXB JType and TypeAndAnnotation. This provides abstration over
* types from JAXBMapping and Property.
*/
public class JAXBTypeAndAnnotation {
TypeAndAnnotation typeAnn;
JType type;
public JAXBTypeAndAnnotation(TypeAndAnnotation typeAnn) {
this.typeAnn = typeAnn;
this.type = typeAnn.getTypeClass();
}
public JAXBTypeAndAnnotation(JType type) {
this.type = type;
}
public JAXBTypeAndAnnotation(TypeAndAnnotation typeAnn, JType type) {
this.typeAnn = typeAnn;
this.type = type;
}
public void annotate(JAnnotatable typeVar) {
if(typeAnn != null)
typeAnn.annotate(typeVar);
}
public JType getType() {
return type;
}
public String getName(){
return type.fullName();
}
public TypeAndAnnotation getTypeAnn() {
return typeAnn;
}
public void setTypeAnn(TypeAndAnnotation typeAnn) {
this.typeAnn = typeAnn;
}
public void setType(JType type) {
this.type = type;
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.ws.processor.model.jaxb;
/**
* @author Vivek Pandey
*
* To change the template for this generated type comment go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
public interface JAXBTypeVisitor {
public void visit(JAXBType type) throws Exception;
public void visit(RpcLitStructure type) throws Exception;
}

View File

@@ -0,0 +1,85 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.ws.processor.model.AbstractType;
import javax.xml.namespace.QName;
/**
* @author Vivek Pandey
*
* Represents RpcLit member parts
*/
public class RpcLitMember extends AbstractType {
//wsdl:part type attribute java mapped object
private String javaTypeName;
private QName schemaTypeName;
/**
*
*/
public RpcLitMember() {
super();
// TODO Auto-generated constructor stub
}
public RpcLitMember(QName name, String javaTypeName){
setName(name);
this.javaTypeName = javaTypeName;
}
public RpcLitMember(QName name, String javaTypeName, QName schemaTypeName){
setName(name);
this.javaTypeName = javaTypeName;
this.schemaTypeName = schemaTypeName;
}
/**
* @return Returns the type.
*/
public String getJavaTypeName() {
return javaTypeName;
}
/**
* @param type The type to set.
*/
public void setJavaTypeName(String type) {
this.javaTypeName = type;
}
/**
* @return Returns the type.
*/
public QName getSchemaTypeName() {
return schemaTypeName;
}
/**
* @param type The type to set.
*/
public void setSchemaTypeName(QName type) {
this.schemaTypeName = type;
}
}

View File

@@ -0,0 +1,92 @@
/*
* 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.ws.processor.model.jaxb;
import com.sun.tools.internal.ws.processor.model.AbstractType;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* @author Vivek Pandey
*
* RPC Structure that will be used to create RpcLitPayload latter
*/
public class RpcLitStructure extends AbstractType {
private List<RpcLitMember> members;
private JAXBModel jaxbModel;
/**
*
*/
public RpcLitStructure() {
super();
// TODO Auto-generated constructor stub
}
public RpcLitStructure(QName name, JAXBModel jaxbModel){
setName(name);
this.jaxbModel = jaxbModel;
this.members = new ArrayList<RpcLitMember>();
}
public RpcLitStructure(QName name, JAXBModel jaxbModel, List<RpcLitMember> members){
setName(name);
this.members = members;
}
public void accept(JAXBTypeVisitor visitor) throws Exception {
visitor.visit(this);
}
public List<RpcLitMember> getRpcLitMembers(){
return members;
}
public List<RpcLitMember> setRpcLitMembers(List<RpcLitMember> members){
return this.members = members;
}
public void addRpcLitMember(RpcLitMember member){
members.add(member);
}
/**
* @return Returns the jaxbModel.
*/
public JAXBModel getJaxbModel() {
return jaxbModel;
}
/**
* @param jaxbModel The jaxbModel to set.
*/
public void setJaxbModel(JAXBModel jaxbModel) {
this.jaxbModel = jaxbModel;
}
public boolean isLiteralType() {
return true;
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.ws.processor.model.jaxb;
/**
* @author Kohsuke Kawaguchi
*/
class Util {
/**
* Replaces the marcros in the first string by the actual given arguments.
*/
static String replace( String macro, String... args ) {
int len = macro.length();
StringBuilder buf = new StringBuilder(len);
for( int i=0; i<len; i++ ) {
char ch = macro.charAt(i);
if(ch=='=' && i+2<len) {
char tail = macro.charAt(i+1);
char ch2 = macro.charAt(i+2);
if('0'<=ch2 && ch2<='9' && tail==':') {
buf.append(args[ch2-'0']);
i+=2;
continue;
}
}
buf.append(ch);
}
return buf.toString();
}
/**
* Creates a macro tempate so that it can be later used with {@link #replace(String, String[])}.
*/
static String createMacroTemplate( String s ) {
return s;
}
static final String MAGIC = "=:";
static final String MAGIC0 = MAGIC+"0";
static final String MAGIC1 = MAGIC+"1";
static final String MAGIC2 = MAGIC+"2";
}

View File

@@ -0,0 +1,121 @@
/*
* 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.ws.processor.modeler;
import com.sun.tools.internal.ws.processor.model.java.JavaSimpleType;
import java.util.HashMap;
import java.util.Map;
import static com.sun.tools.internal.ws.processor.modeler.ModelerConstants.*;
/**
*
* @author WS Development Team
*/
public final class JavaSimpleTypeCreator {
/*
* Mapped JavaSimpleTypes
*/
public static final JavaSimpleType BOOLEAN_JAVATYPE = new JavaSimpleType(BOOLEAN_CLASSNAME.getValue(), FALSE_STR.getValue());
public static final JavaSimpleType BOXED_BOOLEAN_JAVATYPE = new JavaSimpleType(BOXED_BOOLEAN_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType BYTE_JAVATYPE = new JavaSimpleType(BYTE_CLASSNAME.getValue(), "(byte)" + ZERO_STR.getValue());
public static final JavaSimpleType BYTE_ARRAY_JAVATYPE = new JavaSimpleType(BYTE_ARRAY_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType BOXED_BYTE_JAVATYPE = new JavaSimpleType(BOXED_BYTE_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType BOXED_BYTE_ARRAY_JAVATYPE = new JavaSimpleType(BOXED_BYTE_ARRAY_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType DOUBLE_JAVATYPE = new JavaSimpleType(DOUBLE_CLASSNAME.getValue(), ZERO_STR.getValue());
public static final JavaSimpleType BOXED_DOUBLE_JAVATYPE = new JavaSimpleType(BOXED_DOUBLE_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType FLOAT_JAVATYPE = new JavaSimpleType(FLOAT_CLASSNAME.getValue(), ZERO_STR.getValue());
public static final JavaSimpleType BOXED_FLOAT_JAVATYPE = new JavaSimpleType(BOXED_FLOAT_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType INT_JAVATYPE = new JavaSimpleType(INT_CLASSNAME.getValue(), ZERO_STR.getValue());
public static final JavaSimpleType BOXED_INTEGER_JAVATYPE = new JavaSimpleType(BOXED_INTEGER_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType LONG_JAVATYPE = new JavaSimpleType(LONG_CLASSNAME.getValue(), ZERO_STR.getValue());
public static final JavaSimpleType BOXED_LONG_JAVATYPE = new JavaSimpleType(BOXED_LONG_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType SHORT_JAVATYPE = new JavaSimpleType(SHORT_CLASSNAME.getValue(), "(short)" + ZERO_STR.getValue());
public static final JavaSimpleType BOXED_SHORT_JAVATYPE = new JavaSimpleType(BOXED_SHORT_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType DECIMAL_JAVATYPE = new JavaSimpleType(BIGDECIMAL_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType BIG_INTEGER_JAVATYPE = new JavaSimpleType(BIGINTEGER_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType CALENDAR_JAVATYPE = new JavaSimpleType(CALENDAR_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType DATE_JAVATYPE = new JavaSimpleType(DATE_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType STRING_JAVATYPE = new JavaSimpleType(STRING_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType STRING_ARRAY_JAVATYPE = new JavaSimpleType(STRING_ARRAY_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType QNAME_JAVATYPE = new JavaSimpleType(QNAME_CLASSNAME.getValue(), NULL_STR.getValue());
public static final JavaSimpleType VOID_JAVATYPE = new JavaSimpleType(VOID_CLASSNAME.getValue(), null);
public static final JavaSimpleType OBJECT_JAVATYPE = new JavaSimpleType(OBJECT_CLASSNAME.getValue(), null);
public static final JavaSimpleType SOAPELEMENT_JAVATYPE = new JavaSimpleType(SOAPELEMENT_CLASSNAME.getValue(), null);
public static final JavaSimpleType URI_JAVATYPE = new JavaSimpleType(URI_CLASSNAME.getValue(), null);
// Attachment types
public static final JavaSimpleType IMAGE_JAVATYPE = new JavaSimpleType(IMAGE_CLASSNAME.getValue(), null);
public static final JavaSimpleType MIME_MULTIPART_JAVATYPE = new JavaSimpleType(MIME_MULTIPART_CLASSNAME.getValue(), null);
public static final JavaSimpleType SOURCE_JAVATYPE = new JavaSimpleType(SOURCE_CLASSNAME.getValue(), null);
public static final JavaSimpleType DATA_HANDLER_JAVATYPE = new JavaSimpleType(DATA_HANDLER_CLASSNAME.getValue(), null);
// bug fix: 4923650
private static final Map<String, JavaSimpleType> JAVA_TYPES = new HashMap<String, JavaSimpleType>(31);
static {
JAVA_TYPES.put(BOOLEAN_CLASSNAME.getValue(), BOOLEAN_JAVATYPE);
JAVA_TYPES.put(BOXED_BOOLEAN_CLASSNAME.getValue(), BOXED_BOOLEAN_JAVATYPE);
JAVA_TYPES.put(BYTE_CLASSNAME.getValue(), BYTE_JAVATYPE);
JAVA_TYPES.put(BYTE_ARRAY_CLASSNAME.getValue(), BYTE_ARRAY_JAVATYPE);
JAVA_TYPES.put(BOXED_BYTE_CLASSNAME.getValue(), BOXED_BYTE_JAVATYPE);
JAVA_TYPES.put(BOXED_BYTE_ARRAY_CLASSNAME.getValue(), BOXED_BYTE_ARRAY_JAVATYPE);
JAVA_TYPES.put(DOUBLE_CLASSNAME.getValue(), DOUBLE_JAVATYPE);
JAVA_TYPES.put(BOXED_DOUBLE_CLASSNAME.getValue(), BOXED_DOUBLE_JAVATYPE);
JAVA_TYPES.put(FLOAT_CLASSNAME.getValue(), FLOAT_JAVATYPE);
JAVA_TYPES.put(BOXED_FLOAT_CLASSNAME.getValue(), BOXED_FLOAT_JAVATYPE);
JAVA_TYPES.put(INT_CLASSNAME.getValue(), INT_JAVATYPE);
JAVA_TYPES.put(BOXED_INTEGER_CLASSNAME.getValue(), BOXED_INTEGER_JAVATYPE);
JAVA_TYPES.put(LONG_CLASSNAME.getValue(), LONG_JAVATYPE);
JAVA_TYPES.put(BOXED_LONG_CLASSNAME.getValue(), BOXED_LONG_JAVATYPE);
JAVA_TYPES.put(SHORT_CLASSNAME.getValue(), SHORT_JAVATYPE);
JAVA_TYPES.put(BOXED_SHORT_CLASSNAME.getValue(), BOXED_SHORT_JAVATYPE);
JAVA_TYPES.put(BIGDECIMAL_CLASSNAME.getValue(), DECIMAL_JAVATYPE);
JAVA_TYPES.put(BIGINTEGER_CLASSNAME.getValue(), BIG_INTEGER_JAVATYPE);
JAVA_TYPES.put(CALENDAR_CLASSNAME.getValue(), CALENDAR_JAVATYPE);
JAVA_TYPES.put(DATE_CLASSNAME.getValue(), DATE_JAVATYPE);
JAVA_TYPES.put(STRING_CLASSNAME.getValue(), STRING_JAVATYPE);
JAVA_TYPES.put(STRING_ARRAY_CLASSNAME.getValue(), STRING_ARRAY_JAVATYPE);
JAVA_TYPES.put(QNAME_CLASSNAME.getValue(), QNAME_JAVATYPE);
JAVA_TYPES.put(VOID_CLASSNAME.getValue(), VOID_JAVATYPE);
JAVA_TYPES.put(OBJECT_CLASSNAME.getValue(), OBJECT_JAVATYPE);
JAVA_TYPES.put(SOAPELEMENT_CLASSNAME.getValue(), SOAPELEMENT_JAVATYPE);
JAVA_TYPES.put(URI_CLASSNAME.getValue(), URI_JAVATYPE);
JAVA_TYPES.put(IMAGE_CLASSNAME.getValue(), IMAGE_JAVATYPE);
JAVA_TYPES.put(MIME_MULTIPART_CLASSNAME.getValue(), MIME_MULTIPART_JAVATYPE);
JAVA_TYPES.put(SOURCE_CLASSNAME.getValue(), SOURCE_JAVATYPE);
JAVA_TYPES.put(DATA_HANDLER_CLASSNAME.getValue(), DATA_HANDLER_JAVATYPE);
}
private JavaSimpleTypeCreator() {
}
// bug fix: 4923650
public static JavaSimpleType getJavaSimpleType(String className) {
return JAVA_TYPES.get(className);
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.ws.processor.modeler;
import com.sun.tools.internal.ws.processor.model.Model;
/**
* A Modeler is used to create a Model of a Web Service from a particular Web
* Web Service description such as a WSDL
*
* @author WS Development Team
*/
public interface Modeler {
/**
* Returns the top model of a Web Service. May throw a
* ModelException if there is a problem with the model.
*
* @return Model - the root Node of the model of the Web Service
*
* @exception ModelerException
*/
public Model buildModel();
}

View File

@@ -0,0 +1,111 @@
/*
* 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.ws.processor.modeler;
/**
*
* @author WS Development Team
*/
public enum ModelerConstants {
FALSE_STR("false"),
ZERO_STR("0"),
NULL_STR("null"),
ARRAY_STR("Array"),
/*
* Java ClassNames
*/
/*
* Java ClassNames
*/
IOEXCEPTION_CLASSNAME("java.io.IOException"),
BOOLEAN_CLASSNAME("boolean"),
BOXED_BOOLEAN_CLASSNAME("java.lang.Boolean"),
BYTE_CLASSNAME("byte"),
BYTE_ARRAY_CLASSNAME("byte[]"),
BOXED_BYTE_CLASSNAME("java.lang.Byte"),
BOXED_BYTE_ARRAY_CLASSNAME("java.lang.Byte[]"),
CLASS_CLASSNAME("java.lang.Class"),
CHAR_CLASSNAME("char"),
BOXED_CHAR_CLASSNAME("java.lang.Character"),
DOUBLE_CLASSNAME("double"),
BOXED_DOUBLE_CLASSNAME("java.lang.Double"),
FLOAT_CLASSNAME("float"),
BOXED_FLOAT_CLASSNAME("java.lang.Float"),
INT_CLASSNAME("int"),
BOXED_INTEGER_CLASSNAME("java.lang.Integer"),
LONG_CLASSNAME("long"),
BOXED_LONG_CLASSNAME("java.lang.Long"),
SHORT_CLASSNAME("short"),
BOXED_SHORT_CLASSNAME("java.lang.Short"),
BIGDECIMAL_CLASSNAME("java.math.BigDecimal"),
BIGINTEGER_CLASSNAME("java.math.BigInteger"),
CALENDAR_CLASSNAME("java.util.Calendar"),
DATE_CLASSNAME("java.util.Date"),
STRING_CLASSNAME("java.lang.String"),
STRING_ARRAY_CLASSNAME("java.lang.String[]"),
QNAME_CLASSNAME("javax.xml.namespace.QName"),
VOID_CLASSNAME("void"),
OBJECT_CLASSNAME("java.lang.Object"),
SOAPELEMENT_CLASSNAME("javax.xml.soap.SOAPElement"),
IMAGE_CLASSNAME("java.awt.Image"),
MIME_MULTIPART_CLASSNAME("javax.mail.internet.MimeMultipart"),
SOURCE_CLASSNAME("javax.xml.transform.Source"),
DATA_HANDLER_CLASSNAME("javax.activation.DataHandler"),
URI_CLASSNAME("java.net.URI"),
// URI_CLASSNAME ("java.lang.String"),
// Collections
COLLECTION_CLASSNAME("java.util.Collection"),
LIST_CLASSNAME("java.util.List"),
SET_CLASSNAME("java.util.Set"),
VECTOR_CLASSNAME("java.util.Vector"),
STACK_CLASSNAME("java.util.Stack"),
LINKED_LIST_CLASSNAME("java.util.LinkedList"),
ARRAY_LIST_CLASSNAME("java.util.ArrayList"),
HASH_SET_CLASSNAME("java.util.HashSet"),
TREE_SET_CLASSNAME("java.util.TreeSet"),
// Maps
MAP_CLASSNAME("java.util.Map"),
HASH_MAP_CLASSNAME("java.util.HashMap"),
TREE_MAP_CLASSNAME("java.util.TreeMap"),
HASHTABLE_CLASSNAME("java.util.Hashtable"),
PROPERTIES_CLASSNAME("java.util.Properties"),
// WEAK_HASH_MAP_CLASSNAME ("java.util.WeakHashMap"),
JAX_WS_MAP_ENTRY_CLASSNAME("com.sun.xml.internal.ws.encoding.soap.JAXWSMapEntry");
private String value;
private ModelerConstants(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.ws.processor.modeler;
import com.sun.istack.internal.localization.Localizable;
import com.sun.tools.internal.ws.processor.ProcessorException;
/**
* ModelerException represents an exception that occurred while
* visiting service model.
*
* @see ProcessorException
*
* @author WS Development Team
*/
public class ModelerException extends ProcessorException {
public ModelerException(String key) {
super(key);
}
public ModelerException(String key, Object... args) {
super(key, args);
}
public ModelerException(Throwable throwable) {
super(throwable);
}
public ModelerException(Localizable arg) {
super("modeler.nestedModelError", arg);
}
public String getDefaultResourceBundleName() {
return "com.sun.tools.internal.ws.resources.modeler";
}
}

View File

@@ -0,0 +1,181 @@
/*
* 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.ws.processor.modeler.annotation;
import com.sun.tools.internal.ws.processor.model.Model;
import com.sun.tools.internal.ws.processor.model.Operation;
import com.sun.tools.internal.ws.processor.model.Port;
import com.sun.tools.internal.ws.processor.model.Service;
import com.sun.tools.internal.ws.wsdl.document.soap.SOAPUse;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author dkohlert
*/
public class AnnotationProcessorContext {
private Map<Name, SeiContext> seiContextMap = new HashMap<Name, SeiContext>();
private int round = 1;
private boolean modelCompleted = false;
public void addSeiContext(Name seiName, SeiContext seiContext) {
seiContextMap.put(seiName, seiContext);
}
public SeiContext getSeiContext(Name seiName) {
SeiContext context = seiContextMap.get(seiName);
if (context == null) {
context = new SeiContext();
addSeiContext(seiName, context);
}
return context;
}
public SeiContext getSeiContext(TypeElement d) {
return getSeiContext(d.getQualifiedName());
}
public Collection<SeiContext> getSeiContexts() {
return seiContextMap.values();
}
public int getRound() {
return round;
}
public void incrementRound() {
round++;
}
public static boolean isEncoded(Model model) {
if (model == null)
return false;
for (Service service : model.getServices()) {
for (Port port : service.getPorts()) {
for (Operation operation : port.getOperations()) {
if (operation.getUse() != null && operation.getUse().equals(SOAPUse.LITERAL))
return false;
}
}
}
return true;
}
public void setModelCompleted(boolean modelCompleted) {
this.modelCompleted = modelCompleted;
}
public boolean isModelCompleted() {
return modelCompleted;
}
public static class SeiContext {
private Map<String, WrapperInfo> reqOperationWrapperMap = new HashMap<String, WrapperInfo>();
private Map<String, WrapperInfo> resOperationWrapperMap = new HashMap<String, WrapperInfo>();
private Map<Name, FaultInfo> exceptionBeanMap = new HashMap<Name, FaultInfo>();
private Name seiImplName;
private boolean implementsSei;
private String namespaceUri;
public SeiContext() {};
/**
* @deprecated use empty constructor, seiName value is ignored
* @param seiName
*/
public SeiContext(Name seiName) {};
public void setImplementsSei(boolean implementsSei) {
this.implementsSei = implementsSei;
}
public boolean getImplementsSei() {
return implementsSei;
}
public void setNamespaceUri(String namespaceUri) {
this.namespaceUri = namespaceUri;
}
public String getNamespaceUri() {
return namespaceUri;
}
public Name getSeiImplName() {
return seiImplName;
}
public void setSeiImplName(Name implName) {
seiImplName = implName;
}
public void setReqWrapperOperation(ExecutableElement method, WrapperInfo wrapperInfo) {
reqOperationWrapperMap.put(methodToString(method), wrapperInfo);
}
public WrapperInfo getReqOperationWrapper(ExecutableElement method) {
return reqOperationWrapperMap.get(methodToString(method));
}
public void setResWrapperOperation(ExecutableElement method, WrapperInfo wrapperInfo) {
resOperationWrapperMap.put(methodToString(method), wrapperInfo);
}
public WrapperInfo getResOperationWrapper(ExecutableElement method) {
return resOperationWrapperMap.get(methodToString(method));
}
public String methodToString(ExecutableElement method) {
StringBuilder buf = new StringBuilder(method.getSimpleName());
for (VariableElement param : method.getParameters())
buf.append(';').append(param.asType());
return buf.toString();
}
public void clearExceptionMap() {
exceptionBeanMap.clear();
}
public void addExceptionBeanEntry(Name exception, FaultInfo faultInfo, ModelBuilder builder) {
exceptionBeanMap.put(exception, faultInfo);
}
public FaultInfo getExceptionBeanName(Name exception) {
return exceptionBeanMap.get(exception);
}
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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.ws.processor.modeler.annotation;
import javax.xml.namespace.QName;
/**
*
* @author dkohlert
*/
public class FaultInfo {
public String beanName;
public TypeMoniker beanTypeMoniker;
public boolean isWsdlException;
public QName elementName;
/** Creates a new instance of FaultInfo */
public FaultInfo() {
}
public FaultInfo(String beanName) {
this.beanName = beanName;
}
public FaultInfo(String beanName, boolean isWsdlException) {
this.beanName = beanName;
this.isWsdlException = isWsdlException;
}
public FaultInfo(TypeMoniker typeMoniker, boolean isWsdlException) {
this.beanTypeMoniker = typeMoniker;
this.isWsdlException = isWsdlException;
}
public void setIsWsdlException(boolean isWsdlException) {
this.isWsdlException = isWsdlException;
}
public boolean isWsdlException() {
return isWsdlException;
}
public void setBeanName(String beanName) {
this.beanName = beanName;
}
public String getBeanName() {
return beanName;
}
public void setElementName(QName elementName) {
this.elementName = elementName;
}
public QName getElementName() {
return elementName;
}
public void setBeanTypeMoniker(TypeMoniker typeMoniker) {
this.beanTypeMoniker = typeMoniker;
}
public TypeMoniker getBeanTypeMoniker() {
return beanTypeMoniker;
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.ws.processor.modeler.annotation;
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.NoType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleTypeVisitor6;
import javax.lang.model.util.Types;
import java.util.Collection;
import java.util.Map;
/**
*
* @author dkohlert
*/
public class MakeSafeTypeVisitor extends SimpleTypeVisitor6<TypeMirror, Types> {
TypeElement collectionType;
TypeElement mapType;
/**
* Creates a new instance of MakeSafeTypeVisitor
*/
public MakeSafeTypeVisitor(ProcessingEnvironment processingEnvironment) {
collectionType = processingEnvironment.getElementUtils().getTypeElement(Collection.class.getName());
mapType = processingEnvironment.getElementUtils().getTypeElement(Map.class.getName());
}
@Override
public TypeMirror visitDeclared(DeclaredType t, Types types) {
if (TypeModeler.isSubElement((TypeElement) t.asElement(), collectionType)
|| TypeModeler.isSubElement((TypeElement) t.asElement(), mapType)) {
Collection<? extends TypeMirror> args = t.getTypeArguments();
TypeMirror[] safeArgs = new TypeMirror[args.size()];
int i = 0;
for (TypeMirror arg : args) {
safeArgs[i++] = visit(arg, types);
}
return types.getDeclaredType((TypeElement) t.asElement(), safeArgs);
}
return types.erasure(t);
}
@Override
public TypeMirror visitNoType(NoType type, Types types) {
return type;
}
@Override
protected TypeMirror defaultAction(TypeMirror e, Types types) {
return types.erasure(e);
}
}

Some files were not shown because too many files have changed in this diff Show More