Coverage Report - org.mule.transport.file.FileMuleMessageFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
FileMuleMessageFactory
0%
0/17
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: FileMuleMessageFactory.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.file;
 12  
 
 13  
 import org.mule.DefaultMuleMessage;
 14  
 import org.mule.api.MuleContext;
 15  
 import org.mule.api.MuleMessage;
 16  
 import org.mule.transport.AbstractMuleMessageFactory;
 17  
 
 18  
 import java.io.File;
 19  
 
 20  
 /**
 21  
  * <code>FileMuleMessageFactory</code> creates a new {@link MuleMessage} with a
 22  
  * {@link File} or {@link ReceiverFileInputStream} payload. Users can obtain the
 23  
  * filename and directory in the properties using
 24  
  * <code>FileConnector.PROPERTY_FILENAME</code> and
 25  
  * <code>FileConnector.PROPERTY_DIRECTORY</code>.
 26  
  */
 27  
 public class FileMuleMessageFactory extends AbstractMuleMessageFactory
 28  
 {
 29  
     public FileMuleMessageFactory(MuleContext context)
 30  
     {
 31  0
         super(context);
 32  0
     }
 33  
 
 34  
     @Override
 35  
     protected Class<?>[] getSupportedTransportMessageTypes()
 36  
     {
 37  0
         return new Class[]{File.class, ReceiverFileInputStream.class};
 38  
     }
 39  
 
 40  
     @Override
 41  
     protected Object extractPayload(Object transportMessage, String encoding) throws Exception
 42  
     {
 43  0
         return transportMessage;
 44  
     }
 45  
 
 46  
     @Override
 47  
     protected void addProperties(DefaultMuleMessage message, Object transportMessage) throws Exception
 48  
     {
 49  0
         super.addProperties(message, transportMessage);
 50  0
         File file = convertToFile(transportMessage);
 51  0
         setPropertiesFromFile(message, file);
 52  0
     }
 53  
 
 54  
     protected File convertToFile(Object transportMessage)
 55  
     {
 56  0
         File file = null;
 57  
 
 58  0
         if (transportMessage instanceof File)
 59  
         {
 60  0
             file = (File) transportMessage;
 61  
         }
 62  0
         else if (transportMessage instanceof ReceiverFileInputStream)
 63  
         {
 64  0
             file = ((ReceiverFileInputStream) transportMessage).getCurrentFile();
 65  
         }
 66  
 
 67  0
         return file;
 68  
     }
 69  
 
 70  
     protected void setPropertiesFromFile(MuleMessage message, File file)
 71  
     {
 72  0
         message.setOutboundProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME, file.getName());
 73  0
         message.setOutboundProperty(FileConnector.PROPERTY_DIRECTORY, file.getParent());
 74  0
     }
 75  
 }