src/share/jaxws_classes/com/sun/xml/internal/ws/spi/db/OldBridge.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.xml.internal.ws.spi.db;
aoqi@0 27
aoqi@0 28 import java.io.InputStream;
aoqi@0 29 import java.io.OutputStream;
aoqi@0 30
aoqi@0 31 import javax.xml.bind.JAXBException;
aoqi@0 32 import javax.xml.bind.Marshaller;
aoqi@0 33 import javax.xml.bind.Unmarshaller;
aoqi@0 34 import javax.xml.bind.attachment.AttachmentMarshaller;
aoqi@0 35 import javax.xml.bind.attachment.AttachmentUnmarshaller;
aoqi@0 36 import javax.xml.namespace.NamespaceContext;
aoqi@0 37 import javax.xml.stream.XMLStreamReader;
aoqi@0 38 import javax.xml.stream.XMLStreamWriter;
aoqi@0 39 import javax.xml.transform.Result;
aoqi@0 40 import javax.xml.transform.Source;
aoqi@0 41
aoqi@0 42 import com.sun.istack.internal.NotNull;
aoqi@0 43 import com.sun.istack.internal.Nullable;
aoqi@0 44 import com.sun.xml.internal.bind.api.BridgeContext;
aoqi@0 45 import com.sun.xml.internal.bind.v2.runtime.BridgeContextImpl;
aoqi@0 46 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
aoqi@0 47
aoqi@0 48 import org.w3c.dom.Node;
aoqi@0 49 import org.xml.sax.ContentHandler;
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * Mini-marshaller/unmarshaller that is specialized for a particular
aoqi@0 53 * element name and a type.
aoqi@0 54 *
aoqi@0 55 * <p>
aoqi@0 56 * Instances of this class is stateless and multi-thread safe.
aoqi@0 57 * They are reentrant.
aoqi@0 58 *
aoqi@0 59 * <p>
aoqi@0 60 * All the marshal operation generates fragments.
aoqi@0 61 *
aoqi@0 62 * <p>
aoqi@0 63 * <b>Subject to change without notice</b>.
aoqi@0 64 *
aoqi@0 65 * @since JAXB 2.0 EA1
aoqi@0 66 * @author Kohsuke Kawaguchi
aoqi@0 67 */
aoqi@0 68 public abstract class OldBridge<T> {
aoqi@0 69 protected OldBridge(JAXBContextImpl context) {
aoqi@0 70 this.context = context;
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 protected final JAXBContextImpl context;
aoqi@0 74
aoqi@0 75 /**
aoqi@0 76 * Gets the {@link BindingContext} to which this object belongs.
aoqi@0 77 *
aoqi@0 78 * @since 2.1
aoqi@0 79 */
aoqi@0 80 public @NotNull BindingContext getContext() {
aoqi@0 81 // return context;
aoqi@0 82 return null;
aoqi@0 83 }
aoqi@0 84
aoqi@0 85 /**
aoqi@0 86 *
aoqi@0 87 * @throws JAXBException
aoqi@0 88 * if there was an error while marshalling.
aoqi@0 89 *
aoqi@0 90 * @since 2.0 EA1
aoqi@0 91 */
aoqi@0 92 public final void marshal(T object,XMLStreamWriter output) throws JAXBException {
aoqi@0 93 marshal(object,output,null);
aoqi@0 94 }
aoqi@0 95 public final void marshal(T object,XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
aoqi@0 96 Marshaller m = context.marshallerPool.take();
aoqi@0 97 m.setAttachmentMarshaller(am);
aoqi@0 98 marshal(m,object,output);
aoqi@0 99 m.setAttachmentMarshaller(null);
aoqi@0 100 context.marshallerPool.recycle(m);
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 public final void marshal(@NotNull BridgeContext context,T object,XMLStreamWriter output) throws JAXBException {
aoqi@0 104 marshal( ((BridgeContextImpl)context).marshaller, object, output );
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 public abstract void marshal(@NotNull Marshaller m,T object,XMLStreamWriter output) throws JAXBException;
aoqi@0 108
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Marshals the specified type object with the implicit element name
aoqi@0 112 * associated with this instance of {@link XMLBridge}.
aoqi@0 113 *
aoqi@0 114 * @param nsContext
aoqi@0 115 * if this marshalling is done to marshal a subelement, this {@link NamespaceContext}
aoqi@0 116 * represents in-scope namespace bindings available for that element. Can be null,
aoqi@0 117 * in which case JAXB assumes no in-scope namespaces.
aoqi@0 118 * @throws JAXBException
aoqi@0 119 * if there was an error while marshalling.
aoqi@0 120 *
aoqi@0 121 * @since 2.0 EA1
aoqi@0 122 */
aoqi@0 123 public void marshal(T object,OutputStream output, NamespaceContext nsContext) throws JAXBException {
aoqi@0 124 marshal(object,output,nsContext,null);
aoqi@0 125 }
aoqi@0 126 /**
aoqi@0 127 * @since 2.0.2
aoqi@0 128 */
aoqi@0 129 public void marshal(T object,OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
aoqi@0 130 Marshaller m = context.marshallerPool.take();
aoqi@0 131 m.setAttachmentMarshaller(am);
aoqi@0 132 marshal(m,object,output,nsContext);
aoqi@0 133 m.setAttachmentMarshaller(null);
aoqi@0 134 context.marshallerPool.recycle(m);
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 public final void marshal(@NotNull BridgeContext context,T object,OutputStream output, NamespaceContext nsContext) throws JAXBException {
aoqi@0 138 marshal( ((BridgeContextImpl)context).marshaller, object, output, nsContext );
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 public abstract void marshal(@NotNull Marshaller m,T object,OutputStream output, NamespaceContext nsContext) throws JAXBException;
aoqi@0 142
aoqi@0 143
aoqi@0 144 public final void marshal(T object,Node output) throws JAXBException {
aoqi@0 145 Marshaller m = context.marshallerPool.take();
aoqi@0 146 marshal(m,object,output);
aoqi@0 147 context.marshallerPool.recycle(m);
aoqi@0 148 }
aoqi@0 149
aoqi@0 150 public final void marshal(@NotNull BridgeContext context,T object,Node output) throws JAXBException {
aoqi@0 151 marshal( ((BridgeContextImpl)context).marshaller, object, output );
aoqi@0 152 }
aoqi@0 153
aoqi@0 154 public abstract void marshal(@NotNull Marshaller m,T object,Node output) throws JAXBException;
aoqi@0 155
aoqi@0 156
aoqi@0 157 /**
aoqi@0 158 * @since 2.0 EA4
aoqi@0 159 */
aoqi@0 160 public final void marshal(T object, ContentHandler contentHandler) throws JAXBException {
aoqi@0 161 marshal(object,contentHandler,null);
aoqi@0 162 }
aoqi@0 163 /**
aoqi@0 164 * @since 2.0.2
aoqi@0 165 */
aoqi@0 166 public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
aoqi@0 167 Marshaller m = context.marshallerPool.take();
aoqi@0 168 m.setAttachmentMarshaller(am);
aoqi@0 169 marshal(m,object,contentHandler);
aoqi@0 170 m.setAttachmentMarshaller(null);
aoqi@0 171 context.marshallerPool.recycle(m);
aoqi@0 172 }
aoqi@0 173 public final void marshal(@NotNull BridgeContext context,T object, ContentHandler contentHandler) throws JAXBException {
aoqi@0 174 marshal( ((BridgeContextImpl)context).marshaller, object, contentHandler );
aoqi@0 175 }
aoqi@0 176 public abstract void marshal(@NotNull Marshaller m,T object, ContentHandler contentHandler) throws JAXBException;
aoqi@0 177
aoqi@0 178 /**
aoqi@0 179 * @since 2.0 EA4
aoqi@0 180 */
aoqi@0 181 public final void marshal(T object, Result result) throws JAXBException {
aoqi@0 182 Marshaller m = context.marshallerPool.take();
aoqi@0 183 marshal(m,object,result);
aoqi@0 184 context.marshallerPool.recycle(m);
aoqi@0 185 }
aoqi@0 186 public final void marshal(@NotNull BridgeContext context,T object, Result result) throws JAXBException {
aoqi@0 187 marshal( ((BridgeContextImpl)context).marshaller, object, result );
aoqi@0 188 }
aoqi@0 189 public abstract void marshal(@NotNull Marshaller m,T object, Result result) throws JAXBException;
aoqi@0 190
aoqi@0 191
aoqi@0 192
aoqi@0 193 private T exit(T r, Unmarshaller u) {
aoqi@0 194 u.setAttachmentUnmarshaller(null);
aoqi@0 195 context.unmarshallerPool.recycle(u);
aoqi@0 196 return r;
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 /**
aoqi@0 200 * Unmarshals the specified type object.
aoqi@0 201 *
aoqi@0 202 * @param in
aoqi@0 203 * the parser must be pointing at a start tag
aoqi@0 204 * that encloses the XML type that this {@link XMLBridge} is
aoqi@0 205 * instanciated for.
aoqi@0 206 *
aoqi@0 207 * @return
aoqi@0 208 * never null.
aoqi@0 209 *
aoqi@0 210 * @throws JAXBException
aoqi@0 211 * if there was an error while unmarshalling.
aoqi@0 212 *
aoqi@0 213 * @since 2.0 EA1
aoqi@0 214 */
aoqi@0 215 public final @NotNull T unmarshal(@NotNull XMLStreamReader in) throws JAXBException {
aoqi@0 216 return unmarshal(in,null);
aoqi@0 217 }
aoqi@0 218 /**
aoqi@0 219 * @since 2.0.3
aoqi@0 220 */
aoqi@0 221 public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
aoqi@0 222 Unmarshaller u = context.unmarshallerPool.take();
aoqi@0 223 u.setAttachmentUnmarshaller(au);
aoqi@0 224 return exit(unmarshal(u,in),u);
aoqi@0 225 }
aoqi@0 226 public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull XMLStreamReader in) throws JAXBException {
aoqi@0 227 return unmarshal( ((BridgeContextImpl)context).unmarshaller, in );
aoqi@0 228 }
aoqi@0 229 public abstract @NotNull T unmarshal(@NotNull Unmarshaller u, @NotNull XMLStreamReader in) throws JAXBException;
aoqi@0 230
aoqi@0 231 /**
aoqi@0 232 * Unmarshals the specified type object.
aoqi@0 233 *
aoqi@0 234 * @param in
aoqi@0 235 * the parser must be pointing at a start tag
aoqi@0 236 * that encloses the XML type that this {@link XMLBridge} is
aoqi@0 237 * instanciated for.
aoqi@0 238 *
aoqi@0 239 * @return
aoqi@0 240 * never null.
aoqi@0 241 *
aoqi@0 242 * @throws JAXBException
aoqi@0 243 * if there was an error while unmarshalling.
aoqi@0 244 *
aoqi@0 245 * @since 2.0 EA1
aoqi@0 246 */
aoqi@0 247 public final @NotNull T unmarshal(@NotNull Source in) throws JAXBException {
aoqi@0 248 return unmarshal(in,null);
aoqi@0 249 }
aoqi@0 250 /**
aoqi@0 251 * @since 2.0.3
aoqi@0 252 */
aoqi@0 253 public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
aoqi@0 254 Unmarshaller u = context.unmarshallerPool.take();
aoqi@0 255 u.setAttachmentUnmarshaller(au);
aoqi@0 256 return exit(unmarshal(u,in),u);
aoqi@0 257 }
aoqi@0 258 public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull Source in) throws JAXBException {
aoqi@0 259 return unmarshal( ((BridgeContextImpl)context).unmarshaller, in );
aoqi@0 260 }
aoqi@0 261 public abstract @NotNull T unmarshal(@NotNull Unmarshaller u, @NotNull Source in) throws JAXBException;
aoqi@0 262
aoqi@0 263 /**
aoqi@0 264 * Unmarshals the specified type object.
aoqi@0 265 *
aoqi@0 266 * @param in
aoqi@0 267 * the parser must be pointing at a start tag
aoqi@0 268 * that encloses the XML type that this {@link XMLBridge} is
aoqi@0 269 * instanciated for.
aoqi@0 270 *
aoqi@0 271 * @return
aoqi@0 272 * never null.
aoqi@0 273 *
aoqi@0 274 * @throws JAXBException
aoqi@0 275 * if there was an error while unmarshalling.
aoqi@0 276 *
aoqi@0 277 * @since 2.0 EA1
aoqi@0 278 */
aoqi@0 279 public final @NotNull T unmarshal(@NotNull InputStream in) throws JAXBException {
aoqi@0 280 Unmarshaller u = context.unmarshallerPool.take();
aoqi@0 281 return exit(unmarshal(u,in),u);
aoqi@0 282 }
aoqi@0 283 public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull InputStream in) throws JAXBException {
aoqi@0 284 return unmarshal( ((BridgeContextImpl)context).unmarshaller, in );
aoqi@0 285 }
aoqi@0 286 public abstract @NotNull T unmarshal(@NotNull Unmarshaller u, @NotNull InputStream in) throws JAXBException;
aoqi@0 287
aoqi@0 288 /**
aoqi@0 289 * Unmarshals the specified type object.
aoqi@0 290 *
aoqi@0 291 * @param n
aoqi@0 292 * Node to be unmarshalled.
aoqi@0 293 *
aoqi@0 294 * @return
aoqi@0 295 * never null.
aoqi@0 296 *
aoqi@0 297 * @throws JAXBException
aoqi@0 298 * if there was an error while unmarshalling.
aoqi@0 299 *
aoqi@0 300 * @since 2.0 FCS
aoqi@0 301 */
aoqi@0 302 public final @NotNull T unmarshal(@NotNull Node n) throws JAXBException {
aoqi@0 303 return unmarshal(n,null);
aoqi@0 304 }
aoqi@0 305 /**
aoqi@0 306 * @since 2.0.3
aoqi@0 307 */
aoqi@0 308 public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
aoqi@0 309 Unmarshaller u = context.unmarshallerPool.take();
aoqi@0 310 u.setAttachmentUnmarshaller(au);
aoqi@0 311 return exit(unmarshal(u,n),u);
aoqi@0 312 }
aoqi@0 313 public final @NotNull T unmarshal(@NotNull BridgeContext context, @NotNull Node n) throws JAXBException {
aoqi@0 314 return unmarshal( ((BridgeContextImpl)context).unmarshaller, n );
aoqi@0 315 }
aoqi@0 316 public abstract @NotNull T unmarshal(@NotNull Unmarshaller context, @NotNull Node n) throws JAXBException;
aoqi@0 317
aoqi@0 318 /**
aoqi@0 319 * Gets the {@link TypeInfo} from which this bridge was created.
aoqi@0 320 */
aoqi@0 321 public abstract TypeInfo getTypeReference();
aoqi@0 322 }

mercurial