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.attachment.AttachmentMarshaller;
33import javax.xml.bind.attachment.AttachmentUnmarshaller;
34import javax.xml.namespace.NamespaceContext;
35import javax.xml.stream.XMLStreamReader;
36import javax.xml.stream.XMLStreamWriter;
37import javax.xml.transform.Result;
38import javax.xml.transform.Source;
39
40import org.w3c.dom.Node;
41import org.xml.sax.ContentHandler;
42
43import com.sun.xml.internal.bind.api.Bridge;
44import com.sun.xml.internal.bind.api.CompositeStructure;
45import com.sun.xml.internal.ws.spi.db.BindingContext;
46import com.sun.xml.internal.ws.spi.db.XMLBridge;
47import com.sun.xml.internal.ws.spi.db.TypeInfo;
48import com.sun.xml.internal.ws.spi.db.WrapperComposite;
49
50public class WrapperBridge<T> implements XMLBridge<T> {
51
52    private JAXBRIContextWrapper parent;
53    private com.sun.xml.internal.bind.api.Bridge<T> bridge;
54
55    public WrapperBridge(JAXBRIContextWrapper p, com.sun.xml.internal.bind.api.Bridge<T> b) {
56        parent = p;
57        bridge = b;
58    }
59
60    @Override
61    public BindingContext context() {
62        return parent;
63    }
64
65    @Override
66    public boolean equals(Object obj) {
67        return bridge.equals(obj);
68    }
69
70    @Override
71    public TypeInfo getTypeInfo() {
72        return parent.typeInfo(bridge.getTypeReference());
73    }
74
75    @Override
76    public int hashCode() {
77        return bridge.hashCode();
78    }
79
80    static CompositeStructure convert(Object o) {
81        WrapperComposite w = (WrapperComposite) o;
82        CompositeStructure cs = new CompositeStructure();
83        cs.values = w.values;
84        cs.bridges = new Bridge[w.bridges.length];
85        for (int i = 0; i < cs.bridges.length; i++) {
86            cs.bridges[i] = ((BridgeWrapper) w.bridges[i]).getBridge();
87        }
88        return cs;
89    }
90
91    @Override
92    public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
93        bridge.marshal((T) convert(object), contentHandler, am);
94//              bridge.marshal(object, contentHandler, am);
95    }
96
97    @Override
98    public void marshal(T object, Node output) throws JAXBException {
99        throw new UnsupportedOperationException();
100//              bridge.marshal(object, output);
101//              bridge.marshal((T) convert(object), output);
102    }
103
104    @Override
105    public void marshal(T object, OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
106        bridge.marshal((T) convert(object), output, nsContext, am);
107    }
108
109    @Override
110    public final void marshal(T object, Result result) throws JAXBException {
111        throw new UnsupportedOperationException();
112//              bridge.marshal(object, result);
113    }
114
115    @Override
116    public final void marshal(T object, XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
117        bridge.marshal((T) convert(object), output, am);
118    }
119
120    @Override
121    public String toString() {
122        return BridgeWrapper.class.getName() + " : " + bridge.toString();
123    }
124
125    @Override
126    public final T unmarshal(InputStream in) throws JAXBException {
127        //EndpointArgumentsBuilder.RpcLit.readRequest
128        throw new UnsupportedOperationException();
129//              return bridge.unmarshal(in);
130    }
131
132    @Override
133    public final T unmarshal(Node n, AttachmentUnmarshaller au) throws JAXBException {
134        //EndpointArgumentsBuilder.RpcLit.readRequest
135        throw new UnsupportedOperationException();
136//              return bridge.unmarshal(n, au);
137    }
138
139    @Override
140    public final T unmarshal(Source in, AttachmentUnmarshaller au) throws JAXBException {
141        //EndpointArgumentsBuilder.RpcLit.readRequest
142        throw new UnsupportedOperationException();
143//              return bridge.unmarshal(in, au);
144    }
145
146    @Override
147    public final T unmarshal(XMLStreamReader in, AttachmentUnmarshaller au) throws JAXBException {
148        //EndpointArgumentsBuilder.RpcLit.readRequest
149        throw new UnsupportedOperationException();
150//              return bridge.unmarshal(in, au);
151    }
152
153    @Override
154    public boolean supportOutputStream() {
155        return true;
156    }
157}
158