KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > file > FileContentsMessageAdapter


1 /*
2  * $Id: FileContentsMessageAdapter.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.file;
12
13 import java.io.File JavaDoc;
14
15 import org.mule.MuleRuntimeException;
16 import org.mule.config.i18n.Message;
17 import org.mule.config.i18n.Messages;
18 import org.mule.umo.MessagingException;
19
20 /**
21  * <code>FileContentsMessageAdapter</code> provides a wrapper for file data. Users
22  * can obtain the contents of the message through the payload property and can get
23  * the filename and directory in the properties using PROPERTY_FILENAME and
24  * PROPERTY_DIRECTORY.
25  */

26 public class FileContentsMessageAdapter extends FileMessageAdapter
27 {
28     /**
29      * Serial version
30      */

31     private static final long serialVersionUID = 7368719494535568721L;
32
33     public FileContentsMessageAdapter(Object JavaDoc message) throws MessagingException
34     {
35         super(message);
36     }
37
38     protected void setMessage(File JavaDoc message) throws MessagingException
39     {
40         super.setMessage(message);
41         // force reading of file (lazy loading would be really, really complicated)
42
this.getPayload();
43     }
44
45     /*
46      * (non-Javadoc)
47      *
48      * @see org.mule.providers.UMOMessageAdapter#getPayload()
49      */

50     public Object JavaDoc getPayload()
51     {
52         synchronized (this)
53         {
54             try
55             {
56                 return this.getPayloadAsBytes();
57             }
58             catch (Exception JavaDoc noPayloadException)
59             {
60                 throw new MuleRuntimeException(new Message(Messages.FAILED_TO_READ_PAYLOAD),
61                     noPayloadException);
62             }
63         }
64     }
65
66 }
67
Popular Tags