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

changeset 0
373ffda63c9a
equal deleted inserted replaced
-1:000000000000 0:373ffda63c9a
1 /*
2 * Copyright (c) 1997, 2012, 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
26 package com.sun.xml.internal.ws.spi.db;
27
28 import java.io.InputStream;
29 import java.io.OutputStream;
30 import java.util.Iterator;
31
32 import javax.xml.bind.JAXBException;
33 import javax.xml.bind.attachment.AttachmentMarshaller;
34 import javax.xml.bind.attachment.AttachmentUnmarshaller;
35 import javax.xml.namespace.NamespaceContext;
36 import javax.xml.stream.XMLStreamException;
37 import javax.xml.stream.XMLStreamReader;
38 import javax.xml.stream.XMLStreamWriter;
39 import javax.xml.transform.Result;
40 import javax.xml.transform.Source;
41
42 import org.w3c.dom.Node;
43 import org.xml.sax.Attributes;
44 import org.xml.sax.ContentHandler;
45 import org.xml.sax.SAXException;
46
47 //import com.sun.xml.internal.ws.spi.db.BindingContext;
48 //import com.sun.xml.internal.ws.spi.db.RepeatedElementBridge;
49 //import com.sun.xml.internal.ws.spi.db.XMLBridge;
50 //import com.sun.xml.internal.ws.spi.db.DatabindingException;
51 //import com.sun.xml.internal.ws.spi.db.TypeInfo;
52 //import com.sun.xml.internal.ws.spi.db.WrapperComposite;
53
54 /**
55 * WrapperBridge handles RPC-Literal body and Document-Literal wrappers without static
56 * wrapper classes.
57 *
58 * @author shih-chang.chen@oracle.com
59 */
60 public class WrapperBridge<T> implements XMLBridge<T> {
61
62 BindingContext parent;
63 TypeInfo typeInfo;
64 static final String WrapperPrefix = "w";
65 static final String WrapperPrefixColon = WrapperPrefix + ":";
66
67 public WrapperBridge(BindingContext p, TypeInfo ti) {
68 this.parent = p;
69 this.typeInfo = ti;
70 }
71
72 @Override
73 public BindingContext context() {
74 return parent;
75 }
76
77 @Override
78 public TypeInfo getTypeInfo() {
79 return typeInfo;
80 }
81
82 @Override
83 public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
84 WrapperComposite w = (WrapperComposite) object;
85 Attributes att = new Attributes() {
86 @Override public int getLength() { return 0; }
87 @Override public String getURI(int index) { return null; }
88 @Override public String getLocalName(int index) { return null; }
89 @Override public String getQName(int index) { return null; }
90 @Override public String getType(int index) { return null; }
91 @Override public String getValue(int index) { return null; }
92 @Override public int getIndex(String uri, String localName) { return 0; }
93 @Override public int getIndex(String qName) { return 0; }
94 @Override public String getType(String uri, String localName) { return null; }
95 @Override public String getType(String qName) { return null; }
96 @Override public String getValue(String uri, String localName) { return null; }
97 @Override public String getValue(String qName) { return null; }
98 };
99 try {
100 contentHandler.startPrefixMapping(WrapperPrefix, typeInfo.tagName.getNamespaceURI());
101 contentHandler.startElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart(), WrapperPrefixColon + typeInfo.tagName.getLocalPart(), att);
102 } catch (SAXException e) {
103 throw new JAXBException(e);
104 }
105 if (w.bridges != null) for (int i = 0; i < w.bridges.length; i++) {
106 if (w.bridges[i] instanceof RepeatedElementBridge) {
107 RepeatedElementBridge rbridge = (RepeatedElementBridge) w.bridges[i];
108 for (Iterator itr = rbridge.collectionHandler().iterator(w.values[i]); itr.hasNext();) {
109 rbridge.marshal(itr.next(), contentHandler, am);
110 }
111 } else {
112 w.bridges[i].marshal(w.values[i], contentHandler, am);
113 }
114 }
115 try {
116 contentHandler.endElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart(), null);
117 contentHandler.endPrefixMapping(WrapperPrefix);
118 } catch (SAXException e) {
119 throw new JAXBException(e);
120 }
121 // bridge.marshal(object, contentHandler, am);
122 }
123
124 @Override
125 public void marshal(T object, Node output) throws JAXBException {
126 throw new UnsupportedOperationException();
127 // bridge.marshal(object, output);
128 // bridge.marshal((T) convert(object), output);
129 }
130
131 @Override
132 public void marshal(T object, OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
133 // bridge.marshal((T) convert(object), output, nsContext, am);
134 }
135
136 @Override
137 public final void marshal(T object, Result result) throws JAXBException {
138 throw new UnsupportedOperationException();
139 // bridge.marshal(object, result);
140 }
141
142 @Override
143 public final void marshal(T object, XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
144 WrapperComposite w = (WrapperComposite) object;
145 try {
146 // output.writeStartElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart());
147 // System.out.println(typeInfo.tagName.getNamespaceURI());
148
149 //The prefix is to workaround an eclipselink bug
150 String prefix = output.getPrefix(typeInfo.tagName.getNamespaceURI());
151 if (prefix == null) prefix = WrapperPrefix;
152 output.writeStartElement(prefix, typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
153 output.writeNamespace(prefix, typeInfo.tagName.getNamespaceURI());
154
155 // output.writeStartElement("", typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
156 // output.writeDefaultNamespace(typeInfo.tagName.getNamespaceURI());
157 // System.out.println("======== " + output.getPrefix(typeInfo.tagName.getNamespaceURI()));
158 // System.out.println("======== " + output.getNamespaceContext().getPrefix(typeInfo.tagName.getNamespaceURI()));
159 // System.out.println("======== " + output.getNamespaceContext().getNamespaceURI(""));
160 } catch (XMLStreamException e) {
161 e.printStackTrace();
162 throw new DatabindingException(e);
163 }
164 if (w.bridges != null) for (int i = 0; i < w.bridges.length; i++) {
165 if (w.bridges[i] instanceof RepeatedElementBridge) {
166 RepeatedElementBridge rbridge = (RepeatedElementBridge) w.bridges[i];
167 for (Iterator itr = rbridge.collectionHandler().iterator(w.values[i]); itr.hasNext();) {
168 rbridge.marshal(itr.next(), output, am);
169 }
170 } else {
171 w.bridges[i].marshal(w.values[i], output, am);
172 }
173 }
174 try {
175 output.writeEndElement();
176 } catch (XMLStreamException e) {
177 throw new DatabindingException(e);
178 }
179 }
180
181 @Override
182 public final T unmarshal(InputStream in) throws JAXBException {
183 //EndpointArgumentsBuilder.RpcLit.readRequest
184 throw new UnsupportedOperationException();
185 // return bridge.unmarshal(in);
186 }
187
188 @Override
189 public final T unmarshal(Node n, AttachmentUnmarshaller au) throws JAXBException {
190 //EndpointArgumentsBuilder.RpcLit.readRequest
191 throw new UnsupportedOperationException();
192 // return bridge.unmarshal(n, au);
193 }
194
195 @Override
196 public final T unmarshal(Source in, AttachmentUnmarshaller au) throws JAXBException {
197 //EndpointArgumentsBuilder.RpcLit.readRequest
198 throw new UnsupportedOperationException();
199 // return bridge.unmarshal(in, au);
200 }
201
202 @Override
203 public final T unmarshal(XMLStreamReader in, AttachmentUnmarshaller au) throws JAXBException {
204 //EndpointArgumentsBuilder.RpcLit.readRequest
205 throw new UnsupportedOperationException();
206 // return bridge.unmarshal(in, au);
207 }
208
209 @Override
210 public boolean supportOutputStream() {
211 return false;
212 }
213 }

mercurial