src/share/classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java

Mon, 04 May 2009 21:10:41 -0700

author
tbell
date
Mon, 04 May 2009 21:10:41 -0700
changeset 50
42dfec6871f6
parent 45
31822b475baa
child 78
860b95cc8d1d
permissions
-rw-r--r--

6658158: Mutable statics in SAAJ (findbugs)
6658163: txw2.DatatypeWriter.BUILDIN is a mutable static (findbugs)
Reviewed-by: darcy

     1 /*
     2  * Copyright 2005-2006 Sun Microsystems, Inc.  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.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    25 /*
    26  *
    27  *
    28  *
    29  */
    32 package com.sun.xml.internal.messaging.saaj.soap;
    34 import java.util.logging.Logger;
    36 import javax.xml.parsers.SAXParser;
    37 import javax.xml.soap.SOAPException;
    38 import javax.xml.transform.Source;
    39 import javax.xml.transform.Transformer;
    40 import javax.xml.transform.dom.DOMResult;
    41 import javax.xml.transform.sax.SAXSource;
    42 import javax.xml.transform.stream.StreamSource;
    44 import org.xml.sax.InputSource;
    45 import org.xml.sax.XMLReader;
    47 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
    48 import com.sun.xml.internal.messaging.saaj.util.*;
    50 import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
    52 /**
    53  * EnvelopeFactory creates SOAP Envelope objects using different
    54  * underlying implementations.
    55  */
    56 public class EnvelopeFactory {
    58     protected static final Logger
    59         log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
    60         "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
    62     private static ParserPool parserPool = new ParserPool(5);
    64     public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
    65         throws SOAPException
    66     {
    67         // Insert SAX filter to disallow Document Type Declarations since
    68         // they are not legal in SOAP
    69         SAXParser saxParser = null;
    70         if (src instanceof StreamSource) {
    71             if (src instanceof JAXMStreamSource) {
    72                 try {
    73                     ((JAXMStreamSource) src).reset();
    74                 } catch (java.io.IOException ioe) {
    75                     log.severe("SAAJ0515.source.reset.exception");
    76                     throw new SOAPExceptionImpl(ioe);
    77                 }
    78             }
    79             try {
    80                 saxParser = parserPool.get();
    81             } catch (Exception e) {
    82                 log.severe("SAAJ0601.util.newSAXParser.exception");
    83                 throw new SOAPExceptionImpl(
    84                     "Couldn't get a SAX parser while constructing a envelope",
    85                     e);
    86             }
    87             InputSource is = SAXSource.sourceToInputSource(src);
    88             XMLReader rejectFilter;
    89             try {
    90                 rejectFilter = new RejectDoctypeSaxFilter(saxParser);
    91             } catch (Exception ex) {
    92                 log.severe("SAAJ0510.soap.cannot.create.envelope");
    93                 throw new SOAPExceptionImpl(
    94                     "Unable to create envelope from given source: ",
    95                     ex);
    96             }
    97             src = new SAXSource(rejectFilter, is);
    98         }
   100         try {
   101             Transformer transformer =
   102                 EfficientStreamingTransformer.newTransformer();
   103             DOMResult result = new DOMResult(soapPart);
   104             transformer.transform(src, result);
   106             Envelope env = (Envelope) soapPart.getEnvelope();
   107             if (saxParser != null) {
   108                 parserPool.put(saxParser);
   109             }
   110             return env;
   111         } catch (Exception ex) {
   112             if (ex instanceof SOAPVersionMismatchException) {
   113                 throw (SOAPVersionMismatchException) ex;
   114             }
   115             log.severe("SAAJ0511.soap.cannot.create.envelope");
   116             throw new SOAPExceptionImpl(
   117                 "Unable to create envelope from given source: ",
   118                 ex);
   119         }
   120     }
   121 }

mercurial