-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1761: Move JavaCompiler, Reference and J2SJAXBModel from XJC API to …
…JXC API Signed-off-by: Lukas Jungmann <[email protected]>
- Loading branch information
Showing
13 changed files
with
318 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
jaxb-ri/jxc/src/main/java/com/sun/tools/jxc/api/J2SJAXBModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Distribution License v. 1.0, which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
package com.sun.tools.jxc.api; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import com.sun.tools.xjc.api.ErrorListener; | ||
import com.sun.tools.xjc.api.JAXBModel; | ||
import jakarta.xml.bind.SchemaOutputResolver; | ||
|
||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.xml.namespace.QName; | ||
import javax.xml.transform.Result; | ||
|
||
/** | ||
* {@link JAXBModel} that exposes additional information available | ||
* only for the {@code java -> schema} direction. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
@SuppressWarnings({"removal"}) | ||
public interface J2SJAXBModel extends com.sun.tools.xjc.api.J2SJAXBModel { | ||
/** | ||
* 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(Collection, Map, ProcessingEnvironment, String)} method. | ||
* | ||
* @return | ||
* null if it is not a part of the input to {@link JavaCompiler#bind(Collection, Map, ProcessingEnvironment, String)}. | ||
* | ||
* @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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
jaxb-ri/jxc/src/main/java/com/sun/tools/jxc/api/JavaCompiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Distribution License v. 1.0, which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
package com.sun.tools.jxc.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 ([email protected]) | ||
*/ | ||
@SuppressWarnings({"removal"}) | ||
public interface JavaCompiler extends com.sun.tools.xjc.api.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 {@code rootTypes} parameter. | ||
* In this map, a {@link Reference} can be null, in which case the element name is | ||
* declared to have an empty complex type. | ||
* ({@code <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, | ||
ProcessingEnvironment source, | ||
String defaultNamespaceRemap); | ||
} |
93 changes: 93 additions & 0 deletions
93
jaxb-ri/jxc/src/main/java/com/sun/tools/jxc/api/Reference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Distribution License v. 1.0, which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
package com.sun.tools.jxc.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; | ||
} | ||
|
||
@Override | ||
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); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 29 * type.hashCode() + annotations.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.