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