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