KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > notify > NotifyChangeEvent


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.server.notify;
18
19 import org.alfresco.filesys.server.filesys.NotifyChange;
20
21 /**
22  * Notify Change Event Class
23  * <p>
24  * Contains the details of a change notification event
25  */

26 public class NotifyChangeEvent
27 {
28
29     // Notification event action and filter type
30

31     private int m_action;
32     private int m_filter;
33
34     // Notification file/directory name
35

36     private String JavaDoc m_fileName;
37
38     // Path is a directory
39

40     private boolean m_dir;
41
42     // Original file name for file/directory rename
43

44     private String JavaDoc m_oldName;
45
46     /**
47      * Class constructor
48      *
49      * @param filter int
50      * @param action int
51      * @param fname String
52      * @param dir boolean
53      */

54     public NotifyChangeEvent(int filter, int action, String JavaDoc fname, boolean dir)
55     {
56         m_filter = filter;
57         m_action = action;
58         m_fileName = fname;
59         m_dir = dir;
60
61         // Normalize the path
62

63         if (m_fileName.indexOf('/') != -1)
64             m_fileName.replace('/', '\\');
65     }
66
67     /**
68      * Class constructor
69      *
70      * @param filter int
71      * @param action int
72      * @param fname String
73      * @param oldname String
74      * @param dir boolean
75      */

76     public NotifyChangeEvent(int filter, int action, String JavaDoc fname, String JavaDoc oldname, boolean dir)
77     {
78         m_filter = filter;
79         m_action = action;
80         m_fileName = fname;
81         m_oldName = oldname;
82         m_dir = dir;
83
84         // Normalize the path
85

86         if (m_fileName.indexOf('/') != -1)
87             m_fileName.replace('/', '\\');
88
89         if (m_oldName.indexOf('/') != -1)
90             m_oldName.replace('/', '\\');
91     }
92
93     /**
94      * Return the event filter type
95      *
96      * @return int
97      */

98     public final int getFilter()
99     {
100         return m_filter;
101     }
102
103     /**
104      * Return the action
105      *
106      * @return int
107      */

108     public final int getAction()
109     {
110         return m_action;
111     }
112
113     /**
114      * Return the file/directory name
115      *
116      * @return String
117      */

118     public final String JavaDoc getFileName()
119     {
120         return m_fileName;
121     }
122
123     /**
124      * Return the file/directory name only by stripping any leading path
125      *
126      * @return String
127      */

128     public final String JavaDoc getShortFileName()
129     {
130
131         // Find the last '\' in the path string
132

133         int pos = m_fileName.lastIndexOf("\\");
134         if (pos != -1)
135             return m_fileName.substring(pos + 1);
136         return m_fileName;
137     }
138
139     /**
140      * Return the old file/directory name, for rename events
141      *
142      * @return String
143      */

144     public final String JavaDoc getOldFileName()
145     {
146         return m_oldName;
147     }
148
149     /**
150      * Return the old file/directory name only by stripping any leading path
151      *
152      * @return String
153      */

154     public final String JavaDoc getShortOldFileName()
155     {
156
157         // Check if the old path string is valid
158

159         if (m_oldName == null)
160             return null;
161
162         // Find the last '\' in the path string
163

164         int pos = m_oldName.lastIndexOf("\\");
165         if (pos != -1)
166             return m_oldName.substring(pos + 1);
167         return m_oldName;
168     }
169
170     /**
171      * Check if the old file/directory name is valid
172      *
173      * @return boolean
174      */

175     public final boolean hasOldFileName()
176     {
177         return m_oldName != null ? true : false;
178     }
179
180     /**
181      * Check if the path refers to a directory
182      *
183      * @return boolean
184      */

185     public final boolean isDirectory()
186     {
187         return m_dir;
188     }
189
190     /**
191      * Return the notify change event as a string
192      *
193      * @return String
194      */

195     public String JavaDoc toString()
196     {
197         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
198
199         str.append("[");
200         str.append(NotifyChange.getFilterAsString(getFilter()));
201         str.append("-");
202         str.append(NotifyChange.getActionAsString(getAction()));
203         str.append(":");
204         str.append(getFileName());
205
206         if (isDirectory())
207             str.append(",DIR");
208
209         if (hasOldFileName())
210         {
211             str.append(",Old=");
212             str.append(getOldFileName());
213         }
214
215         str.append("]");
216
217         return str.toString();
218     }
219 }
220
Popular Tags