1
2
3
4
5
6
7 package org.mule.transport.sftp.notification;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.mule.api.MuleMessage;
12 import org.mule.api.endpoint.ImmutableEndpoint;
13 import org.mule.context.notification.CustomNotification;
14 import org.mule.context.notification.EndpointMessageNotification;
15
16 public class SftpTransportNotification extends CustomNotification
17 {
18
19
20
21
22 private static final long serialVersionUID = 4662315555948069782L;
23
24
25
26
27 protected static final Log logger = LogFactory.getLog(EndpointMessageNotification.class);
28
29
30
31
32 private static final int SFTP_ACTION_BASE = CUSTOM_EVENT_ACTION_START_RANGE * 2;
33 public static final int SFTP_GET_ACTION = SFTP_ACTION_BASE + 1;
34 public static final int SFTP_PUT_ACTION = SFTP_ACTION_BASE + 2;
35 public static final int SFTP_RENAME_ACTION = SFTP_ACTION_BASE + 3;
36 public static final int SFTP_DELETE_ACTION = SFTP_ACTION_BASE + 4;
37
38 public static final String SFTP_GET_ACTION_MSG = "sftp.get";
39 public static final String SFTP_PUT_ACTION_MSG = "sftp.put";
40 public static final String SFTP_RENAME_ACTION_MSG = "sftp.rename";
41 public static final String SFTP_DELETE_ACTION_MSG = "sftp.delete";
42
43
44
45
46 private ImmutableEndpoint endpoint;
47 private String info;
48 private long size;
49
50 static
51 {
52 registerAction(SFTP_GET_ACTION_MSG, SFTP_GET_ACTION);
53 registerAction(SFTP_PUT_ACTION_MSG, SFTP_PUT_ACTION);
54 registerAction(SFTP_RENAME_ACTION_MSG, SFTP_RENAME_ACTION);
55 registerAction(SFTP_DELETE_ACTION_MSG, SFTP_DELETE_ACTION);
56 }
57
58 public SftpTransportNotification(MuleMessage resource,
59 ImmutableEndpoint endpoint,
60 String resourceIdentifier,
61 int action,
62 String info,
63 long size)
64 {
65
66 super(resource, action, resourceIdentifier);
67
68 if (logger.isDebugEnabled()) logger.debug("*** SftpTransportNotification object created ***");
69
70 this.endpoint = endpoint;
71 this.info = info;
72 this.size = size;
73 }
74
75 protected String getPayloadToString()
76 {
77 try
78 {
79 return ((MuleMessage) source).getPayloadAsString();
80 }
81 catch (Exception e)
82 {
83 return source.toString();
84 }
85 }
86
87 public String toString()
88 {
89 return EVENT_NAME + "{action = " + getActionName(action) + ", endpoint = "
90 + endpoint.getEndpointURI() + ", info = " + info + ", size = " + size
91 + ", resourceIdentifier = " + resourceIdentifier + ", timestamp = " + timestamp
92 + ", serverId = " + serverId + ", message = " + source + "}";
93 }
94
95 public ImmutableEndpoint getEndpoint()
96 {
97 return endpoint;
98 }
99
100 public String getInfo()
101 {
102 return info;
103 }
104
105 public long getSize()
106 {
107 return size;
108 }
109
110 }