src/share/jaxws_classes/com/sun/xml/internal/ws/encoding/xml/XMLCodec.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

     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  */
    26 package com.sun.xml.internal.ws.encoding.xml;
    28 import com.sun.xml.internal.ws.api.message.Message;
    29 import com.sun.xml.internal.ws.api.message.Packet;
    30 import com.sun.xml.internal.ws.api.pipe.Codec;
    31 import com.sun.xml.internal.ws.api.pipe.ContentType;
    32 import com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory;
    33 import com.sun.xml.internal.ws.api.WSBinding;
    34 import com.sun.xml.internal.ws.api.WSFeatureList;
    35 import com.sun.xml.internal.ws.encoding.ContentTypeImpl;
    37 import javax.xml.stream.XMLStreamException;
    38 import javax.xml.stream.XMLStreamWriter;
    39 import javax.xml.ws.WebServiceException;
    40 import javax.xml.ws.WebServiceFeature;
    42 import java.io.IOException;
    43 import java.io.InputStream;
    44 import java.io.OutputStream;
    45 import java.nio.channels.ReadableByteChannel;
    46 import java.nio.channels.WritableByteChannel;
    48 public final class XMLCodec implements Codec {
    49     public static final String XML_APPLICATION_MIME_TYPE = "application/xml";
    51     public static final String XML_TEXT_MIME_TYPE = "text/xml";
    53     private static final ContentType contentType = new ContentTypeImpl(XML_TEXT_MIME_TYPE);
    55 //  private final WSBinding binding;
    56     private WSFeatureList features;
    58     public XMLCodec(WSFeatureList f) {
    59 //        this.binding = binding;
    60         features = f;
    61     }
    63     public String getMimeType() {
    64         return XML_APPLICATION_MIME_TYPE;
    65     }
    67     public ContentType getStaticContentType(Packet packet) {
    68         return contentType;
    69     }
    71     public ContentType encode(Packet packet, OutputStream out) {
    72                 String encoding = (String) packet.invocationProperties
    73                 .get(XMLConstants.OUTPUT_XML_CHARACTER_ENCODING);
    75         XMLStreamWriter writer = null;
    77                 if (encoding != null && encoding.length() > 0) {
    78             writer = XMLStreamWriterFactory.create(out, encoding);
    79         } else {
    80             writer = XMLStreamWriterFactory.create(out);
    81         }
    83         try {
    84             if (packet.getMessage().hasPayload()){
    85                 writer.writeStartDocument();
    86                 packet.getMessage().writePayloadTo(writer);
    87                 writer.flush();
    88             }
    89         } catch (XMLStreamException e) {
    90             throw new WebServiceException(e);
    91         }
    92         return contentType;
    93     }
    95     public ContentType encode(Packet packet, WritableByteChannel buffer) {
    96         //TODO: not yet implemented
    97         throw new UnsupportedOperationException();
    98     }
   100     public Codec copy() {
   101         return this;
   102     }
   104     public void decode(InputStream in, String contentType, Packet packet) throws IOException {
   105         Message message = XMLMessage.create(contentType, in, features);
   106         packet.setMessage(message);
   107     }
   109     public void decode(ReadableByteChannel in, String contentType, Packet packet) {
   110         // TODO
   111         throw new UnsupportedOperationException();
   112     }
   113 }

mercurial