aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.bind.api; aoqi@0: aoqi@0: import java.io.IOException; aoqi@0: import java.lang.reflect.Type; aoqi@0: import java.util.Collection; aoqi@0: import java.util.Collections; aoqi@0: import java.util.List; aoqi@0: import java.util.Map; aoqi@0: aoqi@0: import javax.xml.bind.JAXBContext; aoqi@0: import javax.xml.bind.JAXBException; aoqi@0: import javax.xml.bind.Marshaller; aoqi@0: import javax.xml.bind.SchemaOutputResolver; aoqi@0: import javax.xml.bind.annotation.XmlAttachmentRef; aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.transform.Result; aoqi@0: aoqi@0: import com.sun.istack.internal.NotNull; aoqi@0: import com.sun.istack.internal.Nullable; aoqi@0: import com.sun.xml.internal.bind.api.impl.NameConverter; aoqi@0: import com.sun.xml.internal.bind.v2.ContextFactory; aoqi@0: import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader; aoqi@0: import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet; aoqi@0: import java.util.HashMap; aoqi@0: aoqi@0: /** aoqi@0: * {@link JAXBContext} enhanced with JAXB RI specific functionalities. aoqi@0: * aoqi@0: *
aoqi@0: * Subject to change without notice. aoqi@0: * aoqi@0: * @since 2.0 EA1 aoqi@0: * @author aoqi@0: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) aoqi@0: */ aoqi@0: public abstract class JAXBRIContext extends JAXBContext { aoqi@0: aoqi@0: protected JAXBRIContext() {} aoqi@0: aoqi@0: /** aoqi@0: * Creates a new {@link JAXBRIContext}. aoqi@0: * aoqi@0: *
aoqi@0: * {@link JAXBContext#newInstance(Class[]) JAXBContext.newInstance()} methods may
aoqi@0: * return other JAXB providers that are not compatible with the JAX-RPC RI.
aoqi@0: * This method guarantees that the JAX-WS RI will finds the JAXB RI.
aoqi@0: *
aoqi@0: * @param classes
aoqi@0: * Classes to be bound. See {@link JAXBContext#newInstance(Class[])} for the meaning.
aoqi@0: * @param typeRefs
aoqi@0: * See {@link #TYPE_REFERENCES} for the meaning of this parameter.
aoqi@0: * Can be null.
aoqi@0: * @param subclassReplacements
aoqi@0: * See {@link #SUBCLASS_REPLACEMENTS} for the meaning of this parameter.
aoqi@0: * Can be null.
aoqi@0: * @param defaultNamespaceRemap
aoqi@0: * See {@link #DEFAULT_NAMESPACE_REMAP} for the meaning of this parameter.
aoqi@0: * Can be null (and should be null for ordinary use of JAXB.)
aoqi@0: * @param c14nSupport
aoqi@0: * See {@link #CANONICALIZATION_SUPPORT} for the meaning of this parameter.
aoqi@0: * @param ar
aoqi@0: * See {@link #ANNOTATION_READER} for the meaning of this parameter.
aoqi@0: * Can be null.
aoqi@0: * @since JAXB 2.1 EA2
aoqi@0: */
aoqi@0: public static JAXBRIContext newInstance(@NotNull Class[] classes,
aoqi@0: @Nullable Collection
aoqi@0: * {@link JAXBContext#newInstance(Class[]) JAXBContext.newInstance()} methods may
aoqi@0: * return other JAXB providers that are not compatible with the JAX-RPC RI.
aoqi@0: * This method guarantees that the JAX-WS RI will finds the JAXB RI.
aoqi@0: *
aoqi@0: * @param classes
aoqi@0: * Classes to be bound. See {@link JAXBContext#newInstance(Class[])} for the meaning.
aoqi@0: * @param typeRefs
aoqi@0: * See {@link #TYPE_REFERENCES} for the meaning of this parameter.
aoqi@0: * Can be null.
aoqi@0: * @param subclassReplacements
aoqi@0: * See {@link #SUBCLASS_REPLACEMENTS} for the meaning of this parameter.
aoqi@0: * Can be null.
aoqi@0: * @param defaultNamespaceRemap
aoqi@0: * See {@link #DEFAULT_NAMESPACE_REMAP} for the meaning of this parameter.
aoqi@0: * Can be null (and should be null for ordinary use of JAXB.)
aoqi@0: * @param c14nSupport
aoqi@0: * See {@link #CANONICALIZATION_SUPPORT} for the meaning of this parameter.
aoqi@0: * @param ar
aoqi@0: * See {@link #ANNOTATION_READER} for the meaning of this parameter.
aoqi@0: * Can be null.
aoqi@0: * @param xmlAccessorFactorySupport
aoqi@0: * See {@link #XMLACCESSORFACTORY_SUPPORT} for the meaning of this parameter.
aoqi@0: * @param allNillable
aoqi@0: * See {@link #TREAT_EVERYTHING_NILLABLE} for the meaning of this parameter.
aoqi@0: * @param retainPropertyInfo
aoqi@0: * See {@link #RETAIN_REFERENCE_TO_INFO} for the meaning of this parameter.
aoqi@0: * @param supressAccessorWarnings
aoqi@0: * See {@link #SUPRESS_ACCESSOR_WARNINGS} for the meaning of this parameter.
aoqi@0: */
aoqi@0: public static JAXBRIContext newInstance(@NotNull Class[] classes,
aoqi@0: @Nullable Collection
aoqi@0: * This method is designed to assist the JAX-RPC RI fill in a wrapper bean (in the doc/lit/wrap mode.)
aoqi@0: * In the said mode, a wrapper bean is supposed to only have properties that match elements,
aoqi@0: * and for each element that appear in the content model there's one property.
aoqi@0: *
aoqi@0: *
aoqi@0: * Therefore, this method takes a wrapper bean and a tag name that identifies a property
aoqi@0: * on the given wrapper bean, then returns a {@link RawAccessor} that allows the caller
aoqi@0: * to set/get a value from the property of the bean.
aoqi@0: *
aoqi@0: *
aoqi@0: * This method is not designed for a performance. The caller is expected to cache the result.
aoqi@0: *
aoqi@0: * @param
aoqi@0: * type of the wrapper bean
aoqi@0: * @param
aoqi@0: * When JAXB is used to marshal into sub-trees, it declares
aoqi@0: * these namespace URIs at each top-level element that it marshals.
aoqi@0: *
aoqi@0: * To avoid repeated namespace declarations at sub-elements, the application
aoqi@0: * may declare those namespaces at a higher level.
aoqi@0: *
aoqi@0: * @return
aoqi@0: * always non-null.
aoqi@0: *
aoqi@0: * @since 2.0 EA2
aoqi@0: */
aoqi@0: public abstract @NotNull List
aoqi@0: * The caller can use the additionalElementDecls parameter to
aoqi@0: * add element declarations to the generate schema.
aoqi@0: * For example, if the JAX-RPC passes in the following entry:
aoqi@0: *
aoqi@0: * {foo}bar -> DeclaredType for java.lang.String
aoqi@0: *
aoqi@0: * then JAXB generates the following element declaration (in the schema
aoqi@0: * document for the namespace "foo")"
aoqi@0: *
aoqi@0: * <xs:element name="bar" type="xs:string" />
aoqi@0: *
aoqi@0: * This can be used for generating schema components necessary for WSDL.
aoqi@0: *
aoqi@0: * @param outputResolver
aoqi@0: * this object controls the output to which schemas
aoqi@0: * will be sent.
aoqi@0: *
aoqi@0: * @throws IOException
aoqi@0: * if {@link SchemaOutputResolver} throws an {@link IOException}.
aoqi@0: */
aoqi@0: @Override
aoqi@0: public abstract void generateSchema(@NotNull SchemaOutputResolver outputResolver) throws IOException;
aoqi@0:
aoqi@0: /**
aoqi@0: * Returns the name of the XML Type bound to the
aoqi@0: * specified Java type.
aoqi@0: *
aoqi@0: * @param tr
aoqi@0: * must not be null. This must be one of the {@link TypeReference}s specified
aoqi@0: * in the {@link JAXBRIContext#newInstance} method.
aoqi@0: *
aoqi@0: * @throws IllegalArgumentException
aoqi@0: * if the parameter is null or not a part of the {@link TypeReference}s specified
aoqi@0: * in the {@link JAXBRIContext#newInstance} method.
aoqi@0: *
aoqi@0: * @return null
aoqi@0: * if the referenced type is an anonymous and therefore doesn't have a name.
aoqi@0: */
aoqi@0: public abstract QName getTypeName(@NotNull TypeReference tr);
aoqi@0:
aoqi@0: /**
aoqi@0: * Gets the build information of the JAXB runtime.
aoqi@0: *
aoqi@0: * @return
aoqi@0: * may be null, if the runtime is loaded by a class loader that doesn't support
aoqi@0: * the access to the manifest informatino.
aoqi@0: */
aoqi@0: public abstract @NotNull String getBuildId();
aoqi@0:
aoqi@0: /**
aoqi@0: * Generates the episode file that represents the binding known to this {@link JAXBContext},
aoqi@0: * so that XJC can later do separate compilation.
aoqi@0: *
aoqi@0: *
aoqi@0: * Episode file is really just a JAXB customization file, except that currently
aoqi@0: * we use the RI-specific SCD to refer to schema components.
aoqi@0: *
aoqi@0: * @param output
aoqi@0: * This receives the generated episode file.
aoqi@0: *
aoqi@0: * @since 2.1
aoqi@0: */
aoqi@0: public abstract void generateEpisode(Result output);
aoqi@0:
aoqi@0: /**
aoqi@0: * Allows you to access the runtime model information of the JAXB XML/Java binding.
aoqi@0: *
aoqi@0: *
aoqi@0: * This is useful for doing a deeper integration with the JAXB RI.
aoqi@0: * For more information about the model, see https://jaxb2-reflection.dev.java.net/
aoqi@0: *
aoqi@0: * @since 2.1.10
aoqi@0: */
aoqi@0: public abstract RuntimeTypeInfoSet getRuntimeTypeInfoSet();
aoqi@0:
aoqi@0: /**
aoqi@0: * Computes a Java identifier from a local name.
aoqi@0: *
aoqi@0: *
aoqi@0: * This method faithfully implements the name mangling rule as specified in the JAXB spec.
aoqi@0: *
aoqi@0: *
aoqi@0: * In JAXB, a collision with a Java reserved word (such as "return") never happens.
aoqi@0: * Accordingly, this method may return an identifier that collides with reserved words.
aoqi@0: *
aoqi@0: *
aoqi@0: * Use JJavaName.isJavaIdentifier(String) to check for such collision.
aoqi@0: *
aoqi@0: * @return
aoqi@0: * Typically, this method returns "nameLikeThis".
aoqi@0: */
aoqi@0: public static @NotNull String mangleNameToVariableName(@NotNull String localName) {
aoqi@0: return NameConverter.standard.toVariableName(localName);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Computes a Java class name from a local name.
aoqi@0: *
aoqi@0: *
aoqi@0: * This method faithfully implements the name mangling rule as specified in the JAXB spec.
aoqi@0: *
aoqi@0: * @return
aoqi@0: * Typically, this method returns "NameLikeThis".
aoqi@0: */
aoqi@0: public static @NotNull String mangleNameToClassName(@NotNull String localName) {
aoqi@0: return NameConverter.standard.toClassName(localName);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Computes a Java class name from a local name.
aoqi@0: *
aoqi@0: *
aoqi@0: * This method faithfully implements the name mangling rule as specified in the JAXB spec.
aoqi@0: * This method works like {@link #mangleNameToClassName(String)} except that it looks
aoqi@0: * for "getClass" and returns something else.
aoqi@0: *
aoqi@0: * @return
aoqi@0: * Typically, this method returns "NameLikeThis".
aoqi@0: */
aoqi@0: public static @NotNull String mangleNameToPropertyName(@NotNull String localName) {
aoqi@0: return NameConverter.standard.toPropertyName(localName);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Gets the parameterization of the given base type.
aoqi@0: *
aoqi@0: *
aoqi@0: * For example, given the following
aoqi@0: *
aoqi@0: * The value of the property is {@link String}, and it is used as the namespace URI
aoqi@0: * that succeeds the default namespace URI.
aoqi@0: *
aoqi@0: * @since 2.0 EA1
aoqi@0: */
aoqi@0: public static final String DEFAULT_NAMESPACE_REMAP = "com.sun.xml.internal.bind.defaultNamespaceRemap";
aoqi@0:
aoqi@0: /**
aoqi@0: * The property that you can specify to {@link JAXBContext#newInstance}
aoqi@0: * to put additional JAXB type references into the {@link JAXBContext}.
aoqi@0: *
aoqi@0: *
aoqi@0: * The value of the property is {@link Collection}<{@link TypeReference}>.
aoqi@0: * Those {@link TypeReference}s can then be used to create {@link Bridge}s.
aoqi@0: *
aoqi@0: *
aoqi@0: * This mechanism allows additional element declarations that were not a part of
aoqi@0: * the schema into the created {@link JAXBContext}.
aoqi@0: *
aoqi@0: * @since 2.0 EA1
aoqi@0: */
aoqi@0: public static final String TYPE_REFERENCES = "com.sun.xml.internal.bind.typeReferences";
aoqi@0:
aoqi@0: /**
aoqi@0: * The property that you can specify to {@link JAXBContext#newInstance}
aoqi@0: * and {@link Marshaller#setProperty(String, Object)}
aoqi@0: * to enable the c14n marshalling support in the {@link JAXBContext}.
aoqi@0: *
aoqi@0: * Boolean
aoqi@0: * @see C14nSupport_ArchitectureDocument
aoqi@0: * @since 2.0 EA2
aoqi@0: */
aoqi@0: public static final String CANONICALIZATION_SUPPORT = "com.sun.xml.internal.bind.c14n";
aoqi@0:
aoqi@0: /**
aoqi@0: * The property that you can specify to {@link JAXBContext#newInstance}
aoqi@0: * to allow unmarshaller to honor xsi:nil anywhere, even if they are
aoqi@0: * not specifically allowed by the schema.
aoqi@0: *
aoqi@0: * Boolean
aoqi@0: * @since 2.1.3
aoqi@0: */
aoqi@0: public static final String TREAT_EVERYTHING_NILLABLE = "com.sun.xml.internal.bind.treatEverythingNillable";
aoqi@0:
aoqi@0: /**
aoqi@0: * The property that you can specify to {@link JAXBContext#newInstance}
aoqi@0: * to use alternative {@link RuntimeAnnotationReader} implementation.
aoqi@0: *
aoqi@0: * @since 2.1 EA2
aoqi@0: */
aoqi@0: public static final String ANNOTATION_READER = RuntimeAnnotationReader.class.getName();
aoqi@0:
aoqi@0: /**
aoqi@0: * Marshaller/Unmarshaller property to enable XOP processing.
aoqi@0: *
aoqi@0: * @since 2.0 EA2
aoqi@0: */
aoqi@0: public static final String ENABLE_XOP = "com.sun.xml.internal.bind.XOP";
aoqi@0:
aoqi@0: /**
aoqi@0: * The property that you can specify to {@link JAXBContext#newInstance}
aoqi@0: * to specify specific classes that replace the reference to generic classes.
aoqi@0: *
aoqi@0: *
aoqi@0: * See the release notes for more details about this feature.
aoqi@0: *
aoqi@0: * @since 2.1 EA2
aoqi@0: */
aoqi@0: public static final String SUBCLASS_REPLACEMENTS = "com.sun.xml.internal.bind.subclassReplacements";
aoqi@0:
aoqi@0: /**
aoqi@0: * The property that you can specify to {@link JAXBContext#newInstance}
aoqi@0: * enable support of XmlAccessorFactory annotation in the {@link JAXBContext}.
aoqi@0: *
aoqi@0: * @since 2.1 EA2
aoqi@0: */
aoqi@0: public static final String XMLACCESSORFACTORY_SUPPORT = "com.sun.xml.internal.bind.XmlAccessorFactory";
aoqi@0:
aoqi@0: /**
aoqi@0: * Retains references to PropertyInfos.
aoqi@0: *
aoqi@0: * Boolean
aoqi@0: * @since 2.1.10
aoqi@0: */
aoqi@0: public static final String RETAIN_REFERENCE_TO_INFO = "retainReferenceToInfo";
aoqi@0:
aoqi@0: /**
aoqi@0: * Supress security warnings when trying to access fields through reflection.
aoqi@0: *
aoqi@0: * Boolean
aoqi@0: * @since 2.1.14, 2.2.2
aoqi@0: */
aoqi@0: public static final String SUPRESS_ACCESSOR_WARNINGS = "supressAccessorWarnings";
aoqi@0:
aoqi@0: /**
aoqi@0: * Improves handling of xsi:type used on leaf properties.
aoqi@0: *
aoqi@0: * Boolean
aoqi@0: * @since 2.2.3
aoqi@0: */
aoqi@0: public static final String IMPROVED_XSI_TYPE_HANDLING = "com.sun.xml.internal.bind.improvedXsiTypeHandling";
aoqi@0:
aoqi@0: /**
aoqi@0: * If true XML security features when parsing XML documents will be disabled.
aoqi@0: * The default value is false.
aoqi@0: *
aoqi@0: * Boolean
aoqi@0: * @since 2.2.6
aoqi@0: */
aoqi@0: public static final String DISABLE_XML_SECURITY = "com.sun.xml.internal.bind.disableXmlSecurity";
aoqi@0: }
aoqi@0: * This method works like this:
aoqi@0: * > {}
aoqi@0: * interface Bar extends Foo
aoqi@0: *
aoqi@0: * @param type
aoqi@0: * The type that derives from {@code baseType}
aoqi@0: * @param baseType
aoqi@0: * The class whose parameterization we are interested in.
aoqi@0: * @return
aoqi@0: * The use of {@code baseType} in {@code type}.
aoqi@0: * or null if the type is not assignable to the base type.
aoqi@0: * @since 2.0 FCS
aoqi@0: */
aoqi@0: public static @Nullable Type getBaseType(@NotNull Type type, @NotNull Class baseType) {
aoqi@0: return Utils.REFLECTION_NAVIGATOR.getBaseClass(type, baseType);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * The property that you can specify to {@link JAXBContext#newInstance}
aoqi@0: * to reassign the default namespace URI to something else at the runtime.
aoqi@0: *
aoqi@0: *
aoqi@0: * getBaseClass( Bar, Foo ) = Foo
>
aoqi@0: * getBaseClass( ArrayList extends BigInteger>, List ) = List extends BigInteger>
aoqi@0: *