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/Bridge.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,320 @@ 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.InputStream; 1.32 +import java.io.OutputStream; 1.33 + 1.34 +import javax.xml.bind.JAXBException; 1.35 +import javax.xml.bind.Marshaller; 1.36 +import javax.xml.bind.Unmarshaller; 1.37 +import javax.xml.bind.attachment.AttachmentMarshaller; 1.38 +import javax.xml.bind.attachment.AttachmentUnmarshaller; 1.39 +import javax.xml.namespace.NamespaceContext; 1.40 +import javax.xml.stream.XMLStreamReader; 1.41 +import javax.xml.stream.XMLStreamWriter; 1.42 +import javax.xml.transform.Result; 1.43 +import javax.xml.transform.Source; 1.44 + 1.45 +import com.sun.istack.internal.NotNull; 1.46 +import com.sun.istack.internal.Nullable; 1.47 +import com.sun.xml.internal.bind.v2.runtime.BridgeContextImpl; 1.48 +import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; 1.49 + 1.50 +import org.w3c.dom.Node; 1.51 +import org.xml.sax.ContentHandler; 1.52 + 1.53 +/** 1.54 + * Mini-marshaller/unmarshaller that is specialized for a particular 1.55 + * element name and a type. 1.56 + * 1.57 + * <p> 1.58 + * Instances of this class is stateless and multi-thread safe. 1.59 + * They are reentrant. 1.60 + * 1.61 + * <p> 1.62 + * All the marshal operation generates fragments. 1.63 + * 1.64 + * <p> 1.65 + * <b>Subject to change without notice</b>. 1.66 + * 1.67 + * @since JAXB 2.0 EA1 1.68 + * @author Kohsuke Kawaguchi 1.69 + */ 1.70 +public abstract class Bridge<T> { 1.71 + protected Bridge(JAXBContextImpl context) { 1.72 + this.context = context; 1.73 + } 1.74 + 1.75 + protected final JAXBContextImpl context; 1.76 + 1.77 + /** 1.78 + * Gets the {@link JAXBRIContext} to which this object belongs. 1.79 + * 1.80 + * @since 2.1 1.81 + */ 1.82 + public @NotNull JAXBRIContext getContext() { 1.83 + return context; 1.84 + } 1.85 + 1.86 + /** 1.87 + * 1.88 + * @throws JAXBException 1.89 + * if there was an error while marshalling. 1.90 + * 1.91 + * @since 2.0 EA1 1.92 + */ 1.93 + public final void marshal(T object,XMLStreamWriter output) throws JAXBException { 1.94 + marshal(object,output,null); 1.95 + } 1.96 + public final void marshal(T object,XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException { 1.97 + Marshaller m = context.marshallerPool.take(); 1.98 + m.setAttachmentMarshaller(am); 1.99 + marshal(m,object,output); 1.100 + m.setAttachmentMarshaller(null); 1.101 + context.marshallerPool.recycle(m); 1.102 + } 1.103 + 1.104 + public final void marshal(@NotNull BridgeContext context,T object,XMLStreamWriter output) throws JAXBException { 1.105 + marshal( ((BridgeContextImpl)context).marshaller, object, output ); 1.106 + } 1.107 + 1.108 + public abstract void marshal(@NotNull Marshaller m,T object,XMLStreamWriter output) throws JAXBException; 1.109 + 1.110 + 1.111 + /** 1.112 + * Marshals the specified type object with the implicit element name 1.113 + * associated with this instance of {@link Bridge}. 1.114 + * 1.115 + * @param nsContext 1.116 + * if this marshalling is done to marshal a subelement, this {@link NamespaceContext} 1.117 + * represents in-scope namespace bindings available for that element. Can be null, 1.118 + * in which case JAXB assumes no in-scope namespaces. 1.119 + * @throws JAXBException 1.120 + * if there was an error while marshalling. 1.121 + * 1.122 + * @since 2.0 EA1 1.123 + */ 1.124 + public void marshal(T object,OutputStream output, NamespaceContext nsContext) throws JAXBException { 1.125 + marshal(object,output,nsContext,null); 1.126 + } 1.127 + /** 1.128 + * @since 2.0.2 1.129 + */ 1.130 + public void marshal(T object,OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException { 1.131 + Marshaller m = context.marshallerPool.take(); 1.132 + m.setAttachmentMarshaller(am); 1.133 + marshal(m,object,output,nsContext); 1.134 + m.setAttachmentMarshaller(null); 1.135 + context.marshallerPool.recycle(m); 1.136 + } 1.137 + 1.138 + public final void marshal(@NotNull BridgeContext context,T object,OutputStream output, NamespaceContext nsContext) throws JAXBException { 1.139 + marshal( ((BridgeContextImpl)context).marshaller, object, output, nsContext ); 1.140 + } 1.141 + 1.142 + public abstract void marshal(@NotNull Marshaller m,T object,OutputStream output, NamespaceContext nsContext) throws JAXBException; 1.143 + 1.144 + 1.145 + public final void marshal(T object,Node output) throws JAXBException { 1.146 + Marshaller m = context.marshallerPool.take(); 1.147 + marshal(m,object,output); 1.148 + context.marshallerPool.recycle(m); 1.149 + } 1.150 + 1.151 + public final void marshal(@NotNull BridgeContext context,T object,Node output) throws JAXBException { 1.152 + marshal( ((BridgeContextImpl)context).marshaller, object, output ); 1.153 + } 1.154 + 1.155 + public abstract void marshal(@NotNull Marshaller m,T object,Node output) throws JAXBException; 1.156 + 1.157 + 1.158 + /** 1.159 + * @since 2.0 EA4 1.160 + */ 1.161 + public final void marshal(T object, ContentHandler contentHandler) throws JAXBException { 1.162 + marshal(object,contentHandler,null); 1.163 + } 1.164 + /** 1.165 + * @since 2.0.2 1.166 + */ 1.167 + public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException { 1.168 + Marshaller m = context.marshallerPool.take(); 1.169 + m.setAttachmentMarshaller(am); 1.170 + marshal(m,object,contentHandler); 1.171 + m.setAttachmentMarshaller(null); 1.172 + context.marshallerPool.recycle(m); 1.173 + } 1.174 + public final void marshal(@NotNull BridgeContext context,T object, ContentHandler contentHandler) throws JAXBException { 1.175 + marshal( ((BridgeContextImpl)context).marshaller, object, contentHandler ); 1.176 + } 1.177 + public abstract void marshal(@NotNull Marshaller m,T object, ContentHandler contentHandler) throws JAXBException; 1.178 + 1.179 + /** 1.180 + * @since 2.0 EA4 1.181 + */ 1.182 + public final void marshal(T object, Result result) throws JAXBException { 1.183 + Marshaller m = context.marshallerPool.take(); 1.184 + marshal(m,object,result); 1.185 + context.marshallerPool.recycle(m); 1.186 + } 1.187 + public final void marshal(@NotNull BridgeContext context,T object, Result result) throws JAXBException { 1.188 + marshal( ((BridgeContextImpl)context).marshaller, object, result ); 1.189 + } 1.190 + public abstract void marshal(@NotNull Marshaller m,T object, Result result) throws JAXBException; 1.191 + 1.192 + 1.193 + 1.194 + private T exit(T r, Unmarshaller u) { 1.195 + u.setAttachmentUnmarshaller(null); 1.196 + context.unmarshallerPool.recycle(u); 1.197 + return r; 1.198 + } 1.199 + 1.200 + /** 1.201 + * Unmarshals the specified type object. 1.202 + * 1.203 + * @param in 1.204 + * the parser must be pointing at a start tag 1.205 + * that encloses the XML type that this {@link Bridge} is 1.206 + * instanciated for. 1.207 + * 1.208 + * @return 1.209 + * never null. 1.210 + * 1.211 + * @throws JAXBException 1.212 + * if there was an error while unmarshalling. 1.213 + * 1.214 + * @since 2.0 EA1 1.215 + */ 1.216 + public final @NotNull T unmarshal(@NotNull XMLStreamReader in) throws JAXBException { 1.217 + return unmarshal(in,null); 1.218 + } 1.219 + /** 1.220 + * @since 2.0.3 1.221 + */ 1.222 + public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException { 1.223 + Unmarshaller u = context.unmarshallerPool.take(); 1.224 + u.setAttachmentUnmarshaller(au); 1.225 + return exit(unmarshal(u,in),u); 1.226 + } 1.227 + public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull XMLStreamReader in) throws JAXBException { 1.228 + return unmarshal( ((BridgeContextImpl)context).unmarshaller, in ); 1.229 + } 1.230 + public abstract @NotNull T unmarshal(@NotNull Unmarshaller u, @NotNull XMLStreamReader in) throws JAXBException; 1.231 + 1.232 + /** 1.233 + * Unmarshals the specified type object. 1.234 + * 1.235 + * @param in 1.236 + * the parser must be pointing at a start tag 1.237 + * that encloses the XML type that this {@link Bridge} is 1.238 + * instanciated for. 1.239 + * 1.240 + * @return 1.241 + * never null. 1.242 + * 1.243 + * @throws JAXBException 1.244 + * if there was an error while unmarshalling. 1.245 + * 1.246 + * @since 2.0 EA1 1.247 + */ 1.248 + public final @NotNull T unmarshal(@NotNull Source in) throws JAXBException { 1.249 + return unmarshal(in,null); 1.250 + } 1.251 + /** 1.252 + * @since 2.0.3 1.253 + */ 1.254 + public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException { 1.255 + Unmarshaller u = context.unmarshallerPool.take(); 1.256 + u.setAttachmentUnmarshaller(au); 1.257 + return exit(unmarshal(u,in),u); 1.258 + } 1.259 + public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull Source in) throws JAXBException { 1.260 + return unmarshal( ((BridgeContextImpl)context).unmarshaller, in ); 1.261 + } 1.262 + public abstract @NotNull T unmarshal(@NotNull Unmarshaller u, @NotNull Source in) throws JAXBException; 1.263 + 1.264 + /** 1.265 + * Unmarshals the specified type object. 1.266 + * 1.267 + * @param in 1.268 + * the parser must be pointing at a start tag 1.269 + * that encloses the XML type that this {@link Bridge} is 1.270 + * instanciated for. 1.271 + * 1.272 + * @return 1.273 + * never null. 1.274 + * 1.275 + * @throws JAXBException 1.276 + * if there was an error while unmarshalling. 1.277 + * 1.278 + * @since 2.0 EA1 1.279 + */ 1.280 + public final @NotNull T unmarshal(@NotNull InputStream in) throws JAXBException { 1.281 + Unmarshaller u = context.unmarshallerPool.take(); 1.282 + return exit(unmarshal(u,in),u); 1.283 + } 1.284 + public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull InputStream in) throws JAXBException { 1.285 + return unmarshal( ((BridgeContextImpl)context).unmarshaller, in ); 1.286 + } 1.287 + public abstract @NotNull T unmarshal(@NotNull Unmarshaller u, @NotNull InputStream in) throws JAXBException; 1.288 + 1.289 + /** 1.290 + * Unmarshals the specified type object. 1.291 + * 1.292 + * @param n 1.293 + * Node to be unmarshalled. 1.294 + * 1.295 + * @return 1.296 + * never null. 1.297 + * 1.298 + * @throws JAXBException 1.299 + * if there was an error while unmarshalling. 1.300 + * 1.301 + * @since 2.0 FCS 1.302 + */ 1.303 + public final @NotNull T unmarshal(@NotNull Node n) throws JAXBException { 1.304 + return unmarshal(n,null); 1.305 + } 1.306 + /** 1.307 + * @since 2.0.3 1.308 + */ 1.309 + public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException { 1.310 + Unmarshaller u = context.unmarshallerPool.take(); 1.311 + u.setAttachmentUnmarshaller(au); 1.312 + return exit(unmarshal(u,n),u); 1.313 + } 1.314 + public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull Node n) throws JAXBException { 1.315 + return unmarshal( ((BridgeContextImpl)context).unmarshaller, n ); 1.316 + } 1.317 + public abstract @NotNull T unmarshal(@NotNull Unmarshaller context, @NotNull Node n) throws JAXBException; 1.318 + 1.319 + /** 1.320 + * Gets the {@link TypeReference} from which this bridge was created. 1.321 + */ 1.322 + public abstract TypeReference getTypeReference(); 1.323 +}