1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/api/JAXBRIContext.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,513 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.bind.api; 1.30 + 1.31 +import java.io.IOException; 1.32 +import java.lang.reflect.Type; 1.33 +import java.util.Collection; 1.34 +import java.util.Collections; 1.35 +import java.util.List; 1.36 +import java.util.Map; 1.37 + 1.38 +import javax.xml.bind.JAXBContext; 1.39 +import javax.xml.bind.JAXBException; 1.40 +import javax.xml.bind.Marshaller; 1.41 +import javax.xml.bind.SchemaOutputResolver; 1.42 +import javax.xml.bind.annotation.XmlAttachmentRef; 1.43 +import javax.xml.namespace.QName; 1.44 +import javax.xml.transform.Result; 1.45 + 1.46 +import com.sun.istack.internal.NotNull; 1.47 +import com.sun.istack.internal.Nullable; 1.48 +import com.sun.xml.internal.bind.api.impl.NameConverter; 1.49 +import com.sun.xml.internal.bind.v2.ContextFactory; 1.50 +import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader; 1.51 +import com.sun.xml.internal.bind.v2.model.nav.Navigator; 1.52 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet; 1.53 + 1.54 +/** 1.55 + * {@link JAXBContext} enhanced with JAXB RI specific functionalities. 1.56 + * 1.57 + * <p> 1.58 + * <b>Subject to change without notice</b>. 1.59 + * 1.60 + * @since 2.0 EA1 1.61 + * @author 1.62 + * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 1.63 + */ 1.64 +public abstract class JAXBRIContext extends JAXBContext { 1.65 + 1.66 + protected JAXBRIContext() {} 1.67 + 1.68 + /** 1.69 + * Creates a new {@link JAXBRIContext}. 1.70 + * 1.71 + * <p> 1.72 + * {@link JAXBContext#newInstance(Class[]) JAXBContext.newInstance()} methods may 1.73 + * return other JAXB providers that are not compatible with the JAX-RPC RI. 1.74 + * This method guarantees that the JAX-WS RI will finds the JAXB RI. 1.75 + * 1.76 + * @param classes 1.77 + * Classes to be bound. See {@link JAXBContext#newInstance(Class[])} for the meaning. 1.78 + * @param typeRefs 1.79 + * See {@link #TYPE_REFERENCES} for the meaning of this parameter. 1.80 + * Can be null. 1.81 + * @param subclassReplacements 1.82 + * See {@link #SUBCLASS_REPLACEMENTS} for the meaning of this parameter. 1.83 + * Can be null. 1.84 + * @param defaultNamespaceRemap 1.85 + * See {@link #DEFAULT_NAMESPACE_REMAP} for the meaning of this parameter. 1.86 + * Can be null (and should be null for ordinary use of JAXB.) 1.87 + * @param c14nSupport 1.88 + * See {@link #CANONICALIZATION_SUPPORT} for the meaning of this parameter. 1.89 + * @param ar 1.90 + * See {@link #ANNOTATION_READER} for the meaning of this parameter. 1.91 + * Can be null. 1.92 + * @since JAXB 2.1 EA2 1.93 + */ 1.94 + public static JAXBRIContext newInstance(@NotNull Class[] classes, 1.95 + @Nullable Collection<TypeReference> typeRefs, 1.96 + @Nullable Map<Class,Class> subclassReplacements, 1.97 + @Nullable String defaultNamespaceRemap, boolean c14nSupport, 1.98 + @Nullable RuntimeAnnotationReader ar) throws JAXBException { 1.99 + return ContextFactory.createContext(classes, typeRefs, subclassReplacements, 1.100 + defaultNamespaceRemap, c14nSupport, ar, false, false, false, false); 1.101 + } 1.102 + 1.103 + /** 1.104 + * Creates a new {@link JAXBRIContext}. 1.105 + * 1.106 + * <p> 1.107 + * {@link JAXBContext#newInstance(Class[]) JAXBContext.newInstance()} methods may 1.108 + * return other JAXB providers that are not compatible with the JAX-RPC RI. 1.109 + * This method guarantees that the JAX-WS RI will finds the JAXB RI. 1.110 + * 1.111 + * @param classes 1.112 + * Classes to be bound. See {@link JAXBContext#newInstance(Class[])} for the meaning. 1.113 + * @param typeRefs 1.114 + * See {@link #TYPE_REFERENCES} for the meaning of this parameter. 1.115 + * Can be null. 1.116 + * @param subclassReplacements 1.117 + * See {@link #SUBCLASS_REPLACEMENTS} for the meaning of this parameter. 1.118 + * Can be null. 1.119 + * @param defaultNamespaceRemap 1.120 + * See {@link #DEFAULT_NAMESPACE_REMAP} for the meaning of this parameter. 1.121 + * Can be null (and should be null for ordinary use of JAXB.) 1.122 + * @param c14nSupport 1.123 + * See {@link #CANONICALIZATION_SUPPORT} for the meaning of this parameter. 1.124 + * @param ar 1.125 + * See {@link #ANNOTATION_READER} for the meaning of this parameter. 1.126 + * Can be null. 1.127 + * @param xmlAccessorFactorySupport 1.128 + * See {@link #XMLACCESSORFACTORY_SUPPORT} for the meaning of this parameter. 1.129 + * @param allNillable 1.130 + * See {@link #TREAT_EVERYTHING_NILLABLE} for the meaning of this parameter. 1.131 + * @param retainPropertyInfo 1.132 + * See {@link #RETAIN_REFERENCE_TO_INFO} for the meaning of this parameter. 1.133 + * @param supressAccessorWarnings 1.134 + * See {@link #SUPRESS_ACCESSOR_WARNINGS} for the meaning of this parameter. 1.135 + */ 1.136 + public static JAXBRIContext newInstance(@NotNull Class[] classes, 1.137 + @Nullable Collection<TypeReference> typeRefs, 1.138 + @Nullable Map<Class,Class> subclassReplacements, 1.139 + @Nullable String defaultNamespaceRemap, boolean c14nSupport, 1.140 + @Nullable RuntimeAnnotationReader ar, 1.141 + boolean xmlAccessorFactorySupport, boolean allNillable, boolean retainPropertyInfo, boolean supressAccessorWarnings) throws JAXBException { 1.142 + return ContextFactory.createContext(classes, typeRefs, subclassReplacements, 1.143 + defaultNamespaceRemap, c14nSupport, ar, xmlAccessorFactorySupport, allNillable, retainPropertyInfo, supressAccessorWarnings); 1.144 + } 1.145 + 1.146 + /** 1.147 + * @deprecated 1.148 + * Compatibility with older versions. 1.149 + */ 1.150 + public static JAXBRIContext newInstance(@NotNull Class[] classes, 1.151 + @Nullable Collection<TypeReference> typeRefs, 1.152 + @Nullable String defaultNamespaceRemap, boolean c14nSupport ) throws JAXBException { 1.153 + return newInstance(classes,typeRefs, Collections.<Class,Class>emptyMap(), 1.154 + defaultNamespaceRemap,c14nSupport,null); 1.155 + } 1.156 + 1.157 + /** 1.158 + * Returns true if this context includes a class 1.159 + * that has {@link XmlAttachmentRef}. 1.160 + * 1.161 + * @since 2.1 1.162 + */ 1.163 + public abstract boolean hasSwaRef(); 1.164 + 1.165 + /** 1.166 + * If the given object is bound to an element in XML by JAXB, 1.167 + * returns the element name. 1.168 + * 1.169 + * @return null 1.170 + * if the object is not bound to an element. 1.171 + * @throws JAXBException 1.172 + * if the object is not known to this context. 1.173 + * 1.174 + * @since 2.0 EA1 1.175 + */ 1.176 + public abstract @Nullable QName getElementName(@NotNull Object o) throws JAXBException; 1.177 + 1.178 + /** 1.179 + * Allows to retrieve the element name based on Class. 1.180 + * @param o 1.181 + * @return 1.182 + * @throws javax.xml.bind.JAXBException 1.183 + * @since 2.1.10 1.184 + */ 1.185 + public abstract @Nullable QName getElementName(@NotNull Class o) throws JAXBException; 1.186 + 1.187 + /** 1.188 + * Creates a mini-marshaller/unmarshaller that can process a {@link TypeReference}. 1.189 + * 1.190 + * @return 1.191 + * null if the specified reference is not given to {@link JAXBRIContext#newInstance}. 1.192 + * 1.193 + * @since 2.0 EA1 1.194 + */ 1.195 + public abstract Bridge createBridge(@NotNull TypeReference ref); 1.196 + 1.197 + /** 1.198 + * Creates a new {@link BridgeContext} instance. 1.199 + * 1.200 + * @return 1.201 + * always a valid non-null instance. 1.202 + * 1.203 + * @since 2.0 EA1 1.204 + */ 1.205 + public abstract @NotNull BridgeContext createBridgeContext(); 1.206 + 1.207 + /** 1.208 + * Gets a {@link RawAccessor} for the specified element property of the specified wrapper bean class. 1.209 + * 1.210 + * <p> 1.211 + * This method is designed to assist the JAX-RPC RI fill in a wrapper bean (in the doc/lit/wrap mode.) 1.212 + * In the said mode, a wrapper bean is supposed to only have properties that match elements, 1.213 + * and for each element that appear in the content model there's one property. 1.214 + * 1.215 + * <p> 1.216 + * Therefore, this method takes a wrapper bean and a tag name that identifies a property 1.217 + * on the given wrapper bean, then returns a {@link RawAccessor} that allows the caller 1.218 + * to set/get a value from the property of the bean. 1.219 + * 1.220 + * <p> 1.221 + * This method is not designed for a performance. The caller is expected to cache the result. 1.222 + * 1.223 + * @param <B> 1.224 + * type of the wrapper bean 1.225 + * @param <V> 1.226 + * type of the property of the bean 1.227 + * @return 1.228 + * always return non-null valid accessor object. 1.229 + * @throws JAXBException 1.230 + * if the specified wrapper bean is not bound by JAXB, or if it doesn't have an element property 1.231 + * of the given name. 1.232 + * 1.233 + * @since 2.0 EA1 1.234 + */ 1.235 + public abstract <B,V> RawAccessor<B,V> getElementPropertyAccessor( Class<B> wrapperBean, String nsUri, String localName ) 1.236 + throws JAXBException; 1.237 + 1.238 + /** 1.239 + * Gets the namespace URIs statically known to this {@link JAXBContext}. 1.240 + * 1.241 + * <p> 1.242 + * When JAXB is used to marshal into sub-trees, it declares 1.243 + * these namespace URIs at each top-level element that it marshals. 1.244 + * 1.245 + * To avoid repeated namespace declarations at sub-elements, the application 1.246 + * may declare those namespaces at a higher level. 1.247 + * 1.248 + * @return 1.249 + * always non-null. 1.250 + * 1.251 + * @since 2.0 EA2 1.252 + */ 1.253 + public abstract @NotNull List<String> getKnownNamespaceURIs(); 1.254 + 1.255 + 1.256 + /** 1.257 + * Generates the schema documents from the model. 1.258 + * 1.259 + * <p> 1.260 + * The caller can use the additionalElementDecls parameter to 1.261 + * add element declarations to the generate schema. 1.262 + * For example, if the JAX-RPC passes in the following entry: 1.263 + * 1.264 + * {foo}bar -> DeclaredType for java.lang.String 1.265 + * 1.266 + * then JAXB generates the following element declaration (in the schema 1.267 + * document for the namespace "foo")" 1.268 + * 1.269 + * <xs:element name="bar" type="xs:string" /> 1.270 + * 1.271 + * This can be used for generating schema components necessary for WSDL. 1.272 + * 1.273 + * @param outputResolver 1.274 + * this object controls the output to which schemas 1.275 + * will be sent. 1.276 + * 1.277 + * @throws IOException 1.278 + * if {@link SchemaOutputResolver} throws an {@link IOException}. 1.279 + */ 1.280 + @Override 1.281 + public abstract void generateSchema(@NotNull SchemaOutputResolver outputResolver) throws IOException; 1.282 + 1.283 + /** 1.284 + * Returns the name of the XML Type bound to the 1.285 + * specified Java type. 1.286 + * 1.287 + * @param tr 1.288 + * must not be null. This must be one of the {@link TypeReference}s specified 1.289 + * in the {@link JAXBRIContext#newInstance} method. 1.290 + * 1.291 + * @throws IllegalArgumentException 1.292 + * if the parameter is null or not a part of the {@link TypeReference}s specified 1.293 + * in the {@link JAXBRIContext#newInstance} method. 1.294 + * 1.295 + * @return null 1.296 + * if the referenced type is an anonymous and therefore doesn't have a name. 1.297 + */ 1.298 + public abstract QName getTypeName(@NotNull TypeReference tr); 1.299 + 1.300 + /** 1.301 + * Gets the build information of the JAXB runtime. 1.302 + * 1.303 + * @return 1.304 + * may be null, if the runtime is loaded by a class loader that doesn't support 1.305 + * the access to the manifest informatino. 1.306 + */ 1.307 + public abstract @NotNull String getBuildId(); 1.308 + 1.309 + /** 1.310 + * Generates the episode file that represents the binding known to this {@link JAXBContext}, 1.311 + * so that XJC can later do separate compilation. 1.312 + * 1.313 + * <p> 1.314 + * Episode file is really just a JAXB customization file, except that currently 1.315 + * we use the RI-specific SCD to refer to schema components. 1.316 + * 1.317 + * @param output 1.318 + * This receives the generated episode file. 1.319 + * 1.320 + * @since 2.1 1.321 + */ 1.322 + public abstract void generateEpisode(Result output); 1.323 + 1.324 + /** 1.325 + * Allows you to access the runtime model information of the JAXB XML/Java binding. 1.326 + * 1.327 + * <p> 1.328 + * This is useful for doing a deeper integration with the JAXB RI. 1.329 + * For more information about the model, see https://jaxb2-reflection.dev.java.net/ 1.330 + * 1.331 + * @since 2.1.10 1.332 + */ 1.333 + public abstract RuntimeTypeInfoSet getRuntimeTypeInfoSet(); 1.334 + 1.335 + /** 1.336 + * Computes a Java identifier from a local name. 1.337 + * 1.338 + * <p> 1.339 + * This method faithfully implements the name mangling rule as specified in the JAXB spec. 1.340 + * 1.341 + * <p> 1.342 + * In JAXB, a collision with a Java reserved word (such as "return") never happens. 1.343 + * Accordingly, this method may return an identifier that collides with reserved words. 1.344 + * 1.345 + * <p> 1.346 + * Use <tt>JJavaName.isJavaIdentifier(String)</tt> to check for such collision. 1.347 + * 1.348 + * @return 1.349 + * Typically, this method returns "nameLikeThis". 1.350 + */ 1.351 + public static @NotNull String mangleNameToVariableName(@NotNull String localName) { 1.352 + return NameConverter.standard.toVariableName(localName); 1.353 + } 1.354 + 1.355 + /** 1.356 + * Computes a Java class name from a local name. 1.357 + * 1.358 + * <p> 1.359 + * This method faithfully implements the name mangling rule as specified in the JAXB spec. 1.360 + * 1.361 + * @return 1.362 + * Typically, this method returns "NameLikeThis". 1.363 + */ 1.364 + public static @NotNull String mangleNameToClassName(@NotNull String localName) { 1.365 + return NameConverter.standard.toClassName(localName); 1.366 + } 1.367 + 1.368 + /** 1.369 + * Computes a Java class name from a local name. 1.370 + * 1.371 + * <p> 1.372 + * This method faithfully implements the name mangling rule as specified in the JAXB spec. 1.373 + * This method works like {@link #mangleNameToClassName(String)} except that it looks 1.374 + * for "getClass" and returns something else. 1.375 + * 1.376 + * @return 1.377 + * Typically, this method returns "NameLikeThis". 1.378 + */ 1.379 + public static @NotNull String mangleNameToPropertyName(@NotNull String localName) { 1.380 + return NameConverter.standard.toPropertyName(localName); 1.381 + } 1.382 + 1.383 + /** 1.384 + * Gets the parameterization of the given base type. 1.385 + * 1.386 + * <p> 1.387 + * For example, given the following 1.388 + * <pre><xmp> 1.389 + * interface Foo<T> extends List<List<T>> {} 1.390 + * interface Bar extends Foo<String> {} 1.391 + * </xmp></pre> 1.392 + * This method works like this: 1.393 + * <pre><xmp> 1.394 + * getBaseClass( Bar, List ) = List<List<String> 1.395 + * getBaseClass( Bar, Foo ) = Foo<String> 1.396 + * getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>> 1.397 + * getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger> 1.398 + * </xmp></pre> 1.399 + * 1.400 + * @param type 1.401 + * The type that derives from {@code baseType} 1.402 + * @param baseType 1.403 + * The class whose parameterization we are interested in. 1.404 + * @return 1.405 + * The use of {@code baseType} in {@code type}. 1.406 + * or null if the type is not assignable to the base type. 1.407 + * @since 2.0 FCS 1.408 + */ 1.409 + public static @Nullable Type getBaseType(@NotNull Type type, @NotNull Class baseType) { 1.410 + return Navigator.REFLECTION.getBaseClass(type,baseType); 1.411 + } 1.412 + 1.413 + 1.414 + /** 1.415 + * The property that you can specify to {@link JAXBContext#newInstance} 1.416 + * to reassign the default namespace URI to something else at the runtime. 1.417 + * 1.418 + * <p> 1.419 + * The value of the property is {@link String}, and it is used as the namespace URI 1.420 + * that succeeds the default namespace URI. 1.421 + * 1.422 + * @since 2.0 EA1 1.423 + */ 1.424 + public static final String DEFAULT_NAMESPACE_REMAP = "com.sun.xml.internal.bind.defaultNamespaceRemap"; 1.425 + 1.426 + /** 1.427 + * The property that you can specify to {@link JAXBContext#newInstance} 1.428 + * to put additional JAXB type references into the {@link JAXBContext}. 1.429 + * 1.430 + * <p> 1.431 + * The value of the property is {@link Collection}<{@link TypeReference}>. 1.432 + * Those {@link TypeReference}s can then be used to create {@link Bridge}s. 1.433 + * 1.434 + * <p> 1.435 + * This mechanism allows additional element declarations that were not a part of 1.436 + * the schema into the created {@link JAXBContext}. 1.437 + * 1.438 + * @since 2.0 EA1 1.439 + */ 1.440 + public static final String TYPE_REFERENCES = "com.sun.xml.internal.bind.typeReferences"; 1.441 + 1.442 + /** 1.443 + * The property that you can specify to {@link JAXBContext#newInstance} 1.444 + * and {@link Marshaller#setProperty(String, Object)} 1.445 + * to enable the c14n marshalling support in the {@link JAXBContext}. 1.446 + * 1.447 + * @see C14nSupport_ArchitectureDocument 1.448 + * @since 2.0 EA2 1.449 + */ 1.450 + public static final String CANONICALIZATION_SUPPORT = "com.sun.xml.internal.bind.c14n"; 1.451 + 1.452 + /** 1.453 + * The property that you can specify to {@link JAXBContext#newInstance} 1.454 + * to allow unmarshaller to honor <tt>xsi:nil</tt> anywhere, even if they are 1.455 + * not specifically allowed by the schema. 1.456 + * 1.457 + * @since 2.1.3 1.458 + */ 1.459 + public static final String TREAT_EVERYTHING_NILLABLE = "com.sun.xml.internal.bind.treatEverythingNillable"; 1.460 + 1.461 + /** 1.462 + * The property that you can specify to {@link JAXBContext#newInstance} 1.463 + * to use alternative {@link RuntimeAnnotationReader} implementation. 1.464 + * 1.465 + * @since 2.1 EA2 1.466 + */ 1.467 + public static final String ANNOTATION_READER = RuntimeAnnotationReader.class.getName(); 1.468 + 1.469 + /** 1.470 + * Marshaller/Unmarshaller property to enable XOP processing. 1.471 + * 1.472 + * @since 2.0 EA2 1.473 + */ 1.474 + public static final String ENABLE_XOP = "com.sun.xml.internal.bind.XOP"; 1.475 + 1.476 + /** 1.477 + * The property that you can specify to {@link JAXBContext#newInstance} 1.478 + * to specify specific classes that replace the reference to generic classes. 1.479 + * 1.480 + * <p> 1.481 + * See the release notes for more details about this feature. 1.482 + * 1.483 + * @since 2.1 EA2 1.484 + */ 1.485 + public static final String SUBCLASS_REPLACEMENTS = "com.sun.xml.internal.bind.subclassReplacements"; 1.486 + 1.487 + /** 1.488 + * The property that you can specify to {@link JAXBContext#newInstance} 1.489 + * enable support of XmlAccessorFactory annotation in the {@link JAXBContext}. 1.490 + * 1.491 + * @since 2.1 EA2 1.492 + */ 1.493 + public static final String XMLACCESSORFACTORY_SUPPORT = "com.sun.xml.internal.bind.XmlAccessorFactory"; 1.494 + 1.495 + /** 1.496 + * Retains references to PropertyInfos. 1.497 + * 1.498 + * @since 2.1.10 1.499 + */ 1.500 + public static final String RETAIN_REFERENCE_TO_INFO = "retainReferenceToInfo"; 1.501 + 1.502 + /** 1.503 + * Supress security warnings when trying to access fields through reflection. 1.504 + * 1.505 + * @since 2.1.14, 2.2.2 1.506 + */ 1.507 + public static final String SUPRESS_ACCESSOR_WARNINGS = "supressAccessorWarnings"; 1.508 + 1.509 + /** 1.510 + * Improves handling of xsi:type used on leaf properties. 1.511 + * 1.512 + * @since 2.2.3 1.513 + */ 1.514 + public static final String IMPROVED_XSI_TYPE_HANDLING = "com.sun.xml.internal.bind.improvedXsiTypeHandling"; 1.515 + 1.516 +}