src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/MimeTypedTransducer.java

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2011, 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.bind.v2.runtime;
    28 import java.awt.*;
    29 import java.io.IOException;
    31 import javax.activation.MimeType;
    32 import javax.xml.stream.XMLStreamException;
    34 import com.sun.xml.internal.bind.api.AccessorException;
    36 import org.xml.sax.SAXException;
    38 /**
    39  * {@link Transducer} decorator that wraps another {@link Transducer}
    40  * and sets the expected MIME type to the context.
    41  *
    42  * <p>
    43  * Combined with {@link Transducer} implementations (such as one for {@link Image}),
    44  * this is used to control the marshalling of the BLOB types.
    45  *
    46  * @author Kohsuke Kawaguchi
    47  */
    48 public final class MimeTypedTransducer<V> extends FilterTransducer<V> {
    49     private final MimeType expectedMimeType;
    51     public MimeTypedTransducer(Transducer<V> core,MimeType expectedMimeType) {
    52         super(core);
    53         this.expectedMimeType = expectedMimeType;
    54     }
    56     @Override
    57     public CharSequence print(V o) throws AccessorException {
    58         XMLSerializer w = XMLSerializer.getInstance();
    59         MimeType old = w.setExpectedMimeType(expectedMimeType);
    60         try {
    61             return core.print(o);
    62         } finally {
    63             w.setExpectedMimeType(old);
    64         }
    65     }
    67     @Override
    68     public void writeText(XMLSerializer w, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    69         MimeType old = w.setExpectedMimeType(expectedMimeType);
    70         try {
    71             core.writeText(w, o, fieldName);
    72         } finally {
    73             w.setExpectedMimeType(old);
    74         }
    75     }
    77     @Override
    78     public void writeLeafElement(XMLSerializer w, Name tagName, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
    79         MimeType old = w.setExpectedMimeType(expectedMimeType);
    80         try {
    81             core.writeLeafElement(w, tagName, o, fieldName);
    82         } finally {
    83             w.setExpectedMimeType(old);
    84         }
    85     }
    86 }

mercurial