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

changeset 0
373ffda63c9a
     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/WrapperBridge.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,213 @@
     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 +import java.util.Iterator;
    1.34 +
    1.35 +import javax.xml.bind.JAXBException;
    1.36 +import javax.xml.bind.attachment.AttachmentMarshaller;
    1.37 +import javax.xml.bind.attachment.AttachmentUnmarshaller;
    1.38 +import javax.xml.namespace.NamespaceContext;
    1.39 +import javax.xml.stream.XMLStreamException;
    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 org.w3c.dom.Node;
    1.46 +import org.xml.sax.Attributes;
    1.47 +import org.xml.sax.ContentHandler;
    1.48 +import org.xml.sax.SAXException;
    1.49 +
    1.50 +//import com.sun.xml.internal.ws.spi.db.BindingContext;
    1.51 +//import com.sun.xml.internal.ws.spi.db.RepeatedElementBridge;
    1.52 +//import com.sun.xml.internal.ws.spi.db.XMLBridge;
    1.53 +//import com.sun.xml.internal.ws.spi.db.DatabindingException;
    1.54 +//import com.sun.xml.internal.ws.spi.db.TypeInfo;
    1.55 +//import com.sun.xml.internal.ws.spi.db.WrapperComposite;
    1.56 +
    1.57 +/**
    1.58 + * WrapperBridge handles RPC-Literal body and Document-Literal wrappers without static
    1.59 + * wrapper classes.
    1.60 + *
    1.61 + * @author shih-chang.chen@oracle.com
    1.62 + */
    1.63 +public class WrapperBridge<T> implements XMLBridge<T> {
    1.64 +
    1.65 +    BindingContext parent;
    1.66 +    TypeInfo typeInfo;
    1.67 +    static final String WrapperPrefix  = "w";
    1.68 +    static final String WrapperPrefixColon = WrapperPrefix + ":";
    1.69 +
    1.70 +    public WrapperBridge(BindingContext p, TypeInfo ti) {
    1.71 +        this.parent = p;
    1.72 +        this.typeInfo = ti;
    1.73 +    }
    1.74 +
    1.75 +    @Override
    1.76 +    public BindingContext context() {
    1.77 +        return parent;
    1.78 +    }
    1.79 +
    1.80 +    @Override
    1.81 +    public TypeInfo getTypeInfo() {
    1.82 +        return typeInfo;
    1.83 +    }
    1.84 +
    1.85 +    @Override
    1.86 +    public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
    1.87 +        WrapperComposite w = (WrapperComposite) object;
    1.88 +        Attributes att = new Attributes() {
    1.89 +            @Override public int getLength() { return 0; }
    1.90 +            @Override public String getURI(int index) { return null; }
    1.91 +            @Override public String getLocalName(int index)  { return null; }
    1.92 +            @Override public String getQName(int index) { return null; }
    1.93 +            @Override public String getType(int index) { return null; }
    1.94 +            @Override public String getValue(int index)  { return null; }
    1.95 +            @Override public int getIndex(String uri, String localName)  { return 0; }
    1.96 +            @Override public int getIndex(String qName) {  return 0; }
    1.97 +            @Override public String getType(String uri, String localName)  { return null; }
    1.98 +            @Override public String getType(String qName)  { return null; }
    1.99 +            @Override public String getValue(String uri, String localName)  { return null; }
   1.100 +            @Override public String getValue(String qName)  { return null; }
   1.101 +        };
   1.102 +        try {
   1.103 +            contentHandler.startPrefixMapping(WrapperPrefix, typeInfo.tagName.getNamespaceURI());
   1.104 +            contentHandler.startElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart(), WrapperPrefixColon + typeInfo.tagName.getLocalPart(), att);
   1.105 +        } catch (SAXException e) {
   1.106 +            throw new JAXBException(e);
   1.107 +        }
   1.108 +        if (w.bridges != null) for (int i = 0; i < w.bridges.length; i++) {
   1.109 +            if (w.bridges[i] instanceof RepeatedElementBridge) {
   1.110 +                RepeatedElementBridge rbridge = (RepeatedElementBridge) w.bridges[i];
   1.111 +                for (Iterator itr = rbridge.collectionHandler().iterator(w.values[i]); itr.hasNext();) {
   1.112 +                    rbridge.marshal(itr.next(), contentHandler, am);
   1.113 +                }
   1.114 +            } else {
   1.115 +                w.bridges[i].marshal(w.values[i], contentHandler, am);
   1.116 +            }
   1.117 +        }
   1.118 +        try {
   1.119 +            contentHandler.endElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart(), null);
   1.120 +            contentHandler.endPrefixMapping(WrapperPrefix);
   1.121 +        } catch (SAXException e) {
   1.122 +            throw new JAXBException(e);
   1.123 +        }
   1.124 +//      bridge.marshal(object, contentHandler, am);
   1.125 +    }
   1.126 +
   1.127 +    @Override
   1.128 +    public void marshal(T object, Node output) throws JAXBException {
   1.129 +        throw new UnsupportedOperationException();
   1.130 +//      bridge.marshal(object, output);
   1.131 +//      bridge.marshal((T) convert(object), output);
   1.132 +    }
   1.133 +
   1.134 +    @Override
   1.135 +    public void marshal(T object, OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
   1.136 +//      bridge.marshal((T) convert(object), output, nsContext, am);
   1.137 +    }
   1.138 +
   1.139 +    @Override
   1.140 +    public final void marshal(T object, Result result) throws JAXBException {
   1.141 +        throw new UnsupportedOperationException();
   1.142 +//      bridge.marshal(object, result);
   1.143 +    }
   1.144 +
   1.145 +    @Override
   1.146 +    public final void marshal(T object, XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
   1.147 +        WrapperComposite w = (WrapperComposite) object;
   1.148 +        try {
   1.149 +//          output.writeStartElement(typeInfo.tagName.getNamespaceURI(), typeInfo.tagName.getLocalPart());
   1.150 +//          System.out.println(typeInfo.tagName.getNamespaceURI());
   1.151 +
   1.152 +            //The prefix is to workaround an eclipselink bug
   1.153 +            String prefix = output.getPrefix(typeInfo.tagName.getNamespaceURI());
   1.154 +            if (prefix == null) prefix = WrapperPrefix;
   1.155 +            output.writeStartElement(prefix, typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
   1.156 +            output.writeNamespace(prefix, typeInfo.tagName.getNamespaceURI());
   1.157 +
   1.158 +//          output.writeStartElement("", typeInfo.tagName.getLocalPart(), typeInfo.tagName.getNamespaceURI());
   1.159 +//          output.writeDefaultNamespace(typeInfo.tagName.getNamespaceURI());
   1.160 +//          System.out.println("======== " + output.getPrefix(typeInfo.tagName.getNamespaceURI()));
   1.161 +//          System.out.println("======== " + output.getNamespaceContext().getPrefix(typeInfo.tagName.getNamespaceURI()));
   1.162 +//          System.out.println("======== " + output.getNamespaceContext().getNamespaceURI(""));
   1.163 +        } catch (XMLStreamException e) {
   1.164 +            e.printStackTrace();
   1.165 +            throw new DatabindingException(e);
   1.166 +        }
   1.167 +        if (w.bridges != null) for (int i = 0; i < w.bridges.length; i++) {
   1.168 +            if (w.bridges[i] instanceof RepeatedElementBridge) {
   1.169 +                RepeatedElementBridge rbridge = (RepeatedElementBridge) w.bridges[i];
   1.170 +                for (Iterator itr = rbridge.collectionHandler().iterator(w.values[i]); itr.hasNext();) {
   1.171 +                    rbridge.marshal(itr.next(), output, am);
   1.172 +                }
   1.173 +            } else {
   1.174 +                w.bridges[i].marshal(w.values[i], output, am);
   1.175 +            }
   1.176 +        }
   1.177 +        try {
   1.178 +            output.writeEndElement();
   1.179 +        } catch (XMLStreamException e) {
   1.180 +            throw new DatabindingException(e);
   1.181 +        }
   1.182 +    }
   1.183 +
   1.184 +    @Override
   1.185 +    public final T unmarshal(InputStream in) throws JAXBException {
   1.186 +        //EndpointArgumentsBuilder.RpcLit.readRequest
   1.187 +        throw new UnsupportedOperationException();
   1.188 +//      return bridge.unmarshal(in);
   1.189 +    }
   1.190 +
   1.191 +    @Override
   1.192 +    public final T unmarshal(Node n, AttachmentUnmarshaller au) throws JAXBException {
   1.193 +        //EndpointArgumentsBuilder.RpcLit.readRequest
   1.194 +        throw new UnsupportedOperationException();
   1.195 +//      return bridge.unmarshal(n, au);
   1.196 +    }
   1.197 +
   1.198 +    @Override
   1.199 +    public final T unmarshal(Source in, AttachmentUnmarshaller au) throws JAXBException {
   1.200 +        //EndpointArgumentsBuilder.RpcLit.readRequest
   1.201 +        throw new UnsupportedOperationException();
   1.202 +//      return bridge.unmarshal(in, au);
   1.203 +    }
   1.204 +
   1.205 +    @Override
   1.206 +    public final T unmarshal(XMLStreamReader in, AttachmentUnmarshaller au) throws JAXBException {
   1.207 +        //EndpointArgumentsBuilder.RpcLit.readRequest
   1.208 +        throw new UnsupportedOperationException();
   1.209 +//      return bridge.unmarshal(in, au);
   1.210 +    }
   1.211 +
   1.212 +    @Override
   1.213 +    public boolean supportOutputStream() {
   1.214 +        return false;
   1.215 +    }
   1.216 +}

mercurial