feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
43
jdkSrc/jdk8/com/sun/tools/internal/xjc/AbortException.java
Normal file
43
jdkSrc/jdk8/com/sun/tools/internal/xjc/AbortException.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use is subject to the license terms.
|
||||
*/
|
||||
package com.sun.tools.internal.xjc;
|
||||
|
||||
|
||||
/**
|
||||
* Signals the abortion of the compilation.
|
||||
* <p>
|
||||
* This exception should be only thrown from {@link ErrorReceiver}
|
||||
* for the consistent error handling.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class AbortException extends RuntimeException {
|
||||
public AbortException() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import com.sun.istack.internal.Nullable;
|
||||
|
||||
/**
|
||||
* Signals a bad command line argument.
|
||||
*/
|
||||
public class BadCommandLineException extends Exception {
|
||||
private Options options;
|
||||
|
||||
public BadCommandLineException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public BadCommandLineException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public BadCommandLineException() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public void initOptions(Options opt) {
|
||||
assert this.options==null;
|
||||
this.options = opt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the partly parsed option object, if any.
|
||||
*/
|
||||
public @Nullable Options getOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
122
jdkSrc/jdk8/com/sun/tools/internal/xjc/ClassLoaderBuilder.java
Normal file
122
jdkSrc/jdk8/com/sun/tools/internal/xjc/ClassLoaderBuilder.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
|
||||
import com.sun.istack.internal.tools.MaskingClassLoader;
|
||||
import com.sun.istack.internal.tools.ParallelWorldClassLoader;
|
||||
|
||||
/**
|
||||
* Creates a class loader configured to run XJC 1.0/2.0 safely without
|
||||
* interference with JAXB 2.0 API in Mustang.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
class ClassLoaderBuilder {
|
||||
|
||||
/**
|
||||
* Creates a new class loader that eventually delegates to the given {@link ClassLoader}
|
||||
* such that XJC can be loaded by using this classloader.
|
||||
*
|
||||
* @param v
|
||||
* Either "1.0" or "2.0", indicating the version of the -source value.
|
||||
*/
|
||||
protected static ClassLoader createProtectiveClassLoader(ClassLoader cl, String v) throws ClassNotFoundException, MalformedURLException {
|
||||
if(noHack) return cl; // provide an escape hatch
|
||||
|
||||
boolean mustang = false;
|
||||
|
||||
if (SecureLoader.getClassClassLoader(JAXBContext.class) == null) {
|
||||
// JAXB API is loaded from the bootstrap. We need to override one with ours
|
||||
mustang = true;
|
||||
|
||||
List<String> mask = new ArrayList<String>(Arrays.asList(maskedPackages));
|
||||
mask.add("javax.xml.bind.");
|
||||
|
||||
cl = new MaskingClassLoader(cl,mask);
|
||||
|
||||
URL apiUrl = cl.getResource("javax/xml/bind/JAXBPermission.class");
|
||||
if(apiUrl==null)
|
||||
throw new ClassNotFoundException("There's no JAXB 2.2 API in the classpath");
|
||||
|
||||
cl = new URLClassLoader(new URL[]{ParallelWorldClassLoader.toJarUrl(apiUrl)},cl);
|
||||
}
|
||||
|
||||
//Leave XJC2 in the publicly visible place
|
||||
// and then isolate XJC1 in a child class loader,
|
||||
// then use a MaskingClassLoader
|
||||
// so that the XJC2 classes in the parent class loader
|
||||
// won't interfere with loading XJC1 classes in a child class loader
|
||||
|
||||
if ("1.0".equals(v)) {
|
||||
if(!mustang)
|
||||
// if we haven't used Masking ClassLoader, do so now.
|
||||
cl = new MaskingClassLoader(cl,toolPackages);
|
||||
cl = new ParallelWorldClassLoader(cl,"1.0/");
|
||||
} else {
|
||||
if(mustang)
|
||||
// the whole RI needs to be loaded in a separate class loader
|
||||
cl = new ParallelWorldClassLoader(cl,"");
|
||||
}
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The list of package prefixes we want the
|
||||
* {@link MaskingClassLoader} to prevent the parent
|
||||
* classLoader from loading
|
||||
*/
|
||||
private static String[] maskedPackages = new String[]{
|
||||
// toolPackages + alpha
|
||||
"com.sun.tools.",
|
||||
"com.sun.codemodel.internal.",
|
||||
"com.sun.relaxng.",
|
||||
"com.sun.xml.internal.xsom.",
|
||||
"com.sun.xml.internal.bind.",
|
||||
};
|
||||
|
||||
private static String[] toolPackages = new String[]{
|
||||
"com.sun.tools.",
|
||||
"com.sun.codemodel.internal.",
|
||||
"com.sun.relaxng.",
|
||||
"com.sun.xml.internal.xsom."
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape hatch in case this class loader hack breaks.
|
||||
*/
|
||||
public static final boolean noHack = Boolean.getBoolean(XJCFacade.class.getName()+".nohack");
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* {@link ErrorReceiver} that prints to a {@link PrintStream}.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class ConsoleErrorReporter extends ErrorReceiver {
|
||||
|
||||
/**
|
||||
* Errors, warnings are sent to this output.
|
||||
*/
|
||||
private PrintStream output;
|
||||
|
||||
private boolean hadError = false;
|
||||
|
||||
public ConsoleErrorReporter( PrintStream out) {
|
||||
this.output = out;
|
||||
}
|
||||
public ConsoleErrorReporter( OutputStream out ) {
|
||||
this(new PrintStream(out));
|
||||
}
|
||||
public ConsoleErrorReporter() { this(System.out); }
|
||||
|
||||
public void warning(SAXParseException e) {
|
||||
print(Messages.WARNING_MSG,e);
|
||||
}
|
||||
|
||||
public void error(SAXParseException e) {
|
||||
hadError = true;
|
||||
print(Messages.ERROR_MSG,e);
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException e) {
|
||||
hadError = true;
|
||||
print(Messages.ERROR_MSG,e);
|
||||
}
|
||||
|
||||
public void info(SAXParseException e) {
|
||||
print(Messages.INFO_MSG,e);
|
||||
}
|
||||
|
||||
public boolean hadError() {
|
||||
return hadError;
|
||||
}
|
||||
|
||||
private void print( String resource, SAXParseException e ) {
|
||||
output.println(Messages.format(resource,e.getMessage()));
|
||||
output.println(getLocationString(e));
|
||||
output.println();
|
||||
}
|
||||
}
|
||||
526
jdkSrc/jdk8/com/sun/tools/internal/xjc/Driver.java
Normal file
526
jdkSrc/jdk8/com/sun/tools/internal/xjc/Driver.java
Normal file
@@ -0,0 +1,526 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.sun.codemodel.internal.CodeWriter;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.writer.ZipCodeWriter;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.Nullable;
|
||||
import com.sun.istack.internal.tools.DefaultAuthenticator;
|
||||
import com.sun.tools.internal.xjc.generator.bean.BeanGenerator;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.reader.gbind.Expression;
|
||||
import com.sun.tools.internal.xjc.reader.gbind.Graph;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.DOMForest;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.ExpressionBuilder;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.parser.XMLSchemaInternalizationLogic;
|
||||
import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
|
||||
import com.sun.tools.internal.xjc.util.NullStream;
|
||||
import com.sun.tools.internal.xjc.util.Util;
|
||||
import com.sun.tools.internal.xjc.writer.SignatureWriter;
|
||||
import com.sun.xml.internal.xsom.XSComplexType;
|
||||
import com.sun.xml.internal.xsom.XSParticle;
|
||||
import com.sun.xml.internal.xsom.XSSchemaSet;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
|
||||
/**
|
||||
* Command Line Interface of XJC.
|
||||
*/
|
||||
public class Driver {
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
// use the platform default proxy if available.
|
||||
// see sun.net.spi.DefaultProxySelector for details.
|
||||
try {
|
||||
System.setProperty("java.net.useSystemProxies","true");
|
||||
} catch (SecurityException e) {
|
||||
// failing to set this property isn't fatal
|
||||
}
|
||||
|
||||
if( Util.getSystemProperty(Driver.class,"noThreadSwap")!=null )
|
||||
_main(args); // for the ease of debugging
|
||||
|
||||
// run all the work in another thread so that the -Xss option
|
||||
// will take effect when compiling a large schema. See
|
||||
// http://developer.java.sun.com/developer/bugParade/bugs/4362291.html
|
||||
final Throwable[] ex = new Throwable[1];
|
||||
|
||||
Thread th = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
_main(args);
|
||||
} catch( Throwable e ) {
|
||||
ex[0]=e;
|
||||
}
|
||||
}
|
||||
};
|
||||
th.start();
|
||||
th.join();
|
||||
|
||||
if(ex[0]!=null) {
|
||||
// re-throw
|
||||
if( ex[0] instanceof Exception )
|
||||
throw (Exception)ex[0];
|
||||
else
|
||||
throw (Error)ex[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static void _main( String[] args ) throws Exception {
|
||||
try {
|
||||
System.exit(run( args, System.out, System.out ));
|
||||
} catch (BadCommandLineException e) {
|
||||
// there was an error in the command line.
|
||||
// print usage and abort.
|
||||
if(e.getMessage()!=null) {
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
usage(e.getOptions(),false);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs schema compilation and prints the status/error into the
|
||||
* specified PrintStream.
|
||||
*
|
||||
* <p>
|
||||
* This method could be used to trigger XJC from other tools,
|
||||
* such as Ant or IDE.
|
||||
*
|
||||
* @param args
|
||||
* specified command line parameters. If there is an error
|
||||
* in the parameters, {@link BadCommandLineException} will
|
||||
* be thrown.
|
||||
* @param status
|
||||
* Status report of the compilation will be sent to this object.
|
||||
* Useful to update users so that they will know something is happening.
|
||||
* Only ignorable messages should be sent to this stream.
|
||||
*
|
||||
* This parameter can be null to suppress messages.
|
||||
*
|
||||
* @param out
|
||||
* Various non-ignorable output (error messages, etc)
|
||||
* will go to this stream.
|
||||
*
|
||||
* @return
|
||||
* If the compiler runs successfully, this method returns 0.
|
||||
* All non-zero values indicate an error. The error message
|
||||
* will be sent to the specified PrintStream.
|
||||
*/
|
||||
public static int run(String[] args, final PrintStream status, final PrintStream out)
|
||||
throws Exception {
|
||||
|
||||
class Listener extends XJCListener {
|
||||
ConsoleErrorReporter cer = new ConsoleErrorReporter(out==null?new PrintStream(new NullStream()):out);
|
||||
|
||||
@Override
|
||||
public void generatedFile(String fileName, int count, int total) {
|
||||
message(fileName);
|
||||
}
|
||||
@Override
|
||||
public void message(String msg) {
|
||||
if(status!=null)
|
||||
status.println(msg);
|
||||
}
|
||||
|
||||
public void error(SAXParseException exception) {
|
||||
cer.error(exception);
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException exception) {
|
||||
cer.fatalError(exception);
|
||||
}
|
||||
|
||||
public void warning(SAXParseException exception) {
|
||||
cer.warning(exception);
|
||||
}
|
||||
|
||||
public void info(SAXParseException exception) {
|
||||
cer.info(exception);
|
||||
}
|
||||
}
|
||||
|
||||
return run(args,new Listener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs schema compilation and prints the status/error into the
|
||||
* specified PrintStream.
|
||||
*
|
||||
* <p>
|
||||
* This method could be used to trigger XJC from other tools,
|
||||
* such as Ant or IDE.
|
||||
*
|
||||
* @param args
|
||||
* specified command line parameters. If there is an error
|
||||
* in the parameters, {@link BadCommandLineException} will
|
||||
* be thrown.
|
||||
* @param listener
|
||||
* Receives messages from XJC reporting progress/errors.
|
||||
*
|
||||
* @return
|
||||
* If the compiler runs successfully, this method returns 0.
|
||||
* All non-zero values indicate an error. The error message
|
||||
* will be sent to the specified PrintStream.
|
||||
*/
|
||||
public static int run(String[] args, @NotNull final XJCListener listener) throws BadCommandLineException {
|
||||
|
||||
// recognize those special options before we start parsing options.
|
||||
for (String arg : args) {
|
||||
if (arg.equals("-version")) {
|
||||
listener.message(Messages.format(Messages.VERSION));
|
||||
return -1;
|
||||
}
|
||||
if (arg.equals("-fullversion")) {
|
||||
listener.message(Messages.format(Messages.FULLVERSION));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
final OptionsEx opt = new OptionsEx();
|
||||
opt.setSchemaLanguage(Language.XMLSCHEMA); // disable auto-guessing
|
||||
try {
|
||||
opt.parseArguments(args);
|
||||
} catch (WeAreDone e) {
|
||||
if (opt.proxyAuth != null) {
|
||||
DefaultAuthenticator.reset();
|
||||
}
|
||||
return -1;
|
||||
} catch(BadCommandLineException e) {
|
||||
if (opt.proxyAuth != null) {
|
||||
DefaultAuthenticator.reset();
|
||||
}
|
||||
e.initOptions(opt);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// display a warning if the user specified the default package
|
||||
// this should work, but is generally a bad idea
|
||||
if(opt.defaultPackage != null && opt.defaultPackage.length()==0) {
|
||||
listener.message(Messages.format(Messages.WARNING_MSG, Messages.format(Messages.DEFAULT_PACKAGE_WARNING)));
|
||||
}
|
||||
|
||||
|
||||
// set up the context class loader so that the user-specified classes
|
||||
// can be loaded from there
|
||||
final ClassLoader contextClassLoader = SecureLoader.getContextClassLoader();
|
||||
SecureLoader.setContextClassLoader(opt.getUserClassLoader(contextClassLoader));
|
||||
|
||||
// parse a grammar file
|
||||
//-----------------------------------------
|
||||
try {
|
||||
if( !opt.quiet ) {
|
||||
listener.message(Messages.format(Messages.PARSING_SCHEMA));
|
||||
}
|
||||
|
||||
final boolean[] hadWarning = new boolean[1];
|
||||
|
||||
ErrorReceiver receiver = new ErrorReceiverFilter(listener) {
|
||||
@Override
|
||||
public void info(SAXParseException exception) {
|
||||
if(opt.verbose)
|
||||
super.info(exception);
|
||||
}
|
||||
@Override
|
||||
public void warning(SAXParseException exception) {
|
||||
hadWarning[0] = true;
|
||||
if(!opt.quiet)
|
||||
super.warning(exception);
|
||||
}
|
||||
@Override
|
||||
public void pollAbort() throws AbortException {
|
||||
if(listener.isCanceled())
|
||||
throw new AbortException();
|
||||
}
|
||||
};
|
||||
|
||||
if( opt.mode==Mode.FOREST ) {
|
||||
// dump DOM forest and quit
|
||||
ModelLoader loader = new ModelLoader( opt, new JCodeModel(), receiver );
|
||||
try {
|
||||
DOMForest forest = loader.buildDOMForest(new XMLSchemaInternalizationLogic());
|
||||
forest.dump(System.out);
|
||||
return 0;
|
||||
} catch (SAXException e) {
|
||||
// the error should have already been reported
|
||||
} catch (IOException e) {
|
||||
receiver.error(e);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( opt.mode==Mode.GBIND ) {
|
||||
try {
|
||||
XSSchemaSet xss = new ModelLoader(opt, new JCodeModel(), receiver).loadXMLSchema();
|
||||
Iterator<XSComplexType> it = xss.iterateComplexTypes();
|
||||
while (it.hasNext()) {
|
||||
XSComplexType ct = it.next();
|
||||
XSParticle p = ct.getContentType().asParticle();
|
||||
if(p==null) continue;
|
||||
|
||||
Expression tree = ExpressionBuilder.createTree(p);
|
||||
System.out.println("Graph for "+ct.getName());
|
||||
System.out.println(tree.toString());
|
||||
Graph g = new Graph(tree);
|
||||
System.out.println(g.toString());
|
||||
System.out.println();
|
||||
}
|
||||
return 0;
|
||||
} catch (SAXException e) {
|
||||
// the error should have already been reported
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Model model = ModelLoader.load( opt, new JCodeModel(), receiver );
|
||||
|
||||
if (model == null) {
|
||||
listener.message(Messages.format(Messages.PARSE_FAILED));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( !opt.quiet ) {
|
||||
listener.message(Messages.format(Messages.COMPILING_SCHEMA));
|
||||
}
|
||||
|
||||
switch (opt.mode) {
|
||||
case SIGNATURE :
|
||||
try {
|
||||
SignatureWriter.write(
|
||||
BeanGenerator.generate(model,receiver),
|
||||
new OutputStreamWriter(System.out));
|
||||
return 0;
|
||||
} catch (IOException e) {
|
||||
receiver.error(e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
case CODE :
|
||||
case DRYRUN :
|
||||
case ZIP :
|
||||
{
|
||||
// generate actual code
|
||||
receiver.debug("generating code");
|
||||
{// don't want to hold outline in memory for too long.
|
||||
Outline outline = model.generateCode(opt,receiver);
|
||||
if(outline==null) {
|
||||
listener.message(
|
||||
Messages.format(Messages.FAILED_TO_GENERATE_CODE));
|
||||
return -1;
|
||||
}
|
||||
|
||||
listener.compiled(outline);
|
||||
}
|
||||
|
||||
if( opt.mode == Mode.DRYRUN )
|
||||
break; // enough
|
||||
|
||||
// then print them out
|
||||
try {
|
||||
CodeWriter cw;
|
||||
if( opt.mode==Mode.ZIP ) {
|
||||
OutputStream os;
|
||||
if(opt.targetDir.getPath().equals("."))
|
||||
os = System.out;
|
||||
else
|
||||
os = new FileOutputStream(opt.targetDir);
|
||||
|
||||
cw = opt.createCodeWriter(new ZipCodeWriter(os));
|
||||
} else
|
||||
cw = opt.createCodeWriter();
|
||||
|
||||
if( !opt.quiet ) {
|
||||
cw = new ProgressCodeWriter(cw,listener, model.codeModel.countArtifacts());
|
||||
}
|
||||
model.codeModel.build(cw);
|
||||
} catch (IOException e) {
|
||||
receiver.error(e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default :
|
||||
assert false;
|
||||
}
|
||||
|
||||
if(opt.debugMode) {
|
||||
try {
|
||||
new FileOutputStream(new File(opt.targetDir,hadWarning[0]?"hadWarning":"noWarning")).close();
|
||||
} catch (IOException e) {
|
||||
receiver.error(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
} catch( StackOverflowError e ) {
|
||||
if(opt.verbose)
|
||||
// in the debug mode, propagate the error so that
|
||||
// the full stack trace will be dumped to the screen.
|
||||
throw e;
|
||||
else {
|
||||
// otherwise just print a suggested workaround and
|
||||
// quit without filling the user's screen
|
||||
listener.message(Messages.format(Messages.STACK_OVERFLOW));
|
||||
return -1;
|
||||
}
|
||||
} finally {
|
||||
if (opt.proxyAuth != null) {
|
||||
DefaultAuthenticator.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getBuildID() {
|
||||
return Messages.format(Messages.BUILD_ID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Operation mode.
|
||||
*/
|
||||
private static enum Mode {
|
||||
// normal mode. compile the code
|
||||
CODE,
|
||||
|
||||
// dump the signature of the generated code
|
||||
SIGNATURE,
|
||||
|
||||
// dump DOMForest
|
||||
FOREST,
|
||||
|
||||
// same as CODE but don't produce any Java source code
|
||||
DRYRUN,
|
||||
|
||||
// same as CODE but pack all the outputs into a zip and dumps to stdout
|
||||
ZIP,
|
||||
|
||||
// testing a new binding mode
|
||||
GBIND
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Command-line arguments processor.
|
||||
*
|
||||
* <p>
|
||||
* This class contains options that only make sense
|
||||
* for the command line interface.
|
||||
*/
|
||||
static class OptionsEx extends Options
|
||||
{
|
||||
/** Operation mode. */
|
||||
protected Mode mode = Mode.CODE;
|
||||
|
||||
/** A switch that determines the behavior in the BGM mode. */
|
||||
public boolean noNS = false;
|
||||
|
||||
/** Parse XJC-specific options. */
|
||||
@Override
|
||||
public int parseArgument(String[] args, int i) throws BadCommandLineException {
|
||||
if (args[i].equals("-noNS")) {
|
||||
noNS = true;
|
||||
return 1;
|
||||
}
|
||||
if (args[i].equals("-mode")) {
|
||||
i++;
|
||||
if (i == args.length)
|
||||
throw new BadCommandLineException(
|
||||
Messages.format(Messages.MISSING_MODE_OPERAND));
|
||||
|
||||
String mstr = args[i].toLowerCase();
|
||||
|
||||
for( Mode m : Mode.values() ) {
|
||||
if(m.name().toLowerCase().startsWith(mstr) && mstr.length()>2) {
|
||||
mode = m;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
throw new BadCommandLineException(
|
||||
Messages.format(Messages.UNRECOGNIZED_MODE, args[i]));
|
||||
}
|
||||
if (args[i].equals("-help")) {
|
||||
usage(this,false);
|
||||
throw new WeAreDone();
|
||||
}
|
||||
if (args[i].equals("-private")) {
|
||||
usage(this,true);
|
||||
throw new WeAreDone();
|
||||
}
|
||||
|
||||
return super.parseArgument(args, i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to signal that we've finished processing.
|
||||
*/
|
||||
private static final class WeAreDone extends BadCommandLineException {}
|
||||
|
||||
|
||||
/**
|
||||
* Prints the usage screen and exits the process.
|
||||
*
|
||||
* @param opts
|
||||
* If the parsing of options have started, set a partly populated
|
||||
* {@link Options} object.
|
||||
*/
|
||||
public static void usage( @Nullable Options opts, boolean privateUsage ) {
|
||||
System.out.println(Messages.format(Messages.DRIVER_PUBLIC_USAGE));
|
||||
if (privateUsage) {
|
||||
System.out.println(Messages.format(Messages.DRIVER_PRIVATE_USAGE));
|
||||
}
|
||||
|
||||
if( opts!=null && !opts.getAllPlugins().isEmpty()) {
|
||||
System.out.println(Messages.format(Messages.ADDON_USAGE));
|
||||
for (Plugin p : opts.getAllPlugins()) {
|
||||
System.out.println(p.getUsage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
172
jdkSrc/jdk8/com/sun/tools/internal/xjc/ErrorReceiver.java
Normal file
172
jdkSrc/jdk8/com/sun/tools/internal/xjc/ErrorReceiver.java
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use is subject to the license terms.
|
||||
*/
|
||||
package com.sun.tools.internal.xjc;
|
||||
|
||||
import com.sun.istack.internal.SAXParseException2;
|
||||
import com.sun.tools.internal.xjc.api.ErrorListener;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* Implemented by the driver of the compiler engine to handle
|
||||
* errors found during the compiliation.
|
||||
*
|
||||
* <p>
|
||||
* This class implements {@link ErrorHandler} so it can be
|
||||
* passed to anywhere where {@link ErrorHandler} is expected.
|
||||
*
|
||||
* <p>
|
||||
* However, to make the error handling easy (and make it work
|
||||
* with visitor patterns nicely),
|
||||
* none of the methods on thi class throws {@link org.xml.sax.SAXException}.
|
||||
* Instead, when the compilation needs to be aborted,
|
||||
* it throws {@link AbortException}, which is unchecked.
|
||||
*
|
||||
* <p>
|
||||
* This also implements the externally visible {@link ErrorListener}
|
||||
* so that we can reuse our internal implementation for testing and such.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public abstract class ErrorReceiver implements ErrorHandler, ErrorListener {
|
||||
|
||||
//
|
||||
//
|
||||
// convenience methods for callers
|
||||
//
|
||||
//
|
||||
/**
|
||||
* @param loc
|
||||
* can be null if the location is unknown
|
||||
*/
|
||||
public final void error( Locator loc, String msg ) {
|
||||
error( new SAXParseException2(msg,loc) );
|
||||
}
|
||||
|
||||
public final void error( Locator loc, String msg, Exception e ) {
|
||||
error( new SAXParseException2(msg,loc,e) );
|
||||
}
|
||||
|
||||
public final void error( String msg, Exception e ) {
|
||||
error( new SAXParseException2(msg,null,e) );
|
||||
}
|
||||
|
||||
public void error(Exception e) {
|
||||
error(e.getMessage(),e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param loc
|
||||
* can be null if the location is unknown
|
||||
*/
|
||||
public final void warning( Locator loc, String msg ) {
|
||||
warning( new SAXParseException(msg,loc) );
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// ErrorHandler implementation, but can't throw SAXException
|
||||
//
|
||||
//
|
||||
public abstract void error(SAXParseException exception) throws AbortException;
|
||||
public abstract void fatalError(SAXParseException exception) throws AbortException;
|
||||
public abstract void warning(SAXParseException exception) throws AbortException;
|
||||
|
||||
/**
|
||||
* This method will be invoked periodically to allow {@link AbortException}
|
||||
* to be thrown, especially when this is driven by some kind of GUI.
|
||||
*/
|
||||
public void pollAbort() throws AbortException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports verbose messages to users.
|
||||
*
|
||||
* This method can be used to report additional non-essential
|
||||
* messages. The implementation usually discards them
|
||||
* unless some specific debug option is turned on.
|
||||
*/
|
||||
public abstract void info(SAXParseException exception) /*REVISIT:throws AbortException*/;
|
||||
|
||||
/**
|
||||
* Reports a debug message to users.
|
||||
*
|
||||
* @see #info(SAXParseException)
|
||||
*/
|
||||
public final void debug( String msg ) {
|
||||
info( new SAXParseException(msg,null) );
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// convenience methods for derived classes
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the human readable string representation of the
|
||||
* {@link org.xml.sax.Locator} part of the specified
|
||||
* {@link SAXParseException}.
|
||||
*
|
||||
* @return non-null valid object.
|
||||
*/
|
||||
protected final String getLocationString( SAXParseException e ) {
|
||||
if(e.getLineNumber()!=-1 || e.getSystemId()!=null) {
|
||||
int line = e.getLineNumber();
|
||||
return Messages.format( Messages.LINE_X_OF_Y,
|
||||
line==-1?"?":Integer.toString( line ),
|
||||
getShortName( e.getSystemId() ) );
|
||||
} else {
|
||||
return Messages.format( Messages.UNKNOWN_LOCATION );
|
||||
}
|
||||
}
|
||||
|
||||
/** Computes a short name of a given URL for display. */
|
||||
private String getShortName( String url ) {
|
||||
if(url==null)
|
||||
return Messages.format( Messages.UNKNOWN_FILE );
|
||||
|
||||
// sometimes the user deals with a set of schems that reference each other
|
||||
// in a complicated way, and end up importing two versions of the same schema.
|
||||
// just printing the file name makes it very difficult to recognize of this problem.
|
||||
// so I decided to change it back to print the full URL.
|
||||
|
||||
// int idx;
|
||||
//
|
||||
// // system Id can be URL, so we can't use File.separator
|
||||
// idx = url.lastIndexOf('/');
|
||||
// if(idx!=-1) return url.substring(idx+1);
|
||||
// idx = url.lastIndexOf('\\');
|
||||
// if(idx!=-1) return url.substring(idx+1);
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
37
jdkSrc/jdk8/com/sun/tools/internal/xjc/Language.java
Normal file
37
jdkSrc/jdk8/com/sun/tools/internal/xjc/Language.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
/**
|
||||
* Type of the schema language.
|
||||
*/
|
||||
public enum Language {
|
||||
DTD,
|
||||
XMLSCHEMA,
|
||||
RELAXNG,
|
||||
RELAXNG_COMPACT,
|
||||
WSDL
|
||||
}
|
||||
195
jdkSrc/jdk8/com/sun/tools/internal/xjc/Messages.java
Normal file
195
jdkSrc/jdk8/com/sun/tools/internal/xjc/Messages.java
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Formats error messages.
|
||||
*/
|
||||
public class Messages
|
||||
{
|
||||
/** Loads a string resource and formats it with specified arguments. */
|
||||
public static String format( String property, Object... args ) {
|
||||
String text = ResourceBundle.getBundle(Messages.class.getPackage().getName() +".MessageBundle").getString(property);
|
||||
return MessageFormat.format(text,args);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// Message resources
|
||||
//
|
||||
//
|
||||
static final String UNKNOWN_LOCATION = // 0 args
|
||||
"ConsoleErrorReporter.UnknownLocation";
|
||||
|
||||
static final String LINE_X_OF_Y = // 2 args
|
||||
"ConsoleErrorReporter.LineXOfY";
|
||||
|
||||
static final String UNKNOWN_FILE = // 0 args
|
||||
"ConsoleErrorReporter.UnknownFile";
|
||||
|
||||
static final String DRIVER_PUBLIC_USAGE = // 0 args
|
||||
"Driver.Public.Usage";
|
||||
|
||||
static final String DRIVER_PRIVATE_USAGE = // 0 args
|
||||
"Driver.Private.Usage";
|
||||
|
||||
static final String ADDON_USAGE = // 0 args
|
||||
"Driver.AddonUsage";
|
||||
|
||||
static final String EXPERIMENTAL_LANGUAGE_WARNING = // 2 arg
|
||||
"Driver.ExperimentalLanguageWarning";
|
||||
|
||||
static final String NON_EXISTENT_DIR = // 1 arg
|
||||
"Driver.NonExistentDir";
|
||||
|
||||
// Usage not found. TODO Remove
|
||||
// static final String MISSING_RUNTIME_PACKAGENAME = // 0 args
|
||||
// "Driver.MissingRuntimePackageName";
|
||||
|
||||
static final String MISSING_MODE_OPERAND = // 0 args
|
||||
"Driver.MissingModeOperand";
|
||||
|
||||
// Usage not found. TODO Remove
|
||||
// static final String MISSING_COMPATIBILITY_OPERAND = // 0 args
|
||||
// "Driver.MissingCompatibilityOperand";
|
||||
|
||||
static final String MISSING_PROXY = // 0 args
|
||||
"Driver.MISSING_PROXY";
|
||||
|
||||
static final String MISSING_PROXYFILE = // 0 args
|
||||
"Driver.MISSING_PROXYFILE";
|
||||
|
||||
static final String NO_SUCH_FILE = // 1 arg
|
||||
"Driver.NO_SUCH_FILE";
|
||||
|
||||
static final String ILLEGAL_PROXY = // 1 arg
|
||||
"Driver.ILLEGAL_PROXY";
|
||||
|
||||
static final String ILLEGAL_TARGET_VERSION = // 1 arg
|
||||
"Driver.ILLEGAL_TARGET_VERSION";
|
||||
|
||||
static final String MISSING_OPERAND = // 1 arg
|
||||
"Driver.MissingOperand";
|
||||
|
||||
static final String MISSING_PROXYHOST = // 0 args
|
||||
"Driver.MissingProxyHost";
|
||||
|
||||
static final String MISSING_PROXYPORT = // 0 args
|
||||
"Driver.MissingProxyPort";
|
||||
|
||||
static final String STACK_OVERFLOW = // 0 arg
|
||||
"Driver.StackOverflow";
|
||||
|
||||
static final String UNRECOGNIZED_MODE = // 1 arg
|
||||
"Driver.UnrecognizedMode";
|
||||
|
||||
static final String UNRECOGNIZED_PARAMETER = // 1 arg
|
||||
"Driver.UnrecognizedParameter";
|
||||
|
||||
static final String UNSUPPORTED_ENCODING = // 1 arg
|
||||
"Driver.UnsupportedEncoding";
|
||||
|
||||
static final String MISSING_GRAMMAR = // 0 args
|
||||
"Driver.MissingGrammar";
|
||||
|
||||
static final String PARSING_SCHEMA = // 0 args
|
||||
"Driver.ParsingSchema";
|
||||
|
||||
static final String PARSE_FAILED = // 0 args
|
||||
"Driver.ParseFailed";
|
||||
|
||||
static final String COMPILING_SCHEMA = // 0 args
|
||||
"Driver.CompilingSchema";
|
||||
|
||||
static final String FAILED_TO_GENERATE_CODE = // 0 args
|
||||
"Driver.FailedToGenerateCode";
|
||||
|
||||
static final String FILE_PROLOG_COMMENT = // 1 arg
|
||||
"Driver.FilePrologComment";
|
||||
|
||||
static final String DATE_FORMAT = // 0 args
|
||||
"Driver.DateFormat";
|
||||
|
||||
static final String TIME_FORMAT = // 0 args
|
||||
"Driver.TimeFormat";
|
||||
|
||||
static final String AT = // 0 args
|
||||
"Driver.At";
|
||||
|
||||
static final String VERSION = // 0 args
|
||||
"Driver.Version";
|
||||
|
||||
static final String FULLVERSION = // 0 args
|
||||
"Driver.FullVersion";
|
||||
|
||||
static final String BUILD_ID = // 0 args
|
||||
"Driver.BuildID";
|
||||
|
||||
static final String ERROR_MSG = // 1:arg
|
||||
"Driver.ErrorMessage";
|
||||
|
||||
static final String WARNING_MSG = // 1:arg
|
||||
"Driver.WarningMessage";
|
||||
|
||||
static final String INFO_MSG = // 1:arg
|
||||
"Driver.InfoMessage";
|
||||
|
||||
static final String ERR_NOT_A_BINDING_FILE = // 2 arg
|
||||
"Driver.NotABindingFile";
|
||||
|
||||
static final String ERR_TOO_MANY_SCHEMA = // 0 args
|
||||
"ModelLoader.TooManySchema";
|
||||
|
||||
static final String ERR_BINDING_FILE_NOT_SUPPORTED_FOR_RNC = // 0 args
|
||||
"ModelLoader.BindingFileNotSupportedForRNC";
|
||||
|
||||
static final String DEFAULT_VERSION = // 0 args
|
||||
"Driver.DefaultVersion";
|
||||
|
||||
static final String DEFAULT_PACKAGE_WARNING = // 0 args
|
||||
"Driver.DefaultPackageWarning";
|
||||
|
||||
static final String NOT_A_VALID_FILENAME = // 2 args
|
||||
"Driver.NotAValidFileName";
|
||||
static final String FAILED_TO_PARSE = // 2 args
|
||||
"Driver.FailedToParse";
|
||||
static final String NOT_A_FILE_NOR_URL = // 1 arg
|
||||
"Driver.NotAFileNorURL";
|
||||
|
||||
static final String FIELD_RENDERER_CONFLICT = // 2 args
|
||||
"FIELD_RENDERER_CONFLICT";
|
||||
|
||||
static final String NAME_CONVERTER_CONFLICT = // 2 args
|
||||
"NAME_CONVERTER_CONFLICT";
|
||||
static final String FAILED_TO_LOAD = // 2 args
|
||||
"FAILED_TO_LOAD";
|
||||
|
||||
static final String PLUGIN_LOAD_FAILURE = // 1 arg
|
||||
"PLUGIN_LOAD_FAILURE";
|
||||
}
|
||||
598
jdkSrc/jdk8/com/sun/tools/internal/xjc/ModelLoader.java
Normal file
598
jdkSrc/jdk8/com/sun/tools/internal/xjc/ModelLoader.java
Normal file
@@ -0,0 +1,598 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.reader.Const;
|
||||
import com.sun.tools.internal.xjc.reader.ExtensionBindingChecker;
|
||||
import com.sun.tools.internal.xjc.reader.dtd.TDTDReader;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.DOMForest;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.InternalizationLogic;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.SCDBasedBindingSet;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.VersionChecker;
|
||||
import com.sun.tools.internal.xjc.reader.relaxng.RELAXNGCompiler;
|
||||
import com.sun.tools.internal.xjc.reader.relaxng.RELAXNGInternalizationLogic;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.parser.XMLSchemaInternalizationLogic;
|
||||
import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
|
||||
import com.sun.xml.internal.bind.v2.util.XmlFactory;
|
||||
import com.sun.xml.internal.xsom.XSSchemaSet;
|
||||
import com.sun.xml.internal.xsom.parser.JAXPParser;
|
||||
import com.sun.xml.internal.xsom.parser.XMLParser;
|
||||
import com.sun.xml.internal.xsom.parser.XSOMParser;
|
||||
import javax.xml.XMLConstants;
|
||||
|
||||
import com.sun.xml.internal.rngom.ast.builder.SchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.ast.util.CheckingSchemaBuilder;
|
||||
import com.sun.xml.internal.rngom.digested.DPattern;
|
||||
import com.sun.xml.internal.rngom.digested.DSchemaBuilderImpl;
|
||||
import com.sun.xml.internal.rngom.parse.IllegalSchemaException;
|
||||
import com.sun.xml.internal.rngom.parse.Parseable;
|
||||
import com.sun.xml.internal.rngom.parse.compact.CompactParseable;
|
||||
import com.sun.xml.internal.rngom.parse.xml.SAXParseable;
|
||||
import com.sun.xml.internal.rngom.xml.sax.XMLReaderCreator;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.XMLFilter;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
|
||||
/**
|
||||
* Builds a {@link Model} object.
|
||||
*
|
||||
* This is an utility class that makes it easy to load a grammar object
|
||||
* from various sources.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class ModelLoader {
|
||||
|
||||
private final Options opt;
|
||||
private final ErrorReceiverFilter errorReceiver;
|
||||
private final JCodeModel codeModel;
|
||||
/**
|
||||
* {@link DOMForest#transform(boolean)} creates this on the side.
|
||||
*/
|
||||
private SCDBasedBindingSet scdBasedBindingSet;
|
||||
|
||||
|
||||
/**
|
||||
* A convenience method to load schemas into a {@link Model}.
|
||||
*/
|
||||
public static Model load( Options opt, JCodeModel codeModel, ErrorReceiver er ) {
|
||||
return new ModelLoader(opt,codeModel,er).load();
|
||||
}
|
||||
|
||||
|
||||
public ModelLoader(Options _opt, JCodeModel _codeModel, ErrorReceiver er) {
|
||||
this.opt = _opt;
|
||||
this.codeModel = _codeModel;
|
||||
this.errorReceiver = new ErrorReceiverFilter(er);
|
||||
}
|
||||
|
||||
@SuppressWarnings("CallToThreadDumpStack")
|
||||
private Model load() {
|
||||
Model grammar;
|
||||
|
||||
if(!sanityCheck())
|
||||
return null;
|
||||
|
||||
|
||||
try {
|
||||
switch (opt.getSchemaLanguage()) {
|
||||
case DTD :
|
||||
// TODO: make sure that bindFiles,size()<=1
|
||||
InputSource bindFile = null;
|
||||
if (opt.getBindFiles().length > 0)
|
||||
bindFile = opt.getBindFiles()[0];
|
||||
// if there is no binding file, make a dummy one.
|
||||
if (bindFile == null) {
|
||||
// if no binding information is specified, provide a default
|
||||
bindFile =
|
||||
new InputSource(
|
||||
new StringReader(
|
||||
"<?xml version='1.0'?><xml-java-binding-schema><options package='"
|
||||
+ (opt.defaultPackage==null?"generated":opt.defaultPackage)
|
||||
+ "'/></xml-java-binding-schema>"));
|
||||
}
|
||||
|
||||
checkTooManySchemaErrors();
|
||||
grammar = loadDTD(opt.getGrammars()[0], bindFile );
|
||||
break;
|
||||
|
||||
case RELAXNG :
|
||||
checkTooManySchemaErrors();
|
||||
grammar = loadRELAXNG();
|
||||
break;
|
||||
|
||||
case RELAXNG_COMPACT :
|
||||
checkTooManySchemaErrors();
|
||||
grammar = loadRELAXNGCompact();
|
||||
break;
|
||||
|
||||
case WSDL:
|
||||
grammar = annotateXMLSchema( loadWSDL() );
|
||||
break;
|
||||
|
||||
case XMLSCHEMA:
|
||||
grammar = annotateXMLSchema( loadXMLSchema() );
|
||||
break;
|
||||
|
||||
default :
|
||||
throw new AssertionError(); // assertion failed
|
||||
}
|
||||
|
||||
if (errorReceiver.hadError()) {
|
||||
grammar = null;
|
||||
} else {
|
||||
grammar.setPackageLevelAnnotations(opt.packageLevelAnnotations);
|
||||
}
|
||||
|
||||
return grammar;
|
||||
|
||||
} catch (SAXException e) {
|
||||
// parsing error in the input document.
|
||||
// this error must have been reported to the user vis error handler
|
||||
// so don't print it again.
|
||||
if (opt.verbose) {
|
||||
// however, a bug in XJC might throw unexpected SAXException.
|
||||
// thus when one is debugging, it is useful to print what went
|
||||
// wrong.
|
||||
if (e.getException() != null)
|
||||
e.getException().printStackTrace();
|
||||
else
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
} catch (AbortException e) {
|
||||
// error should have been reported already, since this is requested by the error receiver
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Do some extra checking and return false if the compilation
|
||||
* should abort.
|
||||
*/
|
||||
private boolean sanityCheck() {
|
||||
if( opt.getSchemaLanguage()==Language.XMLSCHEMA ) {
|
||||
Language guess = opt.guessSchemaLanguage();
|
||||
|
||||
String[] msg = null;
|
||||
switch(guess) {
|
||||
case DTD:
|
||||
msg = new String[]{"DTD","-dtd"};
|
||||
break;
|
||||
case RELAXNG:
|
||||
msg = new String[]{"RELAX NG","-relaxng"};
|
||||
break;
|
||||
case RELAXNG_COMPACT:
|
||||
msg = new String[]{"RELAX NG compact syntax","-relaxng-compact"};
|
||||
break;
|
||||
case WSDL:
|
||||
msg = new String[]{"WSDL","-wsdl"};
|
||||
break;
|
||||
}
|
||||
if( msg!=null )
|
||||
errorReceiver.warning( null,
|
||||
Messages.format(
|
||||
Messages.EXPERIMENTAL_LANGUAGE_WARNING,
|
||||
msg[0], msg[1] ));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link XMLParser} implementation that adds additional processors into the chain.
|
||||
*
|
||||
* <p>
|
||||
* This parser will parse a DOM forest as:
|
||||
* DOMForestParser -->
|
||||
* ExtensionBindingChecker -->
|
||||
* ProhibitedFeatureFilter -->
|
||||
* XSOMParser
|
||||
*/
|
||||
private class XMLSchemaParser implements XMLParser {
|
||||
private final XMLParser baseParser;
|
||||
|
||||
private XMLSchemaParser(XMLParser baseParser) {
|
||||
this.baseParser = baseParser;
|
||||
}
|
||||
|
||||
public void parse(InputSource source, ContentHandler handler,
|
||||
ErrorHandler errorHandler, EntityResolver entityResolver ) throws SAXException, IOException {
|
||||
// set up the chain of handlers.
|
||||
handler = wrapBy( new ExtensionBindingChecker(XMLConstants.W3C_XML_SCHEMA_NS_URI,opt,errorReceiver), handler );
|
||||
handler = wrapBy( new IncorrectNamespaceURIChecker(errorReceiver), handler );
|
||||
handler = wrapBy( new CustomizationContextChecker(errorReceiver), handler );
|
||||
// handler = wrapBy( new VersionChecker(controller), handler );
|
||||
|
||||
baseParser.parse( source, handler, errorHandler, entityResolver );
|
||||
}
|
||||
/**
|
||||
* Wraps the specified content handler by a filter.
|
||||
* It is little awkward to use a helper implementation class like XMLFilterImpl
|
||||
* as the method parameter, but this simplifies the code.
|
||||
*/
|
||||
private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) {
|
||||
filter.setContentHandler(handler);
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkTooManySchemaErrors() {
|
||||
if( opt.getGrammars().length!=1 )
|
||||
errorReceiver.error(null,Messages.format(Messages.ERR_TOO_MANY_SCHEMA));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a DTD file into an annotated grammar.
|
||||
*
|
||||
* @param source
|
||||
* DTD file
|
||||
* @param bindFile
|
||||
* External binding file.
|
||||
*/
|
||||
private Model loadDTD( InputSource source, InputSource bindFile) {
|
||||
|
||||
// parse the schema as a DTD.
|
||||
return TDTDReader.parse(
|
||||
source,
|
||||
bindFile,
|
||||
errorReceiver,
|
||||
opt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds DOMForest and performs the internalization.
|
||||
*
|
||||
* @throws SAXException
|
||||
* when a fatal error happens
|
||||
*/
|
||||
public DOMForest buildDOMForest( InternalizationLogic logic )
|
||||
throws SAXException {
|
||||
|
||||
// parse into DOM forest
|
||||
DOMForest forest = new DOMForest(logic, opt);
|
||||
|
||||
forest.setErrorHandler(errorReceiver);
|
||||
if(opt.entityResolver!=null)
|
||||
forest.setEntityResolver(opt.entityResolver);
|
||||
|
||||
// parse source grammars
|
||||
for (InputSource value : opt.getGrammars()) {
|
||||
errorReceiver.pollAbort();
|
||||
forest.parse(value, true);
|
||||
}
|
||||
|
||||
// parse external binding files
|
||||
for (InputSource value : opt.getBindFiles()) {
|
||||
errorReceiver.pollAbort();
|
||||
Document dom = forest.parse(value, true);
|
||||
if(dom==null) continue; // error must have been reported
|
||||
Element root = dom.getDocumentElement();
|
||||
// TODO: it somehow doesn't feel right to do a validation in the Driver class.
|
||||
// think about moving it to somewhere else.
|
||||
if (!fixNull(root.getNamespaceURI()).equals(Const.JAXB_NSURI)
|
||||
|| !root.getLocalName().equals("bindings"))
|
||||
errorReceiver.error(new SAXParseException(Messages.format(Messages.ERR_NOT_A_BINDING_FILE,
|
||||
root.getNamespaceURI(),
|
||||
root.getLocalName()),
|
||||
null,
|
||||
value.getSystemId(),
|
||||
-1, -1));
|
||||
}
|
||||
|
||||
scdBasedBindingSet = forest.transform(opt.isExtensionMode());
|
||||
|
||||
return forest;
|
||||
}
|
||||
|
||||
private String fixNull(String s) {
|
||||
if(s==null) return "";
|
||||
else return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a set of XML Schema files into an annotated grammar.
|
||||
*/
|
||||
public XSSchemaSet loadXMLSchema() throws SAXException {
|
||||
|
||||
if( opt.strictCheck && !SchemaConstraintChecker.check(opt.getGrammars(),errorReceiver,opt.entityResolver, opt.disableXmlSecurity)) {
|
||||
// schema error. error should have been reported
|
||||
return null;
|
||||
}
|
||||
|
||||
if(opt.getBindFiles().length==0) {
|
||||
// no external binding. try the speculative no DOMForest execution,
|
||||
// which is faster if the speculation succeeds.
|
||||
try {
|
||||
return createXSOMSpeculative();
|
||||
} catch( SpeculationFailure e) {
|
||||
// failed. go the slow way
|
||||
}
|
||||
}
|
||||
|
||||
// the default slower way is to parse everything into DOM first.
|
||||
// so that we can take external annotations into account.
|
||||
DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
|
||||
return createXSOM(forest, scdBasedBindingSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a set of schemas inside a WSDL file.
|
||||
*
|
||||
* A WSDL file may contain multiple <xsd:schema> elements.
|
||||
*/
|
||||
private XSSchemaSet loadWSDL()
|
||||
throws SAXException {
|
||||
|
||||
|
||||
// build DOMForest just like we handle XML Schema
|
||||
DOMForest forest = buildDOMForest( new XMLSchemaInternalizationLogic() );
|
||||
|
||||
DOMForestScanner scanner = new DOMForestScanner(forest);
|
||||
|
||||
XSOMParser xsomParser = createXSOMParser( forest );
|
||||
|
||||
// find <xsd:schema>s and parse them individually
|
||||
for( InputSource grammar : opt.getGrammars() ) {
|
||||
Document wsdlDom = forest.get( grammar.getSystemId() );
|
||||
if (wsdlDom == null) {
|
||||
String systemId = Options.normalizeSystemId(grammar.getSystemId());
|
||||
if (forest.get(systemId) != null) {
|
||||
grammar.setSystemId(systemId);
|
||||
wsdlDom = forest.get( grammar.getSystemId() );
|
||||
}
|
||||
}
|
||||
|
||||
NodeList schemas = wsdlDom.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"schema");
|
||||
for( int i=0; i<schemas.getLength(); i++ )
|
||||
scanner.scan( (Element)schemas.item(i), xsomParser.getParserHandler() );
|
||||
}
|
||||
return xsomParser.getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotates the obtained schema set.
|
||||
*
|
||||
* @return
|
||||
* null if an error happens. In that case, the error messages
|
||||
* will be properly reported to the controller by this method.
|
||||
*/
|
||||
public Model annotateXMLSchema(XSSchemaSet xs) {
|
||||
if (xs == null)
|
||||
return null;
|
||||
return BGMBuilder.build(xs, codeModel, errorReceiver, opt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Potentially problematic - make sure the parser instance passed is initialized
|
||||
* with proper security feature.
|
||||
*
|
||||
* @param parser
|
||||
* @return
|
||||
*/
|
||||
public XSOMParser createXSOMParser(XMLParser parser) {
|
||||
// set up other parameters to XSOMParser
|
||||
XSOMParser reader = new XSOMParser(new XMLSchemaParser(parser));
|
||||
reader.setAnnotationParser(new AnnotationParserFactoryImpl(opt));
|
||||
reader.setErrorHandler(errorReceiver);
|
||||
reader.setEntityResolver(opt.entityResolver);
|
||||
return reader;
|
||||
}
|
||||
|
||||
public XSOMParser createXSOMParser(final DOMForest forest) {
|
||||
XSOMParser p = createXSOMParser(forest.createParser());
|
||||
p.setEntityResolver(new EntityResolver() {
|
||||
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
|
||||
// DOMForest only parses documents that are reachable through systemIds,
|
||||
// and it won't pick up references like <xs:import namespace="..." /> without
|
||||
// @schemaLocation. So we still need to use an entity resolver here to resolve
|
||||
// these references, yet we don't want to just run them blindly, since if we do that
|
||||
// DOMForestParser always get the translated system ID when catalog is used
|
||||
// (where DOMForest records trees with their original system IDs.)
|
||||
if(systemId!=null && forest.get(systemId)!=null)
|
||||
return new InputSource(systemId);
|
||||
if(opt.entityResolver!=null)
|
||||
return opt.entityResolver.resolveEntity(publicId,systemId);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
private static final class SpeculationFailure extends Error {}
|
||||
|
||||
private static final class SpeculationChecker extends XMLFilterImpl {
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if(localName.equals("bindings") && uri.equals(Const.JAXB_NSURI))
|
||||
throw new SpeculationFailure();
|
||||
super.startElement(uri,localName,qName,attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses schemas directly into XSOM by assuming that there's
|
||||
* no external annotations.
|
||||
* <p>
|
||||
* When an external annotation is found, a {@link SpeculationFailure} is thrown,
|
||||
* and we will do it all over again by using the slow way.
|
||||
*/
|
||||
private XSSchemaSet createXSOMSpeculative() throws SAXException, SpeculationFailure {
|
||||
|
||||
// check if the schema contains external binding files. If so, speculation is a failure.
|
||||
|
||||
XMLParser parser = new XMLParser() {
|
||||
private final JAXPParser base = new JAXPParser(XmlFactory.createParserFactory(opt.disableXmlSecurity));
|
||||
|
||||
public void parse(InputSource source, ContentHandler handler,
|
||||
ErrorHandler errorHandler, EntityResolver entityResolver ) throws SAXException, IOException {
|
||||
// set up the chain of handlers.
|
||||
handler = wrapBy( new SpeculationChecker(), handler );
|
||||
handler = wrapBy( new VersionChecker(null,errorReceiver,entityResolver), handler );
|
||||
|
||||
base.parse( source, handler, errorHandler, entityResolver );
|
||||
}
|
||||
/**
|
||||
* Wraps the specified content handler by a filter.
|
||||
* It is little awkward to use a helper implementation class like XMLFilterImpl
|
||||
* as the method parameter, but this simplifies the code.
|
||||
*/
|
||||
private ContentHandler wrapBy( XMLFilterImpl filter, ContentHandler handler ) {
|
||||
filter.setContentHandler(handler);
|
||||
return filter;
|
||||
}
|
||||
};
|
||||
|
||||
XSOMParser reader = createXSOMParser(parser);
|
||||
|
||||
// parse source grammars
|
||||
for (InputSource value : opt.getGrammars())
|
||||
reader.parse(value);
|
||||
|
||||
return reader.getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a {@link DOMForest} into a {@link XSSchemaSet}.
|
||||
*
|
||||
* @return
|
||||
* null if the parsing failed.
|
||||
*/
|
||||
public XSSchemaSet createXSOM(DOMForest forest, SCDBasedBindingSet scdBasedBindingSet) throws SAXException {
|
||||
// set up other parameters to XSOMParser
|
||||
XSOMParser reader = createXSOMParser(forest);
|
||||
|
||||
// re-parse the transformed schemas
|
||||
for (String systemId : forest.getRootDocuments()) {
|
||||
errorReceiver.pollAbort();
|
||||
Document dom = forest.get(systemId);
|
||||
if (!dom.getDocumentElement().getNamespaceURI().equals(Const.JAXB_NSURI)) {
|
||||
reader.parse(systemId);
|
||||
}
|
||||
}
|
||||
|
||||
XSSchemaSet result = reader.getResult();
|
||||
|
||||
if(result!=null)
|
||||
scdBasedBindingSet.apply(result,errorReceiver);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a RELAX NG grammar into an annotated grammar.
|
||||
*/
|
||||
private Model loadRELAXNG() throws SAXException {
|
||||
|
||||
// build DOM forest
|
||||
final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );
|
||||
|
||||
// use JAXP masquerading to validate the input document.
|
||||
// DOMForest -> ExtensionBindingChecker -> RNGOM
|
||||
|
||||
XMLReaderCreator xrc = new XMLReaderCreator() {
|
||||
public XMLReader createXMLReader() {
|
||||
|
||||
// foreset parser cannot change the receivers while it's working,
|
||||
// so we need to have one XMLFilter that works as a buffer
|
||||
XMLFilter buffer = new XMLFilterImpl() {
|
||||
@Override
|
||||
public void parse(InputSource source) throws IOException, SAXException {
|
||||
forest.createParser().parse( source, this, this, this );
|
||||
}
|
||||
};
|
||||
|
||||
XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
|
||||
f.setParent(buffer);
|
||||
|
||||
f.setEntityResolver(opt.entityResolver);
|
||||
|
||||
return f;
|
||||
}
|
||||
};
|
||||
|
||||
Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );
|
||||
|
||||
return loadRELAXNG(p);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads RELAX NG compact syntax
|
||||
*/
|
||||
private Model loadRELAXNGCompact() {
|
||||
if(opt.getBindFiles().length>0)
|
||||
errorReceiver.error(new SAXParseException(
|
||||
Messages.format(Messages.ERR_BINDING_FILE_NOT_SUPPORTED_FOR_RNC),null));
|
||||
|
||||
// TODO: entity resolver?
|
||||
Parseable p = new CompactParseable( opt.getGrammars()[0], errorReceiver );
|
||||
|
||||
return loadRELAXNG(p);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Common part between the XML syntax and the compact syntax.
|
||||
*/
|
||||
private Model loadRELAXNG(Parseable p) {
|
||||
SchemaBuilder sb = new CheckingSchemaBuilder(new DSchemaBuilderImpl(),errorReceiver);
|
||||
|
||||
try {
|
||||
DPattern out = (DPattern)p.parse(sb);
|
||||
return RELAXNGCompiler.build(out,codeModel,opt);
|
||||
} catch (IllegalSchemaException e) {
|
||||
errorReceiver.error(e.getMessage(),e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
1053
jdkSrc/jdk8/com/sun/tools/internal/xjc/Options.java
Normal file
1053
jdkSrc/jdk8/com/sun/tools/internal/xjc/Options.java
Normal file
File diff suppressed because it is too large
Load Diff
245
jdkSrc/jdk8/com/sun/tools/internal/xjc/Plugin.java
Normal file
245
jdkSrc/jdk8/com/sun/tools/internal/xjc/Plugin.java
Normal file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.tools.internal.xjc.generator.bean.field.FieldRendererFactory;
|
||||
import com.sun.tools.internal.xjc.model.CPluginCustomization;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Add-on that works on the generated source code.
|
||||
*
|
||||
* <p>
|
||||
* This add-on will be called after the default bean generation
|
||||
* has finished.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*
|
||||
* @since
|
||||
* JAXB RI 2.0 EA
|
||||
*/
|
||||
public abstract class Plugin {
|
||||
|
||||
/**
|
||||
* Gets the option name to turn on this add-on.
|
||||
*
|
||||
* <p>
|
||||
* For example, if "abc" is returned, "-abc" will
|
||||
* turn on this plugin. A plugin needs to be turned
|
||||
* on explicitly, or else no other methods of {@link Plugin}
|
||||
* will be invoked.
|
||||
*
|
||||
* <p>
|
||||
* Starting 2.1, when an option matches the name returned
|
||||
* from this method, XJC will then invoke {@link #parseArgument(Options, String[], int)},
|
||||
* allowing plugins to handle arguments to this option.
|
||||
*/
|
||||
public abstract String getOptionName();
|
||||
|
||||
/**
|
||||
* Gets the description of this add-on. Used to generate
|
||||
* a usage screen.
|
||||
*
|
||||
* @return
|
||||
* localized description message. should be terminated by \n.
|
||||
*/
|
||||
public abstract String getUsage();
|
||||
|
||||
/**
|
||||
* Parses an option <code>args[i]</code> and augment
|
||||
* the <code>opt</code> object appropriately, then return
|
||||
* the number of tokens consumed.
|
||||
*
|
||||
* <p>
|
||||
* The callee doesn't need to recognize the option that the
|
||||
* getOptionName method returns.
|
||||
*
|
||||
* <p>
|
||||
* Once a plugin is activated, this method is called
|
||||
* for options that XJC didn't recognize. This allows
|
||||
* a plugin to define additional options to customize
|
||||
* its behavior.
|
||||
*
|
||||
* <p>
|
||||
* Since options can appear in no particular order,
|
||||
* XJC allows sub-options of a plugin to show up before
|
||||
* the option that activates a plugin (one that's returned
|
||||
* by {@link #getOptionName().)
|
||||
*
|
||||
* But nevertheless a {@link Plugin} needs to be activated
|
||||
* to participate in further processing.
|
||||
*
|
||||
* @return
|
||||
* 0 if the argument is not understood.
|
||||
* Otherwise return the number of tokens that are
|
||||
* consumed, including the option itself.
|
||||
* (so if you have an option like "-foo 3", return 2.)
|
||||
* @exception BadCommandLineException
|
||||
* If the option was recognized but there's an error.
|
||||
* This halts the argument parsing process and causes
|
||||
* XJC to abort, reporting an error.
|
||||
*/
|
||||
public int parseArgument( Options opt, String[] args, int i ) throws BadCommandLineException, IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of namespace URIs that are supported by this plug-in
|
||||
* as schema annotations.
|
||||
*
|
||||
* <p>
|
||||
* If a plug-in returns a non-empty list, the JAXB RI will recognize
|
||||
* these namespace URIs as vendor extensions
|
||||
* (much like "http://java.sun.com/xml/ns/jaxb/xjc"). This allows users
|
||||
* to write those annotations inside a schema, or in external binding files,
|
||||
* and later plug-ins can access those annotations as DOM nodes.
|
||||
*
|
||||
* <p>
|
||||
* See <a href="http://java.sun.com/webservices/docs/1.5/jaxb/vendorCustomizations.html">
|
||||
* http://java.sun.com/webservices/docs/1.5/jaxb/vendorCustomizations.html</a>
|
||||
* for the syntax that users need to use to enable extension URIs.
|
||||
*
|
||||
* @return
|
||||
* can be empty, be never be null.
|
||||
*/
|
||||
public List<String> getCustomizationURIs() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given tag name is a valid tag name for the customization element in this plug-in.
|
||||
*
|
||||
* <p>
|
||||
* This method is invoked by XJC to determine if the user-specified customization element
|
||||
* is really a customization or not. This information is used to pick the proper error message.
|
||||
*
|
||||
* <p>
|
||||
* A plug-in is still encouraged to do the validation of the customization element in the
|
||||
* {@link #run} method before using any {@link CPluginCustomization}, to make sure that it
|
||||
* has proper child elements and attributes.
|
||||
*
|
||||
* @param nsUri
|
||||
* the namespace URI of the element. Never null.
|
||||
* @param localName
|
||||
* the local name of the element. Never null.
|
||||
*/
|
||||
public boolean isCustomizationTagName(String nsUri,String localName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies a plugin that it's activated.
|
||||
*
|
||||
* <p>
|
||||
* This method is called when a plugin is activated
|
||||
* through the command line option (as specified by {@link #getOptionName()}.
|
||||
*
|
||||
* <p>
|
||||
* This is a good opportunity to use
|
||||
* {@link Options#setFieldRendererFactory(FieldRendererFactory, Plugin)}
|
||||
* if a plugin so desires.
|
||||
*
|
||||
* <p>
|
||||
* Noop by default.
|
||||
*
|
||||
* @since JAXB 2.0 EA4
|
||||
*/
|
||||
public void onActivated(Options opts) throws BadCommandLineException {
|
||||
// noop
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the post-processing of the {@link Model}.
|
||||
*
|
||||
* <p>
|
||||
* This method is invoked after XJC has internally finished
|
||||
* the model construction. This is a chance for a plugin to
|
||||
* affect the way code generation is performed.
|
||||
*
|
||||
* <p>
|
||||
* Compared to the {@link #run(Outline, Options, ErrorHandler)}
|
||||
* method, this method allows a plugin to work at the higher level
|
||||
* conceptually closer to the abstract JAXB model, as opposed to
|
||||
* Java syntax level.
|
||||
*
|
||||
* <p>
|
||||
* Note that this method is invoked only when a {@link Plugin}
|
||||
* is activated.
|
||||
*
|
||||
* @param model
|
||||
* The object that represents the classes/properties to
|
||||
* be generated.
|
||||
*
|
||||
* @param errorHandler
|
||||
* Errors should be reported to this handler.
|
||||
*
|
||||
* @since JAXB 2.0.2
|
||||
*/
|
||||
public void postProcessModel(Model model, ErrorHandler errorHandler) {
|
||||
// noop
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the add-on.
|
||||
*
|
||||
* <p>
|
||||
* This method is invoked after XJC has internally finished
|
||||
* the code generation. Plugins can tweak some of the generated
|
||||
* code (or add more code) by using {@link Outline} and {@link Options}.
|
||||
*
|
||||
* <p>
|
||||
* Note that this method is invoked only when a {@link Plugin}
|
||||
* is activated.
|
||||
*
|
||||
* @param outline
|
||||
* This object allows access to various generated code.
|
||||
*
|
||||
* @param errorHandler
|
||||
* Errors should be reported to this handler.
|
||||
*
|
||||
* @return
|
||||
* If the add-on executes successfully, return true.
|
||||
* If it detects some errors but those are reported and
|
||||
* recovered gracefully, return false.
|
||||
*
|
||||
* @throws SAXException
|
||||
* After an error is reported to {@link ErrorHandler}, the
|
||||
* same exception can be thrown to indicate a fatal irrecoverable
|
||||
* error. {@link ErrorHandler} itself may throw it, if it chooses
|
||||
* not to recover from the error.
|
||||
*/
|
||||
public abstract boolean run(
|
||||
Outline outline, Options opt, ErrorHandler errorHandler ) throws SAXException ;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.codemodel.internal.CodeWriter;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.writer.FilterCodeWriter;
|
||||
|
||||
/**
|
||||
* {@link CodeWriter} that reports progress to {@link XJCListener}.
|
||||
*/
|
||||
final class ProgressCodeWriter extends FilterCodeWriter {
|
||||
|
||||
private int current;
|
||||
private final int totalFileCount;
|
||||
|
||||
public ProgressCodeWriter( CodeWriter output, XJCListener progress, int totalFileCount ) {
|
||||
super(output);
|
||||
this.progress = progress;
|
||||
this.totalFileCount = totalFileCount;
|
||||
if(progress==null)
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
private final XJCListener progress;
|
||||
|
||||
public Writer openSource(JPackage pkg, String fileName) throws IOException {
|
||||
report(pkg,fileName);
|
||||
return super.openSource(pkg, fileName);
|
||||
}
|
||||
|
||||
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
|
||||
report(pkg,fileName);
|
||||
return super.openBinary(pkg,fileName);
|
||||
}
|
||||
|
||||
private void report(JPackage pkg, String fileName) {
|
||||
String name = pkg.name().replace('.', File.separatorChar);
|
||||
if(name.length()!=0) name += File.separatorChar;
|
||||
name += fileName;
|
||||
|
||||
if(progress.isCanceled())
|
||||
throw new AbortException();
|
||||
progress.generatedFile(name,current++,totalFileCount);
|
||||
}
|
||||
}
|
||||
76
jdkSrc/jdk8/com/sun/tools/internal/xjc/SchemaCache.java
Normal file
76
jdkSrc/jdk8/com/sun/tools/internal/xjc/SchemaCache.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.ValidatorHandler;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.util.XmlFactory;
|
||||
import javax.xml.XMLConstants;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import static com.sun.xml.internal.bind.v2.util.XmlFactory.allowExternalAccess;
|
||||
|
||||
/**
|
||||
* Wraps a JAXP {@link Schema} object and lazily instantiate it.
|
||||
*
|
||||
* This object is thread-safe. There should be only one instance of
|
||||
* this for the whole VM.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class SchemaCache {
|
||||
|
||||
private Schema schema;
|
||||
|
||||
private final URL source;
|
||||
|
||||
public SchemaCache(URL source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public ValidatorHandler newValidator() {
|
||||
synchronized(this) {
|
||||
if(schema==null) {
|
||||
try {
|
||||
// do not disable secure processing - these are well-known schemas
|
||||
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
|
||||
schema = allowExternalAccess(sf, "file", false).newSchema(source);
|
||||
} catch (SAXException e) {
|
||||
// we make sure that the schema is correct before we ship.
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ValidatorHandler handler = schema.newValidatorHandler();
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
||||
103
jdkSrc/jdk8/com/sun/tools/internal/xjc/SecureLoader.java
Normal file
103
jdkSrc/jdk8/com/sun/tools/internal/xjc/SecureLoader.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void setContextClassLoader(final ClassLoader cl) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
} else {
|
||||
java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static ClassLoader getParentClassLoader(final ClassLoader cl) {
|
||||
if (System.getSecurityManager() == null) {
|
||||
return cl.getParent();
|
||||
} else {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<ClassLoader>() {
|
||||
public ClassLoader run() {
|
||||
return cl.getParent();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
104
jdkSrc/jdk8/com/sun/tools/internal/xjc/XJCFacade.java
Normal file
104
jdkSrc/jdk8/com/sun/tools/internal/xjc/XJCFacade.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
/**
|
||||
* A shabby driver to invoke XJC1 or XJC2 depending on the command line switch.
|
||||
*
|
||||
* <p>
|
||||
* This class is compiled with -source 1.2 so that we can report a nice
|
||||
* user-friendly "you require Tiger" error message.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class XJCFacade {
|
||||
|
||||
private static final String JDK6_REQUIRED = "XJC requires JDK 6.0 or later. Please download it from http://www.oracle.com/technetwork/java/javase/downloads";
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
String v = "2.0"; // by default, we go 2.0
|
||||
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i].equals("-source")) {
|
||||
if (i + 1 < args.length) {
|
||||
v = parseVersion(args[i + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClassLoader oldContextCl = SecureLoader.getContextClassLoader();
|
||||
try {
|
||||
ClassLoader cl = ClassLoaderBuilder.createProtectiveClassLoader(SecureLoader.getClassClassLoader(XJCFacade.class), v);
|
||||
SecureLoader.setContextClassLoader(cl);
|
||||
Class<?> driver = cl.loadClass("com.sun.tools.internal.xjc.Driver");
|
||||
Method mainMethod = driver.getDeclaredMethod("main", new Class[]{String[].class});
|
||||
try {
|
||||
mainMethod.invoke(null, new Object[]{args});
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getTargetException() != null) {
|
||||
throw e.getTargetException();
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedClassVersionError e) {
|
||||
System.err.println(JDK6_REQUIRED);
|
||||
} finally {
|
||||
ClassLoader cl = SecureLoader.getContextClassLoader();
|
||||
SecureLoader.setContextClassLoader(oldContextCl);
|
||||
|
||||
//close/cleanup all classLoaders but the one which loaded this class
|
||||
while (cl != null && !oldContextCl.equals(cl)) {
|
||||
if (cl instanceof Closeable) {
|
||||
//JDK7+, ParallelWorldClassLoader
|
||||
((Closeable) cl).close();
|
||||
} else {
|
||||
if (cl instanceof URLClassLoader) {
|
||||
//JDK6 - API jars are loaded by instance of URLClassLoader
|
||||
//so use proprietary API to release holded resources
|
||||
try {
|
||||
Class<?> clUtil = oldContextCl.loadClass("sun.misc.ClassLoaderUtil");
|
||||
Method release = clUtil.getDeclaredMethod("releaseLoader", URLClassLoader.class);
|
||||
release.invoke(null, cl);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
//not Sun JDK 6, ignore
|
||||
System.err.println(JDK6_REQUIRED);
|
||||
}
|
||||
}
|
||||
}
|
||||
cl = SecureLoader.getParentClassLoader(cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String parseVersion(String version) {
|
||||
// no other versions supported as of now
|
||||
return "2.0";
|
||||
}
|
||||
}
|
||||
119
jdkSrc/jdk8/com/sun/tools/internal/xjc/XJCListener.java
Normal file
119
jdkSrc/jdk8/com/sun/tools/internal/xjc/XJCListener.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.xjc;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import com.sun.tools.internal.xjc.api.ErrorListener;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
|
||||
/**
|
||||
* Call-back interface that can be implemented by the caller of {@link Driver}
|
||||
* to receive output from XJC.
|
||||
*
|
||||
* <p>
|
||||
* Most of the messages XJC produce once the real work starts is structured
|
||||
* as (message,source). Those outputs will be reported to various methods on
|
||||
* {@link ErrorListener}, which is inherited by this interface.
|
||||
*
|
||||
* <p>
|
||||
* The other messages (such as the usage screen when there was an error in
|
||||
* the command line option) will go to the {@link #message(String)} method.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @since JAXB 2.0 EA
|
||||
*/
|
||||
public abstract class XJCListener implements ErrorListener {
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Override {@link #generatedFile(String, int, int)}.
|
||||
* Deprecated in 2.0.1.
|
||||
*/
|
||||
public void generatedFile(String fileName) {}
|
||||
|
||||
/**
|
||||
* Called for each file generated by XJC.
|
||||
*
|
||||
* <p>
|
||||
* XJC may generate not only source files but also resources files.
|
||||
* The file name includes the path portions that correspond with the package name.
|
||||
*
|
||||
* <p>
|
||||
* When generating files into a directory, file names will be relative to the
|
||||
* output directory. When generating files into a zip file, file names will be
|
||||
* those in the zip file.
|
||||
*
|
||||
* @param fileName
|
||||
* file names like "org/acme/foo/Foo.java" or "org/acme/foo/jaxb.properties".
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public void generatedFile(String fileName, int current, int total ) {
|
||||
generatedFile(fileName); // backward compatibility
|
||||
}
|
||||
|
||||
/**
|
||||
* Other miscellenous messages that do not have structures
|
||||
* will be reported through this method.
|
||||
*
|
||||
* This method is used like {@link PrintStream#println(String)}.
|
||||
* The callee is expected to add '\n'.
|
||||
*/
|
||||
public void message(String msg) {}
|
||||
|
||||
/**
|
||||
* Called after the schema is compiled and the code generation strategy is determined,
|
||||
* but before any code is actually generated as files.
|
||||
*
|
||||
* @param outline
|
||||
* never null. this is the root object that represents the code generation strategy.
|
||||
*/
|
||||
public void compiled(Outline outline) {}
|
||||
|
||||
/**
|
||||
* XJC will periodically invoke this method to see if it should cancel a compilation.
|
||||
*
|
||||
* <p>
|
||||
* As long as this method returns false, XJC will keep going. If this method ever returns
|
||||
* true, XJC will abort the processing right away and
|
||||
* returns non-zero from {@link Driver#run(String[], XJCListener)}.
|
||||
* Note that XJC will not report an abortion through the {@link #message(String)} method.
|
||||
*
|
||||
* <p>
|
||||
* Note that despite all the efforts to check this method frequently, XJC may still fail to
|
||||
* invoke this method for a long time. Such scenario would include network related problems
|
||||
* or other I/O block (you can't even interrupt the thread while I/O is blocking.)
|
||||
* So just beware that this is not a cure-all.
|
||||
*
|
||||
* @return
|
||||
* true if the {@link XJCListener} wants to abort the processing.
|
||||
* @since 2.1
|
||||
*/
|
||||
public boolean isCanceled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.xjc.addon.accessors;
|
||||
|
||||
import com.sun.codemodel.internal.JAnnotationUse;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import java.io.IOException;
|
||||
import com.sun.tools.internal.xjc.BadCommandLineException;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Generates synchronized methods.
|
||||
*
|
||||
* @author
|
||||
* Martin Grebac (martin.grebac@sun.com)
|
||||
*/
|
||||
public class PluginImpl extends Plugin {
|
||||
|
||||
public String getOptionName() {
|
||||
return "Xpropertyaccessors";
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return " -Xpropertyaccessors : Use XmlAccessType PROPERTY instead of FIELD for generated classes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException {
|
||||
return 0; // no option recognized
|
||||
}
|
||||
|
||||
public boolean run( Outline model, Options opt, ErrorHandler errorHandler ) {
|
||||
|
||||
for( ClassOutline co : model.getClasses() ) {
|
||||
Iterator<JAnnotationUse> ann = co.ref.annotations().iterator();
|
||||
while (ann.hasNext()) {
|
||||
try {
|
||||
JAnnotationUse a = ann.next();
|
||||
Field clazzField = a.getClass().getDeclaredField("clazz");
|
||||
clazzField.setAccessible(true);
|
||||
JClass cl = (JClass) clazzField.get(a);
|
||||
if (cl.equals(model.getCodeModel()._ref(XmlAccessorType.class))) {
|
||||
a.param("value", XmlAccessType.PROPERTY);
|
||||
break;
|
||||
}
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.getLogger(PluginImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
Logger.getLogger(PluginImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
Logger.getLogger(PluginImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (SecurityException ex) {
|
||||
Logger.getLogger(PluginImpl.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.xjc.addon.at_generated;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.tools.internal.xjc.Driver;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.EnumOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
|
||||
/**
|
||||
* {@link Plugin} that marks the generated code by using JSR-250's '@Generated'.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class PluginImpl extends Plugin {
|
||||
|
||||
public String getOptionName() {
|
||||
return "mark-generated";
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return " -mark-generated : mark the generated code as @javax.annotation.Generated";
|
||||
}
|
||||
|
||||
private JClass annotation;
|
||||
|
||||
public boolean run( Outline model, Options opt, ErrorHandler errorHandler ) {
|
||||
// we want this to work without requiring JSR-250 jar.
|
||||
annotation = model.getCodeModel().ref("javax.annotation.Generated");
|
||||
|
||||
for( ClassOutline co : model.getClasses() )
|
||||
augument(co);
|
||||
for( EnumOutline eo : model.getEnums() )
|
||||
augument(eo);
|
||||
|
||||
//TODO: process generated ObjectFactory classes?
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void augument(EnumOutline eo) {
|
||||
annotate(eo.clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "@Generated" to the classes, methods, and fields.
|
||||
*/
|
||||
private void augument(ClassOutline co) {
|
||||
annotate(co.implClass);
|
||||
for (JMethod m : co.implClass.methods())
|
||||
annotate(m);
|
||||
for (JFieldVar f : co.implClass.fields().values())
|
||||
annotate(f);
|
||||
}
|
||||
|
||||
private void annotate(JAnnotatable m) {
|
||||
m.annotate(annotation)
|
||||
.param("value",Driver.class.getName())
|
||||
.param("date", getISO8601Date())
|
||||
.param("comments", "JAXB RI v" + Options.getBuildID());
|
||||
}
|
||||
|
||||
// cache the timestamp so that all the @Generated annotations match
|
||||
private String date = null;
|
||||
|
||||
/**
|
||||
* calculate the date value in ISO8601 format for the @Generated annotation
|
||||
* @return the date value
|
||||
*/
|
||||
private String getISO8601Date() {
|
||||
if(date==null) {
|
||||
StringBuffer tstamp = new StringBuffer();
|
||||
tstamp.append((new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ")).format(new Date()));
|
||||
// hack to get ISO 8601 style timezone - is there a better way that doesn't require
|
||||
// a bunch of timezone offset calculations?
|
||||
tstamp.insert(tstamp.length()-2, ':');
|
||||
date = tstamp.toString();
|
||||
}
|
||||
return date;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.xjc.addon.code_injector;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class Const {
|
||||
/**
|
||||
* Customization namespace URI.
|
||||
*/
|
||||
public static final String NS = "http://jaxb.dev.java.net/plugin/code-injector";
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.xjc.addon.code_injector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
import com.sun.tools.internal.xjc.model.CPluginCustomization;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.util.DOMUtils;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Entry point of a plugin.
|
||||
*
|
||||
* See the javadoc of {@link Plugin} for what those methods mean.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class PluginImpl extends Plugin {
|
||||
public String getOptionName() {
|
||||
return "Xinject-code";
|
||||
}
|
||||
|
||||
public List<String> getCustomizationURIs() {
|
||||
return Collections.singletonList(Const.NS);
|
||||
}
|
||||
|
||||
public boolean isCustomizationTagName(String nsUri, String localName) {
|
||||
return nsUri.equals(Const.NS) && localName.equals("code");
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return " -Xinject-code : inject specified Java code fragments into the generated code";
|
||||
}
|
||||
|
||||
// meat of the processing
|
||||
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) {
|
||||
for( ClassOutline co : model.getClasses() ) {
|
||||
CPluginCustomization c = co.target.getCustomizations().find(Const.NS,"code");
|
||||
if(c==null)
|
||||
continue; // no customization --- nothing to inject here
|
||||
|
||||
c.markAsAcknowledged();
|
||||
// TODO: ideally you should validate this DOM element to make sure
|
||||
// that there's no typo/etc. JAXP 1.3 can do this very easily.
|
||||
String codeFragment = DOMUtils.getElementText(c.element);
|
||||
|
||||
// inject the specified code fragment into the implementation class.
|
||||
co.implClass.direct(codeFragment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* 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.xjc.addon.episode;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.tools.internal.xjc.BadCommandLineException;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.outline.EnumOutline;
|
||||
import com.sun.tools.internal.xjc.reader.Const;
|
||||
import com.sun.xml.internal.txw2.TXW;
|
||||
import com.sun.xml.internal.txw2.output.StreamSerializer;
|
||||
import com.sun.xml.internal.xsom.XSAnnotation;
|
||||
import com.sun.xml.internal.xsom.XSAttGroupDecl;
|
||||
import com.sun.xml.internal.xsom.XSAttributeDecl;
|
||||
import com.sun.xml.internal.xsom.XSAttributeUse;
|
||||
import com.sun.xml.internal.xsom.XSComplexType;
|
||||
import com.sun.xml.internal.xsom.XSComponent;
|
||||
import com.sun.xml.internal.xsom.XSContentType;
|
||||
import com.sun.xml.internal.xsom.XSDeclaration;
|
||||
import com.sun.xml.internal.xsom.XSElementDecl;
|
||||
import com.sun.xml.internal.xsom.XSFacet;
|
||||
import com.sun.xml.internal.xsom.XSIdentityConstraint;
|
||||
import com.sun.xml.internal.xsom.XSModelGroup;
|
||||
import com.sun.xml.internal.xsom.XSModelGroupDecl;
|
||||
import com.sun.xml.internal.xsom.XSNotation;
|
||||
import com.sun.xml.internal.xsom.XSParticle;
|
||||
import com.sun.xml.internal.xsom.XSSchema;
|
||||
import com.sun.xml.internal.xsom.XSSimpleType;
|
||||
import com.sun.xml.internal.xsom.XSWildcard;
|
||||
import com.sun.xml.internal.xsom.XSXPath;
|
||||
import com.sun.xml.internal.xsom.visitor.XSFunction;
|
||||
import com.sun.xml.internal.bind.v2.schemagen.episode.Bindings;
|
||||
import com.sun.xml.internal.bind.v2.schemagen.episode.SchemaBindings;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* Creates the episode file,
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @author Ben Tomasini (ben.tomasini@gmail.com)
|
||||
*/
|
||||
public class PluginImpl extends Plugin {
|
||||
|
||||
private File episodeFile;
|
||||
|
||||
public String getOptionName() {
|
||||
return "episode";
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return " -episode <FILE> : generate the episode file for separate compilation";
|
||||
}
|
||||
|
||||
public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException {
|
||||
if(args[i].equals("-episode")) {
|
||||
episodeFile = new File(opt.requireArgument("-episode",args,++i));
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture all the generated classes from global schema components
|
||||
* and generate them in an episode file.
|
||||
*/
|
||||
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) throws SAXException {
|
||||
try {
|
||||
// reorganize qualifying components by their namespaces to
|
||||
// generate the list nicely
|
||||
Map<XSSchema, PerSchemaOutlineAdaptors> perSchema = new HashMap<XSSchema,PerSchemaOutlineAdaptors>();
|
||||
boolean hasComponentInNoNamespace = false;
|
||||
|
||||
// Combine classes and enums into a single list
|
||||
List<OutlineAdaptor> outlines = new ArrayList<OutlineAdaptor>();
|
||||
|
||||
for (ClassOutline co : model.getClasses()) {
|
||||
XSComponent sc = co.target.getSchemaComponent();
|
||||
String fullName = co.implClass.fullName();
|
||||
String packageName = co.implClass.getPackage().name();
|
||||
OutlineAdaptor adaptor = new OutlineAdaptor(sc,
|
||||
OutlineAdaptor.OutlineType.CLASS, fullName, packageName);
|
||||
outlines.add(adaptor);
|
||||
}
|
||||
|
||||
for (EnumOutline eo : model.getEnums()) {
|
||||
XSComponent sc = eo.target.getSchemaComponent();
|
||||
String fullName = eo.clazz.fullName();
|
||||
String packageName = eo.clazz.getPackage().name();
|
||||
OutlineAdaptor adaptor = new OutlineAdaptor(sc,
|
||||
OutlineAdaptor.OutlineType.ENUM, fullName, packageName);
|
||||
outlines.add(adaptor);
|
||||
}
|
||||
|
||||
for (OutlineAdaptor oa : outlines) {
|
||||
XSComponent sc = oa.schemaComponent;
|
||||
|
||||
if (sc == null) continue;
|
||||
if (!(sc instanceof XSDeclaration))
|
||||
continue;
|
||||
XSDeclaration decl = (XSDeclaration) sc;
|
||||
if (decl.isLocal())
|
||||
continue; // local components cannot be referenced from outside, so no need to list.
|
||||
|
||||
PerSchemaOutlineAdaptors list = perSchema.get(decl.getOwnerSchema());
|
||||
if (list == null) {
|
||||
list = new PerSchemaOutlineAdaptors();
|
||||
perSchema.put(decl.getOwnerSchema(), list);
|
||||
}
|
||||
|
||||
list.add(oa);
|
||||
|
||||
if (decl.getTargetNamespace().equals(""))
|
||||
hasComponentInNoNamespace = true;
|
||||
}
|
||||
|
||||
OutputStream os = new FileOutputStream(episodeFile);
|
||||
Bindings bindings = TXW.create(Bindings.class, new StreamSerializer(os, "UTF-8"));
|
||||
if(hasComponentInNoNamespace) // otherwise jaxb binding NS should be the default namespace
|
||||
bindings._namespace(Const.JAXB_NSURI,"jaxb");
|
||||
else
|
||||
bindings._namespace(Const.JAXB_NSURI,"");
|
||||
bindings.version("2.1");
|
||||
bindings._comment("\n\n"+opt.getPrologComment()+"\n ");
|
||||
|
||||
// generate listing per schema
|
||||
for (Map.Entry<XSSchema,PerSchemaOutlineAdaptors> e : perSchema.entrySet()) {
|
||||
PerSchemaOutlineAdaptors ps = e.getValue();
|
||||
Bindings group = bindings.bindings();
|
||||
String tns = e.getKey().getTargetNamespace();
|
||||
if(!tns.equals(""))
|
||||
group._namespace(tns,"tns");
|
||||
|
||||
group.scd("x-schema::"+(tns.equals("")?"":"tns"));
|
||||
SchemaBindings schemaBindings = group.schemaBindings();
|
||||
schemaBindings.map(false);
|
||||
if (ps.packageNames.size() == 1)
|
||||
{
|
||||
final String packageName = ps.packageNames.iterator().next();
|
||||
if (packageName != null && packageName.length() > 0) {
|
||||
schemaBindings._package().name(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
for (OutlineAdaptor oa : ps.outlineAdaptors) {
|
||||
Bindings child = group.bindings();
|
||||
oa.buildBindings(child);
|
||||
}
|
||||
group.commit(true);
|
||||
}
|
||||
|
||||
bindings.commit();
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
errorHandler.error(new SAXParseException("Failed to write to "+episodeFile,null,e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes SCD.
|
||||
* This is fairly limited as JAXB can only map a certain kind of components to classes.
|
||||
*/
|
||||
private static final XSFunction<String> SCD = new XSFunction<String>() {
|
||||
private String name(XSDeclaration decl) {
|
||||
if(decl.getTargetNamespace().equals(""))
|
||||
return decl.getName();
|
||||
else
|
||||
return "tns:"+decl.getName();
|
||||
}
|
||||
|
||||
public String complexType(XSComplexType type) {
|
||||
return "~"+name(type);
|
||||
}
|
||||
|
||||
public String simpleType(XSSimpleType simpleType) {
|
||||
return "~"+name(simpleType);
|
||||
}
|
||||
|
||||
public String elementDecl(XSElementDecl decl) {
|
||||
return name(decl);
|
||||
}
|
||||
|
||||
// the rest is doing nothing
|
||||
public String annotation(XSAnnotation ann) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String attGroupDecl(XSAttGroupDecl decl) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String attributeDecl(XSAttributeDecl decl) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String attributeUse(XSAttributeUse use) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String schema(XSSchema schema) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String facet(XSFacet facet) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String notation(XSNotation notation) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String identityConstraint(XSIdentityConstraint decl) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String xpath(XSXPath xpath) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String particle(XSParticle particle) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String empty(XSContentType empty) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String wildcard(XSWildcard wc) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String modelGroupDecl(XSModelGroupDecl decl) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String modelGroup(XSModelGroup group) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
|
||||
private final static class OutlineAdaptor {
|
||||
|
||||
private enum OutlineType {
|
||||
|
||||
CLASS(new BindingsBuilder() {
|
||||
public void build(OutlineAdaptor adaptor, Bindings bindings) {
|
||||
bindings.klass().ref(adaptor.implName);
|
||||
|
||||
}
|
||||
}),
|
||||
ENUM(new BindingsBuilder() {
|
||||
public void build(OutlineAdaptor adaptor, Bindings bindings) {
|
||||
bindings.typesafeEnumClass().ref(adaptor.implName);
|
||||
}
|
||||
});
|
||||
|
||||
private final BindingsBuilder bindingsBuilder;
|
||||
|
||||
private OutlineType(BindingsBuilder bindingsBuilder) {
|
||||
this.bindingsBuilder = bindingsBuilder;
|
||||
}
|
||||
|
||||
private interface BindingsBuilder {
|
||||
void build(OutlineAdaptor adaptor, Bindings bindings);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private final XSComponent schemaComponent;
|
||||
private final OutlineType outlineType;
|
||||
private final String implName;
|
||||
private final String packageName;
|
||||
|
||||
public OutlineAdaptor(XSComponent schemaComponent, OutlineType outlineType,
|
||||
String implName, String packageName) {
|
||||
this.schemaComponent = schemaComponent;
|
||||
this.outlineType = outlineType;
|
||||
this.implName = implName;
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
private void buildBindings(Bindings bindings) {
|
||||
bindings.scd(schemaComponent.apply(SCD));
|
||||
outlineType.bindingsBuilder.build(this, bindings);
|
||||
}
|
||||
}
|
||||
|
||||
private final static class PerSchemaOutlineAdaptors {
|
||||
|
||||
private final List<OutlineAdaptor> outlineAdaptors = new ArrayList<OutlineAdaptor>();
|
||||
|
||||
private final Set<String> packageNames = new HashSet<String>();
|
||||
|
||||
private void add(OutlineAdaptor outlineAdaptor)
|
||||
{
|
||||
this.outlineAdaptors.add(outlineAdaptor);
|
||||
this.packageNames.add(outlineAdaptor.packageName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@XmlNamespace(Const.JAXB_NSURI)
|
||||
package com.sun.tools.internal.xjc.addon.episode;
|
||||
|
||||
import com.sun.xml.internal.txw2.annotation.XmlNamespace;
|
||||
import com.sun.tools.internal.xjc.reader.Const;
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.xjc.addon.locator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.tools.internal.xjc.BadCommandLineException;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.xml.internal.bind.Locatable;
|
||||
import com.sun.xml.internal.bind.annotation.XmlLocation;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
/**
|
||||
* Generates JAXB objects that implement {@link Locatable}.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class SourceLocationAddOn extends Plugin {
|
||||
|
||||
public String getOptionName() {
|
||||
return "Xlocator";
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return " -Xlocator : enable source location support for generated code";
|
||||
}
|
||||
|
||||
public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException {
|
||||
return 0; // no option recognized
|
||||
}
|
||||
|
||||
private static final String fieldName = "locator";
|
||||
|
||||
public boolean run(
|
||||
Outline outline,
|
||||
Options opt,
|
||||
ErrorHandler errorHandler ) {
|
||||
|
||||
for( ClassOutline ci : outline.getClasses() ) {
|
||||
JDefinedClass impl = ci.implClass;
|
||||
if (ci.getSuperClass() == null) {
|
||||
JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName);
|
||||
$loc.annotate(XmlLocation.class);
|
||||
$loc.annotate(XmlTransient.class);
|
||||
|
||||
impl._implements(Locatable.class);
|
||||
|
||||
impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc);
|
||||
|
||||
JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation");
|
||||
JVar $newLoc = setter.param(Locator.class, "newLocator");
|
||||
setter.body().assign($loc, $newLoc);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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.xjc.addon.sync;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.tools.internal.xjc.BadCommandLineException;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Generates synchronized methods.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public class SynchronizedMethodAddOn extends Plugin {
|
||||
|
||||
public String getOptionName() {
|
||||
return "Xsync-methods";
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
return " -Xsync-methods : generate accessor methods with the 'synchronized' keyword";
|
||||
}
|
||||
|
||||
public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException {
|
||||
return 0; // no option recognized
|
||||
}
|
||||
|
||||
public boolean run( Outline model, Options opt, ErrorHandler errorHandler ) {
|
||||
|
||||
for( ClassOutline co : model.getClasses() )
|
||||
augument(co);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "synchoronized" to all the methods.
|
||||
*/
|
||||
private void augument(ClassOutline co) {
|
||||
for (JMethod m : co.implClass.methods())
|
||||
m.getMods().setSynchronized(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
/**
|
||||
* Callback interface that allows the driver of the XJC API
|
||||
* to rename JAXB-generated classes/interfaces/enums.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface ClassNameAllocator {
|
||||
/**
|
||||
* Hook that allows the client of the XJC API to rename some of the JAXB-generated classes.
|
||||
*
|
||||
* <p>
|
||||
* When registered, this calllbcak is consulted for every package-level
|
||||
* classes/interfaces/enums (hereafter, simply "classes")
|
||||
* that the JAXB RI generates. Note that
|
||||
* the JAXB RI does not use this allocator for nested/inner classes.
|
||||
*
|
||||
* <p>
|
||||
* If the allocator chooses to rename some classes. It is
|
||||
* the allocator's responsibility to find unique names.
|
||||
* If the returned name collides with other classes, the JAXB RI will
|
||||
* report errors.
|
||||
*
|
||||
* @param packageName
|
||||
* The package name, such as "" or "foo.bar". Never be null.
|
||||
* @param className
|
||||
* The short name of the proposed class name. Such as
|
||||
* "Foo" or "Bar". Never be null, never be empty.
|
||||
* Always a valid Java identifier.
|
||||
*
|
||||
* @return
|
||||
* The short name of the class name that should be used.
|
||||
* The class will be generated into the same package with this name.
|
||||
* The return value must be a valid Java identifier. May not be null.
|
||||
*/
|
||||
String assignClassName( String packageName, String className );
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* Implemented by the driver of the compiler engine to handle
|
||||
* errors found during the compiliation.
|
||||
*
|
||||
* <p>
|
||||
* This class implements {@link ErrorHandler} so it can be
|
||||
* passed to anywhere where {@link ErrorHandler} is expected.
|
||||
*
|
||||
* <p>
|
||||
* However, to make the error handling easy (and make it work
|
||||
* with visitor patterns nicely), this interface is not allowed
|
||||
* to abort the processing. It merely receives errors.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface ErrorListener extends com.sun.xml.internal.bind.api.ErrorListener {
|
||||
void error(SAXParseException exception);
|
||||
void fatalError(SAXParseException exception);
|
||||
void warning(SAXParseException exception);
|
||||
/**
|
||||
* Used to report possibly verbose information that
|
||||
* can be safely ignored.
|
||||
*/
|
||||
void info(SAXParseException exception);
|
||||
}
|
||||
82
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/J2SJAXBModel.java
Normal file
82
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/J2SJAXBModel.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
/**
|
||||
* {@link JAXBModel} that exposes additional information available
|
||||
* only for the java->schema direction.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface J2SJAXBModel extends JAXBModel {
|
||||
/**
|
||||
* Returns the name of the XML Type bound to the
|
||||
* specified Java type.
|
||||
*
|
||||
* @param javaType
|
||||
* must not be null. This must be one of the {@link Reference}s specified
|
||||
* in the {@link JavaCompiler#bind} method.
|
||||
*
|
||||
* @return
|
||||
* null if it is not a part of the input to {@link JavaCompiler#bind}.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the parameter is null
|
||||
*/
|
||||
QName getXmlTypeName(Reference javaType);
|
||||
|
||||
/**
|
||||
* Generates the schema documents from the model.
|
||||
*
|
||||
* @param outputResolver
|
||||
* this object controls the output to which schemas
|
||||
* will be sent.
|
||||
*
|
||||
* @throws IOException
|
||||
* if {@link SchemaOutputResolver} throws an {@link IOException}.
|
||||
*/
|
||||
void generateSchema(SchemaOutputResolver outputResolver, ErrorListener errorListener) throws IOException;
|
||||
|
||||
/**
|
||||
* Generates the episode file from the model.
|
||||
*
|
||||
* <p>
|
||||
* The "episode file" is really just a JAXB customization file (but with vendor extensions,
|
||||
* at this point), that can be used later with a schema compilation to support separate
|
||||
* compilation.
|
||||
*
|
||||
* @param output
|
||||
* This receives the generated episode file.
|
||||
* @since 2.1
|
||||
*/
|
||||
void generateEpisodeFile(Result output);
|
||||
}
|
||||
59
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/JAXBModel.java
Normal file
59
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/JAXBModel.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.xjc.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
|
||||
/**
|
||||
* The in-memory representation of the JAXB binding.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface JAXBModel {
|
||||
|
||||
/**
|
||||
* Returns a list of fully-qualified class names, which should
|
||||
* be used at the runtime to create a new {@link JAXBContext}.
|
||||
*
|
||||
* <p>
|
||||
* Until the JAXB team fixes the bootstrapping issue, we have
|
||||
* two bootstrapping methods. This one is to use a list of class names
|
||||
* to call {@link JAXBContext#newInstance(Class[])} method. If
|
||||
* this method returns non-null, the caller is expected to use
|
||||
* that method. <b>This is meant to be a temporary workaround.</b>
|
||||
*
|
||||
* @return
|
||||
* non-null read-only list.
|
||||
*
|
||||
* @deprecated
|
||||
* this method is provided for now to allow gradual migration for JAX-RPC.
|
||||
*/
|
||||
List<String> getClassList();
|
||||
|
||||
}
|
||||
83
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/JavaCompiler.java
Normal file
83
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/JavaCompiler.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
|
||||
|
||||
/**
|
||||
* Java-to-Schema compiler.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface JavaCompiler {
|
||||
|
||||
/**
|
||||
* Compiles the given annotated Java source code.
|
||||
*
|
||||
* <p>
|
||||
* This operation takes a set of "root types", then compute the list of
|
||||
* all the types that need to be bound by forming a transitive reflexive
|
||||
* closure of types that are referenced by the root types.
|
||||
*
|
||||
* <p>
|
||||
* Errors will be sent to {@link javax.annotation.processing.ProcessingEnvironment#getMessager()}.
|
||||
*
|
||||
* @param rootTypes
|
||||
* The list of types that needs to be bound to XML.
|
||||
* "root references" from JAX-RPC to JAXB is always in the form of (type,annotations) pair.
|
||||
*
|
||||
* @param additionalElementDecls
|
||||
* Add element declarations for the specified element names to
|
||||
* the XML types mapped from the corresponding {@link Reference}s.
|
||||
* Those {@link Reference}s must be included in the <tt>rootTypes</tt> parameter.
|
||||
* In this map, a {@link Reference} can be null, in which case the element name is
|
||||
* declared to have an empty complex type.
|
||||
* (<xs:element name='foo'><xs:complexType/></xs:element>)
|
||||
* This parameter can be null, in which case the method behaves as if the empty map is given.
|
||||
*
|
||||
* @param defaultNamespaceRemap
|
||||
* If not-null, all the uses of the empty default namespace ("") will
|
||||
* be replaced by this namespace URI.
|
||||
*
|
||||
* @param source
|
||||
* The caller supplied view to the annotated source code that JAXB is going to process.
|
||||
*
|
||||
* @return
|
||||
* Non-null if no error was reported. Otherwise null.
|
||||
*/
|
||||
J2SJAXBModel bind(
|
||||
Collection<Reference> rootTypes,
|
||||
Map<QName, Reference> additionalElementDecls,
|
||||
String defaultNamespaceRemap,
|
||||
ProcessingEnvironment source);
|
||||
}
|
||||
99
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/Mapping.java
Normal file
99
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/Mapping.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
* JAXB-induced mapping between a Java class
|
||||
* and an XML element declaration. A part of the compiler artifacts.
|
||||
*
|
||||
* <p>
|
||||
* To be precise, this is a mapping between two Java classes and an
|
||||
* XML element declaration. There's one Java class/interface that
|
||||
* represents the element, and there's another Java class/interface that
|
||||
* represents the type of the element.
|
||||
*
|
||||
* The former is called "element representation" and the latter is called
|
||||
* "type representation".
|
||||
*
|
||||
* <p>
|
||||
* The {@link Mapping} interface provides operation that lets the caller
|
||||
* convert an instance of the element representation to that of the
|
||||
* type representation or vice versa.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface Mapping {
|
||||
/**
|
||||
* Name of the XML element.
|
||||
*
|
||||
* @return
|
||||
* never be null.
|
||||
*/
|
||||
QName getElement();
|
||||
|
||||
/**
|
||||
* Returns the fully-qualified name of the java class for the type of this element.
|
||||
*
|
||||
* TODO: does this method returns the name of the wrapper bean when it's qualified
|
||||
* for the wrapper style? Seems no (consider <xs:element name='foo' type='xs:long' />),
|
||||
* but then how does JAX-RPC captures that bean?
|
||||
*
|
||||
* @return
|
||||
* never be null.
|
||||
*/
|
||||
TypeAndAnnotation getType();
|
||||
|
||||
/**
|
||||
* If this element is a so-called "wrapper-style" element,
|
||||
* obtains its member information.
|
||||
*
|
||||
* <p>
|
||||
* The notion of the wrapper style should be defined by the JAXB spec,
|
||||
* and ideally it should differ from that of the JAX-RPC only at
|
||||
* the point where the JAX-RPC imposes additional restriction
|
||||
* on the element name.
|
||||
*
|
||||
* <p>
|
||||
* As of this writing the JAXB spec doesn't define "the wrapper style"
|
||||
* and as such the exact definition of what XJC thinks
|
||||
* "the wrapper style" isn't spec-ed.
|
||||
*
|
||||
* <p>
|
||||
* Ths returned list includes {@link Property} defined not just
|
||||
* in this class but in all its base classes.
|
||||
*
|
||||
* @return
|
||||
* null if this isn't a wrapper-style element.
|
||||
* Otherwise list of {@link Property}s. The order signifies
|
||||
* the order they appeared inside a schema.
|
||||
*/
|
||||
List<? extends Property> getWrapperStyleDrilldown();
|
||||
}
|
||||
87
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/Property.java
Normal file
87
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/Property.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* Represents a property of a wrapper-style element.
|
||||
*
|
||||
* <p>
|
||||
* Carrys information about one property of a wrapper-style
|
||||
* element. This interface is solely intended for the use by
|
||||
* the JAX-RPC and otherwise the use is discouraged.
|
||||
*
|
||||
* <p>
|
||||
* REVISIT: use CodeModel.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
* @see Mapping
|
||||
*/
|
||||
public interface Property {
|
||||
/**
|
||||
* The name of the property.
|
||||
*
|
||||
* <p>
|
||||
* This method returns a valid identifier suitable for
|
||||
* the use as a variable name.
|
||||
*
|
||||
* @return
|
||||
* always non-null. Camel-style name like "foo" or "barAndZot".
|
||||
* Note that it may contain non-ASCII characters (CJK, etc.)
|
||||
* The caller is responsible for proper escaping if it
|
||||
* wants to print this as a variable name.
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* The Java type of the property.
|
||||
*
|
||||
* @return
|
||||
* always non-null.
|
||||
* {@link JType} is a representation of a Java type in a codeModel.
|
||||
* If you just need the fully-qualified class name, call {@link JType#fullName()}.
|
||||
*/
|
||||
JType type();
|
||||
|
||||
/**
|
||||
* Name of the XML element that corresponds to the property.
|
||||
*
|
||||
* <p>
|
||||
* Each child of a wrapper style element corresponds with an
|
||||
* element, and this method returns that name.
|
||||
*
|
||||
* @return
|
||||
* always non-null valid {@link QName}.
|
||||
*/
|
||||
QName elementName();
|
||||
|
||||
QName rawName();
|
||||
|
||||
}
|
||||
106
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/Reference.java
Normal file
106
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/Reference.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
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.TypeMirror;
|
||||
|
||||
/**
|
||||
* Reference to a JAXB type (from JAX-RPC.)
|
||||
*
|
||||
* <p>
|
||||
* A reference is a Java type (represented as a {@link javax.lang.model.type.TypeMirror})
|
||||
* and a set of annotations (represented as a {@link javax.lang.model.element.Element}).
|
||||
* Together they describe a root reference to a JAXB type binding.
|
||||
*
|
||||
* <p>
|
||||
* Those two values can be supplied independently, or you can use
|
||||
* other convenience constructors to supply two values at once.
|
||||
*
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class Reference {
|
||||
/**
|
||||
* The JAXB type being referenced. Must not be null.
|
||||
*/
|
||||
public final TypeMirror type;
|
||||
/**
|
||||
* The declaration from which annotations for the {@link #type} is read.
|
||||
* Must not be null.
|
||||
*/
|
||||
public final Element annotations;
|
||||
|
||||
/**
|
||||
* Creates a reference from the return type of the method
|
||||
* and annotations on the method.
|
||||
*/
|
||||
public Reference(ExecutableElement method) {
|
||||
this(method.getReturnType(),method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a reference from the parameter type
|
||||
* and annotations on the parameter.
|
||||
*/
|
||||
public Reference(VariableElement param) {
|
||||
this(param.asType(), param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a reference from a class declaration and its annotations.
|
||||
*/
|
||||
public Reference(TypeElement type, ProcessingEnvironment env) {
|
||||
this(env.getTypeUtils().getDeclaredType(type),type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a reference by providing two values independently.
|
||||
*/
|
||||
public Reference(TypeMirror type, Element annotations) {
|
||||
if(type==null || annotations==null)
|
||||
throw new IllegalArgumentException();
|
||||
this.type = type;
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Reference)) return false;
|
||||
|
||||
final Reference that = (Reference) o;
|
||||
|
||||
return annotations.equals(that.annotations) && type.equals(that.type);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 29 * type.hashCode() + annotations.hashCode();
|
||||
}
|
||||
}
|
||||
112
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/S2JJAXBModel.java
Normal file
112
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/S2JJAXBModel.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
|
||||
import com.sun.codemodel.internal.CodeWriter;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
|
||||
/**
|
||||
* {@link JAXBModel} that exposes additional information available
|
||||
* only for the schema->java direction.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface S2JJAXBModel extends JAXBModel {
|
||||
|
||||
/**
|
||||
* Gets a {@link Mapping} object for the given global element.
|
||||
*
|
||||
* @return
|
||||
* null if the element name is not a defined global element in the schema.
|
||||
*/
|
||||
Mapping get( QName elementName );
|
||||
|
||||
/**
|
||||
* Gets all the <tt>ObjectFactory</tt> classes generated by the compilation.
|
||||
*
|
||||
* <p>
|
||||
* This should be used for generating {@link XmlSeeAlso} on the SEI.
|
||||
*/
|
||||
List<JClass> getAllObjectFactories();
|
||||
|
||||
|
||||
/**
|
||||
* Gets a read-only view of all the {@link Mapping}s.
|
||||
*/
|
||||
Collection<? extends Mapping> getMappings();
|
||||
|
||||
/**
|
||||
* Returns the fully-qualified name of the Java type that is bound to the
|
||||
* specified XML type.
|
||||
*
|
||||
* @param xmlTypeName
|
||||
* must not be null.
|
||||
* @return
|
||||
* null if the XML type is not bound to any Java type.
|
||||
*/
|
||||
TypeAndAnnotation getJavaType(QName xmlTypeName);
|
||||
|
||||
/**
|
||||
* Generates artifacts.
|
||||
*
|
||||
* <p>
|
||||
* TODO: if JAXB supports various modes of code generations
|
||||
* (such as public interface only or implementation only or
|
||||
* etc), we should define bit flags to control those.
|
||||
*
|
||||
* <p>
|
||||
* This operation is only supported for a model built from a schema.
|
||||
*
|
||||
* @param extensions
|
||||
* The JAXB RI extensions to run. This can be null or empty
|
||||
* array if the caller wishes not to run any extension.
|
||||
* <br>
|
||||
*
|
||||
* Those specified extensions
|
||||
* will participate in the code generation. Specifying an extension
|
||||
* in this list has the same effect of turning that extension on
|
||||
* via command line.
|
||||
* <br>
|
||||
*
|
||||
* It is the caller's responsibility to configure each augmenter
|
||||
* properly by using {@link Plugin#parseArgument(Options, String[], int)}.
|
||||
*
|
||||
* @return
|
||||
* object filled with the generated code. Use
|
||||
* {@link JCodeModel#build(CodeWriter)} to write them
|
||||
* to a disk.
|
||||
*/
|
||||
JCodeModel generateCode( Plugin[] extensions, ErrorListener errorListener );
|
||||
}
|
||||
254
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/SchemaCompiler.java
Normal file
254
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/SchemaCompiler.java
Normal file
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* Schema-to-Java compiler.
|
||||
*
|
||||
* <p>
|
||||
* The caller can parse multiple schema documents,
|
||||
* JAXB external binding files (or potentially WSDL
|
||||
* and JSR-109.next mapping files in the future).
|
||||
*
|
||||
* <p>
|
||||
* All the errors found during this process will be sent
|
||||
* to the registered {@link ErrorListener}.
|
||||
*
|
||||
* <p>
|
||||
* Once all the documents are parsed, call the {@link #bind()}
|
||||
* method to get the compiled {@link JAXBModel} object.
|
||||
*
|
||||
*
|
||||
* <h2>Tips: namespace URI -> package customization</h2>
|
||||
* <p>
|
||||
* The caller can feed the following synthesized schema
|
||||
* to achive the namespace URI -> Java package customization:
|
||||
* <pre><xmp>
|
||||
* <schema targetNamespace="xml.namespace.uri"
|
||||
* xmlns="http://www.w3.org/2001/XMLSchema"
|
||||
* xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
|
||||
* jaxb:version="1.0">
|
||||
* <annotation><appinfo>
|
||||
* <jaxb:schemaBindings>
|
||||
* <jaxb:package name="java.package.name"/>
|
||||
* </jaxb:schemaBindings>
|
||||
* </appinfo></annotation>
|
||||
* </schema>
|
||||
* </xmp></pre>
|
||||
* Feed this synthesized schema document for each namespace URI
|
||||
* you need to map.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public interface SchemaCompiler {
|
||||
/**
|
||||
* Parses schemas or external bindings
|
||||
* through SAX events by feeding events into
|
||||
* SAX {@link ContentHandler}.
|
||||
*
|
||||
* @param systemId
|
||||
* The system ID of the document to be read in.
|
||||
*
|
||||
* @see #parseSchema(String, XMLStreamReader)
|
||||
*/
|
||||
ContentHandler getParserHandler( String systemId );
|
||||
|
||||
/**
|
||||
* Parses a schema or an external binding file
|
||||
* from an external source.
|
||||
*
|
||||
* @param source
|
||||
* Its system Id must be set to an absolute URI.
|
||||
*/
|
||||
void parseSchema( InputSource source );
|
||||
|
||||
/**
|
||||
* Specifies the target spec version for this compilaion.
|
||||
*
|
||||
* @param version
|
||||
* If null, XJC will generate the source code that
|
||||
* takes advantage of the latest JAXB spec that it understands.
|
||||
* @since 2.1 EA2
|
||||
*/
|
||||
void setTargetVersion( SpecVersion version );
|
||||
|
||||
/**
|
||||
* Parses a schema or an external binding file
|
||||
* from the specified DOM element.
|
||||
*
|
||||
* <p>
|
||||
* The given DOM element is treated as if it's the root of a
|
||||
* virtual document.
|
||||
*
|
||||
* <p>
|
||||
* XJC will not be able to print location information for
|
||||
* errors found in this document, since DOM doesn't have them.
|
||||
* For this reason, use of this method is strongly discouraged.
|
||||
*
|
||||
* @param systemId
|
||||
* We need an absolute system ID that uniquely designates the virtual
|
||||
* document. This should be different from the system ID of
|
||||
* the document which contains this element.
|
||||
* <p>
|
||||
* One way to do that is by adding a fragment identifier
|
||||
* to the system ID of the document. For example, if the document
|
||||
* is "foo.wsdl" and you are passing in its types section, you
|
||||
* can use an unique identifier like "foo.wsdl#types"
|
||||
*/
|
||||
void parseSchema( String systemId, Element element );
|
||||
|
||||
/**
|
||||
* Parses a schema or an external binding file
|
||||
* from the given source.
|
||||
*
|
||||
* <p>
|
||||
* A stream reader must be pointing at the element or
|
||||
* at the start of the document.
|
||||
* XML is parsed until the corresponding end tag, then the
|
||||
* sub tree is processed as a schema document.
|
||||
*
|
||||
* <p>
|
||||
* When this method returns successfully, the parser is at
|
||||
* the next token of the end element.
|
||||
*
|
||||
* @param systemId
|
||||
* The absolute system ID of the document that is being parsed.
|
||||
* This information is necessary to avoid double-inclusion
|
||||
* and etc.
|
||||
*
|
||||
* Note that {@link XMLStreamReader#getLocation()} only
|
||||
* returns the system ID of the entity it is parsing, not
|
||||
* necessarily the system ID of the document itself.
|
||||
*
|
||||
* @throws XMLStreamException
|
||||
* If an error happens while parsing a document.
|
||||
* Note that not only the parser but also the XJC itself
|
||||
* may throw this error (as a result of the additional validation
|
||||
* for example.)
|
||||
*/
|
||||
void parseSchema( String systemId, XMLStreamReader reader ) throws XMLStreamException;
|
||||
|
||||
void setErrorListener( ErrorListener errorListener );
|
||||
void setEntityResolver( EntityResolver entityResolver );
|
||||
|
||||
|
||||
/**
|
||||
* Sets the default Java package name into which the generated code will be placed.
|
||||
*
|
||||
* <p>
|
||||
* Customizations in the binding files/schemas will have precedence over this setting.
|
||||
* Set to null to use the default package name computation algorithm as specified by
|
||||
* the JAXB spec (which is the default behavior.)
|
||||
*
|
||||
* <p>
|
||||
* Initially this parameter is set to null.
|
||||
*
|
||||
* @param packageName
|
||||
* Java pckage name such as "org.foo.bar". Use "" to represent the root package,
|
||||
* and null to defer to the default computation algorithm.
|
||||
*
|
||||
* @see #forcePackageName(String)
|
||||
*/
|
||||
void setDefaultPackageName( String packageName );
|
||||
|
||||
/**
|
||||
* Forces all the JAXB-generated classes to go into the specific package.
|
||||
*
|
||||
* <p>
|
||||
* This setting takes precedence over the {@link #setDefaultPackageName(String)}
|
||||
* or any of the customization found in the JAXB binding files. This method
|
||||
* is designed to implement the semantics of the command-line '-p' option.
|
||||
*
|
||||
* <p>
|
||||
* This somewhat ugly semantics actually have a long history now and too late
|
||||
* to change.
|
||||
*
|
||||
* @see #setDefaultPackageName(String)
|
||||
*/
|
||||
void forcePackageName( String packageName );
|
||||
|
||||
/**
|
||||
* Sets the {@link ClassNameAllocator} to be used for the binding operation.
|
||||
*
|
||||
* <p>
|
||||
* This mechanism would allow the caller to participate in the binding operation.
|
||||
*
|
||||
* @see ClassNameAllocator
|
||||
*/
|
||||
void setClassNameAllocator( ClassNameAllocator allocator );
|
||||
|
||||
/**
|
||||
* Clears all the schema files parsed so far.
|
||||
*
|
||||
* @since 2.1.1
|
||||
*/
|
||||
void resetSchema();
|
||||
|
||||
/**
|
||||
* Obtains the compiled schema object model.
|
||||
*
|
||||
* Once this method is called, no other method should be
|
||||
* invoked on the {@link SchemaCompiler}.
|
||||
*
|
||||
* @return
|
||||
* null if the compilation fails. The errors should have been
|
||||
* delivered to the registered error handler in such a case.
|
||||
*/
|
||||
S2JJAXBModel bind();
|
||||
|
||||
/**
|
||||
* Allows the calling code to tweak more schema compilation details.
|
||||
*
|
||||
* <p>
|
||||
* The caller can use this method to obtain an {@link Options} instance,
|
||||
* then tweak settings on it. The updated settings will be used when the
|
||||
* {@link #bind()} method is invoked.
|
||||
*
|
||||
* <p>
|
||||
* The returned {@link Options} object is useful for example to specify
|
||||
* command-line arguments.
|
||||
*
|
||||
* @since 2.0.2
|
||||
* @deprecated
|
||||
* This method is not really "deprecated" (in the sense of being removed
|
||||
* from future versions), but the JAXB team is not committed to evolve
|
||||
* {@link Options} class in the compatible fashion. So please don't
|
||||
* use this method unless you know what you're doing.
|
||||
*/
|
||||
@NotNull Options getOptions();
|
||||
}
|
||||
59
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/SpecVersion.java
Normal file
59
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/SpecVersion.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.xjc.api;
|
||||
|
||||
/**
|
||||
* Represents the spec version constant.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public enum SpecVersion {
|
||||
V2_0, V2_1, V2_2;
|
||||
|
||||
/**
|
||||
* Returns true if this version is equal or later than the given one.
|
||||
*/
|
||||
public boolean isLaterThan(SpecVersion t) {
|
||||
return this.ordinal()>=t.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses "2.0", "2.1", and "2.2" into the {@link SpecVersion} object.
|
||||
*
|
||||
* @return null for parsing failure.
|
||||
*/
|
||||
public static SpecVersion parse(String token) {
|
||||
if(token.equals("2.0"))
|
||||
return V2_0;
|
||||
if(token.equals("2.1"))
|
||||
return V2_1;
|
||||
if(token.equals("2.2"))
|
||||
return V2_2;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final SpecVersion LATEST = V2_2;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* Java type and associated JAXB annotations.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface TypeAndAnnotation {
|
||||
/**
|
||||
* Returns the Java type.
|
||||
*
|
||||
* <p>
|
||||
* {@link JType} is a representation of a Java type in a codeModel.
|
||||
* If you just need the fully-qualified class name, call {@link JType#fullName()}.
|
||||
*
|
||||
* @return
|
||||
* never be null.
|
||||
*/
|
||||
JType getTypeClass();
|
||||
|
||||
/**
|
||||
* Annotates the given program element by additional JAXB annotations that need to be there
|
||||
* at the point of reference.
|
||||
*/
|
||||
void annotate( JAnnotatable programElement );
|
||||
|
||||
/**
|
||||
* Two {@link TypeAndAnnotation} are equal if they
|
||||
* has the same type and annotations.
|
||||
*/
|
||||
boolean equals(Object o);
|
||||
}
|
||||
66
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/XJC.java
Normal file
66
jdkSrc/jdk8/com/sun/tools/internal/xjc/api/XJC.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api;
|
||||
|
||||
import com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
|
||||
/**
|
||||
* Entry point to the programatic API to access
|
||||
* schema compiler (XJC) and schema generator (schemagen).
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class XJC {
|
||||
|
||||
/**
|
||||
* Gets a fresh {@link SchemaCompiler}.
|
||||
*
|
||||
* @return
|
||||
* always return non-null object.
|
||||
*/
|
||||
public static SchemaCompiler createSchemaCompiler() {
|
||||
return new SchemaCompilerImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the namespace URI -> package name conversion
|
||||
* as specified by the JAXB spec.
|
||||
*
|
||||
* @param namespaceUri
|
||||
* Namespace URI. Can be empty, but must not be null.
|
||||
* @return
|
||||
* A Java package name (e.g., "foo.bar"). "" to represent the root package.
|
||||
* This method returns null if the method fails to derive the package name
|
||||
* (there are certain namespace URIs with which this algorithm does not
|
||||
* work --- such as ":::" as the URI.)
|
||||
*/
|
||||
public static String getDefaultPackageName( String namespaceUri ) {
|
||||
if(namespaceUri==null) throw new IllegalArgumentException();
|
||||
return NameConverter.standard.toPackageName( namespaceUri );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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.xjc.api.impl.s2j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.tools.internal.xjc.api.Mapping;
|
||||
import com.sun.tools.internal.xjc.api.Property;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElement;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElementPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeRef;
|
||||
import com.sun.xml.internal.bind.v2.model.core.ClassInfo;
|
||||
import com.sun.xml.internal.bind.v2.model.core.ReferencePropertyInfo;
|
||||
|
||||
import com.sun.xml.internal.xsom.XSComplexType;
|
||||
import com.sun.xml.internal.xsom.XSComponent;
|
||||
import com.sun.xml.internal.xsom.XSContentType;
|
||||
import com.sun.xml.internal.xsom.XSModelGroup;
|
||||
import com.sun.xml.internal.xsom.XSParticle;
|
||||
import com.sun.xml.internal.xsom.XSTerm;
|
||||
|
||||
/**
|
||||
* Partial common implementation between {@link ElementMappingImpl} and {@link BeanMappingImpl}
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
abstract class AbstractMappingImpl<InfoT extends CElement> implements Mapping {
|
||||
|
||||
protected final JAXBModelImpl parent;
|
||||
protected final InfoT clazz;
|
||||
/**
|
||||
* Lazily computed.
|
||||
*
|
||||
* @see #getWrapperStyleDrilldown()
|
||||
*/
|
||||
private List<Property> drilldown = null;
|
||||
private boolean drilldownComputed = false;
|
||||
|
||||
protected AbstractMappingImpl(JAXBModelImpl parent, InfoT clazz) {
|
||||
this.parent = parent;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public final QName getElement() {
|
||||
return clazz.getElementName();
|
||||
}
|
||||
|
||||
public final String getClazz() {
|
||||
return clazz.getType().fullName();
|
||||
}
|
||||
|
||||
public final List<? extends Property> getWrapperStyleDrilldown() {
|
||||
if (!drilldownComputed) {
|
||||
drilldownComputed = true;
|
||||
drilldown = calcDrilldown();
|
||||
}
|
||||
return drilldown;
|
||||
}
|
||||
|
||||
protected abstract List<Property> calcDrilldown();
|
||||
|
||||
/**
|
||||
* Derived classes can use this method to implement {@link #calcDrilldown}.
|
||||
*/
|
||||
protected List<Property> buildDrilldown(CClassInfo typeBean) {
|
||||
//JAXWS 2.1 spec 2.3.1.2:
|
||||
//Wrapper style if the wrapper elements only contain child elements,
|
||||
//they must not contain xsd:choice
|
||||
if (containingChoice(typeBean)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Property> result;
|
||||
|
||||
CClassInfo bc = typeBean.getBaseClass();
|
||||
if (bc != null) {
|
||||
result = buildDrilldown(bc);
|
||||
if (result == null) {
|
||||
return null; // aborted
|
||||
}
|
||||
} else {
|
||||
result = new ArrayList<Property>();
|
||||
}
|
||||
|
||||
for (CPropertyInfo p : typeBean.getProperties()) {
|
||||
if (p instanceof CElementPropertyInfo) {
|
||||
CElementPropertyInfo ep = (CElementPropertyInfo) p;
|
||||
// wrong. A+,B,C is eligible for drill-down.
|
||||
// if(ep.isCollection())
|
||||
// // content model like A+,B,C is not eligible
|
||||
// return null;
|
||||
|
||||
List<? extends CTypeRef> ref = ep.getTypes();
|
||||
if (ref.size() != 1) {// content model like (A|B),C is not eligible
|
||||
return null;
|
||||
}
|
||||
|
||||
result.add(createPropertyImpl(ep, ref.get(0).getTagName()));
|
||||
} else if (p instanceof ReferencePropertyInfo) {
|
||||
CReferencePropertyInfo rp = (CReferencePropertyInfo) p;
|
||||
|
||||
Collection<CElement> elements = rp.getElements();
|
||||
if (elements.size() != 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CElement ref = elements.iterator().next();
|
||||
if (ref instanceof ClassInfo) {
|
||||
result.add(createPropertyImpl(rp, ref.getElementName()));
|
||||
} else {
|
||||
CElementInfo eref = (CElementInfo) ref;
|
||||
if (!eref.getSubstitutionMembers().isEmpty()) {
|
||||
return null; // elements with a substitution group isn't qualified for the wrapper style
|
||||
}
|
||||
// JAX-WS doesn't want to see JAXBElement, so we have to hide it for them.
|
||||
ElementAdapter fr;
|
||||
if (rp.isCollection()) {
|
||||
fr = new ElementCollectionAdapter(parent.outline.getField(rp), eref);
|
||||
} else {
|
||||
fr = new ElementSingleAdapter(parent.outline.getField(rp), eref);
|
||||
}
|
||||
|
||||
result.add(new PropertyImpl(this,
|
||||
fr, eref.getElementName()));
|
||||
}
|
||||
} else {// to be eligible for the wrapper style, only elements are allowed.
|
||||
// according to the JAX-RPC spec 2.3.1.2, element refs are disallowed
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean containingChoice(CClassInfo typeBean) {
|
||||
XSComponent component = typeBean.getSchemaComponent();
|
||||
if (component instanceof XSComplexType) {
|
||||
XSContentType contentType = ((XSComplexType) component).getContentType();
|
||||
XSParticle particle = contentType.asParticle();
|
||||
if (particle != null) {
|
||||
XSTerm term = particle.getTerm();
|
||||
XSModelGroup modelGroup = term.asModelGroup();
|
||||
if (modelGroup != null) {
|
||||
return (modelGroup.getCompositor() == XSModelGroup.Compositor.CHOICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Property createPropertyImpl(CPropertyInfo p, QName tagName) {
|
||||
return new PropertyImpl(this,
|
||||
parent.outline.getField(p), tagName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
|
||||
/**
|
||||
* Partial implementation of {@link Mapping}
|
||||
* for bean classes.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class BeanMappingImpl extends AbstractMappingImpl<CClassInfo> {
|
||||
|
||||
private final TypeAndAnnotationImpl taa = new TypeAndAnnotationImpl(parent.outline,clazz);
|
||||
|
||||
BeanMappingImpl(JAXBModelImpl parent, CClassInfo classInfo) {
|
||||
super(parent,classInfo);
|
||||
assert classInfo.isElement();
|
||||
}
|
||||
|
||||
public TypeAndAnnotation getType() {
|
||||
return taa;
|
||||
}
|
||||
|
||||
public final String getTypeClass() {
|
||||
return getClazz();
|
||||
}
|
||||
|
||||
public List<Property> calcDrilldown() {
|
||||
if(!clazz.isOrdered())
|
||||
return null; // all is not eligible for the wrapper style
|
||||
return buildDrilldown(clazz);
|
||||
}
|
||||
}
|
||||
@@ -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.xjc.api.impl.s2j;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* {@link ErrorHandler} that reports all errors as warnings.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class DowngradingErrorHandler implements ErrorHandler {
|
||||
private final ErrorHandler core;
|
||||
|
||||
public DowngradingErrorHandler(ErrorHandler core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public void warning(SAXParseException exception) throws SAXException {
|
||||
core.warning(exception);
|
||||
}
|
||||
|
||||
public void error(SAXParseException exception) throws SAXException {
|
||||
core.warning(exception);
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException exception) throws SAXException {
|
||||
core.warning(exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.codemodel.internal.JConditional;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JInvocation;
|
||||
|
||||
/**
|
||||
* {@link FieldOutline} that wraps another {@link FieldOutline}
|
||||
* and allows JAX-WS to access values without using about
|
||||
* {@link JAXBElement}.
|
||||
*
|
||||
* <p>
|
||||
* That means if a value is requested, we unwrap JAXBElement
|
||||
* and give it to them. If a value is set, we wrap that into
|
||||
* JAXBElement, etc.
|
||||
*
|
||||
* <p>
|
||||
* This can be used only with {@link CReferencePropertyInfo}
|
||||
* (or else it won't be {@link JAXBElement),
|
||||
* with one {@link CElementInfo} (or else we can't infer the tag name.)
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
abstract class ElementAdapter implements FieldOutline {
|
||||
protected final FieldOutline core;
|
||||
|
||||
/**
|
||||
* The only one {@link CElementInfo} that can be in the property.
|
||||
*/
|
||||
protected final CElementInfo ei;
|
||||
|
||||
public ElementAdapter(FieldOutline core, CElementInfo ei) {
|
||||
this.core = core;
|
||||
this.ei = ei;
|
||||
}
|
||||
|
||||
public ClassOutline parent() {
|
||||
return core.parent();
|
||||
}
|
||||
|
||||
public CPropertyInfo getPropertyInfo() {
|
||||
return core.getPropertyInfo();
|
||||
}
|
||||
|
||||
protected final Outline outline() {
|
||||
return core.parent().parent();
|
||||
}
|
||||
|
||||
protected final JCodeModel codeModel() {
|
||||
return outline().getCodeModel();
|
||||
}
|
||||
|
||||
protected abstract class FieldAccessorImpl implements FieldAccessor {
|
||||
final FieldAccessor acc;
|
||||
|
||||
public FieldAccessorImpl(JExpression target) {
|
||||
acc = core.create(target);
|
||||
}
|
||||
|
||||
public void unsetValues(JBlock body) {
|
||||
acc.unsetValues(body);
|
||||
}
|
||||
|
||||
public JExpression hasSetValue() {
|
||||
return acc.hasSetValue();
|
||||
}
|
||||
|
||||
public FieldOutline owner() {
|
||||
return ElementAdapter.this;
|
||||
}
|
||||
|
||||
public CPropertyInfo getPropertyInfo() {
|
||||
return core.getPropertyInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a type value into a {@link JAXBElement}.
|
||||
*/
|
||||
protected final JInvocation createJAXBElement(JExpression $var) {
|
||||
JCodeModel cm = codeModel();
|
||||
|
||||
return JExpr._new(cm.ref(JAXBElement.class))
|
||||
.arg(JExpr._new(cm.ref(QName.class))
|
||||
.arg(ei.getElementName().getNamespaceURI())
|
||||
.arg(ei.getElementName().getLocalPart()))
|
||||
.arg(getRawType().boxify().erasure().dotclass())
|
||||
.arg($var);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JConditional;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JForEach;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import static com.sun.tools.internal.xjc.outline.Aspect.EXPOSED;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
/**
|
||||
* {@link ElementAdapter} that works with a collection
|
||||
* of {@link JAXBElement}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ElementCollectionAdapter extends ElementAdapter {
|
||||
public ElementCollectionAdapter(FieldOutline core, CElementInfo ei) {
|
||||
super(core, ei);
|
||||
}
|
||||
|
||||
public JType getRawType() {
|
||||
return codeModel().ref(List.class).narrow(itemType().boxify());
|
||||
}
|
||||
|
||||
private JType itemType() {
|
||||
return ei.getContentInMemoryType().toType(outline(), EXPOSED);
|
||||
}
|
||||
|
||||
public FieldAccessor create(JExpression targetObject) {
|
||||
return new FieldAccessorImpl(targetObject);
|
||||
}
|
||||
|
||||
final class FieldAccessorImpl extends ElementAdapter.FieldAccessorImpl {
|
||||
public FieldAccessorImpl(JExpression target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
JCodeModel cm = outline().getCodeModel();
|
||||
JClass elementType = ei.toType(outline(),EXPOSED).boxify();
|
||||
|
||||
// [RESULT]
|
||||
// $var = new ArrayList();
|
||||
// for( JAXBElement e : [core.toRawValue] ) {
|
||||
// if(e==null)
|
||||
// $var.add(null);
|
||||
// else
|
||||
// $var.add(e.getValue());
|
||||
// }
|
||||
|
||||
block.assign($var,JExpr._new(cm.ref(ArrayList.class).narrow(itemType().boxify())));
|
||||
JVar $col = block.decl(core.getRawType(), "col" + hashCode());
|
||||
acc.toRawValue(block,$col);
|
||||
JForEach loop = block.forEach(elementType, "v" + hashCode()/*unique string handling*/, $col);
|
||||
|
||||
JConditional cond = loop.body()._if(loop.var().eq(JExpr._null()));
|
||||
cond._then().invoke($var,"add").arg(JExpr._null());
|
||||
cond._else().invoke($var,"add").arg(loop.var().invoke("getValue"));
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
JCodeModel cm = outline().getCodeModel();
|
||||
JClass elementType = ei.toType(outline(),EXPOSED).boxify();
|
||||
|
||||
// [RESULT]
|
||||
// $t = new ArrayList();
|
||||
// for( Type e : $var ) {
|
||||
// $var.add(new JAXBElement(e));
|
||||
// }
|
||||
// [core.fromRawValue]
|
||||
|
||||
JClass col = cm.ref(ArrayList.class).narrow(elementType);
|
||||
JVar $t = block.decl(col,uniqueName+"_col",JExpr._new(col));
|
||||
|
||||
JForEach loop = block.forEach(itemType(), uniqueName+"_i", $t);
|
||||
loop.body().invoke($var,"add").arg(createJAXBElement(loop.var()));
|
||||
|
||||
acc.fromRawValue(block, uniqueName, $t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.tools.internal.xjc.api.Property;
|
||||
import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
|
||||
import com.sun.tools.internal.xjc.model.CAdapter;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElementPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeInfo;
|
||||
import com.sun.tools.internal.xjc.model.TypeUse;
|
||||
import com.sun.tools.internal.xjc.model.TypeUseFactory;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ElementMappingImpl extends AbstractMappingImpl<CElementInfo> {
|
||||
|
||||
private final TypeAndAnnotation taa;
|
||||
|
||||
protected ElementMappingImpl(JAXBModelImpl parent, CElementInfo elementInfo) {
|
||||
super(parent,elementInfo);
|
||||
|
||||
TypeUse t = clazz.getContentType();
|
||||
if(clazz.getProperty().isCollection())
|
||||
t = TypeUseFactory.makeCollection(t);
|
||||
CAdapter a = clazz.getProperty().getAdapter();
|
||||
if(a!=null)
|
||||
t = TypeUseFactory.adapt(t,a);
|
||||
taa = new TypeAndAnnotationImpl(parent.outline,t);
|
||||
}
|
||||
|
||||
public TypeAndAnnotation getType() {
|
||||
return taa;
|
||||
}
|
||||
|
||||
public final List<Property> calcDrilldown() {
|
||||
CElementPropertyInfo p = clazz.getProperty();
|
||||
|
||||
if(p.getAdapter()!=null)
|
||||
return null; // if adapted, avoid drill down
|
||||
|
||||
if(p.isCollection())
|
||||
// things like <xs:element name="foo" type="xs:NMTOKENS" /> is not eligible.
|
||||
return null;
|
||||
|
||||
CTypeInfo typeClass = p.ref().get(0);
|
||||
|
||||
if(!(typeClass instanceof CClassInfo))
|
||||
// things like <xs:element name="foo" type="xs:string" /> is not eligible.
|
||||
return null;
|
||||
|
||||
CClassInfo ci = (CClassInfo)typeClass;
|
||||
|
||||
// if the type is abstract we can't use it.
|
||||
if(ci.isAbstract())
|
||||
return null;
|
||||
|
||||
// the 'all' compositor doesn't qualify
|
||||
if(!ci.isOrdered())
|
||||
return null;
|
||||
|
||||
return buildDrilldown(ci);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.codemodel.internal.JConditional;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JInvocation;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
|
||||
/**
|
||||
* {@link ElementAdapter} that works with a single {@link JAXBElement}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ElementSingleAdapter extends ElementAdapter {
|
||||
public ElementSingleAdapter(FieldOutline core, CElementInfo ei) {
|
||||
super(core, ei);
|
||||
}
|
||||
|
||||
public JType getRawType() {
|
||||
return ei.getContentInMemoryType().toType(outline(), Aspect.EXPOSED);
|
||||
}
|
||||
|
||||
public FieldAccessor create(JExpression targetObject) {
|
||||
return new FieldAccessorImpl(targetObject);
|
||||
}
|
||||
|
||||
final class FieldAccessorImpl extends ElementAdapter.FieldAccessorImpl {
|
||||
public FieldAccessorImpl(JExpression target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
// [RESULT]
|
||||
// if([core.hasSetValue])
|
||||
// $var = [core.toRawValue].getValue();
|
||||
// else
|
||||
// $var = null;
|
||||
|
||||
JConditional cond = block._if(acc.hasSetValue());
|
||||
JVar $v = cond._then().decl(core.getRawType(), "v" + hashCode());// TODO: unique value control
|
||||
acc.toRawValue(cond._then(),$v);
|
||||
cond._then().assign($var,$v.invoke("getValue"));
|
||||
cond._else().assign($var, JExpr._null());
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
// [RESULT]
|
||||
// [core.fromRawValue](new JAXBElement(tagName, TYPE, $var));
|
||||
|
||||
acc.fromRawValue(block,uniqueName, createJAXBElement($var));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.tools.internal.xjc.Plugin;
|
||||
import com.sun.tools.internal.xjc.api.ErrorListener;
|
||||
import com.sun.tools.internal.xjc.api.JAXBModel;
|
||||
import com.sun.tools.internal.xjc.api.Mapping;
|
||||
import com.sun.tools.internal.xjc.api.S2JJAXBModel;
|
||||
import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.model.TypeUse;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.outline.PackageOutline;
|
||||
|
||||
/**
|
||||
* {@link JAXBModel} implementation.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
final class JAXBModelImpl implements S2JJAXBModel {
|
||||
/*package*/ final Outline outline;
|
||||
|
||||
/**
|
||||
* All the known classes.
|
||||
*/
|
||||
private final Model model;
|
||||
|
||||
private final Map<QName,Mapping> byXmlName = new HashMap<QName,Mapping>();
|
||||
|
||||
JAXBModelImpl(Outline outline) {
|
||||
this.model = outline.getModel();
|
||||
this.outline = outline;
|
||||
|
||||
for (CClassInfo ci : model.beans().values()) {
|
||||
if(!ci.isElement())
|
||||
continue;
|
||||
byXmlName.put(ci.getElementName(),new BeanMappingImpl(this,ci));
|
||||
}
|
||||
for (CElementInfo ei : model.getElementMappings(null).values()) {
|
||||
byXmlName.put(ei.getElementName(),new ElementMappingImpl(this,ei));
|
||||
}
|
||||
}
|
||||
|
||||
public JCodeModel generateCode(Plugin[] extensions,ErrorListener errorListener) {
|
||||
// we no longer do any code generation
|
||||
return outline.getCodeModel();
|
||||
}
|
||||
|
||||
public List<JClass> getAllObjectFactories() {
|
||||
List<JClass> r = new ArrayList<JClass>();
|
||||
for (PackageOutline pkg : outline.getAllPackageContexts()) {
|
||||
r.add(pkg.objectFactory());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public final Mapping get(QName elementName) {
|
||||
return byXmlName.get(elementName);
|
||||
}
|
||||
|
||||
public final Collection<? extends Mapping> getMappings() {
|
||||
return byXmlName.values();
|
||||
}
|
||||
|
||||
public TypeAndAnnotation getJavaType(QName xmlTypeName) {
|
||||
// TODO: primitive type handling?
|
||||
TypeUse use = model.typeUses().get(xmlTypeName);
|
||||
if(use==null) return null;
|
||||
|
||||
return new TypeAndAnnotationImpl(outline,use);
|
||||
}
|
||||
|
||||
public final List<String> getClassList() {
|
||||
List<String> classList = new ArrayList<String>();
|
||||
|
||||
// list up root classes
|
||||
for( PackageOutline p : outline.getAllPackageContexts() )
|
||||
classList.add( p.objectFactory().fullName() );
|
||||
return classList;
|
||||
}
|
||||
}
|
||||
@@ -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.xjc.api.impl.s2j;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.tools.internal.xjc.api.Mapping;
|
||||
import com.sun.tools.internal.xjc.api.Property;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public /*for BSH*/ final class PropertyImpl implements Property {
|
||||
protected final FieldOutline fr;
|
||||
protected final QName elementName;
|
||||
protected final Mapping parent;
|
||||
protected final JCodeModel codeModel;
|
||||
|
||||
PropertyImpl( Mapping parent, FieldOutline fr, QName elementName ) {
|
||||
this.parent = parent;
|
||||
this.fr = fr;
|
||||
this.elementName = elementName;
|
||||
this.codeModel = fr.getRawType().owner();
|
||||
}
|
||||
|
||||
public final String name() {
|
||||
return fr.getPropertyInfo().getName(false);
|
||||
}
|
||||
|
||||
/** Returns raw schema name for simpleType property. May return null for other types. */
|
||||
public final QName rawName() {
|
||||
if (fr instanceof ElementAdapter) {
|
||||
CElementInfo eInfo = ((ElementAdapter)fr).ei;
|
||||
if ((eInfo != null) && (eInfo.getProperty() != null)) {
|
||||
return eInfo.getProperty().getTypes().get(0).getTypeName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final QName elementName() {
|
||||
return elementName;
|
||||
}
|
||||
|
||||
public final JType type() {
|
||||
return fr.getRawType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.istack.internal.SAXParseException2;
|
||||
import com.sun.tools.internal.xjc.ErrorReceiver;
|
||||
import com.sun.tools.internal.xjc.ModelLoader;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.api.ClassNameAllocator;
|
||||
import com.sun.tools.internal.xjc.api.ErrorListener;
|
||||
import com.sun.tools.internal.xjc.api.SchemaCompiler;
|
||||
import com.sun.tools.internal.xjc.api.SpecVersion;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.DOMForest;
|
||||
import com.sun.tools.internal.xjc.reader.internalizer.SCDBasedBindingSet;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.parser.LSInputSAXWrapper;
|
||||
import com.sun.tools.internal.xjc.reader.xmlschema.parser.XMLSchemaInternalizationLogic;
|
||||
import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
|
||||
import com.sun.xml.internal.bind.v2.util.XmlFactory;
|
||||
import com.sun.xml.internal.xsom.XSSchemaSet;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.ls.LSInput;
|
||||
import org.w3c.dom.ls.LSResourceResolver;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.LocatorImpl;
|
||||
|
||||
/**
|
||||
* {@link SchemaCompiler} implementation.
|
||||
*
|
||||
* This class builds a {@link DOMForest} until the {@link #bind()} method,
|
||||
* then this method does the rest of the hard work.
|
||||
*
|
||||
* @see ModelLoader
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class SchemaCompilerImpl extends ErrorReceiver implements SchemaCompiler {
|
||||
|
||||
/**
|
||||
* User-specified error receiver.
|
||||
* This field can be null, in which case errors need to be discarded.
|
||||
*/
|
||||
private ErrorListener errorListener;
|
||||
|
||||
protected final Options opts = new Options();
|
||||
|
||||
protected @NotNull DOMForest forest;
|
||||
|
||||
/**
|
||||
* Set to true once an error is found.
|
||||
*/
|
||||
private boolean hadError;
|
||||
|
||||
public SchemaCompilerImpl() {
|
||||
opts.compatibilityMode = Options.EXTENSION;
|
||||
resetSchema();
|
||||
|
||||
if(System.getProperty("xjc-api.test")!=null) {
|
||||
opts.debugMode = true;
|
||||
opts.verbose = true;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Options getOptions() {
|
||||
return opts;
|
||||
}
|
||||
|
||||
public ContentHandler getParserHandler( String systemId ) {
|
||||
return forest.getParserHandler(systemId,true);
|
||||
}
|
||||
|
||||
public void parseSchema( String systemId, Element element ) {
|
||||
checkAbsoluteness(systemId);
|
||||
try {
|
||||
DOMScanner scanner = new DOMScanner();
|
||||
|
||||
// use a locator that sets the system ID correctly
|
||||
// so that we can resolve relative URLs in most of the case.
|
||||
// it still doesn't handle xml:base and XInclude and all those things
|
||||
// correctly. There's just no way to make all those things work with DOM!
|
||||
LocatorImpl loc = new LocatorImpl();
|
||||
loc.setSystemId(systemId);
|
||||
scanner.setLocator(loc);
|
||||
|
||||
scanner.setContentHandler(getParserHandler(systemId));
|
||||
scanner.scan(element);
|
||||
} catch (SAXException e) {
|
||||
// since parsing DOM shouldn't cause a SAX exception
|
||||
// and our handler will never throw it, it's not clear
|
||||
// if this will ever happen.
|
||||
fatalError(new SAXParseException2(
|
||||
e.getMessage(), null, systemId,-1,-1, e));
|
||||
}
|
||||
}
|
||||
|
||||
public void parseSchema(InputSource source) {
|
||||
checkAbsoluteness(source.getSystemId());
|
||||
try {
|
||||
forest.parse(source,true);
|
||||
} catch (SAXException e) {
|
||||
// parsers are required to report an error to ErrorHandler,
|
||||
// so we should never see this error.
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTargetVersion(SpecVersion version) {
|
||||
if(version==null)
|
||||
version = SpecVersion.LATEST;
|
||||
opts.target = version;
|
||||
}
|
||||
|
||||
public void parseSchema(String systemId, XMLStreamReader reader) throws XMLStreamException {
|
||||
checkAbsoluteness(systemId);
|
||||
forest.parse(systemId,reader,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the system ID is absolute.
|
||||
*/
|
||||
@SuppressWarnings("ResultOfObjectAllocationIgnored")
|
||||
private void checkAbsoluteness(String systemId) {
|
||||
// we need to be able to handle system IDs like "urn:foo", which java.net.URL can't process,
|
||||
// but OTOH we also need to be able to process system IDs like "file://a b c/def.xsd",
|
||||
// which java.net.URI can't process. So for now, let's fail only if both of them fail.
|
||||
// eventually we need a proper URI class that works for us.
|
||||
try {
|
||||
new URL(systemId);
|
||||
} catch( MalformedURLException mue) {
|
||||
try {
|
||||
new URI(systemId);
|
||||
} catch (URISyntaxException e ) {
|
||||
throw new IllegalArgumentException("system ID '"+systemId+"' isn't absolute",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setEntityResolver(EntityResolver entityResolver) {
|
||||
forest.setEntityResolver(entityResolver);
|
||||
opts.entityResolver = entityResolver;
|
||||
}
|
||||
|
||||
public void setDefaultPackageName(String packageName) {
|
||||
opts.defaultPackage2 = packageName;
|
||||
}
|
||||
|
||||
public void forcePackageName(String packageName) {
|
||||
opts.defaultPackage = packageName;
|
||||
}
|
||||
|
||||
public void setClassNameAllocator(ClassNameAllocator allocator) {
|
||||
opts.classNameAllocator = allocator;
|
||||
}
|
||||
|
||||
public void resetSchema() {
|
||||
forest = new DOMForest(new XMLSchemaInternalizationLogic(), opts);
|
||||
forest.setErrorHandler(this);
|
||||
forest.setEntityResolver(opts.entityResolver);
|
||||
}
|
||||
|
||||
public JAXBModelImpl bind() {
|
||||
// this has been problematic. turn it off.
|
||||
// if(!forest.checkSchemaCorrectness(this))
|
||||
// return null;
|
||||
|
||||
// parse all the binding files given via XJC -b options.
|
||||
// this also takes care of the binding files given in the -episode option.
|
||||
for (InputSource is : opts.getBindFiles())
|
||||
parseSchema(is);
|
||||
|
||||
// internalization
|
||||
SCDBasedBindingSet scdBasedBindingSet = forest.transform(opts.isExtensionMode());
|
||||
|
||||
if (!NO_CORRECTNESS_CHECK) {
|
||||
// correctness check
|
||||
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, opts.disableXmlSecurity);
|
||||
|
||||
// fix for https://jaxb.dev.java.net/issues/show_bug.cgi?id=795
|
||||
// taken from SchemaConstraintChecker, TODO XXX FIXME UGLY
|
||||
if (opts.entityResolver != null) {
|
||||
sf.setResourceResolver(new LSResourceResolver() {
|
||||
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
|
||||
try {
|
||||
// XSOM passes the namespace URI to the publicID parameter.
|
||||
// we do the same here .
|
||||
InputSource is = opts.entityResolver.resolveEntity(namespaceURI, systemId);
|
||||
if (is == null) return null;
|
||||
return new LSInputSAXWrapper(is);
|
||||
} catch (SAXException e) {
|
||||
// TODO: is this sufficient?
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
// TODO: is this sufficient?
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sf.setErrorHandler(new DowngradingErrorHandler(this));
|
||||
forest.weakSchemaCorrectnessCheck(sf);
|
||||
if (hadError)
|
||||
return null; // error in the correctness check. abort now
|
||||
}
|
||||
|
||||
JCodeModel codeModel = new JCodeModel();
|
||||
|
||||
ModelLoader gl = new ModelLoader(opts,codeModel,this);
|
||||
try {
|
||||
XSSchemaSet result = gl.createXSOM(forest, scdBasedBindingSet);
|
||||
if(result==null)
|
||||
return null;
|
||||
|
||||
// we need info about each field, so we go ahead and generate the
|
||||
// skeleton at this point.
|
||||
// REVISIT: we should separate FieldRenderer and FieldAccessor
|
||||
// so that accessors can be used before we build the code.
|
||||
Model model = gl.annotateXMLSchema(result);
|
||||
if(model==null) return null;
|
||||
|
||||
if(hadError) return null; // if we have any error by now, abort
|
||||
|
||||
model.setPackageLevelAnnotations(opts.packageLevelAnnotations);
|
||||
|
||||
Outline context = model.generateCode(opts,this);
|
||||
if(context==null) return null;
|
||||
|
||||
if(hadError) return null;
|
||||
|
||||
return new JAXBModelImpl(context);
|
||||
} catch( SAXException e ) {
|
||||
// since XSOM uses our parser that scans DOM,
|
||||
// no parser error is possible.
|
||||
// all the other errors will be directed to ErrorReceiver
|
||||
// before it's thrown, so when the exception is thrown
|
||||
// the error should have already been reported.
|
||||
|
||||
// thus ignore.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setErrorListener(ErrorListener errorListener) {
|
||||
this.errorListener = errorListener;
|
||||
}
|
||||
|
||||
public void info(SAXParseException exception) {
|
||||
if(errorListener!=null)
|
||||
errorListener.info(exception);
|
||||
}
|
||||
public void warning(SAXParseException exception) {
|
||||
if(errorListener!=null)
|
||||
errorListener.warning(exception);
|
||||
}
|
||||
public void error(SAXParseException exception) {
|
||||
hadError = true;
|
||||
if(errorListener!=null)
|
||||
errorListener.error(exception);
|
||||
}
|
||||
public void fatalError(SAXParseException exception) {
|
||||
hadError = true;
|
||||
if(errorListener!=null)
|
||||
errorListener.fatalError(exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* We use JAXP 1.3 to do a schema correctness check, but we know
|
||||
* it doesn't always work. So in case some people hit the problem,
|
||||
* this switch is here so that they can turn it off as a workaround.
|
||||
*/
|
||||
private static boolean NO_CORRECTNESS_CHECK = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
NO_CORRECTNESS_CHECK = Boolean.getBoolean(SchemaCompilerImpl.class.getName()+".noCorrectnessCheck");
|
||||
} catch( Throwable t) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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.xjc.api.impl.s2j;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttachmentRef;
|
||||
import javax.xml.bind.annotation.XmlList;
|
||||
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import com.sun.codemodel.internal.JPrimitiveType;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlJavaTypeAdapterWriter;
|
||||
import com.sun.tools.internal.xjc.model.CAdapter;
|
||||
import com.sun.tools.internal.xjc.model.TypeUse;
|
||||
import com.sun.tools.internal.xjc.model.nav.NType;
|
||||
import static com.sun.tools.internal.xjc.outline.Aspect.EXPOSED;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.xml.internal.bind.v2.runtime.SwaRefAdapterMarker;
|
||||
|
||||
/**
|
||||
* {@link TypeAndAnnotation} implementation.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class TypeAndAnnotationImpl implements TypeAndAnnotation {
|
||||
private final TypeUse typeUse;
|
||||
private final Outline outline;
|
||||
|
||||
public TypeAndAnnotationImpl(Outline outline, TypeUse typeUse) {
|
||||
this.typeUse = typeUse;
|
||||
this.outline = outline;
|
||||
}
|
||||
|
||||
public JType getTypeClass() {
|
||||
CAdapter a = typeUse.getAdapterUse();
|
||||
NType nt;
|
||||
if(a!=null)
|
||||
nt = a.customType;
|
||||
else
|
||||
nt = typeUse.getInfo().getType();
|
||||
|
||||
JType jt = nt.toType(outline,EXPOSED);
|
||||
|
||||
JPrimitiveType prim = jt.boxify().getPrimitiveType();
|
||||
if(!typeUse.isCollection() && prim!=null)
|
||||
jt = prim;
|
||||
|
||||
if(typeUse.isCollection())
|
||||
jt = jt.array();
|
||||
|
||||
return jt;
|
||||
}
|
||||
|
||||
public void annotate(JAnnotatable programElement) {
|
||||
if(typeUse.getAdapterUse()==null && !typeUse.isCollection())
|
||||
return; // nothing
|
||||
|
||||
CAdapter adapterUse = typeUse.getAdapterUse();
|
||||
if(adapterUse!=null) {
|
||||
// ugly, ugly hack
|
||||
if(adapterUse.getAdapterIfKnown() == SwaRefAdapterMarker.class) {
|
||||
programElement.annotate(XmlAttachmentRef.class);
|
||||
} else {
|
||||
// [RESULT]
|
||||
// @XmlJavaTypeAdapter( Foo.class )
|
||||
programElement.annotate2(XmlJavaTypeAdapterWriter.class).value(
|
||||
adapterUse.adapterType.toType(outline,EXPOSED));
|
||||
}
|
||||
}
|
||||
if(typeUse.isCollection())
|
||||
programElement.annotate(XmlList.class);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
// TODO: support annotations
|
||||
builder.append(getTypeClass());
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof TypeAndAnnotationImpl)) return false;
|
||||
TypeAndAnnotationImpl that = (TypeAndAnnotationImpl) o;
|
||||
return this.typeUse==that.typeUse;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return typeUse.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -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.xjc.api.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import com.sun.istack.internal.Nullable;
|
||||
|
||||
/**
|
||||
* {@link ClassLoader} that loads Annotation Processing and specified classes
|
||||
* both into the same classloader, so that they can reference each other.
|
||||
*
|
||||
* @author Bhakti Mehta
|
||||
* @since 2.0 beta
|
||||
*/
|
||||
public final class ApClassLoader extends URLClassLoader {
|
||||
/**
|
||||
* List of package prefixes we want to mask the
|
||||
* parent classLoader from loading
|
||||
*/
|
||||
private final String[] packagePrefixes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param packagePrefixes
|
||||
* The package prefixes that are forced to resolve within this class loader.
|
||||
* @param parent
|
||||
* The parent class loader to delegate to. Null to indicate bootstrap classloader.
|
||||
*/
|
||||
public ApClassLoader(@Nullable ClassLoader parent, String[] packagePrefixes) throws ToolsJarNotFoundException {
|
||||
super(getToolsJar(parent),parent);
|
||||
if(getURLs().length==0)
|
||||
// if tools.jar was found in our classloader, no need to create
|
||||
// a parallel classes
|
||||
this.packagePrefixes = new String[0];
|
||||
else
|
||||
this.packagePrefixes = packagePrefixes;
|
||||
}
|
||||
|
||||
public Class loadClass(String className) throws ClassNotFoundException {
|
||||
for( String prefix : packagePrefixes ) {
|
||||
if (className.startsWith(prefix) ) {
|
||||
// we need to load those classes in this class loader
|
||||
// without delegation.
|
||||
return findClass(className);
|
||||
}
|
||||
}
|
||||
|
||||
return super.loadClass(className);
|
||||
|
||||
}
|
||||
|
||||
protected Class findClass(String name) throws ClassNotFoundException {
|
||||
|
||||
StringBuilder sb = new StringBuilder(name.length() + 6);
|
||||
sb.append(name.replace('.','/')).append(".class");
|
||||
|
||||
InputStream is = getResourceAsStream(sb.toString());
|
||||
if (is==null)
|
||||
throw new ClassNotFoundException("Class not found" + sb);
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while((len=is.read(buf))>=0)
|
||||
baos.write(buf,0,len);
|
||||
|
||||
buf = baos.toByteArray();
|
||||
|
||||
// define package if not defined yet
|
||||
int i = name.lastIndexOf('.');
|
||||
if (i != -1) {
|
||||
String pkgname = name.substring(0, i);
|
||||
Package pkg = getPackage(pkgname);
|
||||
if(pkg==null)
|
||||
definePackage(pkgname, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
return defineClass(name,buf,0,buf.length);
|
||||
} catch (IOException e) {
|
||||
throw new ClassNotFoundException(name,e);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ioe) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a class loader that can load classes from JDK tools.jar.
|
||||
* @param parent
|
||||
*/
|
||||
private static URL[] getToolsJar(@Nullable ClassLoader parent) throws ToolsJarNotFoundException {
|
||||
|
||||
try {
|
||||
Class.forName("com.sun.tools.javac.Main", false, parent);
|
||||
return new URL[0];
|
||||
// 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);
|
||||
}
|
||||
|
||||
try {
|
||||
return new URL[]{toolsJar.toURL()};
|
||||
} catch (MalformedURLException e) {
|
||||
// impossible
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.xjc.api.util;
|
||||
|
||||
import javax.tools.StandardLocation;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
|
||||
import com.sun.codemodel.internal.CodeWriter;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import javax.annotation.processing.Filer;
|
||||
|
||||
import static javax.tools.StandardLocation.CLASS_PATH;
|
||||
import static javax.tools.StandardLocation.SOURCE_PATH;
|
||||
|
||||
/**
|
||||
* {@link CodeWriter} that generates source code to {@link Filer}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class FilerCodeWriter extends CodeWriter {
|
||||
|
||||
private final Filer filer;
|
||||
|
||||
public FilerCodeWriter(Filer filer) {
|
||||
this.filer = filer;
|
||||
}
|
||||
|
||||
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
|
||||
StandardLocation loc;
|
||||
if(fileName.endsWith(".java")) {
|
||||
// Annotation Processing doesn't do the proper Unicode escaping on Java source files,
|
||||
// so we can't rely on Filer.createSourceFile.
|
||||
loc = SOURCE_PATH;
|
||||
} else {
|
||||
// put non-Java files directly to the output folder
|
||||
loc = CLASS_PATH;
|
||||
}
|
||||
return filer.createResource(loc, pkg.name(), fileName).openOutputStream();
|
||||
}
|
||||
|
||||
public Writer openSource(JPackage pkg, String fileName) throws IOException {
|
||||
String name;
|
||||
if(pkg.isUnnamed())
|
||||
name = fileName;
|
||||
else
|
||||
name = pkg.name()+'.'+fileName;
|
||||
|
||||
name = name.substring(0,name.length()-5); // strip ".java"
|
||||
|
||||
return filer.createSourceFile(name).openWriter();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
; // noop
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.xjc.api.util;
|
||||
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Message resources
|
||||
*/
|
||||
enum Messages {
|
||||
TOOLS_JAR_NOT_FOUND, // 1 arg
|
||||
;
|
||||
|
||||
private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getName());
|
||||
|
||||
public String toString() {
|
||||
return format();
|
||||
}
|
||||
|
||||
public String format( Object... args ) {
|
||||
return MessageFormat.format( rb.getString(name()), args );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.xjc.api.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Signals an error when tools.jar was not found.
|
||||
*
|
||||
* Simply print out the message obtained by {@link #getMessage()}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class ToolsJarNotFoundException extends Exception {
|
||||
/**
|
||||
* Location where we expected to find tools.jar
|
||||
*/
|
||||
public final File toolsJar;
|
||||
|
||||
public ToolsJarNotFoundException(File toolsJar) {
|
||||
super(calcMessage(toolsJar));
|
||||
this.toolsJar = toolsJar;
|
||||
}
|
||||
|
||||
private static String calcMessage(File toolsJar) {
|
||||
return Messages.TOOLS_JAR_NOT_FOUND.format(toolsJar.getPath());
|
||||
}
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessOrder;
|
||||
import javax.xml.bind.annotation.XmlAccessorOrder;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAccessorOrderWriter
|
||||
extends JAnnotationWriter<XmlAccessorOrder>
|
||||
{
|
||||
|
||||
|
||||
XmlAccessorOrderWriter value(XmlAccessOrder value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAccessorTypeWriter
|
||||
extends JAnnotationWriter<XmlAccessorType>
|
||||
{
|
||||
|
||||
|
||||
XmlAccessorTypeWriter value(XmlAccessType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyAttribute;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAnyAttributeWriter
|
||||
extends JAnnotationWriter<XmlAnyAttribute>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyElement;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAnyElementWriter
|
||||
extends JAnnotationWriter<XmlAnyElement>
|
||||
{
|
||||
|
||||
|
||||
XmlAnyElementWriter value(Class value);
|
||||
|
||||
XmlAnyElementWriter value(JType value);
|
||||
|
||||
XmlAnyElementWriter lax(boolean value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttachmentRef;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAttachmentRefWriter
|
||||
extends JAnnotationWriter<XmlAttachmentRef>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlAttributeWriter
|
||||
extends JAnnotationWriter<XmlAttribute>
|
||||
{
|
||||
|
||||
|
||||
XmlAttributeWriter name(String value);
|
||||
|
||||
XmlAttributeWriter namespace(String value);
|
||||
|
||||
XmlAttributeWriter required(boolean value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementDecl;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementDeclWriter
|
||||
extends JAnnotationWriter<XmlElementDecl>
|
||||
{
|
||||
|
||||
|
||||
XmlElementDeclWriter name(String value);
|
||||
|
||||
XmlElementDeclWriter scope(Class value);
|
||||
|
||||
XmlElementDeclWriter scope(JType value);
|
||||
|
||||
XmlElementDeclWriter namespace(String value);
|
||||
|
||||
XmlElementDeclWriter defaultValue(String value);
|
||||
|
||||
XmlElementDeclWriter substitutionHeadNamespace(String value);
|
||||
|
||||
XmlElementDeclWriter substitutionHeadName(String value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementRef;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementRefWriter
|
||||
extends JAnnotationWriter<XmlElementRef>
|
||||
{
|
||||
|
||||
|
||||
XmlElementRefWriter name(String value);
|
||||
|
||||
XmlElementRefWriter type(Class value);
|
||||
|
||||
XmlElementRefWriter type(JType value);
|
||||
|
||||
XmlElementRefWriter namespace(String value);
|
||||
|
||||
XmlElementRefWriter required(boolean value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementRefs;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementRefsWriter
|
||||
extends JAnnotationWriter<XmlElementRefs>
|
||||
{
|
||||
|
||||
|
||||
XmlElementRefWriter value();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementWrapperWriter
|
||||
extends JAnnotationWriter<XmlElementWrapper>
|
||||
{
|
||||
|
||||
|
||||
XmlElementWrapperWriter name(String value);
|
||||
|
||||
XmlElementWrapperWriter namespace(String value);
|
||||
|
||||
XmlElementWrapperWriter required(boolean value);
|
||||
|
||||
XmlElementWrapperWriter nillable(boolean value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementWriter
|
||||
extends JAnnotationWriter<XmlElement>
|
||||
{
|
||||
|
||||
|
||||
XmlElementWriter name(String value);
|
||||
|
||||
XmlElementWriter type(Class value);
|
||||
|
||||
XmlElementWriter type(JType value);
|
||||
|
||||
XmlElementWriter namespace(String value);
|
||||
|
||||
XmlElementWriter defaultValue(String value);
|
||||
|
||||
XmlElementWriter required(boolean value);
|
||||
|
||||
XmlElementWriter nillable(boolean value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElements;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlElementsWriter
|
||||
extends JAnnotationWriter<XmlElements>
|
||||
{
|
||||
|
||||
|
||||
XmlElementWriter value();
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlEnumValueWriter
|
||||
extends JAnnotationWriter<XmlEnumValue>
|
||||
{
|
||||
|
||||
|
||||
XmlEnumValueWriter value(String value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlEnumWriter
|
||||
extends JAnnotationWriter<XmlEnum>
|
||||
{
|
||||
|
||||
|
||||
XmlEnumWriter value(Class value);
|
||||
|
||||
XmlEnumWriter value(JType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlIDREF;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlIDREFWriter
|
||||
extends JAnnotationWriter<XmlIDREF>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlIDWriter
|
||||
extends JAnnotationWriter<XmlID>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlInlineBinaryData;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlInlineBinaryDataWriter
|
||||
extends JAnnotationWriter<XmlInlineBinaryData>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlJavaTypeAdapterWriter
|
||||
extends JAnnotationWriter<XmlJavaTypeAdapter>
|
||||
{
|
||||
|
||||
|
||||
XmlJavaTypeAdapterWriter type(Class value);
|
||||
|
||||
XmlJavaTypeAdapterWriter type(JType value);
|
||||
|
||||
XmlJavaTypeAdapterWriter value(Class value);
|
||||
|
||||
XmlJavaTypeAdapterWriter value(JType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlList;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlListWriter
|
||||
extends JAnnotationWriter<XmlList>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlMimeType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlMimeTypeWriter
|
||||
extends JAnnotationWriter<XmlMimeType>
|
||||
{
|
||||
|
||||
|
||||
XmlMimeTypeWriter value(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlMixed;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlMixedWriter
|
||||
extends JAnnotationWriter<XmlMixed>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNs;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlNsWriter
|
||||
extends JAnnotationWriter<XmlNs>
|
||||
{
|
||||
|
||||
|
||||
XmlNsWriter prefix(String value);
|
||||
|
||||
XmlNsWriter namespaceURI(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRegistry;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlRegistryWriter
|
||||
extends JAnnotationWriter<XmlRegistry>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlRootElementWriter
|
||||
extends JAnnotationWriter<XmlRootElement>
|
||||
{
|
||||
|
||||
|
||||
XmlRootElementWriter name(String value);
|
||||
|
||||
XmlRootElementWriter namespace(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlSchemaType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSchemaTypeWriter
|
||||
extends JAnnotationWriter<XmlSchemaType>
|
||||
{
|
||||
|
||||
|
||||
XmlSchemaTypeWriter name(String value);
|
||||
|
||||
XmlSchemaTypeWriter type(Class value);
|
||||
|
||||
XmlSchemaTypeWriter type(JType value);
|
||||
|
||||
XmlSchemaTypeWriter namespace(String value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlSchemaTypes;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSchemaTypesWriter
|
||||
extends JAnnotationWriter<XmlSchemaTypes>
|
||||
{
|
||||
|
||||
|
||||
XmlSchemaTypeWriter value();
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNsForm;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSchemaWriter
|
||||
extends JAnnotationWriter<XmlSchema>
|
||||
{
|
||||
|
||||
|
||||
XmlSchemaWriter location(String value);
|
||||
|
||||
XmlSchemaWriter namespace(String value);
|
||||
|
||||
XmlNsWriter xmlns();
|
||||
|
||||
XmlSchemaWriter elementFormDefault(XmlNsForm value);
|
||||
|
||||
XmlSchemaWriter attributeFormDefault(XmlNsForm value);
|
||||
|
||||
}
|
||||
@@ -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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlSeeAlsoWriter
|
||||
extends JAnnotationWriter<XmlSeeAlso>
|
||||
{
|
||||
|
||||
|
||||
XmlSeeAlsoWriter value(Class value);
|
||||
|
||||
XmlSeeAlsoWriter value(JType value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlTransientWriter
|
||||
extends JAnnotationWriter<XmlTransient>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlTypeWriter
|
||||
extends JAnnotationWriter<XmlType>
|
||||
{
|
||||
|
||||
|
||||
XmlTypeWriter name(String value);
|
||||
|
||||
XmlTypeWriter namespace(String value);
|
||||
|
||||
XmlTypeWriter propOrder(String value);
|
||||
|
||||
XmlTypeWriter factoryClass(Class value);
|
||||
|
||||
XmlTypeWriter factoryClass(JType value);
|
||||
|
||||
XmlTypeWriter factoryMethod(String value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.xjc.generator.annotation.spec;
|
||||
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import com.sun.codemodel.internal.JAnnotationWriter;
|
||||
|
||||
/**
|
||||
* <p><b>
|
||||
* Auto-generated, do not edit.
|
||||
* </b></p>
|
||||
*/
|
||||
public interface XmlValueWriter
|
||||
extends JAnnotationWriter<XmlValue>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,834 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import static com.sun.tools.internal.xjc.outline.Aspect.EXPOSED;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlAttachmentRef;
|
||||
import javax.xml.bind.annotation.XmlID;
|
||||
import javax.xml.bind.annotation.XmlIDREF;
|
||||
import javax.xml.bind.annotation.XmlMimeType;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.ClassType;
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JClassAlreadyExistsException;
|
||||
import com.sun.codemodel.internal.JClassContainer;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JEnumConstant;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JForEach;
|
||||
import com.sun.codemodel.internal.JInvocation;
|
||||
import com.sun.codemodel.internal.JJavaName;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.codemodel.internal.fmt.JStaticJavaFile;
|
||||
import com.sun.tools.internal.xjc.AbortException;
|
||||
import com.sun.tools.internal.xjc.ErrorReceiver;
|
||||
import com.sun.tools.internal.xjc.api.SpecVersion;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAnyAttributeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlEnumValueWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlEnumWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlJavaTypeAdapterWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlMimeTypeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlRootElementWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlSeeAlsoWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlTypeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.bean.field.FieldRenderer;
|
||||
import com.sun.tools.internal.xjc.model.CAdapter;
|
||||
import com.sun.tools.internal.xjc.model.CAttributePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfoParent;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CEnumConstant;
|
||||
import com.sun.tools.internal.xjc.model.CEnumLeafInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeRef;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.model.CClassRef;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.EnumConstantOutline;
|
||||
import com.sun.tools.internal.xjc.outline.EnumOutline;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
import com.sun.tools.internal.xjc.outline.PackageOutline;
|
||||
import com.sun.tools.internal.xjc.util.CodeModelClassFactory;
|
||||
import com.sun.xml.internal.bind.v2.model.core.PropertyInfo;
|
||||
import com.sun.xml.internal.bind.v2.runtime.SwaRefAdapterMarker;
|
||||
import com.sun.xml.internal.xsom.XmlString;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
|
||||
/**
|
||||
* Generates fields and accessors.
|
||||
*/
|
||||
public final class BeanGenerator implements Outline {
|
||||
|
||||
/** Simplifies class/interface creation and collision detection. */
|
||||
private final CodeModelClassFactory codeModelClassFactory;
|
||||
private final ErrorReceiver errorReceiver;
|
||||
/** all {@link PackageOutline}s keyed by their {@link PackageOutline#_package}. */
|
||||
private final Map<JPackage, PackageOutlineImpl> packageContexts = new LinkedHashMap<JPackage, PackageOutlineImpl>();
|
||||
/** all {@link ClassOutline}s keyed by their {@link ClassOutline#target}. */
|
||||
private final Map<CClassInfo, ClassOutlineImpl> classes = new LinkedHashMap<CClassInfo, ClassOutlineImpl>();
|
||||
/** all {@link EnumOutline}s keyed by their {@link EnumOutline#target}. */
|
||||
private final Map<CEnumLeafInfo, EnumOutline> enums = new LinkedHashMap<CEnumLeafInfo, EnumOutline>();
|
||||
/**
|
||||
* Generated runtime classes.
|
||||
*/
|
||||
private final Map<Class, JClass> generatedRuntime = new LinkedHashMap<Class, JClass>();
|
||||
/** the model object which we are processing. */
|
||||
private final Model model;
|
||||
private final JCodeModel codeModel;
|
||||
/**
|
||||
* for each property, the information about the generated field.
|
||||
*/
|
||||
private final Map<CPropertyInfo, FieldOutline> fields = new LinkedHashMap<CPropertyInfo, FieldOutline>();
|
||||
/**
|
||||
* elements that generate classes to the generated classes.
|
||||
*/
|
||||
/*package*/ final Map<CElementInfo, ElementOutlineImpl> elements = new LinkedHashMap<CElementInfo, ElementOutlineImpl>();
|
||||
|
||||
/**
|
||||
* Generates beans into code model according to the BGM,
|
||||
* and produces the reflection model.
|
||||
*
|
||||
* @param _errorReceiver
|
||||
* This object will receive all the errors discovered
|
||||
* during the back-end stage.
|
||||
*
|
||||
* @return
|
||||
* returns a {@link Outline} which will in turn
|
||||
* be used to further generate marshaller/unmarshaller,
|
||||
* or null if the processing fails (errors should have been
|
||||
* reported to the error recevier.)
|
||||
*/
|
||||
public static Outline generate(Model model, ErrorReceiver _errorReceiver) {
|
||||
|
||||
try {
|
||||
return new BeanGenerator(model, _errorReceiver);
|
||||
} catch (AbortException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private BeanGenerator(Model _model, ErrorReceiver _errorReceiver) {
|
||||
|
||||
this.model = _model;
|
||||
this.codeModel = model.codeModel;
|
||||
this.errorReceiver = _errorReceiver;
|
||||
this.codeModelClassFactory = new CodeModelClassFactory(errorReceiver);
|
||||
|
||||
// build enum classes
|
||||
for (CEnumLeafInfo p : model.enums().values()) {
|
||||
enums.put(p, generateEnumDef(p));
|
||||
}
|
||||
|
||||
JPackage[] packages = getUsedPackages(EXPOSED);
|
||||
|
||||
// generates per-package code and remember the results as contexts.
|
||||
for (JPackage pkg : packages) {
|
||||
getPackageContext(pkg);
|
||||
}
|
||||
|
||||
// create the class definitions for all the beans first.
|
||||
// this should also fill in PackageContext#getClasses
|
||||
for (CClassInfo bean : model.beans().values()) {
|
||||
getClazz(bean);
|
||||
}
|
||||
|
||||
// compute the package-level setting
|
||||
for (PackageOutlineImpl p : packageContexts.values()) {
|
||||
p.calcDefaultValues();
|
||||
}
|
||||
|
||||
JClass OBJECT = codeModel.ref(Object.class);
|
||||
|
||||
// inheritance relationship needs to be set before we generate fields, or otherwise
|
||||
// we'll fail to compute the correct type signature (namely the common base type computation)
|
||||
for (ClassOutlineImpl cc : getClasses()) {
|
||||
|
||||
// setup inheritance between implementation hierarchy.
|
||||
CClassInfo superClass = cc.target.getBaseClass();
|
||||
if (superClass != null) {
|
||||
// use the specified super class
|
||||
model.strategy._extends(cc, getClazz(superClass));
|
||||
} else {
|
||||
CClassRef refSuperClass = cc.target.getRefBaseClass();
|
||||
if (refSuperClass != null) {
|
||||
cc.implClass._extends(refSuperClass.toType(this, EXPOSED));
|
||||
} else {
|
||||
// use the default one, if any
|
||||
if (model.rootClass != null && cc.implClass._extends().equals(OBJECT)) {
|
||||
cc.implClass._extends(model.rootClass);
|
||||
}
|
||||
if (model.rootInterface != null) {
|
||||
cc.ref._implements(model.rootInterface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if serialization support is turned on, generate
|
||||
// [RESULT]
|
||||
// class ... implements Serializable {
|
||||
// private static final long serialVersionUID = <id>;
|
||||
// ....
|
||||
// }
|
||||
if (model.serializable) {
|
||||
cc.implClass._implements(Serializable.class);
|
||||
if (model.serialVersionUID != null) {
|
||||
cc.implClass.field(
|
||||
JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
|
||||
codeModel.LONG,
|
||||
"serialVersionUID",
|
||||
JExpr.lit(model.serialVersionUID));
|
||||
}
|
||||
}
|
||||
|
||||
CClassInfoParent base = cc.target.parent();
|
||||
if ((base != null) && (base instanceof CClassInfo)) {
|
||||
String pkg = base.getOwnerPackage().name();
|
||||
String shortName = base.fullName().substring(base.fullName().indexOf(pkg)+pkg.length()+1);
|
||||
if (cc.target.shortName.equals(shortName)) {
|
||||
getErrorReceiver().error(cc.target.getLocator(), Messages.ERR_KEYNAME_COLLISION.format(shortName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// fill in implementation classes
|
||||
for (ClassOutlineImpl co : getClasses()) {
|
||||
generateClassBody(co);
|
||||
}
|
||||
|
||||
for (EnumOutline eo : enums.values()) {
|
||||
generateEnumBody(eo);
|
||||
}
|
||||
|
||||
// create factories for the impl-less elements
|
||||
for (CElementInfo ei : model.getAllElements()) {
|
||||
getPackageContext(ei._package()).objectFactoryGenerator().populate(ei);
|
||||
}
|
||||
|
||||
if (model.options.debugMode) {
|
||||
generateClassList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a class that knows how to create an instance of JAXBContext
|
||||
*
|
||||
* <p>
|
||||
* This is used in the debug mode so that a new properly configured
|
||||
* {@link JAXBContext} object can be used.
|
||||
*/
|
||||
@SuppressWarnings("CallToThreadDumpStack")
|
||||
private void generateClassList() {
|
||||
try {
|
||||
JDefinedClass jc = codeModel.rootPackage()._class("JAXBDebug");
|
||||
JMethod m = jc.method(JMod.PUBLIC | JMod.STATIC, JAXBContext.class, "createContext");
|
||||
JVar $classLoader = m.param(ClassLoader.class, "classLoader");
|
||||
m._throws(JAXBException.class);
|
||||
JInvocation inv = codeModel.ref(JAXBContext.class).staticInvoke("newInstance");
|
||||
m.body()._return(inv);
|
||||
|
||||
switch (model.strategy) {
|
||||
case INTF_AND_IMPL: {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (PackageOutlineImpl po : packageContexts.values()) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(':');
|
||||
}
|
||||
buf.append(po._package().name());
|
||||
}
|
||||
inv.arg(buf.toString()).arg($classLoader);
|
||||
break;
|
||||
}
|
||||
case BEAN_ONLY:
|
||||
for (ClassOutlineImpl cc : getClasses()) {
|
||||
inv.arg(cc.implRef.dotclass());
|
||||
}
|
||||
for (PackageOutlineImpl po : packageContexts.values()) {
|
||||
inv.arg(po.objectFactory().dotclass());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
} catch (JClassAlreadyExistsException e) {
|
||||
e.printStackTrace();
|
||||
// after all, we are in the debug mode. a little sloppiness is OK.
|
||||
// this error is not fatal. just continue.
|
||||
}
|
||||
}
|
||||
|
||||
public Model getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public JCodeModel getCodeModel() {
|
||||
return codeModel;
|
||||
}
|
||||
|
||||
public JClassContainer getContainer(CClassInfoParent parent, Aspect aspect) {
|
||||
CClassInfoParent.Visitor<JClassContainer> v;
|
||||
switch (aspect) {
|
||||
case EXPOSED:
|
||||
v = exposedContainerBuilder;
|
||||
break;
|
||||
case IMPLEMENTATION:
|
||||
v = implContainerBuilder;
|
||||
break;
|
||||
default:
|
||||
assert false;
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return parent.accept(v);
|
||||
}
|
||||
|
||||
public final JType resolve(CTypeRef ref, Aspect a) {
|
||||
return ref.getTarget().getType().toType(this, a);
|
||||
}
|
||||
private final CClassInfoParent.Visitor<JClassContainer> exposedContainerBuilder =
|
||||
new CClassInfoParent.Visitor<JClassContainer>() {
|
||||
|
||||
public JClassContainer onBean(CClassInfo bean) {
|
||||
return getClazz(bean).ref;
|
||||
}
|
||||
|
||||
public JClassContainer onElement(CElementInfo element) {
|
||||
// hmm...
|
||||
return getElement(element).implClass;
|
||||
}
|
||||
|
||||
public JClassContainer onPackage(JPackage pkg) {
|
||||
return model.strategy.getPackage(pkg, EXPOSED);
|
||||
}
|
||||
};
|
||||
private final CClassInfoParent.Visitor<JClassContainer> implContainerBuilder =
|
||||
new CClassInfoParent.Visitor<JClassContainer>() {
|
||||
|
||||
public JClassContainer onBean(CClassInfo bean) {
|
||||
return getClazz(bean).implClass;
|
||||
}
|
||||
|
||||
public JClassContainer onElement(CElementInfo element) {
|
||||
return getElement(element).implClass;
|
||||
}
|
||||
|
||||
public JClassContainer onPackage(JPackage pkg) {
|
||||
return model.strategy.getPackage(pkg, Aspect.IMPLEMENTATION);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all <i>used</i> JPackages.
|
||||
*
|
||||
* A JPackage is considered as "used" if a ClassItem or
|
||||
* a InterfaceItem resides in that package.
|
||||
*
|
||||
* This value is dynamically calculated every time because
|
||||
* one can freely remove ClassItem/InterfaceItem.
|
||||
*
|
||||
* @return
|
||||
* Given the same input, the order of packages in the array
|
||||
* is always the same regardless of the environment.
|
||||
*/
|
||||
public final JPackage[] getUsedPackages(Aspect aspect) {
|
||||
Set<JPackage> s = new TreeSet<JPackage>();
|
||||
|
||||
for (CClassInfo bean : model.beans().values()) {
|
||||
JClassContainer cont = getContainer(bean.parent(), aspect);
|
||||
if (cont.isPackage()) {
|
||||
s.add((JPackage) cont);
|
||||
}
|
||||
}
|
||||
|
||||
for (CElementInfo e : model.getElementMappings(null).values()) {
|
||||
// at the first glance you might think we should be iterating all elements,
|
||||
// not just global ones, but if you think about it, local ones live inside
|
||||
// another class, so those packages are already enumerated when we were
|
||||
// walking over CClassInfos.
|
||||
s.add(e._package());
|
||||
}
|
||||
|
||||
return s.toArray(new JPackage[s.size()]);
|
||||
}
|
||||
|
||||
public ErrorReceiver getErrorReceiver() {
|
||||
return errorReceiver;
|
||||
}
|
||||
|
||||
public CodeModelClassFactory getClassFactory() {
|
||||
return codeModelClassFactory;
|
||||
}
|
||||
|
||||
public PackageOutlineImpl getPackageContext(JPackage p) {
|
||||
PackageOutlineImpl r = packageContexts.get(p);
|
||||
if (r == null) {
|
||||
r = new PackageOutlineImpl(this, model, p);
|
||||
packageContexts.put(p, r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the minimum {@link JDefinedClass} skeleton
|
||||
* without filling in its body.
|
||||
*/
|
||||
private ClassOutlineImpl generateClassDef(CClassInfo bean) {
|
||||
ImplStructureStrategy.Result r = model.strategy.createClasses(this, bean);
|
||||
JClass implRef;
|
||||
|
||||
if (bean.getUserSpecifiedImplClass() != null) {
|
||||
// create a place holder for a user-specified class.
|
||||
JDefinedClass usr;
|
||||
try {
|
||||
usr = codeModel._class(bean.getUserSpecifiedImplClass());
|
||||
// but hide that file so that it won't be generated.
|
||||
usr.hide();
|
||||
} catch (JClassAlreadyExistsException e) {
|
||||
// it's OK for this to collide.
|
||||
usr = e.getExistingClass();
|
||||
}
|
||||
usr._extends(r.implementation);
|
||||
implRef = usr;
|
||||
} else {
|
||||
implRef = r.implementation;
|
||||
}
|
||||
|
||||
return new ClassOutlineImpl(this, bean, r.exposed, r.implementation, implRef);
|
||||
}
|
||||
|
||||
public Collection<ClassOutlineImpl> getClasses() {
|
||||
// make sure that classes are fully populated
|
||||
assert model.beans().size() == classes.size();
|
||||
return classes.values();
|
||||
}
|
||||
|
||||
public ClassOutlineImpl getClazz(CClassInfo bean) {
|
||||
ClassOutlineImpl r = classes.get(bean);
|
||||
if (r == null) {
|
||||
classes.put(bean, r = generateClassDef(bean));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
public ElementOutlineImpl getElement(CElementInfo ei) {
|
||||
ElementOutlineImpl def = elements.get(ei);
|
||||
if (def == null && ei.hasClass()) {
|
||||
// create one. in the constructor it adds itself to the elements.
|
||||
def = new ElementOutlineImpl(this, ei);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
public EnumOutline getEnum(CEnumLeafInfo eli) {
|
||||
return enums.get(eli);
|
||||
}
|
||||
|
||||
public Collection<EnumOutline> getEnums() {
|
||||
return enums.values();
|
||||
}
|
||||
|
||||
public Iterable<? extends PackageOutline> getAllPackageContexts() {
|
||||
return packageContexts.values();
|
||||
}
|
||||
|
||||
public FieldOutline getField(CPropertyInfo prop) {
|
||||
return fields.get(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the body of a class.
|
||||
*
|
||||
*/
|
||||
private void generateClassBody(ClassOutlineImpl cc) {
|
||||
CClassInfo target = cc.target;
|
||||
|
||||
// used to simplify the generated annotations
|
||||
String mostUsedNamespaceURI = cc._package().getMostUsedNamespaceURI();
|
||||
|
||||
// [RESULT]
|
||||
// @XmlType(name="foo", targetNamespace="bar://baz")
|
||||
XmlTypeWriter xtw = cc.implClass.annotate2(XmlTypeWriter.class);
|
||||
writeTypeName(cc.target.getTypeName(), xtw, mostUsedNamespaceURI);
|
||||
|
||||
if (model.options.target.isLaterThan(SpecVersion.V2_1)) {
|
||||
// @XmlSeeAlso
|
||||
Iterator<CClassInfo> subclasses = cc.target.listSubclasses();
|
||||
if (subclasses.hasNext()) {
|
||||
XmlSeeAlsoWriter saw = cc.implClass.annotate2(XmlSeeAlsoWriter.class);
|
||||
while (subclasses.hasNext()) {
|
||||
CClassInfo s = subclasses.next();
|
||||
saw.value(getClazz(s).implRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (target.isElement()) {
|
||||
String namespaceURI = target.getElementName().getNamespaceURI();
|
||||
String localPart = target.getElementName().getLocalPart();
|
||||
|
||||
// [RESULT]
|
||||
// @XmlRootElement(name="foo", targetNamespace="bar://baz")
|
||||
XmlRootElementWriter xrew = cc.implClass.annotate2(XmlRootElementWriter.class);
|
||||
xrew.name(localPart);
|
||||
if (!namespaceURI.equals(mostUsedNamespaceURI)) // only generate if necessary
|
||||
{
|
||||
xrew.namespace(namespaceURI);
|
||||
}
|
||||
}
|
||||
|
||||
if (target.isOrdered()) {
|
||||
for (CPropertyInfo p : target.getProperties()) {
|
||||
if (!(p instanceof CAttributePropertyInfo)) {
|
||||
if (!((p instanceof CReferencePropertyInfo)
|
||||
&& ((CReferencePropertyInfo) p).isDummy())) {
|
||||
xtw.propOrder(p.getName(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// produce empty array
|
||||
xtw.getAnnotationUse().paramArray("propOrder");
|
||||
}
|
||||
|
||||
for (CPropertyInfo prop : target.getProperties()) {
|
||||
generateFieldDecl(cc, prop);
|
||||
}
|
||||
|
||||
if (target.declaresAttributeWildcard()) {
|
||||
generateAttributeWildcard(cc);
|
||||
}
|
||||
|
||||
// generate some class level javadoc
|
||||
cc.ref.javadoc().append(target.javadoc);
|
||||
|
||||
cc._package().objectFactoryGenerator().populate(cc);
|
||||
}
|
||||
|
||||
private void writeTypeName(QName typeName, XmlTypeWriter xtw, String mostUsedNamespaceURI) {
|
||||
if (typeName == null) {
|
||||
xtw.name("");
|
||||
} else {
|
||||
xtw.name(typeName.getLocalPart());
|
||||
final String typeNameURI = typeName.getNamespaceURI();
|
||||
if (!typeNameURI.equals(mostUsedNamespaceURI)) // only generate if necessary
|
||||
{
|
||||
xtw.namespace(typeNameURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an attribute wildcard property on a class.
|
||||
*/
|
||||
private void generateAttributeWildcard(ClassOutlineImpl cc) {
|
||||
String FIELD_NAME = "otherAttributes";
|
||||
String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME);
|
||||
|
||||
JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class);
|
||||
JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class);
|
||||
|
||||
// [RESULT]
|
||||
// Map<QName,String> m = new HashMap<QName,String>();
|
||||
JFieldVar $ref = cc.implClass.field(JMod.PRIVATE,
|
||||
mapType, FIELD_NAME, JExpr._new(mapImpl));
|
||||
$ref.annotate2(XmlAnyAttributeWriter.class);
|
||||
|
||||
MethodWriter writer = cc.createMethodWriter();
|
||||
|
||||
JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED);
|
||||
$get.javadoc().append(
|
||||
"Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n"
|
||||
+ "<p>\n"
|
||||
+ "the map is keyed by the name of the attribute and \n"
|
||||
+ "the value is the string value of the attribute.\n"
|
||||
+ "\n"
|
||||
+ "the map returned by this method is live, and you can add new attribute\n"
|
||||
+ "by updating the map directly. Because of this design, there's no setter.\n");
|
||||
$get.javadoc().addReturn().append("always non-null");
|
||||
|
||||
$get.body()._return($ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the minimum {@link JDefinedClass} skeleton
|
||||
* without filling in its body.
|
||||
*/
|
||||
private EnumOutline generateEnumDef(CEnumLeafInfo e) {
|
||||
JDefinedClass type;
|
||||
|
||||
type = getClassFactory().createClass(
|
||||
getContainer(e.parent, EXPOSED), e.shortName, e.getLocator(), ClassType.ENUM);
|
||||
type.javadoc().append(e.javadoc);
|
||||
|
||||
return new EnumOutline(e, type) {
|
||||
|
||||
@Override
|
||||
public
|
||||
@NotNull
|
||||
Outline parent() {
|
||||
return BeanGenerator.this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void generateEnumBody(EnumOutline eo) {
|
||||
JDefinedClass type = eo.clazz;
|
||||
CEnumLeafInfo e = eo.target;
|
||||
|
||||
XmlTypeWriter xtw = type.annotate2(XmlTypeWriter.class);
|
||||
writeTypeName(e.getTypeName(), xtw,
|
||||
eo._package().getMostUsedNamespaceURI());
|
||||
|
||||
JCodeModel cModel = model.codeModel;
|
||||
|
||||
// since constant values are never null, no point in using the boxed types.
|
||||
JType baseExposedType = e.base.toType(this, EXPOSED).unboxify();
|
||||
JType baseImplType = e.base.toType(this, Aspect.IMPLEMENTATION).unboxify();
|
||||
|
||||
|
||||
XmlEnumWriter xew = type.annotate2(XmlEnumWriter.class);
|
||||
xew.value(baseExposedType);
|
||||
|
||||
|
||||
boolean needsValue = e.needsValueField();
|
||||
|
||||
// for each member <m>,
|
||||
// [RESULT]
|
||||
// <EnumName>(<deserializer of m>(<value>));
|
||||
|
||||
Set<String> enumFieldNames = new HashSet<String>(); // record generated field names to detect collision
|
||||
|
||||
for (CEnumConstant mem : e.members) {
|
||||
String constName = mem.getName();
|
||||
|
||||
if (!JJavaName.isJavaIdentifier(constName)) {
|
||||
// didn't produce a name.
|
||||
getErrorReceiver().error(e.getLocator(),
|
||||
Messages.ERR_UNUSABLE_NAME.format(mem.getLexicalValue(), constName));
|
||||
}
|
||||
|
||||
if (!enumFieldNames.add(constName)) {
|
||||
getErrorReceiver().error(e.getLocator(), Messages.ERR_NAME_COLLISION.format(constName));
|
||||
}
|
||||
|
||||
// [RESULT]
|
||||
// <Const>(...)
|
||||
// ASSUMPTION: datatype is outline-independent
|
||||
JEnumConstant constRef = type.enumConstant(constName);
|
||||
if (needsValue) {
|
||||
constRef.arg(e.base.createConstant(this, new XmlString(mem.getLexicalValue())));
|
||||
}
|
||||
|
||||
if (!mem.getLexicalValue().equals(constName)) {
|
||||
constRef.annotate2(XmlEnumValueWriter.class).value(mem.getLexicalValue());
|
||||
}
|
||||
|
||||
// set javadoc
|
||||
if (mem.javadoc != null) {
|
||||
constRef.javadoc().append(mem.javadoc);
|
||||
}
|
||||
|
||||
eo.constants.add(new EnumConstantOutline(mem, constRef) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (needsValue) {
|
||||
// [RESULT]
|
||||
// final <valueType> value;
|
||||
JFieldVar $value = type.field(JMod.PRIVATE | JMod.FINAL, baseExposedType, "value");
|
||||
|
||||
// [RESULT]
|
||||
// public <valuetype> value() { return value; }
|
||||
type.method(JMod.PUBLIC, baseExposedType, "value").body()._return($value);
|
||||
|
||||
// [RESULT]
|
||||
// <constructor>(<valueType> v) {
|
||||
// this.value=v;
|
||||
// }
|
||||
{
|
||||
JMethod m = type.constructor(0);
|
||||
m.body().assign($value, m.param(baseImplType, "v"));
|
||||
}
|
||||
|
||||
// [RESULT]
|
||||
// public static <Const> fromValue(<valueType> v) {
|
||||
// for( <Const> c : <Const>.values() ) {
|
||||
// if(c.value == v) // or equals
|
||||
// return c;
|
||||
// }
|
||||
// throw new IllegalArgumentException(...);
|
||||
// }
|
||||
{
|
||||
JMethod m = type.method(JMod.PUBLIC | JMod.STATIC, type, "fromValue");
|
||||
JVar $v = m.param(baseExposedType, "v");
|
||||
JForEach fe = m.body().forEach(type, "c", type.staticInvoke("values"));
|
||||
JExpression eq;
|
||||
if (baseExposedType.isPrimitive()) {
|
||||
eq = fe.var().ref($value).eq($v);
|
||||
} else {
|
||||
eq = fe.var().ref($value).invoke("equals").arg($v);
|
||||
}
|
||||
|
||||
fe.body()._if(eq)._then()._return(fe.var());
|
||||
|
||||
JInvocation ex = JExpr._new(cModel.ref(IllegalArgumentException.class));
|
||||
|
||||
JExpression strForm;
|
||||
if (baseExposedType.isPrimitive()) {
|
||||
strForm = cModel.ref(String.class).staticInvoke("valueOf").arg($v);
|
||||
} else if (baseExposedType == cModel.ref(String.class)) {
|
||||
strForm = $v;
|
||||
} else {
|
||||
strForm = $v.invoke("toString");
|
||||
}
|
||||
m.body()._throw(ex.arg(strForm));
|
||||
}
|
||||
} else {
|
||||
// [RESULT]
|
||||
// public String value() { return name(); }
|
||||
type.method(JMod.PUBLIC, String.class, "value").body()._return(JExpr.invoke("name"));
|
||||
|
||||
// [RESULT]
|
||||
// public <Const> fromValue(String v) { return valueOf(v); }
|
||||
JMethod m = type.method(JMod.PUBLIC | JMod.STATIC, type, "fromValue");
|
||||
m.body()._return(JExpr.invoke("valueOf").arg(m.param(String.class, "v")));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the FieldRenderer used for the given FieldUse,
|
||||
* then generates the field declaration and accessor methods.
|
||||
*
|
||||
* The <code>fields</code> map will be updated with the newly
|
||||
* created FieldRenderer.
|
||||
*/
|
||||
private FieldOutline generateFieldDecl(ClassOutlineImpl cc, CPropertyInfo prop) {
|
||||
FieldRenderer fr = prop.realization;
|
||||
if (fr == null) // none is specified. use the default factory
|
||||
{
|
||||
fr = model.options.getFieldRendererFactory().getDefault();
|
||||
}
|
||||
|
||||
FieldOutline field = fr.generate(cc, prop);
|
||||
fields.put(prop, field);
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates {@link XmlJavaTypeAdapter} from {@link PropertyInfo} if necessary.
|
||||
* Also generates other per-property annotations
|
||||
* (such as {@link XmlID}, {@link XmlIDREF}, and {@link XmlMimeType} if necessary.
|
||||
*/
|
||||
public final void generateAdapterIfNecessary(CPropertyInfo prop, JAnnotatable field) {
|
||||
CAdapter adapter = prop.getAdapter();
|
||||
if (adapter != null) {
|
||||
if (adapter.getAdapterIfKnown() == SwaRefAdapterMarker.class) {
|
||||
field.annotate(XmlAttachmentRef.class);
|
||||
} else {
|
||||
// [RESULT]
|
||||
// @XmlJavaTypeAdapter( Foo.class )
|
||||
XmlJavaTypeAdapterWriter xjtw = field.annotate2(XmlJavaTypeAdapterWriter.class);
|
||||
xjtw.value(adapter.adapterType.toType(this, EXPOSED));
|
||||
}
|
||||
}
|
||||
|
||||
switch (prop.id()) {
|
||||
case ID:
|
||||
field.annotate(XmlID.class);
|
||||
break;
|
||||
case IDREF:
|
||||
field.annotate(XmlIDREF.class);
|
||||
break;
|
||||
}
|
||||
|
||||
if (prop.getExpectedMimeType() != null) {
|
||||
field.annotate2(XmlMimeTypeWriter.class).value(prop.getExpectedMimeType().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public final JClass addRuntime(Class clazz) {
|
||||
JClass g = generatedRuntime.get(clazz);
|
||||
if (g == null) {
|
||||
// put code into a separate package to avoid name conflicts.
|
||||
JPackage implPkg = getUsedPackages(Aspect.IMPLEMENTATION)[0].subPackage("runtime");
|
||||
g = generateStaticClass(clazz, implPkg);
|
||||
generatedRuntime.put(clazz, g);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
public JClass generateStaticClass(Class src, JPackage out) {
|
||||
String shortName = getShortName(src.getName());
|
||||
|
||||
// some people didn't like our jars to contain files with .java extension,
|
||||
// so when we build jars, we'' use ".java_". But when we run from the workspace,
|
||||
// we want the original source code to be used, so we check both here.
|
||||
// see bug 6211503.
|
||||
URL res = src.getResource(shortName + ".java");
|
||||
if (res == null) {
|
||||
res = src.getResource(shortName + ".java_");
|
||||
}
|
||||
if (res == null) {
|
||||
throw new InternalError("Unable to load source code of " + src.getName() + " as a resource");
|
||||
}
|
||||
|
||||
JStaticJavaFile sjf = new JStaticJavaFile(out, shortName, res, null);
|
||||
out.addResourceFile(sjf);
|
||||
return sjf.getJClass();
|
||||
}
|
||||
|
||||
private String getShortName(String name) {
|
||||
return name.substring(name.lastIndexOf('.') + 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
|
||||
/**
|
||||
* {@link ClassOutline} enhanced with schema2java specific
|
||||
* information.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public final class ClassOutlineImpl extends ClassOutline {
|
||||
private final BeanGenerator _parent;
|
||||
|
||||
|
||||
public MethodWriter createMethodWriter() {
|
||||
return _parent.getModel().strategy.createMethodWriter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets {@link #_package} as {@link PackageOutlineImpl},
|
||||
* since it's guaranteed to be of that type.
|
||||
*/
|
||||
public PackageOutlineImpl _package() {
|
||||
return (PackageOutlineImpl)super._package();
|
||||
}
|
||||
|
||||
ClassOutlineImpl( BeanGenerator _parent,
|
||||
CClassInfo _target, JDefinedClass exposedClass, JDefinedClass _implClass, JClass _implRef ) {
|
||||
super(_target,exposedClass,_implRef,_implClass);
|
||||
this._parent = _parent;
|
||||
_package().classes.add(this);
|
||||
}
|
||||
|
||||
public BeanGenerator parent() {
|
||||
return _parent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
|
||||
/**
|
||||
* {@link ObjectFactoryGenerator} used when we generate
|
||||
* interfaces and implementations in separate packages.
|
||||
*
|
||||
* <p>
|
||||
* {@link #publicOFG} and {@link #privateOFG} gives you access to
|
||||
* {@code ObjectFactory}s in both packages, if you need to.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class DualObjectFactoryGenerator extends ObjectFactoryGenerator {
|
||||
public final ObjectFactoryGenerator publicOFG;
|
||||
public final ObjectFactoryGenerator privateOFG;
|
||||
|
||||
DualObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
|
||||
this.publicOFG = new PublicObjectFactoryGenerator(outline,model,targetPackage);
|
||||
this.privateOFG = new PrivateObjectFactoryGenerator(outline,model,targetPackage);
|
||||
|
||||
// put the marker so that we can detect missing jaxb.properties
|
||||
publicOFG.getObjectFactory().field(JMod.PRIVATE|JMod.STATIC|JMod.FINAL,
|
||||
Void.class, "_useJAXBProperties", JExpr._null());
|
||||
}
|
||||
|
||||
void populate(CElementInfo ei) {
|
||||
publicOFG.populate(ei);
|
||||
privateOFG.populate(ei);
|
||||
}
|
||||
|
||||
void populate(ClassOutlineImpl cc) {
|
||||
publicOFG.populate(cc);
|
||||
privateOFG.populate(cc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the private version (which is what gets used at runtime.)
|
||||
*/
|
||||
public JDefinedClass getObjectFactory() {
|
||||
return privateOFG.getObjectFactory();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
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.JType;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.ElementOutline;
|
||||
|
||||
/**
|
||||
* {@link ElementOutline} implementation.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class ElementOutlineImpl extends ElementOutline {
|
||||
private final BeanGenerator parent;
|
||||
|
||||
public BeanGenerator parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/*package*/ ElementOutlineImpl(BeanGenerator parent, CElementInfo ei) {
|
||||
super(ei,
|
||||
parent.getClassFactory().createClass(
|
||||
parent.getContainer( ei.parent, Aspect.EXPOSED ), ei.shortName(), ei.getLocator() ));
|
||||
this.parent = parent;
|
||||
parent.elements.put(ei,this);
|
||||
|
||||
JCodeModel cm = parent.getCodeModel();
|
||||
|
||||
implClass._extends(
|
||||
cm.ref(JAXBElement.class).narrow(
|
||||
target.getContentInMemoryType().toType(parent,Aspect.EXPOSED).boxify()));
|
||||
|
||||
if(ei.hasClass()) {
|
||||
JType implType = ei.getContentInMemoryType().toType(parent,Aspect.IMPLEMENTATION);
|
||||
JExpression declaredType = JExpr.cast(cm.ref(Class.class),implType.boxify().dotclass()); // why do we have to cast?
|
||||
JClass scope=null;
|
||||
if(ei.getScope()!=null)
|
||||
scope = parent.getClazz(ei.getScope()).implRef;
|
||||
JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
|
||||
JFieldVar valField = implClass.field(JMod.PROTECTED|JMod.FINAL|JMod.STATIC,QName.class,"NAME",createQName(cm,ei.getElementName()));
|
||||
|
||||
// take this opportunity to generate a constructor in the element class
|
||||
JMethod cons = implClass.constructor(JMod.PUBLIC);
|
||||
cons.body().invoke("super")
|
||||
.arg(valField)
|
||||
.arg(declaredType)
|
||||
.arg(scopeClass)
|
||||
.arg(cons.param(implType,"value"));
|
||||
|
||||
// generate no-arg constructor in the element class (bug #391; section 5.6.2 in JAXB spec 2.1)
|
||||
JMethod noArgCons = implClass.constructor(JMod.PUBLIC);
|
||||
noArgCons.body().invoke("super")
|
||||
.arg(valField)
|
||||
.arg(declaredType)
|
||||
.arg(scopeClass)
|
||||
.arg(JExpr._null());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an expression that evaluates to "new QName(...)"
|
||||
*/
|
||||
private JInvocation createQName(JCodeModel codeModel,QName name) {
|
||||
return JExpr._new(codeModel.ref(QName.class)).arg(name.getNamespaceURI()).arg(name.getLocalPart());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use is subject to the license terms.
|
||||
*/
|
||||
package com.sun.tools.internal.xjc.generator.bean;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
|
||||
import com.sun.codemodel.internal.JClassContainer;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JDocComment;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAccessorTypeWriter;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.Outline;
|
||||
|
||||
/**
|
||||
* Decides how a bean token is mapped to the generated classes.
|
||||
*
|
||||
* <p>
|
||||
* The actual implementations of this interface is tightly coupled with
|
||||
* the backend, but the front-end gets to choose which strategy to be used.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
@XmlEnum(Boolean.class)
|
||||
public enum ImplStructureStrategy {
|
||||
/**
|
||||
* Generates beans only. The simplest code generation.
|
||||
*/
|
||||
@XmlEnumValue("true")
|
||||
BEAN_ONLY() {
|
||||
protected Result createClasses(Outline outline, CClassInfo bean) {
|
||||
JClassContainer parent = outline.getContainer( bean.parent(), Aspect.EXPOSED );
|
||||
|
||||
JDefinedClass impl = outline.getClassFactory().createClass(
|
||||
parent,
|
||||
JMod.PUBLIC|(parent.isPackage()?0:JMod.STATIC)|(bean.isAbstract()?JMod.ABSTRACT:0),
|
||||
bean.shortName, bean.getLocator() );
|
||||
impl.annotate2(XmlAccessorTypeWriter.class).value(XmlAccessType.FIELD);
|
||||
|
||||
return new Result(impl,impl);
|
||||
}
|
||||
|
||||
protected JPackage getPackage(JPackage pkg, Aspect a) {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
protected MethodWriter createMethodWriter(final ClassOutlineImpl target) {
|
||||
assert target.ref==target.implClass;
|
||||
|
||||
return new MethodWriter(target) {
|
||||
private final JDefinedClass impl = target.implClass;
|
||||
|
||||
private JMethod implMethod;
|
||||
|
||||
public JVar addParameter(JType type, String name) {
|
||||
return implMethod.param(type,name);
|
||||
}
|
||||
|
||||
public JMethod declareMethod(JType returnType, String methodName) {
|
||||
implMethod = impl.method( JMod.PUBLIC, returnType, methodName );
|
||||
return implMethod;
|
||||
}
|
||||
|
||||
public JDocComment javadoc() {
|
||||
return implMethod.javadoc();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void _extends(ClassOutlineImpl derived, ClassOutlineImpl base) {
|
||||
derived.implClass._extends(base.implRef);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Generates the interfaces to describe beans (content interfaces)
|
||||
* and then the beans themselves in a hidden impl package.
|
||||
*
|
||||
* Similar to JAXB 1.0.
|
||||
*/
|
||||
@XmlEnumValue("false")
|
||||
INTF_AND_IMPL() {
|
||||
protected Result createClasses( Outline outline, CClassInfo bean ) {
|
||||
JClassContainer parent = outline.getContainer( bean.parent(), Aspect.EXPOSED );
|
||||
|
||||
JDefinedClass intf = outline.getClassFactory().createInterface(
|
||||
parent, bean.shortName, bean.getLocator() );
|
||||
|
||||
parent = outline.getContainer(bean.parent(), Aspect.IMPLEMENTATION);
|
||||
JDefinedClass impl = outline.getClassFactory().createClass(
|
||||
parent,
|
||||
JMod.PUBLIC|(parent.isPackage()?0:JMod.STATIC)|(bean.isAbstract()?JMod.ABSTRACT:0),
|
||||
bean.shortName+"Impl", bean.getLocator() );
|
||||
impl.annotate2(XmlAccessorTypeWriter.class).value(XmlAccessType.FIELD);
|
||||
|
||||
impl._implements(intf);
|
||||
|
||||
return new Result(intf,impl);
|
||||
}
|
||||
|
||||
protected JPackage getPackage(JPackage pkg, Aspect a) {
|
||||
switch(a) {
|
||||
case EXPOSED:
|
||||
return pkg;
|
||||
case IMPLEMENTATION:
|
||||
return pkg.subPackage("impl");
|
||||
default:
|
||||
assert false;
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
protected MethodWriter createMethodWriter(final ClassOutlineImpl target) {
|
||||
return new MethodWriter(target) {
|
||||
private final JDefinedClass intf = target.ref;
|
||||
private final JDefinedClass impl = target.implClass;
|
||||
|
||||
private JMethod intfMethod;
|
||||
private JMethod implMethod;
|
||||
|
||||
public JVar addParameter(JType type, String name) {
|
||||
// TODO: do we still need to deal with the case where intf is null?
|
||||
if(intf!=null)
|
||||
intfMethod.param(type,name);
|
||||
return implMethod.param(type,name);
|
||||
}
|
||||
|
||||
public JMethod declareMethod(JType returnType, String methodName) {
|
||||
if(intf!=null)
|
||||
intfMethod = intf.method( 0, returnType, methodName );
|
||||
implMethod = impl.method( JMod.PUBLIC, returnType, methodName );
|
||||
return implMethod;
|
||||
}
|
||||
|
||||
public JDocComment javadoc() {
|
||||
if(intf!=null)
|
||||
return intfMethod.javadoc();
|
||||
else
|
||||
return implMethod.javadoc();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void _extends(ClassOutlineImpl derived, ClassOutlineImpl base) {
|
||||
derived.implClass._extends(base.implRef);
|
||||
derived.ref._implements(base.ref);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates class(es) for the given bean.
|
||||
*/
|
||||
protected abstract Result createClasses( Outline outline, CClassInfo bean );
|
||||
|
||||
/**
|
||||
* Gets the specified aspect of the given package.
|
||||
*/
|
||||
protected abstract JPackage getPackage( JPackage pkg, Aspect a );
|
||||
|
||||
protected abstract MethodWriter createMethodWriter( ClassOutlineImpl target );
|
||||
|
||||
/**
|
||||
* Sets up an inheritance relationship.
|
||||
*/
|
||||
protected abstract void _extends( ClassOutlineImpl derived, ClassOutlineImpl base );
|
||||
|
||||
public static final class Result {
|
||||
/**
|
||||
* Corresponds to {@link Aspect#EXPOSED}
|
||||
*/
|
||||
public final JDefinedClass exposed;
|
||||
/**
|
||||
* Corresponds to {@link Aspect#IMPLEMENTATION}
|
||||
*/
|
||||
public final JDefinedClass implementation;
|
||||
|
||||
public Result(JDefinedClass exposed, JDefinedClass implementation) {
|
||||
this.exposed = exposed;
|
||||
this.implementation = implementation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Formats error messages.
|
||||
*/
|
||||
enum Messages {
|
||||
// AnnotationParser
|
||||
METHOD_COLLISION, // 3 args
|
||||
ERR_UNUSABLE_NAME, // 2 args
|
||||
ERR_KEYNAME_COLLISION, // 1 arg
|
||||
ERR_NAME_COLLISION, // 1 arg
|
||||
ILLEGAL_CONSTRUCTOR_PARAM, // 1 arg
|
||||
OBJECT_FACTORY_CONFLICT, // 1 arg
|
||||
OBJECT_FACTORY_CONFLICT_RELATED,
|
||||
;
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use is subject to the license terms.
|
||||
*/
|
||||
package com.sun.tools.internal.xjc.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JDocComment;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
|
||||
/**
|
||||
* The back-end may or may not generate the content interface
|
||||
* separately from the implementation class. If so, a method
|
||||
* needs to be declared on both the interface and the implementation class.
|
||||
* <p>
|
||||
* This class hides those details and allow callers to declare
|
||||
* methods just once.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
public abstract class MethodWriter {
|
||||
protected final JCodeModel codeModel;
|
||||
|
||||
protected MethodWriter(ClassOutline context) {
|
||||
this.codeModel = context.parent().getCodeModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares a method in both the interface and the implementation.
|
||||
*
|
||||
* @return
|
||||
* JMethod object that represents a newly declared method
|
||||
* on the implementation class.
|
||||
*/
|
||||
public abstract JMethod declareMethod( JType returnType, String methodName );
|
||||
|
||||
public final JMethod declareMethod( Class returnType, String methodName ) {
|
||||
return declareMethod( codeModel.ref(returnType), methodName );
|
||||
}
|
||||
|
||||
/**
|
||||
* To generate javadoc for the previously declared method, use this method
|
||||
* to obtain a {@link JDocComment} object. This may return a value
|
||||
* different from declareMethod().javadoc().
|
||||
*/
|
||||
public abstract JDocComment javadoc();
|
||||
|
||||
|
||||
/**
|
||||
* Adds a parameter to the previously declared method.
|
||||
*
|
||||
* @return
|
||||
* JVar object that represents a newly added parameter
|
||||
* on the implementation class.
|
||||
*/
|
||||
public abstract JVar addParameter( JType type, String name );
|
||||
|
||||
public final JVar addParameter( Class type, String name ) {
|
||||
return addParameter( codeModel.ref(type), name );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
|
||||
/**
|
||||
* Generates <code>ObjectFactory</code> then wraps it and provides
|
||||
* access to it.
|
||||
*
|
||||
* <p>
|
||||
* The ObjectFactory contains
|
||||
* factory methods for each schema derived content class
|
||||
*
|
||||
* @author
|
||||
* Ryan Shoemaker
|
||||
*/
|
||||
public abstract class ObjectFactoryGenerator {
|
||||
/**
|
||||
* Adds code for the given {@link CElementInfo} to ObjectFactory.
|
||||
*/
|
||||
abstract void populate( CElementInfo ei );
|
||||
|
||||
/**
|
||||
* Adds code that is relevant to a given {@link ClassOutlineImpl} to
|
||||
* ObjectFactory.
|
||||
*/
|
||||
abstract void populate( ClassOutlineImpl cc );
|
||||
|
||||
/**
|
||||
* Returns a reference to the generated (public) ObjectFactory
|
||||
*/
|
||||
public abstract JDefinedClass getObjectFactory();
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlInlineBinaryData;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
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.JPackage;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementDeclWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlRegistryWriter;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.Constructor;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.xml.internal.bind.v2.TODO;
|
||||
|
||||
/**
|
||||
* Generates <code>ObjectFactory</code> then wraps it and provides
|
||||
* access to it.
|
||||
*
|
||||
* <p>
|
||||
* The ObjectFactory contains
|
||||
* factory methods for each schema derived content class
|
||||
*
|
||||
* @author
|
||||
* Ryan Shoemaker
|
||||
*/
|
||||
abstract class ObjectFactoryGeneratorImpl extends ObjectFactoryGenerator {
|
||||
|
||||
private final BeanGenerator outline;
|
||||
private final Model model;
|
||||
private final JCodeModel codeModel;
|
||||
/**
|
||||
* Ref to {@link Class}.
|
||||
*/
|
||||
private final JClass classRef;
|
||||
|
||||
/**
|
||||
* Reference to the generated ObjectFactory class.
|
||||
*/
|
||||
private final JDefinedClass objectFactory;
|
||||
|
||||
/** map of qname to the QName constant field. */
|
||||
private final HashMap<QName,JFieldVar> qnameMap = new HashMap<QName,JFieldVar>();
|
||||
|
||||
/**
|
||||
* Names of the element factory methods that are created.
|
||||
* Used to detect collisions.
|
||||
*
|
||||
* The value is used for reporting error locations.
|
||||
*/
|
||||
private final Map<String,CElementInfo> elementFactoryNames = new HashMap<String,CElementInfo>();
|
||||
|
||||
/**
|
||||
* Names of the value factory methods that are created.
|
||||
* Used to detect collisions.
|
||||
*
|
||||
* The value is used for reporting error locations.
|
||||
*/
|
||||
private final Map<String,ClassOutlineImpl> valueFactoryNames = new HashMap<String,ClassOutlineImpl>();
|
||||
|
||||
/**
|
||||
* Returns a reference to the generated (public) ObjectFactory
|
||||
*/
|
||||
public JDefinedClass getObjectFactory() {
|
||||
return objectFactory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ObjectFactoryGeneratorImpl( BeanGenerator outline, Model model, JPackage targetPackage ) {
|
||||
this.outline = outline;
|
||||
this.model = model;
|
||||
this.codeModel = this.model.codeModel;
|
||||
this.classRef = codeModel.ref(Class.class);
|
||||
|
||||
// create the ObjectFactory class skeleton
|
||||
objectFactory = this.outline.getClassFactory().createClass(
|
||||
targetPackage, "ObjectFactory", null );
|
||||
objectFactory.annotate2(XmlRegistryWriter.class);
|
||||
|
||||
// generate the default constructor
|
||||
//
|
||||
// m1 result:
|
||||
// public ObjectFactory() {}
|
||||
JMethod m1 = objectFactory.constructor(JMod.PUBLIC);
|
||||
m1.javadoc().append("Create a new ObjectFactory that can be used to " +
|
||||
"create new instances of schema derived classes " +
|
||||
"for package: " + targetPackage.name());
|
||||
|
||||
// add some class javadoc
|
||||
objectFactory.javadoc().append(
|
||||
"This object contains factory methods for each \n" +
|
||||
"Java content interface and Java element interface \n" +
|
||||
"generated in the " + targetPackage.name() + " package. \n" +
|
||||
"<p>An ObjectFactory allows you to programatically \n" +
|
||||
"construct new instances of the Java representation \n" +
|
||||
"for XML content. The Java representation of XML \n" +
|
||||
"content can consist of schema derived interfaces \n" +
|
||||
"and classes representing the binding of schema \n" +
|
||||
"type definitions, element declarations and model \n" +
|
||||
"groups. Factory methods for each of these are \n" +
|
||||
"provided in this class." );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds code for the given {@link CElementInfo} to ObjectFactory.
|
||||
*/
|
||||
protected final void populate( CElementInfo ei, Aspect impl, Aspect exposed ) {
|
||||
JType exposedElementType = ei.toType(outline,exposed);
|
||||
JType exposedType = ei.getContentInMemoryType().toType(outline,exposed);
|
||||
JType implType = ei.getContentInMemoryType().toType(outline,impl);
|
||||
String namespaceURI = ei.getElementName().getNamespaceURI();
|
||||
String localPart = ei.getElementName().getLocalPart();
|
||||
|
||||
JClass scope=null;
|
||||
if(ei.getScope()!=null)
|
||||
scope = outline.getClazz(ei.getScope()).implClass;
|
||||
|
||||
|
||||
JMethod m;
|
||||
|
||||
if(ei.isAbstract()) {
|
||||
// TODO: see the "Abstract elements and mighty IXmlElement" e-mail
|
||||
// that I sent to jaxb-tech
|
||||
TODO.checkSpec();
|
||||
}
|
||||
|
||||
{// collision check
|
||||
CElementInfo existing = elementFactoryNames.put(ei.getSqueezedName(),ei);
|
||||
if( existing!=null ) {
|
||||
outline.getErrorReceiver().error(existing.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT.format(ei.getSqueezedName()));
|
||||
outline.getErrorReceiver().error(ei.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT_RELATED.format());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// no arg constructor
|
||||
// [RESULT] if the element doesn't have its own class, something like:
|
||||
//
|
||||
// @XmlElementMapping(uri = "", name = "foo")
|
||||
// public JAXBElement<Foo> createFoo( Foo value ) {
|
||||
// return new JAXBElement<Foo>(
|
||||
// new QName("","foo"),(Class)FooImpl.class,scope,(FooImpl)value);
|
||||
// }
|
||||
// NOTE: when we generate value classes Foo==FooImpl
|
||||
//
|
||||
// [RESULT] otherwise
|
||||
//
|
||||
// @XmlElementMapping(uri = "", name = "foo")
|
||||
// public Foo createFoo( FooType value ) {
|
||||
// return new Foo((FooTypeImpl)value);
|
||||
// }
|
||||
// NOTE: when we generate value classes FooType==FooTypeImpl
|
||||
//
|
||||
// to deal with
|
||||
// new JAXBElement<List<String>>( ..., List.class, ... );
|
||||
// we sometimes have to produce (Class)List.class instead of just List.class
|
||||
|
||||
m = objectFactory.method( JMod.PUBLIC, exposedElementType, "create" + ei.getSqueezedName() );
|
||||
JVar $value = m.param(exposedType,"value");
|
||||
|
||||
JExpression declaredType;
|
||||
if(implType.boxify().isParameterized() || !exposedType.equals(implType))
|
||||
declaredType = JExpr.cast(classRef,implType.boxify().dotclass());
|
||||
else
|
||||
declaredType = implType.boxify().dotclass();
|
||||
JExpression scopeClass = scope==null?JExpr._null():scope.dotclass();
|
||||
|
||||
// build up the return extpression
|
||||
JInvocation exp = JExpr._new(exposedElementType);
|
||||
if(!ei.hasClass()) {
|
||||
exp.arg(getQNameInvocation(ei));
|
||||
exp.arg(declaredType);
|
||||
exp.arg(scopeClass);
|
||||
}
|
||||
if(implType==exposedType)
|
||||
exp.arg($value);
|
||||
else
|
||||
exp.arg(JExpr.cast(implType,$value));
|
||||
|
||||
m.body()._return( exp );
|
||||
|
||||
m.javadoc()
|
||||
.append("Create an instance of ")
|
||||
.append(exposedElementType)
|
||||
.append("}");
|
||||
|
||||
XmlElementDeclWriter xemw = m.annotate2(XmlElementDeclWriter.class);
|
||||
xemw.namespace(namespaceURI).name(localPart);
|
||||
if(scope!=null)
|
||||
xemw.scope(scope);
|
||||
|
||||
if(ei.getSubstitutionHead()!=null) {
|
||||
QName n = ei.getSubstitutionHead().getElementName();
|
||||
xemw.substitutionHeadNamespace(n.getNamespaceURI());
|
||||
xemw.substitutionHeadName(n.getLocalPart());
|
||||
}
|
||||
|
||||
if(ei.getDefaultValue()!=null)
|
||||
xemw.defaultValue(ei.getDefaultValue());
|
||||
|
||||
if(ei.getProperty().inlineBinaryData())
|
||||
m.annotate(XmlInlineBinaryData.class);
|
||||
|
||||
// if the element is adapter, put that annotation on the factory method
|
||||
outline.generateAdapterIfNecessary(ei.getProperty(),m);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a JFieldVar that represents the QName field for the given information.
|
||||
*
|
||||
* if it doesn't exist, create a static field in the class and store a new JFieldVar.
|
||||
*/
|
||||
private JExpression getQNameInvocation(CElementInfo ei) {
|
||||
QName name = ei.getElementName();
|
||||
if(qnameMap.containsKey(name)) {
|
||||
return qnameMap.get(name);
|
||||
}
|
||||
|
||||
if(qnameMap.size()>1024)
|
||||
// stop gap measure to avoid 'code too large' error in javac.
|
||||
return createQName(name);
|
||||
|
||||
// [RESULT]
|
||||
// private static final QName _XYZ_NAME = new QName("uri", "local");
|
||||
JFieldVar qnameField = objectFactory.field(
|
||||
JMod.PRIVATE | JMod.STATIC | JMod.FINAL,
|
||||
QName.class,
|
||||
'_' + ei.getSqueezedName() + "_QNAME", createQName(name));
|
||||
|
||||
qnameMap.put(name, qnameField);
|
||||
|
||||
return qnameField;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an expression that evaluates to "new QName(...)"
|
||||
*/
|
||||
private JInvocation createQName(QName name) {
|
||||
return JExpr._new(codeModel.ref(QName.class)).arg(name.getNamespaceURI()).arg(name.getLocalPart());
|
||||
}
|
||||
|
||||
protected final void populate( ClassOutlineImpl cc, JClass sigType ) {
|
||||
// add static factory method for this class to JAXBContext.
|
||||
//
|
||||
// generate methods like:
|
||||
// public static final SIGTYPE createFoo() {
|
||||
// return new FooImpl();
|
||||
// }
|
||||
|
||||
if(!cc.target.isAbstract()) {
|
||||
JMethod m = objectFactory.method(
|
||||
JMod.PUBLIC, sigType, "create" + cc.target.getSqueezedName() );
|
||||
m.body()._return( JExpr._new(cc.implRef) );
|
||||
|
||||
// add some jdoc to avoid javadoc warnings in jdk1.4
|
||||
m.javadoc()
|
||||
.append("Create an instance of ")
|
||||
.append(cc.ref);
|
||||
}
|
||||
|
||||
|
||||
// add static factory methods for all the other constructors.
|
||||
Collection<? extends Constructor> consl = cc.target.getConstructors();
|
||||
if(consl.size()!=0) {
|
||||
// if we are going to add constructors with parameters,
|
||||
// first we need to have a default constructor.
|
||||
cc.implClass.constructor(JMod.PUBLIC);
|
||||
}
|
||||
|
||||
{// collision check
|
||||
String name = cc.target.getSqueezedName();
|
||||
ClassOutlineImpl existing = valueFactoryNames.put(name,cc);
|
||||
if( existing!=null ) {
|
||||
outline.getErrorReceiver().error(existing.target.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT.format(name));
|
||||
outline.getErrorReceiver().error(cc.target.getLocator(),
|
||||
Messages.OBJECT_FACTORY_CONFLICT_RELATED.format());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for( Constructor cons : consl ) {
|
||||
// method on ObjectFactory
|
||||
// [RESULT]
|
||||
// Foo createFoo( T1 a, T2 b, T3 c, ... ) throws JAXBException {
|
||||
// return new FooImpl(a,b,c,...);
|
||||
// }
|
||||
JMethod m = objectFactory.method( JMod.PUBLIC,
|
||||
cc.ref, "create" + cc.target.getSqueezedName() );
|
||||
JInvocation inv = JExpr._new(cc.implRef);
|
||||
m.body()._return(inv);
|
||||
|
||||
// let's not throw this exception.
|
||||
// m._throws(codeModel.ref(JAXBException.class));
|
||||
|
||||
// add some jdoc to avoid javadoc warnings in jdk1.4
|
||||
m.javadoc()
|
||||
.append( "Create an instance of " )
|
||||
.append( cc.ref )
|
||||
.addThrows(JAXBException.class).append("if an error occurs");
|
||||
|
||||
// constructor
|
||||
// [RESULT]
|
||||
// FooImpl( T1 a, T2 b, T3 c, ... ) {
|
||||
// }
|
||||
JMethod c = cc.implClass.constructor(JMod.PUBLIC);
|
||||
|
||||
for( String fieldName : cons.fields ) {
|
||||
CPropertyInfo field = cc.target.getProperty(fieldName);
|
||||
if(field==null) {
|
||||
outline.getErrorReceiver().error(cc.target.getLocator(),
|
||||
Messages.ILLEGAL_CONSTRUCTOR_PARAM.format(fieldName));
|
||||
continue;
|
||||
}
|
||||
|
||||
fieldName = camelize(fieldName);
|
||||
|
||||
FieldOutline fo = outline.getField(field);
|
||||
FieldAccessor accessor = fo.create(JExpr._this());
|
||||
|
||||
// declare a parameter on this factory method and set
|
||||
// it to the field
|
||||
inv.arg(m.param( fo.getRawType(), fieldName ));
|
||||
|
||||
JVar $var = c.param( fo.getRawType(), fieldName );
|
||||
accessor.fromRawValue(c.body(),'_'+fieldName,$var);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Change the first character to the lower case. */
|
||||
private static String camelize( String s ) {
|
||||
return Character.toLowerCase(s.charAt(0)) + s.substring(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlNsForm;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JDefinedClass;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlSchemaWriter;
|
||||
import com.sun.tools.internal.xjc.model.CAttributePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CClassInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElement;
|
||||
import com.sun.tools.internal.xjc.model.CElementPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyVisitor;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeRef;
|
||||
import com.sun.tools.internal.xjc.model.CValuePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.PackageOutline;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
|
||||
/**
|
||||
* {@link PackageOutline} enhanced with schema2java specific
|
||||
* information.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com), Martin Grebac (martin.grebac@oracle.com)
|
||||
*/
|
||||
public final class PackageOutlineImpl implements PackageOutline {
|
||||
private final Model _model;
|
||||
private final JPackage _package;
|
||||
private final ObjectFactoryGenerator objectFactoryGenerator;
|
||||
|
||||
/*package*/ final Set<ClassOutlineImpl> classes = new HashSet<ClassOutlineImpl>();
|
||||
private final Set<ClassOutlineImpl> classesView = Collections.unmodifiableSet(classes);
|
||||
|
||||
private String mostUsedNamespaceURI;
|
||||
private XmlNsForm elementFormDefault;
|
||||
private XmlNsForm attributeFormDefault;
|
||||
|
||||
/**
|
||||
* The namespace URI most commonly used in classes in this package.
|
||||
* This should be used as the namespace URI for {@link XmlSchema#namespace()}.
|
||||
*
|
||||
* <p>
|
||||
* Null if no default
|
||||
*
|
||||
* @see #calcDefaultValues().
|
||||
*/
|
||||
public String getMostUsedNamespaceURI() {
|
||||
return mostUsedNamespaceURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* The attribute form default for this package.
|
||||
* <p>
|
||||
* The value is computed by examining what would yield the smallest generated code.
|
||||
*/
|
||||
public XmlNsForm getAttributeFormDefault() {
|
||||
assert attributeFormDefault!=null;
|
||||
return attributeFormDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* The element form default for this package.
|
||||
* <p>
|
||||
* The value is computed by examining what would yield the smallest generated code.
|
||||
*/
|
||||
public XmlNsForm getElementFormDefault() {
|
||||
assert elementFormDefault!=null;
|
||||
return elementFormDefault;
|
||||
}
|
||||
|
||||
public JPackage _package() {
|
||||
return _package;
|
||||
}
|
||||
|
||||
public ObjectFactoryGenerator objectFactoryGenerator() {
|
||||
return objectFactoryGenerator;
|
||||
}
|
||||
|
||||
public Set<ClassOutlineImpl> getClasses() {
|
||||
return classesView;
|
||||
}
|
||||
|
||||
public JDefinedClass objectFactory() {
|
||||
return objectFactoryGenerator.getObjectFactory();
|
||||
}
|
||||
|
||||
protected PackageOutlineImpl( BeanGenerator outline, Model model, JPackage _pkg ) {
|
||||
this._model = model;
|
||||
this._package = _pkg;
|
||||
switch(model.strategy) {
|
||||
case BEAN_ONLY:
|
||||
objectFactoryGenerator = new PublicObjectFactoryGenerator(outline,model,_pkg);
|
||||
break;
|
||||
case INTF_AND_IMPL:
|
||||
objectFactoryGenerator = new DualObjectFactoryGenerator(outline,model,_pkg);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the most common namespace URI in this package
|
||||
* (to put into {@link XmlSchema#namespace()} and what value
|
||||
* we should put into {@link XmlSchema#elementFormDefault()}.
|
||||
*
|
||||
* This method is called after {@link #classes} field is filled up.
|
||||
*/
|
||||
public void calcDefaultValues() {
|
||||
// short-circuit if xjc was told not to generate package level annotations in
|
||||
// package-info.java
|
||||
if(!_model.isPackageLevelAnnotations()) {
|
||||
mostUsedNamespaceURI = "";
|
||||
elementFormDefault = XmlNsForm.UNQUALIFIED;
|
||||
return;
|
||||
}
|
||||
|
||||
// used to visit properties
|
||||
CPropertyVisitor<Void> propVisitor = new CPropertyVisitor<Void>() {
|
||||
public Void onElement(CElementPropertyInfo p) {
|
||||
for (CTypeRef tr : p.getTypes()) {
|
||||
countURI(propUriCountMap, tr.getTagName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onReference(CReferencePropertyInfo p) {
|
||||
for (CElement e : p.getElements()) {
|
||||
countURI(propUriCountMap, e.getElementName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onAttribute(CAttributePropertyInfo p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Void onValue(CValuePropertyInfo p) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
for (ClassOutlineImpl co : classes) {
|
||||
CClassInfo ci = co.target;
|
||||
countURI(uriCountMap, ci.getTypeName());
|
||||
countURI(uriCountMap, ci.getElementName());
|
||||
|
||||
for( CPropertyInfo p : ci.getProperties() )
|
||||
p.accept(propVisitor);
|
||||
}
|
||||
mostUsedNamespaceURI = getMostUsedURI(uriCountMap);
|
||||
|
||||
elementFormDefault = getFormDefault();
|
||||
attributeFormDefault = XmlNsForm.UNQUALIFIED;
|
||||
try {
|
||||
XmlNsForm modelValue = _model.getAttributeFormDefault(mostUsedNamespaceURI);
|
||||
attributeFormDefault = modelValue;
|
||||
} catch (Exception e) {
|
||||
// ignore and accept default
|
||||
}
|
||||
|
||||
// generate package-info.java
|
||||
// we won't get this far if the user specified -npa
|
||||
if(!mostUsedNamespaceURI.equals("") || elementFormDefault==XmlNsForm.QUALIFIED || (attributeFormDefault == XmlNsForm.QUALIFIED)) {
|
||||
XmlSchemaWriter w = _model.strategy.getPackage(_package, Aspect.IMPLEMENTATION).annotate2(XmlSchemaWriter.class);
|
||||
if(!mostUsedNamespaceURI.equals(""))
|
||||
w.namespace(mostUsedNamespaceURI);
|
||||
if(elementFormDefault==XmlNsForm.QUALIFIED)
|
||||
w.elementFormDefault(elementFormDefault);
|
||||
if(attributeFormDefault==XmlNsForm.QUALIFIED)
|
||||
w.attributeFormDefault(attributeFormDefault);
|
||||
}
|
||||
}
|
||||
|
||||
// Map to keep track of how often each type or element uri is used in this package
|
||||
// mostly used to calculate mostUsedNamespaceURI
|
||||
private HashMap<String, Integer> uriCountMap = new HashMap<String, Integer>();
|
||||
|
||||
// Map to keep track of how often each property uri is used in this package
|
||||
// used to calculate elementFormDefault
|
||||
private HashMap<String, Integer> propUriCountMap = new HashMap<String, Integer>();
|
||||
|
||||
/**
|
||||
* pull the uri out of the specified QName and keep track of it in the
|
||||
* specified hash map
|
||||
*
|
||||
* @param qname
|
||||
*/
|
||||
private void countURI(HashMap<String, Integer> map, QName qname) {
|
||||
if (qname == null) return;
|
||||
|
||||
String uri = qname.getNamespaceURI();
|
||||
|
||||
if (map.containsKey(uri)) {
|
||||
map.put(uri, map.get(uri) + 1);
|
||||
} else {
|
||||
map.put(uri, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through the hash map looking for the namespace used
|
||||
* most frequently. Ties are arbitrarily broken by the order
|
||||
* in which the map keys are iterated over.
|
||||
*
|
||||
* <p>
|
||||
* Because JAX-WS often reassigns the "" namespace URI,
|
||||
* and when that happens it unintentionally also renames (normally
|
||||
* unqualified) local elements, prefer non-"" URI when there's a tie.
|
||||
*/
|
||||
private String getMostUsedURI(HashMap<String, Integer> map) {
|
||||
String mostPopular = null;
|
||||
int count = 0;
|
||||
|
||||
for (Map.Entry<String,Integer> e : map.entrySet()) {
|
||||
String uri = e.getKey();
|
||||
int uriCount = e.getValue();
|
||||
if (mostPopular == null) {
|
||||
mostPopular = uri;
|
||||
count = uriCount;
|
||||
} else {
|
||||
if (uriCount > count || (uriCount==count && mostPopular.equals(""))) {
|
||||
mostPopular = uri;
|
||||
count = uriCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mostPopular == null) return "";
|
||||
return mostPopular;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the element form defaulting.
|
||||
*
|
||||
* Compare the most frequently used property URI to the most frequently used
|
||||
* element/type URI. If they match, then return QUALIFIED
|
||||
*/
|
||||
private XmlNsForm getFormDefault() {
|
||||
if (getMostUsedURI(propUriCountMap).equals("")) return XmlNsForm.UNQUALIFIED;
|
||||
else return XmlNsForm.QUALIFIED;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.codemodel.internal.fmt.JPropertyFile;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import com.sun.tools.internal.xjc.runtime.JAXBContextFactory;
|
||||
|
||||
/**
|
||||
* Generates private ObjectFactory.
|
||||
*
|
||||
* <p>
|
||||
* This class also puts a copy of {@link JAXBContextFactory}
|
||||
* to the impl package.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class PrivateObjectFactoryGenerator extends ObjectFactoryGeneratorImpl {
|
||||
public PrivateObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
|
||||
super(outline, model, targetPackage.subPackage("impl"));
|
||||
|
||||
JPackage implPkg = targetPackage.subPackage("impl");
|
||||
|
||||
// put JAXBContextFactory into the impl package
|
||||
JClass factory = outline.generateStaticClass(JAXBContextFactory.class,implPkg);
|
||||
|
||||
// and then put jaxb.properties to point to it
|
||||
JPropertyFile jaxbProperties = new JPropertyFile("jaxb.properties");
|
||||
targetPackage.addResourceFile(jaxbProperties);
|
||||
jaxbProperties.add(
|
||||
JAXBContext.JAXB_CONTEXT_FACTORY,
|
||||
factory.fullName());
|
||||
}
|
||||
|
||||
void populate(CElementInfo ei) {
|
||||
populate(ei,Aspect.IMPLEMENTATION,Aspect.IMPLEMENTATION);
|
||||
}
|
||||
|
||||
void populate(ClassOutlineImpl cc) {
|
||||
populate(cc,cc.implRef);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean;
|
||||
|
||||
import com.sun.codemodel.internal.JPackage;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.Model;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
|
||||
/**
|
||||
* Generates public ObjectFactory.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
final class PublicObjectFactoryGenerator extends ObjectFactoryGeneratorImpl {
|
||||
public PublicObjectFactoryGenerator(BeanGenerator outline, Model model, JPackage targetPackage) {
|
||||
super(outline, model, targetPackage);
|
||||
}
|
||||
|
||||
void populate(CElementInfo ei) {
|
||||
populate(ei,Aspect.IMPLEMENTATION,Aspect.EXPOSED);
|
||||
}
|
||||
|
||||
void populate(ClassOutlineImpl cc) {
|
||||
populate(cc,cc.ref);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean.field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.W3CDomHandler;
|
||||
import javax.xml.bind.annotation.XmlList;
|
||||
import javax.xml.bind.annotation.XmlMixed;
|
||||
import javax.xml.bind.annotation.XmlNsForm;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.XmlInlineBinaryData;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import com.sun.codemodel.internal.JAnnotatable;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JCodeModel;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAnyElementWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlAttributeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementRefWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementRefsWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlElementsWriter;
|
||||
import com.sun.tools.internal.xjc.generator.annotation.spec.XmlSchemaTypeWriter;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CAttributePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElement;
|
||||
import com.sun.tools.internal.xjc.model.CElementInfo;
|
||||
import com.sun.tools.internal.xjc.model.CElementPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CReferencePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeInfo;
|
||||
import com.sun.tools.internal.xjc.model.CTypeRef;
|
||||
import com.sun.tools.internal.xjc.model.CValuePropertyInfo;
|
||||
import com.sun.tools.internal.xjc.model.nav.NClass;
|
||||
import com.sun.tools.internal.xjc.outline.Aspect;
|
||||
import static com.sun.tools.internal.xjc.outline.Aspect.IMPLEMENTATION;
|
||||
import com.sun.tools.internal.xjc.outline.ClassOutline;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
import com.sun.tools.internal.xjc.outline.FieldOutline;
|
||||
import com.sun.tools.internal.xjc.reader.TypeUtil;
|
||||
import com.sun.tools.internal.xjc.Options;
|
||||
import com.sun.tools.internal.xjc.api.SpecVersion;
|
||||
import com.sun.xml.internal.bind.api.impl.NameConverter;
|
||||
import com.sun.xml.internal.bind.v2.TODO;
|
||||
|
||||
/**
|
||||
* Useful base class for implementing {@link FieldOutline}.
|
||||
*
|
||||
* <p>
|
||||
* This class just provides a few utility methods and keep some
|
||||
* important variables so that they can be readily accessed any time.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
abstract class AbstractField implements FieldOutline {
|
||||
|
||||
protected final ClassOutlineImpl outline;
|
||||
|
||||
protected final CPropertyInfo prop;
|
||||
|
||||
protected final JCodeModel codeModel;
|
||||
|
||||
/**
|
||||
* The type of this field, which can hold all the possible types.
|
||||
*/
|
||||
protected final JType implType;
|
||||
|
||||
/**
|
||||
* The publicly visible type of this field.
|
||||
* If we are generating value classes implType==exposedType.
|
||||
*/
|
||||
protected final JType exposedType;
|
||||
|
||||
protected AbstractField( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
this.outline = outline;
|
||||
this.prop = prop;
|
||||
this.codeModel = outline.parent().getCodeModel();
|
||||
this.implType = getType(IMPLEMENTATION);
|
||||
this.exposedType = getType(Aspect.EXPOSED);
|
||||
}
|
||||
|
||||
public final ClassOutline parent() {
|
||||
return outline;
|
||||
}
|
||||
|
||||
public final CPropertyInfo getPropertyInfo() {
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Annotate the field according to the recipes given as {@link CPropertyInfo}.
|
||||
*/
|
||||
protected void annotate( JAnnotatable field ) {
|
||||
|
||||
assert(field!=null);
|
||||
|
||||
/*
|
||||
TODO: consider moving this logic to somewhere else
|
||||
so that it can be better shared, for how a field gets
|
||||
annotated doesn't really depend on how we generate accessors.
|
||||
|
||||
so perhaps we should separate those two.
|
||||
*/
|
||||
|
||||
// TODO: consider a visitor
|
||||
if (prop instanceof CAttributePropertyInfo) {
|
||||
annotateAttribute(field);
|
||||
} else if (prop instanceof CElementPropertyInfo) {
|
||||
annotateElement(field);
|
||||
} else if (prop instanceof CValuePropertyInfo) {
|
||||
field.annotate(XmlValue.class);
|
||||
} else if (prop instanceof CReferencePropertyInfo) {
|
||||
annotateReference(field);
|
||||
}
|
||||
|
||||
outline.parent().generateAdapterIfNecessary(prop,field);
|
||||
|
||||
QName st = prop.getSchemaType();
|
||||
if(st!=null)
|
||||
field.annotate2(XmlSchemaTypeWriter.class)
|
||||
.name(st.getLocalPart())
|
||||
.namespace(st.getNamespaceURI());
|
||||
|
||||
if(prop.inlineBinaryData())
|
||||
field.annotate(XmlInlineBinaryData.class);
|
||||
}
|
||||
|
||||
private void annotateReference(JAnnotatable field) {
|
||||
CReferencePropertyInfo rp = (CReferencePropertyInfo) prop;
|
||||
|
||||
TODO.prototype();
|
||||
// this is just a quick hack to get the basic test working
|
||||
|
||||
Collection<CElement> elements = rp.getElements();
|
||||
|
||||
XmlElementRefWriter refw;
|
||||
if(elements.size()==1) {
|
||||
refw = field.annotate2(XmlElementRefWriter.class);
|
||||
CElement e = elements.iterator().next();
|
||||
refw.name(e.getElementName().getLocalPart())
|
||||
.namespace(e.getElementName().getNamespaceURI())
|
||||
.type(e.getType().toType(outline.parent(),IMPLEMENTATION));
|
||||
if(getOptions().target.isLaterThan(SpecVersion.V2_2))
|
||||
refw.required(rp.isRequired());
|
||||
} else
|
||||
if(elements.size()>1) {
|
||||
XmlElementRefsWriter refsw = field.annotate2(XmlElementRefsWriter.class);
|
||||
for( CElement e : elements ) {
|
||||
refw = refsw.value();
|
||||
refw.name(e.getElementName().getLocalPart())
|
||||
.namespace(e.getElementName().getNamespaceURI())
|
||||
.type(e.getType().toType(outline.parent(),IMPLEMENTATION));
|
||||
if(getOptions().target.isLaterThan(SpecVersion.V2_2))
|
||||
refw.required(rp.isRequired());
|
||||
}
|
||||
}
|
||||
|
||||
if(rp.isMixed())
|
||||
field.annotate(XmlMixed.class);
|
||||
|
||||
NClass dh = rp.getDOMHandler();
|
||||
if(dh!=null) {
|
||||
XmlAnyElementWriter xaew = field.annotate2(XmlAnyElementWriter.class);
|
||||
xaew.lax(rp.getWildcard().allowTypedObject);
|
||||
|
||||
final JClass value = dh.toType(outline.parent(),IMPLEMENTATION);
|
||||
if(!value.equals(codeModel.ref(W3CDomHandler.class))) {
|
||||
xaew.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotate the element property 'field'
|
||||
*/
|
||||
private void annotateElement(JAnnotatable field) {
|
||||
CElementPropertyInfo ep = (CElementPropertyInfo) prop;
|
||||
List<CTypeRef> types = ep.getTypes();
|
||||
|
||||
if(ep.isValueList()) {
|
||||
field.annotate(XmlList.class);
|
||||
}
|
||||
|
||||
assert ep.getXmlName()==null;
|
||||
// if( eName!=null ) { // wrapper
|
||||
// XmlElementWrapperWriter xcw = field.annotate2(XmlElementWrapperWriter.class);
|
||||
// xcw.name(eName.getLocalPart())
|
||||
// .namespace(eName.getNamespaceURI());
|
||||
// }
|
||||
|
||||
if (types.size() == 1) {
|
||||
CTypeRef t = types.get(0);
|
||||
writeXmlElementAnnotation(field, t, resolve(t,IMPLEMENTATION), false);
|
||||
} else {
|
||||
for (CTypeRef t : types) {
|
||||
// generate @XmlElements
|
||||
writeXmlElementAnnotation(field, t, resolve(t,IMPLEMENTATION), true);
|
||||
}
|
||||
xesw = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the simplest XmlElement annotation possible taking all semantic optimizations
|
||||
* into account. This method is essentially equivalent to:
|
||||
*
|
||||
* xew.name(ctype.getTagName().getLocalPart())
|
||||
* .namespace(ctype.getTagName().getNamespaceURI())
|
||||
* .type(jtype)
|
||||
* .defaultValue(ctype.getDefaultValue());
|
||||
*
|
||||
* @param field
|
||||
* @param ctype
|
||||
* @param jtype
|
||||
* @param checkWrapper true if the method might need to generate XmlElements
|
||||
*/
|
||||
private void writeXmlElementAnnotation( JAnnotatable field, CTypeRef ctype, JType jtype,
|
||||
boolean checkWrapper ) {
|
||||
|
||||
// lazily create - we don't know if we need to generate anything yet
|
||||
XmlElementWriter xew = null;
|
||||
|
||||
// these values are used to determine how to optimize the generated annotation
|
||||
XmlNsForm formDefault = parent()._package().getElementFormDefault();
|
||||
String propName = prop.getName(false);
|
||||
|
||||
String enclosingTypeNS;
|
||||
|
||||
if(parent().target.getTypeName()==null)
|
||||
enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
|
||||
else
|
||||
enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();
|
||||
|
||||
// generate the name property?
|
||||
String generatedName = ctype.getTagName().getLocalPart();
|
||||
if(!generatedName.equals(propName)) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.name(generatedName);
|
||||
}
|
||||
|
||||
// generate the namespace property?
|
||||
String generatedNS = ctype.getTagName().getNamespaceURI();
|
||||
if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) ||
|
||||
((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.namespace(generatedNS);
|
||||
}
|
||||
|
||||
// generate the required() property?
|
||||
CElementPropertyInfo ep = (CElementPropertyInfo) prop;
|
||||
if(ep.isRequired() && exposedType.isReference()) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.required(true);
|
||||
}
|
||||
|
||||
// generate the type property?
|
||||
|
||||
// I'm not too sure if this is the right place to handle this, but
|
||||
// if the schema definition is requiring this element, we should point to a primitive type,
|
||||
// not wrapper type (to correctly carry forward the required semantics.)
|
||||
// if it's a collection, we can't use a primitive, however.
|
||||
if(ep.isRequired() && !prop.isCollection())
|
||||
jtype = jtype.unboxify();
|
||||
|
||||
// when generating code for 1.4, the runtime can't infer that ArrayList<Foo> derives
|
||||
// from Collection<Foo> (because List isn't parameterized), so always expclitly
|
||||
// generate @XmlElement(type=...)
|
||||
if( !jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.type(jtype);
|
||||
}
|
||||
|
||||
// generate defaultValue property?
|
||||
final String defaultValue = ctype.getDefaultValue();
|
||||
if (defaultValue!=null) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.defaultValue(defaultValue);
|
||||
}
|
||||
|
||||
// generate the nillable property?
|
||||
if (ctype.isNillable()) {
|
||||
if(xew == null) xew = getXew(checkWrapper, field);
|
||||
xew.nillable(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Options} in the current compilation context.
|
||||
*/
|
||||
protected final Options getOptions() {
|
||||
return parent().parent().getModel().options;
|
||||
}
|
||||
|
||||
// ugly hack to lazily create
|
||||
private XmlElementsWriter xesw = null;
|
||||
|
||||
private XmlElementWriter getXew(boolean checkWrapper, JAnnotatable field) {
|
||||
XmlElementWriter xew;
|
||||
if(checkWrapper) {
|
||||
if(xesw==null) {
|
||||
xesw = field.annotate2(XmlElementsWriter.class);
|
||||
}
|
||||
xew = xesw.value();
|
||||
} else {
|
||||
xew = field.annotate2(XmlElementWriter.class);
|
||||
}
|
||||
return xew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotate the attribute property 'field'
|
||||
*/
|
||||
private void annotateAttribute(JAnnotatable field) {
|
||||
CAttributePropertyInfo ap = (CAttributePropertyInfo) prop;
|
||||
QName attName = ap.getXmlName();
|
||||
|
||||
// [RESULT]
|
||||
// @XmlAttribute(name="foo", required=true, namespace="bar://baz")
|
||||
XmlAttributeWriter xaw = field.annotate2(XmlAttributeWriter.class);
|
||||
|
||||
final String generatedName = attName.getLocalPart();
|
||||
final String generatedNS = attName.getNamespaceURI();
|
||||
|
||||
// Issue 570; always force generating name="" when do it when globalBindings underscoreBinding is set to non default value
|
||||
// generate name property?
|
||||
if(!generatedName.equals(ap.getName(false)) || !generatedName.equals(ap.getName(true)) || (outline.parent().getModel().getNameConverter() != NameConverter.standard)) {
|
||||
xaw.name(generatedName);
|
||||
}
|
||||
|
||||
// generate namespace property?
|
||||
if(!generatedNS.equals("")) { // assume attributeFormDefault == unqualified
|
||||
xaw.namespace(generatedNS);
|
||||
}
|
||||
|
||||
// generate required property?
|
||||
if(ap.isRequired()) {
|
||||
xaw.required(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful base class for implementing {@link FieldAccessor}.
|
||||
*/
|
||||
protected abstract class Accessor implements FieldAccessor {
|
||||
|
||||
/**
|
||||
* Evaluates to the target object this accessor should access.
|
||||
*/
|
||||
protected final JExpression $target;
|
||||
|
||||
protected Accessor( JExpression $target ) {
|
||||
this.$target = $target;
|
||||
}
|
||||
|
||||
public final FieldOutline owner() {
|
||||
return AbstractField.this;
|
||||
}
|
||||
|
||||
public final CPropertyInfo getPropertyInfo() {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// utility methods
|
||||
//
|
||||
//
|
||||
|
||||
/**
|
||||
* Generates the field declaration.
|
||||
*/
|
||||
protected final JFieldVar generateField( JType type ) {
|
||||
return outline.implClass.field( JMod.PROTECTED, type, prop.getName(false) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Case from {@link #exposedType} to {@link #implType} if necessary.
|
||||
*/
|
||||
protected final JExpression castToImplType( JExpression exp ) {
|
||||
if(implType==exposedType)
|
||||
return exp;
|
||||
else
|
||||
return JExpr.cast(implType,exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the type of a {@link CPropertyInfo}
|
||||
* @param aspect
|
||||
*/
|
||||
protected JType getType(final Aspect aspect) {
|
||||
if(prop.getAdapter()!=null)
|
||||
return prop.getAdapter().customType.toType(outline.parent(),aspect);
|
||||
|
||||
final class TypeList extends ArrayList<JType> {
|
||||
void add( CTypeInfo t ) {
|
||||
add( t.getType().toType(outline.parent(),aspect) );
|
||||
if(t instanceof CElementInfo) {
|
||||
// UGLY. element substitution is implemented in a way that
|
||||
// the derived elements are not assignable to base elements.
|
||||
// so when we compute the signature, we have to take derived types
|
||||
// into account
|
||||
add( ((CElementInfo)t).getSubstitutionMembers());
|
||||
}
|
||||
}
|
||||
|
||||
void add( Collection<? extends CTypeInfo> col ) {
|
||||
for (CTypeInfo typeInfo : col)
|
||||
add(typeInfo);
|
||||
}
|
||||
}
|
||||
TypeList r = new TypeList();
|
||||
r.add(prop.ref());
|
||||
|
||||
JType t;
|
||||
if(prop.baseType!=null)
|
||||
t = prop.baseType;
|
||||
else
|
||||
t = TypeUtil.getCommonBaseType(codeModel,r);
|
||||
|
||||
// if item type is unboxable, convert t=Integer -> t=int
|
||||
// the in-memory data structure can't have primitives directly,
|
||||
// but this guarantees that items cannot legal hold null,
|
||||
// which helps us improve the boundary signature between our
|
||||
// data structure and user code
|
||||
if(prop.isUnboxable())
|
||||
t = t.unboxify();
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns contents to be added to javadoc.
|
||||
*/
|
||||
protected final List<Object> listPossibleTypes( CPropertyInfo prop ) {
|
||||
List<Object> r = new ArrayList<Object>();
|
||||
for( CTypeInfo tt : prop.ref() ) {
|
||||
JType t = tt.getType().toType(outline.parent(),Aspect.EXPOSED);
|
||||
if( t.isPrimitive() || t.isArray() )
|
||||
r.add(t.fullName());
|
||||
else {
|
||||
r.add(t);
|
||||
r.add("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the Java type for the given type reference in the model.
|
||||
*/
|
||||
private JType resolve(CTypeRef typeRef,Aspect a) {
|
||||
return outline.parent().resolve(typeRef,a);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldRef;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com), Martin Grebac
|
||||
*/
|
||||
abstract class AbstractFieldWithVar extends AbstractField {
|
||||
|
||||
/**
|
||||
* Field declaration of the actual list object that we use
|
||||
* to store data.
|
||||
*/
|
||||
private JFieldVar field;
|
||||
|
||||
/**
|
||||
* Invoke {@link #createField()} after calling the
|
||||
* constructor.
|
||||
*/
|
||||
AbstractFieldWithVar( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
super(outline,prop);
|
||||
}
|
||||
|
||||
protected final void createField() {
|
||||
field = outline.implClass.field( JMod.PROTECTED,
|
||||
getFieldType(), prop.getName(false) );
|
||||
|
||||
annotate(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the getter method.
|
||||
*
|
||||
* <p>
|
||||
* This encapsulation is necessary because sometimes we use
|
||||
* {@code isXXXX} as the method name.
|
||||
*/
|
||||
protected String getGetterMethod() {
|
||||
if (getOptions().enableIntrospection) {
|
||||
return ((getFieldType().isPrimitive() &&
|
||||
getFieldType().boxify().getPrimitiveType()==codeModel.BOOLEAN) ?
|
||||
"is":"get") + prop.getName(true);
|
||||
} else {
|
||||
return (getFieldType().boxify().getPrimitiveType()==codeModel.BOOLEAN?"is":"get")+prop.getName(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type used to store the value of the field in memory.
|
||||
*/
|
||||
protected abstract JType getFieldType();
|
||||
|
||||
protected JFieldVar ref() { return field; }
|
||||
|
||||
public final JType getRawType() {
|
||||
return exposedType;
|
||||
}
|
||||
|
||||
protected abstract class Accessor extends AbstractField.Accessor {
|
||||
|
||||
protected Accessor(JExpression $target) {
|
||||
super($target);
|
||||
this.$ref = $target.ref(AbstractFieldWithVar.this.ref());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference to the field bound by the target object.
|
||||
*/
|
||||
protected final JFieldRef $ref;
|
||||
|
||||
public final void toRawValue(JBlock block, JVar $var) {
|
||||
if (getOptions().enableIntrospection) {
|
||||
block.assign($var,$target.invoke(getGetterMethod()));
|
||||
} else {
|
||||
block.assign($var,$target.invoke(getGetterMethod()));
|
||||
}
|
||||
}
|
||||
|
||||
public final void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
block.invoke($target,("set"+prop.getName(true))).arg($var);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean.field;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
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.JOp;
|
||||
import com.sun.codemodel.internal.JPrimitiveType;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
|
||||
/**
|
||||
* Common code for property renderer that generates a List as
|
||||
* its underlying data structure.
|
||||
*
|
||||
* <p>
|
||||
* For performance reasons, the actual list object used to store
|
||||
* data is lazily created.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
abstract class AbstractListField extends AbstractField {
|
||||
/** The field that stores the list. */
|
||||
protected JFieldVar field;
|
||||
|
||||
/**
|
||||
* a method that lazily initializes a List.
|
||||
* Lazily created.
|
||||
*
|
||||
* [RESULT]
|
||||
* List _getFoo() {
|
||||
* if(field==null)
|
||||
* field = create new list;
|
||||
* return field;
|
||||
* }
|
||||
*/
|
||||
private JMethod internalGetter;
|
||||
|
||||
/**
|
||||
* If this collection property is a collection of a primitive type,
|
||||
* this variable refers to that primitive type.
|
||||
* Otherwise null.
|
||||
*/
|
||||
protected final JPrimitiveType primitiveType;
|
||||
|
||||
protected final JClass listT = codeModel.ref(List.class).narrow(exposedType.boxify());
|
||||
|
||||
/**
|
||||
* True to create a new instance of List eagerly in the constructor.
|
||||
* False otherwise.
|
||||
*
|
||||
* <p>
|
||||
* Setting it to true makes the generated code slower (as more list instances need to be
|
||||
* allocated), but it works correctly if the user specifies the custom type of a list.
|
||||
*/
|
||||
private final boolean eagerInstanciation;
|
||||
|
||||
/**
|
||||
* Call {@link #generate()} method right after this.
|
||||
*/
|
||||
protected AbstractListField(ClassOutlineImpl outline, CPropertyInfo prop, boolean eagerInstanciation) {
|
||||
super(outline,prop);
|
||||
this.eagerInstanciation = eagerInstanciation;
|
||||
|
||||
if( implType instanceof JPrimitiveType ) {
|
||||
// primitive types don't have this tricky distinction
|
||||
assert implType==exposedType;
|
||||
primitiveType = (JPrimitiveType)implType;
|
||||
} else
|
||||
primitiveType = null;
|
||||
}
|
||||
|
||||
protected final void generate() {
|
||||
|
||||
// for the collectionType customization to take effect, the field needs to be strongly typed,
|
||||
// not just List<Foo>.
|
||||
field = outline.implClass.field( JMod.PROTECTED, listT, prop.getName(false) );
|
||||
if(eagerInstanciation)
|
||||
field.init(newCoreList());
|
||||
|
||||
annotate(field);
|
||||
|
||||
// generate the rest of accessors
|
||||
generateAccessors();
|
||||
}
|
||||
|
||||
private void generateInternalGetter() {
|
||||
internalGetter = outline.implClass.method(JMod.PROTECTED,listT,"_get"+prop.getName(true));
|
||||
if(!eagerInstanciation) {
|
||||
// if eagerly instanciated, the field can't be null
|
||||
fixNullRef(internalGetter.body());
|
||||
}
|
||||
internalGetter.body()._return(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates statement(s) so that the successive {@link Accessor#ref(boolean)} with
|
||||
* true will always return a non-null list.
|
||||
*
|
||||
* This is useful to avoid generating redundant internal getter.
|
||||
*/
|
||||
protected final void fixNullRef(JBlock block) {
|
||||
block._if(field.eq(JExpr._null()))._then()
|
||||
.assign(field,newCoreList());
|
||||
}
|
||||
|
||||
public JType getRawType() {
|
||||
return codeModel.ref(List.class).narrow(exposedType.boxify());
|
||||
}
|
||||
|
||||
private JExpression newCoreList() {
|
||||
return JExpr._new(getCoreListType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Concrete class that implements the List interface.
|
||||
* Used as the actual data storage.
|
||||
*/
|
||||
protected abstract JClass getCoreListType();
|
||||
|
||||
|
||||
/** Generates accessor methods. */
|
||||
protected abstract void generateAccessors();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
protected abstract class Accessor extends AbstractField.Accessor {
|
||||
|
||||
/**
|
||||
* Reference to the {@link AbstractListField#field}
|
||||
* of the target object.
|
||||
*/
|
||||
protected final JFieldRef field;
|
||||
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
field = $target.ref(AbstractListField.this.field);
|
||||
}
|
||||
|
||||
|
||||
protected final JExpression unbox( JExpression exp ) {
|
||||
if(primitiveType==null) return exp;
|
||||
else return primitiveType.unwrap(exp);
|
||||
}
|
||||
protected final JExpression box( JExpression exp ) {
|
||||
if(primitiveType==null) return exp;
|
||||
else return primitiveType.wrap(exp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the List field that stores the data.
|
||||
* <p>
|
||||
* Using this method hides the fact that the list is lazily
|
||||
* created.
|
||||
*
|
||||
* @param canBeNull
|
||||
* if true, the returned expression may be null (this is
|
||||
* when the list is still not constructed.) This could be
|
||||
* useful when the caller can deal with null more efficiently.
|
||||
* When the list is null, it should be treated as if the list
|
||||
* is empty.
|
||||
*
|
||||
* if false, the returned expression will never be null.
|
||||
* This is the behavior users would see.
|
||||
*/
|
||||
protected final JExpression ref(boolean canBeNull) {
|
||||
if(canBeNull)
|
||||
return field;
|
||||
if(internalGetter==null)
|
||||
generateInternalGetter();
|
||||
return $target.invoke(internalGetter);
|
||||
}
|
||||
|
||||
public JExpression count() {
|
||||
return JOp.cond( field.eq(JExpr._null()), JExpr.lit(0), field.invoke("size") );
|
||||
}
|
||||
|
||||
public void unsetValues( JBlock body ) {
|
||||
body.assign(field,JExpr._null());
|
||||
}
|
||||
public JExpression hasSetValue() {
|
||||
return field.ne(JExpr._null()).cand(field.invoke("isEmpty").not());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JAssignmentTarget;
|
||||
import java.util.List;
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JClass;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JForLoop;
|
||||
import com.sun.codemodel.internal.JMethod;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JOp;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.generator.bean.MethodWriter;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
|
||||
/**
|
||||
* Realizes a property as an "indexed property"
|
||||
* as specified in the JAXB spec.
|
||||
*
|
||||
* <p>
|
||||
* We will generate the following set of methods:
|
||||
* <pre>
|
||||
* T[] getX();
|
||||
* T getX( int idx );
|
||||
* void setX(T[] values);
|
||||
* void setX( int idx, T value );
|
||||
* </pre>
|
||||
*
|
||||
* We still use List as our back storage.
|
||||
* This renderer also handles boxing/unboxing if
|
||||
* T is a boxed type.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
final class ArrayField extends AbstractListField {
|
||||
|
||||
class Accessor extends AbstractListField.Accessor {
|
||||
protected Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
block.assign($var,$target.invoke($getAll));
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
block.invoke($target,$setAll).arg($var);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JExpression hasSetValue() {
|
||||
return field.ne(JExpr._null()).cand(field.ref("length").gt(JExpr.lit(0)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JMethod $setAll;
|
||||
|
||||
private JMethod $getAll;
|
||||
|
||||
ArrayField(ClassOutlineImpl context, CPropertyInfo prop) {
|
||||
super(context,prop,false);
|
||||
generateArray();
|
||||
}
|
||||
|
||||
protected final void generateArray() {
|
||||
field = outline.implClass.field( JMod.PROTECTED, getCoreListType(), prop.getName(false) );
|
||||
annotate(field);
|
||||
|
||||
// generate the rest of accessors
|
||||
generateAccessors();
|
||||
}
|
||||
|
||||
public void generateAccessors() {
|
||||
|
||||
MethodWriter writer = outline.createMethodWriter();
|
||||
Accessor acc = create(JExpr._this());
|
||||
JVar $idx,$value; JBlock body;
|
||||
|
||||
// [RESULT] T[] getX() {
|
||||
// if( <var>==null ) return new T[0];
|
||||
// T[] retVal = new T[this._return.length] ;
|
||||
// System.arraycopy(this._return, 0, "retVal", 0, this._return.length);
|
||||
// return (retVal);
|
||||
// }
|
||||
$getAll = writer.declareMethod( exposedType.array(),"get"+prop.getName(true));
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
body = $getAll.body();
|
||||
|
||||
body._if( acc.ref(true).eq(JExpr._null()) )._then()
|
||||
._return(JExpr.newArray(exposedType,0));
|
||||
JVar var = body.decl(exposedType.array(), "retVal", JExpr.newArray(implType,acc.ref(true).ref("length")));
|
||||
body.add(codeModel.ref(System.class).staticInvoke("arraycopy")
|
||||
.arg(acc.ref(true)).arg(JExpr.lit(0))
|
||||
.arg(var)
|
||||
.arg(JExpr.lit(0)).arg(acc.ref(true).ref("length")));
|
||||
body._return(JExpr.direct("retVal"));
|
||||
|
||||
List<Object> returnTypes = listPossibleTypes(prop);
|
||||
writer.javadoc().addReturn().append("array of\n").append(returnTypes);
|
||||
|
||||
// [RESULT]
|
||||
// ET getX(int idx) {
|
||||
// if( <var>==null ) throw new IndexOutOfBoundsException();
|
||||
// return unbox(<var>.get(idx));
|
||||
// }
|
||||
JMethod $get = writer.declareMethod(exposedType,"get"+prop.getName(true));
|
||||
$idx = writer.addParameter(codeModel.INT,"idx");
|
||||
|
||||
$get.body()._if(acc.ref(true).eq(JExpr._null()))._then()
|
||||
._throw(JExpr._new(codeModel.ref(IndexOutOfBoundsException.class)));
|
||||
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
$get.body()._return(acc.ref(true).component($idx));
|
||||
|
||||
writer.javadoc().addReturn().append("one of\n").append(returnTypes);
|
||||
|
||||
// [RESULT] int getXLength() {
|
||||
// if( <var>==null ) throw new IndexOutOfBoundsException();
|
||||
// return <ref>.length;
|
||||
// }
|
||||
JMethod $getLength = writer.declareMethod(codeModel.INT,"get"+prop.getName(true)+"Length");
|
||||
$getLength.body()._if(acc.ref(true).eq(JExpr._null()))._then()
|
||||
._return(JExpr.lit(0));
|
||||
$getLength.body()._return(acc.ref(true).ref("length"));
|
||||
|
||||
// [RESULT] void setX(ET[] values) {
|
||||
// int len = values.length;
|
||||
// for( int i=0; i<len; i++ )
|
||||
// <ref>[i] = values[i];
|
||||
// }
|
||||
$setAll = writer.declareMethod(
|
||||
codeModel.VOID,
|
||||
"set"+prop.getName(true));
|
||||
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
$value = writer.addParameter(exposedType.array(),"values");
|
||||
JVar $len = $setAll.body().decl(codeModel.INT,"len", $value.ref("length"));
|
||||
|
||||
$setAll.body().assign(
|
||||
(JAssignmentTarget) acc.ref(true),
|
||||
castToImplTypeArray(JExpr.newArray(
|
||||
codeModel.ref(exposedType.erasure().fullName()),
|
||||
$len)));
|
||||
|
||||
JForLoop _for = $setAll.body()._for();
|
||||
JVar $i = _for.init( codeModel.INT, "i", JExpr.lit(0) );
|
||||
_for.test( JOp.lt($i,$len) );
|
||||
_for.update( $i.incr() );
|
||||
_for.body().assign(acc.ref(true).component($i), castToImplType(acc.box($value.component($i))));
|
||||
|
||||
writer.javadoc().addParam($value)
|
||||
.append("allowed objects are\n")
|
||||
.append(returnTypes);
|
||||
|
||||
// [RESULT] ET setX(int idx, ET value)
|
||||
// <ref>[idx] = value
|
||||
JMethod $set = writer.declareMethod(
|
||||
exposedType,
|
||||
"set"+prop.getName(true));
|
||||
$idx = writer.addParameter( codeModel.INT, "idx" );
|
||||
$value = writer.addParameter( exposedType, "value" );
|
||||
|
||||
writer.javadoc().append(prop.javadoc);
|
||||
|
||||
body = $set.body();
|
||||
body._return( JExpr.assign(acc.ref(true).component($idx),
|
||||
castToImplType(acc.box($value))));
|
||||
|
||||
writer.javadoc().addParam($value)
|
||||
.append("allowed object is\n")
|
||||
.append(returnTypes);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JType getRawType() {
|
||||
return exposedType.array();
|
||||
}
|
||||
|
||||
protected JClass getCoreListType() {
|
||||
return exposedType.array();
|
||||
}
|
||||
|
||||
public Accessor create(JExpression targetObject) {
|
||||
return new Accessor(targetObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Case from {@link #exposedType} to array of {@link #implType} .
|
||||
*/
|
||||
protected final JExpression castToImplTypeArray( JExpression exp ) {
|
||||
return JExpr.cast(implType.array(), exp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.xjc.generator.bean.field;
|
||||
|
||||
import com.sun.codemodel.internal.JBlock;
|
||||
import com.sun.codemodel.internal.JExpr;
|
||||
import com.sun.codemodel.internal.JExpression;
|
||||
import com.sun.codemodel.internal.JFieldVar;
|
||||
import com.sun.codemodel.internal.JMod;
|
||||
import com.sun.codemodel.internal.JPrimitiveType;
|
||||
import com.sun.codemodel.internal.JType;
|
||||
import com.sun.codemodel.internal.JVar;
|
||||
import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
|
||||
import com.sun.tools.internal.xjc.model.CPropertyInfo;
|
||||
import com.sun.tools.internal.xjc.outline.FieldAccessor;
|
||||
|
||||
/**
|
||||
* Realizes a property as a "public static final" property on the interface.
|
||||
* This class can handle both boxed/unboxed types and both
|
||||
* single/colllection.
|
||||
*
|
||||
* @author
|
||||
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
||||
*/
|
||||
final class ConstField extends AbstractField {
|
||||
// /**
|
||||
// * Number of items in this property, when
|
||||
// * {@link #isCollection}==true.
|
||||
// */
|
||||
// private final int count=1;
|
||||
|
||||
/** Generated constant property on the interface. */
|
||||
private final JFieldVar $ref;
|
||||
|
||||
ConstField( ClassOutlineImpl outline, CPropertyInfo prop ) {
|
||||
super(outline,prop);
|
||||
|
||||
// we only support value constraints for a single-value property.
|
||||
assert !prop.isCollection();
|
||||
|
||||
JPrimitiveType ptype = implType.boxify().getPrimitiveType();
|
||||
|
||||
// generate the constant
|
||||
JExpression defaultValue = null;
|
||||
if(prop.defaultValue!=null)
|
||||
defaultValue = prop.defaultValue.compute(outline.parent());
|
||||
|
||||
$ref = outline.ref.field(JMod.PUBLIC|JMod.STATIC|JMod.FINAL,
|
||||
ptype!=null?ptype:implType, prop.getName(true), defaultValue );
|
||||
$ref.javadoc().append(prop.javadoc);
|
||||
|
||||
annotate($ref);
|
||||
}
|
||||
|
||||
public JType getRawType() {
|
||||
// if( isCollection ) return getInfo().array();
|
||||
return exposedType;
|
||||
}
|
||||
|
||||
|
||||
public FieldAccessor create(JExpression target) {
|
||||
return new Accessor(target);
|
||||
}
|
||||
|
||||
private class Accessor extends AbstractField.Accessor {
|
||||
|
||||
Accessor( JExpression $target ) {
|
||||
super($target);
|
||||
}
|
||||
|
||||
public void unsetValues( JBlock body ) {
|
||||
; // can't unset values
|
||||
}
|
||||
public JExpression hasSetValue() {
|
||||
return null; // can't generate the isSet/unset methods
|
||||
}
|
||||
public void toRawValue(JBlock block, JVar $var) {
|
||||
// TODO: rethink abstraction. Those constant fields
|
||||
// don't have "access" to them.
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void fromRawValue(JBlock block, String uniqueName, JExpression $var) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user