KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > filesys > NotifyChange


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.server.filesys;
18
19 /**
20  * Notify Change Transaction Class
21  */

22 public class NotifyChange
23 {
24
25     // Change notification filter flags
26

27     public final static int FileName = 0x0001;
28     public final static int DirectoryName = 0x0002;
29     public final static int Attributes = 0x0004;
30     public final static int Size = 0x0008;
31     public final static int LastWrite = 0x0010;
32     public final static int LastAccess = 0x0020;
33     public final static int Creation = 0x0040;
34     public final static int Security = 0x0100;
35
36     // Change notification actions
37

38     public final static int ActionAdded = 1;
39     public final static int ActionRemoved = 2;
40     public final static int ActionModified = 3;
41     public final static int ActionRenamedOldName = 4;
42     public final static int ActionRenamedNewName = 5;
43     public final static int ActionAddedStream = 6;
44     public final static int ActionRemovedStream = 7;
45     public final static int ActionModifiedStream = 8;
46
47     // Change notification action names
48

49     private final static String JavaDoc[] _actnNames = { "Added", "Removed", "Modified", "RenamedOldName", "RenamedNewName",
50             "AddedStream", "RemovedStream", "ModifiedStream" };
51
52     /**
53      * Return the change notification action as a string
54      *
55      * @param action int
56      * @return String
57      */

58     public static final String JavaDoc getActionAsString(int action)
59     {
60
61         // Range check the action
62

63         if (action <= 0 || action > _actnNames.length)
64             return "Unknown";
65
66         // Return the action as a string
67

68         return _actnNames[action - 1];
69     }
70
71     /**
72      * Return the change notification filter flag as a string. This method assumes a single flag is
73      * set.
74      *
75      * @param filter int
76      * @return String
77      */

78     public static final String JavaDoc getFilterAsString(int filter)
79     {
80
81         // Check if there are any flags set
82

83         if (filter == 0)
84             return "";
85
86         // Determine the filter type
87

88         String JavaDoc filtStr = null;
89
90         switch (filter)
91         {
92         case FileName:
93             filtStr = "FileName";
94             break;
95         case DirectoryName:
96             filtStr = "DirectoryName";
97             break;
98         case Attributes:
99             filtStr = "Attributes";
100             break;
101         case Size:
102             filtStr = "Size";
103             break;
104         case LastWrite:
105             filtStr = "LastWrite";
106             break;
107         case LastAccess:
108             filtStr = "LastAccess";
109             break;
110         case Creation:
111             filtStr = "Creation";
112             break;
113         case Security:
114             filtStr = "Security";
115             break;
116         }
117
118         // Return the filter type string
119

120         return filtStr;
121     }
122
123     /**
124      * Return the change notification filter flags as a string.
125      *
126      * @param filter int
127      * @return String
128      */

129     public static final String JavaDoc getFilterFlagsAsString(int filter)
130     {
131
132         // Check if there are any flags set
133

134         if (filter == 0)
135             return "";
136
137         // Build the filter flags string
138

139         StringBuffer JavaDoc filtStr = new StringBuffer JavaDoc();
140         int i = 0x0001;
141
142         while (i < Security)
143         {
144
145             // Check if the current filter flag is set
146

147             if ((filter & i) != 0)
148             {
149
150                 // Get the filter flag name
151

152                 String JavaDoc name = getFilterAsString(i);
153                 if (name != null)
154                 {
155                     if (filtStr.length() > 0)
156                         filtStr.append(",");
157                     filtStr.append(name);
158                 }
159             }
160
161             // Update the filter flag mask
162

163             i = i << 1;
164         }
165
166         // Return the filter flags string
167

168         return filtStr.toString();
169     }
170 }
171
Popular Tags