1/* 2 * Copyright (c) 1997, 2013, 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 */ 25 26package com.sun.xml.internal.ws.db.glassfish; 27 28import java.io.InputStream; 29import java.io.OutputStream; 30 31import javax.xml.bind.JAXBException; 32import javax.xml.bind.Marshaller; 33import javax.xml.bind.Unmarshaller; 34import javax.xml.bind.attachment.AttachmentMarshaller; 35import javax.xml.bind.attachment.AttachmentUnmarshaller; 36import javax.xml.namespace.NamespaceContext; 37import javax.xml.stream.XMLStreamReader; 38import javax.xml.stream.XMLStreamWriter; 39import javax.xml.transform.Result; 40import javax.xml.transform.Source; 41 42import org.w3c.dom.Node; 43import org.xml.sax.ContentHandler; 44 45import com.sun.xml.internal.bind.api.JAXBRIContext; 46import com.sun.xml.internal.ws.spi.db.BindingContext; 47import com.sun.xml.internal.ws.spi.db.XMLBridge; 48import com.sun.xml.internal.ws.spi.db.DatabindingException; 49import com.sun.xml.internal.ws.spi.db.TypeInfo; 50 51public class BridgeWrapper<T> implements XMLBridge<T> { 52 53 private JAXBRIContextWrapper parent; 54 private com.sun.xml.internal.bind.api.Bridge<T> bridge; 55 56 public BridgeWrapper(JAXBRIContextWrapper p, com.sun.xml.internal.bind.api.Bridge<T> b) { 57 parent = p; 58 bridge = b; 59 } 60 61 @Override 62 public BindingContext context() { 63 return parent; 64 } 65 66 com.sun.xml.internal.bind.api.Bridge getBridge() { 67 return bridge; 68 } 69 70 @Override 71 public boolean equals(Object obj) { 72 return bridge.equals(obj); 73 } 74 75 public JAXBRIContext getContext() { 76 return bridge.getContext(); 77 } 78 79 @Override 80 public TypeInfo getTypeInfo() { 81 return parent.typeInfo(bridge.getTypeReference()); 82 } 83 84 @Override 85 public int hashCode() { 86 return bridge.hashCode(); 87 } 88 89// public final void marshal(BridgeContext context, T object, ContentHandler contentHandler) throws JAXBException { 90// bridge.marshal(context, object, contentHandler); 91// } 92// 93// public final void marshal(BridgeContext context, T object, Node output) throws JAXBException { 94// bridge.marshal(context, object, output); 95// } 96// 97// public final void marshal(BridgeContext context, T object, OutputStream output, NamespaceContext nsContext) throws JAXBException { 98// bridge.marshal(context, object, output, nsContext); 99// } 100// 101// public final void marshal(BridgeContext context, T object, Result result) throws JAXBException { 102// bridge.marshal(context, object, result); 103// } 104// 105// public final void marshal(BridgeContext context, T object, XMLStreamWriter output) throws JAXBException { 106// bridge.marshal(context, object, output); 107// } 108 public void marshal(Marshaller m, T object, ContentHandler contentHandler) throws JAXBException { 109 bridge.marshal(m, object, contentHandler); 110 } 111 112 public void marshal(Marshaller m, T object, Node output) throws JAXBException { 113 bridge.marshal(m, object, output); 114 } 115 116 public void marshal(Marshaller m, T object, OutputStream output, NamespaceContext nsContext) throws JAXBException { 117 bridge.marshal(m, object, output, nsContext); 118 } 119 120 public void marshal(Marshaller m, T object, Result result) throws JAXBException { 121 bridge.marshal(m, object, result); 122 } 123 124 public void marshal(Marshaller m, T object, XMLStreamWriter output) throws JAXBException { 125 bridge.marshal(m, object, output); 126// bridge.marshal(m, (T) convert(object), output); 127 } 128 129 @Override 130 public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException { 131// bridge.marshal((T) convert(object), contentHandler, am); 132 bridge.marshal(object, contentHandler, am); 133 } 134 135// Object convert(Object o) { 136// return (o instanceof WrapperComposite)? convertWrapper((WrapperComposite)o) : o; 137// } 138// 139// static CompositeStructure convertWrapper(WrapperComposite w) { 140// CompositeStructure cs = new CompositeStructure(); 141// cs.values = w.values; 142// cs.bridges = new Bridge[w.bridges.length]; 143// for (int i = 0; i < cs.bridges.length; i++) 144// cs.bridges[i] = ((BridgeWrapper)w.bridges[i]).getBridge(); 145// return cs; 146// } 147 public void marshal(T object, ContentHandler contentHandler) throws JAXBException { 148 bridge.marshal(object, contentHandler); 149// bridge.marshal((T) convert(object), contentHandler); 150 } 151 152 @Override 153 public void marshal(T object, Node output) throws JAXBException { 154 bridge.marshal(object, output); 155// bridge.marshal((T) convert(object), output); 156 } 157 158 @Override 159 public void marshal(T object, OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException { 160// bridge.marshal((T) convert(object), output, nsContext, am); 161 bridge.marshal(object, output, nsContext, am); 162 } 163 164 public void marshal(T object, OutputStream output, NamespaceContext nsContext) throws JAXBException { 165 bridge.marshal(object, output, nsContext); 166// bridge.marshal((T) convert(object), output, nsContext); 167 } 168 169 @Override 170 public final void marshal(T object, Result result) throws JAXBException { 171 bridge.marshal(object, result); 172 } 173 174 @Override 175 public final void marshal(T object, XMLStreamWriter output, 176 AttachmentMarshaller am) throws JAXBException { 177 bridge.marshal(object, output, am); 178 } 179 180 public final void marshal(T object, XMLStreamWriter output) 181 throws JAXBException { 182 bridge.marshal(object, output); 183 } 184 185 @Override 186 public String toString() { 187 return BridgeWrapper.class.getName() + " : " + bridge.toString(); 188 } 189 190// public final T unmarshal(BridgeContext context, InputStream in) 191// throws JAXBException { 192// return bridge.unmarshal(context, in); 193// } 194// 195// public final T unmarshal(BridgeContext context, Node n) 196// throws JAXBException { 197// return bridge.unmarshal(context, n); 198// } 199// 200// public final T unmarshal(BridgeContext context, Source in) 201// throws JAXBException { 202// return bridge.unmarshal(context, in); 203// } 204// 205// public final T unmarshal(BridgeContext context, XMLStreamReader in) 206// throws JAXBException { 207// return bridge.unmarshal(context, in); 208// } 209 @Override 210 public final T unmarshal(InputStream in) throws JAXBException { 211 return bridge.unmarshal(in); 212 } 213 214 @Override 215 public final T unmarshal(Node n, AttachmentUnmarshaller au) 216 throws JAXBException { 217 return bridge.unmarshal(n, au); 218 } 219 220 public final T unmarshal(Node n) throws JAXBException { 221 return bridge.unmarshal(n); 222 } 223 224 @Override 225 public final T unmarshal(Source in, AttachmentUnmarshaller au) 226 throws JAXBException { 227 return bridge.unmarshal(in, au); 228 } 229 230 public final T unmarshal(Source in) throws DatabindingException { 231 try { 232 return bridge.unmarshal(in); 233 } catch (JAXBException e) { 234 throw new DatabindingException(e); 235 } 236 } 237 238 public T unmarshal(Unmarshaller u, InputStream in) throws JAXBException { 239 return bridge.unmarshal(u, in); 240 } 241 242 public T unmarshal(Unmarshaller context, Node n) throws JAXBException { 243 return bridge.unmarshal(context, n); 244 } 245 246 public T unmarshal(Unmarshaller u, Source in) throws JAXBException { 247 return bridge.unmarshal(u, in); 248 } 249 250 public T unmarshal(Unmarshaller u, XMLStreamReader in) throws JAXBException { 251 return bridge.unmarshal(u, in); 252 } 253 254 @Override 255 public final T unmarshal(XMLStreamReader in, AttachmentUnmarshaller au) 256 throws JAXBException { 257 return bridge.unmarshal(in, au); 258 } 259 260 public final T unmarshal(XMLStreamReader in) throws JAXBException { 261 return bridge.unmarshal(in); 262 } 263 264 @Override 265 public boolean supportOutputStream() { 266 return true; 267 } 268} 269