001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * $Id: MessageFactoryImpl.java,v 1.2 2007/07/16 16:41:21 ofung Exp $
022: * $Revision: 1.2 $
023: * $Date: 2007/07/16 16:41:21 $
024: */
025:
026: /*
027: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
028: *
029: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
030: *
031: * The contents of this file are subject to the terms of either the GNU
032: * General Public License Version 2 only ("GPL") or the Common Development
033: * and Distribution License("CDDL") (collectively, the "License"). You
034: * may not use this file except in compliance with the License. You can obtain
035: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
036: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
037: * language governing permissions and limitations under the License.
038: *
039: * When distributing the software, include this License Header Notice in each
040: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
041: * Sun designates this particular file as subject to the "Classpath" exception
042: * as provided by Sun in the GPL Version 2 section of the License file that
043: * accompanied this code. If applicable, add the following below the License
044: * Header, with the fields enclosed by brackets [] replaced by your own
045: * identifying information: "Portions Copyrighted [year]
046: * [name of copyright owner]"
047: *
048: * Contributor(s):
049: *
050: * If you wish your version of this file to be governed by only the CDDL or
051: * only the GPL Version 2, indicate your decision by adding "[Contributor]
052: * elects to include this software in this distribution under the [CDDL or GPL
053: * Version 2] license." If you don't indicate a single choice of license, a
054: * recipient has the option to distribute your version of this file under
055: * either the CDDL, the GPL Version 2 or to extend the choice of license to
056: * its licensees as provided above. However, if you add GPL Version 2 code
057: * and therefore, elected the GPL Version 2 license, then the option applies
058: * only if the new code is made subject to such option by the copyright
059: * holder.
060: */
061: package com.sun.xml.messaging.saaj.soap;
062:
063: import java.io.*;
064: import java.util.logging.Logger;
065:
066: import javax.xml.soap.*;
067:
068: import com.sun.xml.messaging.saaj.packaging.mime.internet.ContentType;
069: import com.sun.xml.messaging.saaj.packaging.mime.internet.ParseException;
070: import com.sun.xml.messaging.saaj.SOAPExceptionImpl;
071: import com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl;
072: import com.sun.xml.messaging.saaj.soap.ver1_2.Message1_2Impl;
073: import com.sun.xml.messaging.saaj.util.LogDomainConstants;
074: import com.sun.xml.messaging.saaj.util.TeeInputStream;
075:
076: /**
077: * A factory for creating SOAP messages.
078: *
079: * Converted to a placeholder for common functionality between SOAP
080: * implementations.
081: *
082: * @author Phil Goodwin (phil.goodwin@sun.com)
083: */
084: public class MessageFactoryImpl extends MessageFactory {
085:
086: protected static Logger log = Logger.getLogger(
087: LogDomainConstants.SOAP_DOMAIN,
088: "com.sun.xml.messaging.saaj.soap.LocalStrings");
089:
090: protected static OutputStream listener;
091:
092: protected boolean lazyAttachments = false;
093:
094: public static OutputStream listen(OutputStream newListener) {
095: OutputStream oldListener = listener;
096: listener = newListener;
097: return oldListener;
098: }
099:
100: public SOAPMessage createMessage() throws SOAPException {
101: throw new UnsupportedOperationException();
102: }
103:
104: public SOAPMessage createMessage(boolean isFastInfoset,
105: boolean acceptFastInfoset) throws SOAPException {
106: throw new UnsupportedOperationException();
107: }
108:
109: public SOAPMessage createMessage(MimeHeaders headers, InputStream in)
110: throws SOAPException, IOException {
111: String contentTypeString = MessageImpl.getContentType(headers);
112:
113: if (listener != null) {
114: in = new TeeInputStream(in, listener);
115: }
116:
117: try {
118: ContentType contentType = new ContentType(contentTypeString);
119: int stat = MessageImpl.identifyContentType(contentType);
120:
121: if (MessageImpl.isSoap1_1Content(stat)) {
122: return new Message1_1Impl(headers, contentType, stat,
123: in);
124: } else if (MessageImpl.isSoap1_2Content(stat)) {
125: return new Message1_2Impl(headers, contentType, stat,
126: in);
127: } else {
128: log.severe("SAAJ0530.soap.unknown.Content-Type");
129: throw new SOAPExceptionImpl("Unrecognized Content-Type");
130: }
131: } catch (ParseException e) {
132: log.severe("SAAJ0531.soap.cannot.parse.Content-Type");
133: throw new SOAPExceptionImpl(
134: "Unable to parse content type: " + e.getMessage());
135: }
136: }
137:
138: protected static final String getContentType(MimeHeaders headers) {
139: String[] values = headers.getHeader("Content-Type");
140: if (values == null)
141: return null;
142: else
143: return values[0];
144: }
145:
146: public void setLazyAttachmentOptimization(boolean flag) {
147: lazyAttachments = flag;
148: }
149:
150: }
|