feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user