/MRI-J/jaxws/src/share/classes/com/sun/xml/internal/messaging/saaj/soap/MessageFactoryImpl.java

http://github.com/GregBowyer/ManagedRuntimeInitiative · Java · 120 lines · 64 code · 19 blank · 37 comment · 8 complexity · 3e6c31fa6b3aaee360c8eb866fc3615f MD5 · raw file

  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. */
  30. package com.sun.xml.internal.messaging.saaj.soap;
  31. import java.io.*;
  32. import java.util.logging.Logger;
  33. import javax.xml.soap.*;
  34. import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
  35. import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ParseException;
  36. import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
  37. import com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl;
  38. import com.sun.xml.internal.messaging.saaj.soap.ver1_2.Message1_2Impl;
  39. import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
  40. import com.sun.xml.internal.messaging.saaj.util.TeeInputStream;
  41. /**
  42. * A factory for creating SOAP messages.
  43. *
  44. * Converted to a placeholder for common functionality between SOAP
  45. * implementations.
  46. *
  47. * @author Phil Goodwin (phil.goodwin@sun.com)
  48. */
  49. public class MessageFactoryImpl extends MessageFactory {
  50. protected static final Logger log =
  51. Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
  52. "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
  53. protected OutputStream listener;
  54. protected boolean lazyAttachments = false;
  55. public OutputStream listen(OutputStream newListener) {
  56. OutputStream oldListener = listener;
  57. listener = newListener;
  58. return oldListener;
  59. }
  60. public SOAPMessage createMessage() throws SOAPException {
  61. throw new UnsupportedOperationException();
  62. }
  63. public SOAPMessage createMessage(boolean isFastInfoset,
  64. boolean acceptFastInfoset) throws SOAPException
  65. {
  66. throw new UnsupportedOperationException();
  67. }
  68. public SOAPMessage createMessage(MimeHeaders headers, InputStream in)
  69. throws SOAPException, IOException {
  70. String contentTypeString = MessageImpl.getContentType(headers);
  71. if (listener != null) {
  72. in = new TeeInputStream(in, listener);
  73. }
  74. try {
  75. ContentType contentType = new ContentType(contentTypeString);
  76. int stat = MessageImpl.identifyContentType(contentType);
  77. if (MessageImpl.isSoap1_1Content(stat)) {
  78. return new Message1_1Impl(headers,contentType,stat,in);
  79. } else if (MessageImpl.isSoap1_2Content(stat)) {
  80. return new Message1_2Impl(headers,contentType,stat,in);
  81. } else {
  82. log.severe("SAAJ0530.soap.unknown.Content-Type");
  83. throw new SOAPExceptionImpl("Unrecognized Content-Type");
  84. }
  85. } catch (ParseException e) {
  86. log.severe("SAAJ0531.soap.cannot.parse.Content-Type");
  87. throw new SOAPExceptionImpl(
  88. "Unable to parse content type: " + e.getMessage());
  89. }
  90. }
  91. protected static final String getContentType(MimeHeaders headers) {
  92. String[] values = headers.getHeader("Content-Type");
  93. if (values == null)
  94. return null;
  95. else
  96. return values[0];
  97. }
  98. public void setLazyAttachmentOptimization(boolean flag) {
  99. lazyAttachments = flag;
  100. }
  101. }