Save This Page
Home » synapse-1.2-src » org.apache.synapse.format » [javadoc | source]
    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   package org.apache.synapse.format;
   20   
   21   import java.io.OutputStream;
   22   import java.net.URL;
   23   
   24   import javax.activation.DataSource;
   25   
   26   import org.apache.axiom.attachments.ByteArrayDataSource;
   27   import org.apache.axiom.om.OMOutputFormat;
   28   import org.apache.axis2.AxisFault;
   29   import org.apache.axis2.context.MessageContext;
   30   import org.apache.axis2.transport.MessageFormatter;
   31   
   32   /**
   33    * Adapter to add the {@link MessageFormatterEx} interface to an
   34    * existing {@link MessageFormatter}.
   35    * It implements the {@link MessageFormatterEx#getDataSource(MessageContext, OMOutputFormat, String)} method
   36    * using {@link MessageFormatter#getBytes(MessageContext, OMOutputFormat)} and
   37    * {@link MessageFormatter#getContentType(MessageContext, OMOutputFormat, String)}.
   38    */
   39   public class MessageFormatterExAdapter implements MessageFormatterEx {
   40       private final MessageFormatter messageFormatter;
   41   
   42       public MessageFormatterExAdapter(MessageFormatter messageFormatter) {
   43           this.messageFormatter = messageFormatter;
   44       }
   45   
   46       public DataSource getDataSource(MessageContext messageContext,
   47                                       OMOutputFormat format,
   48                                       String soapAction) throws AxisFault {
   49           return new ByteArrayDataSource(
   50                   getBytes(messageContext, format),
   51                   getContentType(messageContext, format, soapAction));
   52       }
   53   
   54       public String formatSOAPAction(MessageContext messageContext,
   55                                      OMOutputFormat format,
   56                                      String soapAction) {
   57           return messageFormatter.formatSOAPAction(messageContext, format, soapAction);
   58       }
   59   
   60       public byte[] getBytes(MessageContext messageContext,
   61                              OMOutputFormat format) throws AxisFault {
   62           return messageFormatter.getBytes(messageContext, format);
   63       }
   64   
   65       public String getContentType(MessageContext messageContext,
   66                                    OMOutputFormat format,
   67                                    String soapAction) {
   68           return messageFormatter.getContentType(messageContext, format, soapAction);
   69       }
   70   
   71       public URL getTargetAddress(MessageContext messageContext,
   72                                   OMOutputFormat format,
   73                                   URL targetURL) throws AxisFault {
   74           return messageFormatter.getTargetAddress(messageContext, format, targetURL);
   75       }
   76   
   77       public void writeTo(MessageContext messageContext,
   78                           OMOutputFormat format,
   79                           OutputStream outputStream,
   80                           boolean preserve) throws AxisFault {
   81           messageFormatter.writeTo(messageContext, format, outputStream, preserve);
   82       }
   83   }

Save This Page
Home » synapse-1.2-src » org.apache.synapse.format » [javadoc | source]