src/share/jaxws_classes/com/sun/xml/internal/bind/api/JAXBRIContext.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.bind.api;
    28 import java.io.IOException;
    29 import java.lang.reflect.Type;
    30 import java.util.Collection;
    31 import java.util.Collections;
    32 import java.util.List;
    33 import java.util.Map;
    35 import javax.xml.bind.JAXBContext;
    36 import javax.xml.bind.JAXBException;
    37 import javax.xml.bind.Marshaller;
    38 import javax.xml.bind.SchemaOutputResolver;
    39 import javax.xml.bind.annotation.XmlAttachmentRef;
    40 import javax.xml.namespace.QName;
    41 import javax.xml.transform.Result;
    43 import com.sun.istack.internal.NotNull;
    44 import com.sun.istack.internal.Nullable;
    45 import com.sun.xml.internal.bind.api.impl.NameConverter;
    46 import com.sun.xml.internal.bind.v2.ContextFactory;
    47 import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader;
    48 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
    49 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet;
    51 /**
    52  * {@link JAXBContext} enhanced with JAXB RI specific functionalities.
    53  *
    54  * <p>
    55  * <b>Subject to change without notice</b>.
    56  *
    57  * @since 2.0 EA1
    58  * @author
    59  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
    60  */
    61 public abstract class JAXBRIContext extends JAXBContext {
    63     protected JAXBRIContext() {}
    65     /**
    66      * Creates a new {@link JAXBRIContext}.
    67      *
    68      * <p>
    69      * {@link JAXBContext#newInstance(Class[]) JAXBContext.newInstance()} methods may
    70      * return other JAXB providers that are not compatible with the JAX-RPC RI.
    71      * This method guarantees that the JAX-WS RI will finds the JAXB RI.
    72      *
    73      * @param classes
    74      *      Classes to be bound. See {@link JAXBContext#newInstance(Class[])} for the meaning.
    75      * @param typeRefs
    76      *      See {@link #TYPE_REFERENCES} for the meaning of this parameter.
    77      *      Can be null.
    78      * @param subclassReplacements
    79      *      See {@link #SUBCLASS_REPLACEMENTS} for the meaning of this parameter.
    80      *      Can be null.
    81      * @param defaultNamespaceRemap
    82      *      See {@link #DEFAULT_NAMESPACE_REMAP} for the meaning of this parameter.
    83      *      Can be null (and should be null for ordinary use of JAXB.)
    84      * @param c14nSupport
    85      *      See {@link #CANONICALIZATION_SUPPORT} for the meaning of this parameter.
    86      * @param ar
    87      *      See {@link #ANNOTATION_READER} for the meaning of this parameter.
    88      *      Can be null.
    89      * @since JAXB 2.1 EA2
    90      */
    91     public static JAXBRIContext newInstance(@NotNull Class[] classes,
    92        @Nullable Collection<TypeReference> typeRefs,
    93        @Nullable Map<Class,Class> subclassReplacements,
    94        @Nullable String defaultNamespaceRemap, boolean c14nSupport,
    95        @Nullable RuntimeAnnotationReader ar) throws JAXBException {
    96         return ContextFactory.createContext(classes, typeRefs, subclassReplacements,
    97                 defaultNamespaceRemap, c14nSupport, ar, false, false, false, false);
    98     }
   100     /**
   101      * Creates a new {@link JAXBRIContext}.
   102      *
   103      * <p>
   104      * {@link JAXBContext#newInstance(Class[]) JAXBContext.newInstance()} methods may
   105      * return other JAXB providers that are not compatible with the JAX-RPC RI.
   106      * This method guarantees that the JAX-WS RI will finds the JAXB RI.
   107      *
   108      * @param classes
   109      *      Classes to be bound. See {@link JAXBContext#newInstance(Class[])} for the meaning.
   110      * @param typeRefs
   111      *      See {@link #TYPE_REFERENCES} for the meaning of this parameter.
   112      *      Can be null.
   113      * @param subclassReplacements
   114      *      See {@link #SUBCLASS_REPLACEMENTS} for the meaning of this parameter.
   115      *      Can be null.
   116      * @param defaultNamespaceRemap
   117      *      See {@link #DEFAULT_NAMESPACE_REMAP} for the meaning of this parameter.
   118      *      Can be null (and should be null for ordinary use of JAXB.)
   119      * @param c14nSupport
   120      *      See {@link #CANONICALIZATION_SUPPORT} for the meaning of this parameter.
   121      * @param ar
   122      *      See {@link #ANNOTATION_READER} for the meaning of this parameter.
   123      *      Can be null.
   124      * @param xmlAccessorFactorySupport
   125      *      See {@link #XMLACCESSORFACTORY_SUPPORT} for the meaning of this parameter.
   126      * @param allNillable
   127      *      See {@link #TREAT_EVERYTHING_NILLABLE} for the meaning of this parameter.
   128      * @param retainPropertyInfo
   129      *      See {@link #RETAIN_REFERENCE_TO_INFO} for the meaning of this parameter.
   130      * @param supressAccessorWarnings
   131      *      See {@link #SUPRESS_ACCESSOR_WARNINGS} for the meaning of this parameter.
   132      */
   133     public static JAXBRIContext newInstance(@NotNull Class[] classes,
   134        @Nullable Collection<TypeReference> typeRefs,
   135        @Nullable Map<Class,Class> subclassReplacements,
   136        @Nullable String defaultNamespaceRemap, boolean c14nSupport,
   137        @Nullable RuntimeAnnotationReader ar,
   138        boolean xmlAccessorFactorySupport, boolean allNillable, boolean retainPropertyInfo, boolean supressAccessorWarnings) throws JAXBException {
   139         return ContextFactory.createContext(classes, typeRefs, subclassReplacements,
   140                 defaultNamespaceRemap, c14nSupport, ar, xmlAccessorFactorySupport, allNillable, retainPropertyInfo, supressAccessorWarnings);
   141     }
   143     /**
   144      * @deprecated
   145      *      Compatibility with older versions.
   146      */
   147     public static JAXBRIContext newInstance(@NotNull Class[] classes,
   148         @Nullable Collection<TypeReference> typeRefs,
   149         @Nullable String defaultNamespaceRemap, boolean c14nSupport ) throws JAXBException {
   150         return newInstance(classes,typeRefs, Collections.<Class,Class>emptyMap(),
   151                 defaultNamespaceRemap,c14nSupport,null);
   152     }
   154     /**
   155      * Returns true if this context includes a class
   156      * that has {@link XmlAttachmentRef}.
   157      *
   158      * @since 2.1
   159      */
   160     public abstract boolean hasSwaRef();
   162     /**
   163      * If the given object is bound to an element in XML by JAXB,
   164      * returns the element name.
   165      *
   166      * @return null
   167      *      if the object is not bound to an element.
   168      * @throws JAXBException
   169      *      if the object is not known to this context.
   170      *
   171      * @since 2.0 EA1
   172      */
   173     public abstract @Nullable QName getElementName(@NotNull Object o) throws JAXBException;
   175     /**
   176      * Allows to retrieve the element name based on Class.
   177      * @param o
   178      * @return
   179      * @throws javax.xml.bind.JAXBException
   180      * @since 2.1.10
   181      */
   182     public abstract @Nullable QName getElementName(@NotNull Class o) throws JAXBException;
   184     /**
   185      * Creates a mini-marshaller/unmarshaller that can process a {@link TypeReference}.
   186      *
   187      * @return
   188      *      null if the specified reference is not given to {@link JAXBRIContext#newInstance}.
   189      *
   190      * @since 2.0 EA1
   191      */
   192     public abstract Bridge createBridge(@NotNull TypeReference ref);
   194     /**
   195      * Creates a new {@link BridgeContext} instance.
   196      *
   197      * @return
   198      *      always a valid non-null instance.
   199      *
   200      * @since 2.0 EA1
   201      */
   202     public abstract @NotNull BridgeContext createBridgeContext();
   204     /**
   205      * Gets a {@link RawAccessor} for the specified element property of the specified wrapper bean class.
   206      *
   207      * <p>
   208      * This method is designed to assist the JAX-RPC RI fill in a wrapper bean (in the doc/lit/wrap mode.)
   209      * In the said mode, a wrapper bean is supposed to only have properties that match elements,
   210      * and for each element that appear in the content model there's one property.
   211      *
   212      * <p>
   213      * Therefore, this method takes a wrapper bean and a tag name that identifies a property
   214      * on the given wrapper bean, then returns a {@link RawAccessor} that allows the caller
   215      * to set/get a value from the property of the bean.
   216      *
   217      * <p>
   218      * This method is not designed for a performance. The caller is expected to cache the result.
   219      *
   220      * @param <B>
   221      *      type of the wrapper bean
   222      * @param <V>
   223      *      type of the property of the bean
   224      * @return
   225      *      always return non-null valid accessor object.
   226      * @throws JAXBException
   227      *      if the specified wrapper bean is not bound by JAXB, or if it doesn't have an element property
   228      *      of the given name.
   229      *
   230      * @since 2.0 EA1
   231      */
   232     public abstract <B,V> RawAccessor<B,V> getElementPropertyAccessor( Class<B> wrapperBean, String nsUri, String localName )
   233             throws JAXBException;
   235     /**
   236      * Gets the namespace URIs statically known to this {@link JAXBContext}.
   237      *
   238      * <p>
   239      * When JAXB is used to marshal into sub-trees, it declares
   240      * these namespace URIs at each top-level element that it marshals.
   241      *
   242      * To avoid repeated namespace declarations at sub-elements, the application
   243      * may declare those namespaces at a higher level.
   244      *
   245      * @return
   246      *      always non-null.
   247      *
   248      * @since 2.0 EA2
   249      */
   250     public abstract @NotNull List<String> getKnownNamespaceURIs();
   253     /**
   254      * Generates the schema documents from the model.
   255      *
   256      * <p>
   257      * The caller can use the additionalElementDecls parameter to
   258      * add element declarations to the generate schema.
   259      * For example, if the JAX-RPC passes in the following entry:
   260      *
   261      * {foo}bar -> DeclaredType for java.lang.String
   262      *
   263      * then JAXB generates the following element declaration (in the schema
   264      * document for the namespace "foo")"
   265      *
   266      * &lt;xs:element name="bar" type="xs:string" />
   267      *
   268      * This can be used for generating schema components necessary for WSDL.
   269      *
   270      * @param outputResolver
   271      *      this object controls the output to which schemas
   272      *      will be sent.
   273      *
   274      * @throws IOException
   275      *      if {@link SchemaOutputResolver} throws an {@link IOException}.
   276      */
   277     @Override
   278     public abstract void generateSchema(@NotNull SchemaOutputResolver outputResolver) throws IOException;
   280     /**
   281      * Returns the name of the XML Type bound to the
   282      * specified Java type.
   283      *
   284      * @param tr
   285      *      must not be null. This must be one of the {@link TypeReference}s specified
   286      *      in the {@link JAXBRIContext#newInstance} method.
   287      *
   288      * @throws IllegalArgumentException
   289      *      if the parameter is null or not a part of the {@link TypeReference}s specified
   290      *      in the {@link JAXBRIContext#newInstance} method.
   291      *
   292      * @return null
   293      *      if the referenced type is an anonymous and therefore doesn't have a name.
   294      */
   295     public abstract QName getTypeName(@NotNull TypeReference tr);
   297     /**
   298      * Gets the build information of the JAXB runtime.
   299      *
   300      * @return
   301      *      may be null, if the runtime is loaded by a class loader that doesn't support
   302      *      the access to the manifest informatino.
   303      */
   304     public abstract @NotNull String getBuildId();
   306     /**
   307      * Generates the episode file that represents the binding known to this {@link JAXBContext},
   308      * so that XJC can later do separate compilation.
   309      *
   310      * <p>
   311      * Episode file is really just a JAXB customization file, except that currently
   312      * we use the RI-specific SCD to refer to schema components.
   313      *
   314      * @param output
   315      *      This receives the generated episode file.
   316      *
   317      * @since 2.1
   318      */
   319     public abstract void generateEpisode(Result output);
   321     /**
   322      * Allows you to access the runtime model information of the JAXB XML/Java binding.
   323      *
   324      * <p>
   325      * This is useful for doing a deeper integration with the JAXB RI.
   326      * For more information about the model, see https://jaxb2-reflection.dev.java.net/
   327      *
   328      * @since 2.1.10
   329      */
   330     public abstract RuntimeTypeInfoSet getRuntimeTypeInfoSet();
   332     /**
   333      * Computes a Java identifier from a local name.
   334      *
   335      * <p>
   336      * This method faithfully implements the name mangling rule as specified in the JAXB spec.
   337      *
   338      * <p>
   339      * In JAXB, a collision with a Java reserved word (such as "return") never happens.
   340      * Accordingly, this method may return an identifier that collides with reserved words.
   341      *
   342      * <p>
   343      * Use <tt>JJavaName.isJavaIdentifier(String)</tt> to check for such collision.
   344      *
   345      * @return
   346      *      Typically, this method returns "nameLikeThis".
   347      */
   348     public static @NotNull String mangleNameToVariableName(@NotNull String localName) {
   349         return NameConverter.standard.toVariableName(localName);
   350     }
   352     /**
   353      * Computes a Java class name from a local name.
   354      *
   355      * <p>
   356      * This method faithfully implements the name mangling rule as specified in the JAXB spec.
   357      *
   358      * @return
   359      *      Typically, this method returns "NameLikeThis".
   360      */
   361     public static @NotNull String mangleNameToClassName(@NotNull String localName) {
   362         return NameConverter.standard.toClassName(localName);
   363     }
   365     /**
   366      * Computes a Java class name from a local name.
   367      *
   368      * <p>
   369      * This method faithfully implements the name mangling rule as specified in the JAXB spec.
   370      * This method works like {@link #mangleNameToClassName(String)} except that it looks
   371      * for "getClass" and returns something else.
   372      *
   373      * @return
   374      *      Typically, this method returns "NameLikeThis".
   375      */
   376     public static @NotNull String mangleNameToPropertyName(@NotNull String localName) {
   377         return NameConverter.standard.toPropertyName(localName);
   378     }
   380     /**
   381      * Gets the parameterization of the given base type.
   382      *
   383      * <p>
   384      * For example, given the following
   385      * <pre><xmp>
   386      * interface Foo<T> extends List<List<T>> {}
   387      * interface Bar extends Foo<String> {}
   388      * </xmp></pre>
   389      * This method works like this:
   390      * <pre><xmp>
   391      * getBaseClass( Bar, List ) = List<List<String>
   392      * getBaseClass( Bar, Foo  ) = Foo<String>
   393      * getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>>
   394      * getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger>
   395      * </xmp></pre>
   396      *
   397      * @param type
   398      *      The type that derives from {@code baseType}
   399      * @param baseType
   400      *      The class whose parameterization we are interested in.
   401      * @return
   402      *      The use of {@code baseType} in {@code type}.
   403      *      or null if the type is not assignable to the base type.
   404      * @since 2.0 FCS
   405      */
   406     public static @Nullable Type getBaseType(@NotNull Type type, @NotNull Class baseType) {
   407         return Navigator.REFLECTION.getBaseClass(type,baseType);
   408     }
   411     /**
   412      * The property that you can specify to {@link JAXBContext#newInstance}
   413      * to reassign the default namespace URI to something else at the runtime.
   414      *
   415      * <p>
   416      * The value of the property is {@link String}, and it is used as the namespace URI
   417      * that succeeds the default namespace URI.
   418      *
   419      * @since 2.0 EA1
   420      */
   421     public static final String DEFAULT_NAMESPACE_REMAP = "com.sun.xml.internal.bind.defaultNamespaceRemap";
   423     /**
   424      * The property that you can specify to {@link JAXBContext#newInstance}
   425      * to put additional JAXB type references into the {@link JAXBContext}.
   426      *
   427      * <p>
   428      * The value of the property is {@link Collection}&lt;{@link TypeReference}>.
   429      * Those {@link TypeReference}s can then be used to create {@link Bridge}s.
   430      *
   431      * <p>
   432      * This mechanism allows additional element declarations that were not a part of
   433      * the schema into the created {@link JAXBContext}.
   434      *
   435      * @since 2.0 EA1
   436      */
   437     public static final String TYPE_REFERENCES = "com.sun.xml.internal.bind.typeReferences";
   439     /**
   440      * The property that you can specify to {@link JAXBContext#newInstance}
   441      * and {@link Marshaller#setProperty(String, Object)}
   442      * to enable the c14n marshalling support in the {@link JAXBContext}.
   443      *
   444      * @see C14nSupport_ArchitectureDocument
   445      * @since 2.0 EA2
   446      */
   447     public static final String CANONICALIZATION_SUPPORT = "com.sun.xml.internal.bind.c14n";
   449     /**
   450      * The property that you can specify to {@link JAXBContext#newInstance}
   451      * to allow unmarshaller to honor <tt>xsi:nil</tt> anywhere, even if they are
   452      * not specifically allowed by the schema.
   453      *
   454      * @since 2.1.3
   455      */
   456     public static final String TREAT_EVERYTHING_NILLABLE = "com.sun.xml.internal.bind.treatEverythingNillable";
   458     /**
   459      * The property that you can specify to {@link JAXBContext#newInstance}
   460      * to use alternative {@link RuntimeAnnotationReader} implementation.
   461      *
   462      * @since 2.1 EA2
   463      */
   464     public static final String ANNOTATION_READER = RuntimeAnnotationReader.class.getName();
   466     /**
   467      * Marshaller/Unmarshaller property to enable XOP processing.
   468      *
   469      * @since 2.0 EA2
   470      */
   471     public static final String ENABLE_XOP = "com.sun.xml.internal.bind.XOP";
   473     /**
   474      * The property that you can specify to {@link JAXBContext#newInstance}
   475      * to specify specific classes that replace the reference to generic classes.
   476      *
   477      * <p>
   478      * See the release notes for more details about this feature.
   479      *
   480      * @since 2.1 EA2
   481      */
   482     public static final String SUBCLASS_REPLACEMENTS = "com.sun.xml.internal.bind.subclassReplacements";
   484     /**
   485      * The property that you can specify to {@link JAXBContext#newInstance}
   486      * enable support of XmlAccessorFactory annotation in the {@link JAXBContext}.
   487      *
   488      * @since 2.1 EA2
   489      */
   490     public static final String XMLACCESSORFACTORY_SUPPORT = "com.sun.xml.internal.bind.XmlAccessorFactory";
   492     /**
   493      * Retains references to PropertyInfos.
   494      *
   495      * @since 2.1.10
   496      */
   497     public static final String RETAIN_REFERENCE_TO_INFO = "retainReferenceToInfo";
   499     /**
   500      * Supress security warnings when trying to access fields through reflection.
   501      *
   502      * @since 2.1.14, 2.2.2
   503      */
   504     public static final String SUPRESS_ACCESSOR_WARNINGS = "supressAccessorWarnings";
   506     /**
   507      * Improves handling of xsi:type used on leaf properties.
   508      *
   509      * @since 2.2.3
   510      */
   511     public static final String IMPROVED_XSI_TYPE_HANDLING = "com.sun.xml.internal.bind.improvedXsiTypeHandling";
   513 }

mercurial