KickJava   Java API By Example, From Geeks To Geeks.

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


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  * <p>
21  * The file actions are sent in OpenAndX and NTCreateAndX request/response SMBs.
22  */

23 public final class FileAction
24 {
25     // File open action request codes
26

27     public static final int FailIfExists = 0x0000;
28     public static final int OpenIfExists = 0x0001;
29     public static final int TruncateExisting = 0x0002;
30     public static final int CreateNotExist = 0x0010;
31
32     // File open action response codes
33

34     public static final int FileExisted = 0x0001;
35     public static final int FileCreated = 0x0002;
36     public static final int FileTruncated = 0x0003;
37
38     // NT file/device open action codes
39

40     public final static int NTSupersede = 0; // supersede if exists, else create a new file
41
public final static int NTOpen = 1; // only open if the file exists
42
public final static int NTCreate = 2; // create if file does not exist, else fail
43
public final static int NTOpenIf = 3; // open if exists else create
44
public final static int NTOverwrite = 4; // overwrite if exists, else fail
45
public final static int NTOverwriteIf = 5; // overwrite if exists, else create
46

47     /**
48      * Check if the file action value indicates that the file should be created if the file does not
49      * exist.
50      *
51      * @return boolean
52      * @param action int
53      */

54     public final static boolean createNotExists(int action)
55     {
56         if ((action & CreateNotExist) != 0)
57             return true;
58         return false;
59     }
60
61     /**
62      * Check if the open file if exists action is set.
63      *
64      * @return boolean
65      * @param action int
66      */

67     public final static boolean openIfExists(int action)
68     {
69         if ((action & OpenIfExists) != 0)
70             return true;
71         return false;
72     }
73
74     /**
75      * Check if the existing file should be truncated.
76      *
77      * @return boolean
78      * @param action int
79      */

80     public final static boolean truncateExistingFile(int action)
81     {
82         if ((action & TruncateExisting) != 0)
83             return true;
84         return false;
85     }
86
87     /**
88      * Convert the file exists action flags to a string
89      *
90      * @param flags int
91      * @return String
92      */

93     public final static String JavaDoc asString(int flags)
94     {
95         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
96
97         str.append("[0x");
98         str.append(Integer.toHexString(flags));
99         str.append(":");
100
101         if (openIfExists(flags))
102             str.append("OpenExists|");
103
104         if (truncateExistingFile(flags))
105             str.append("Truncate|");
106
107         if (createNotExists(flags))
108             str.append("CreateNotExist");
109
110         str.append("]");
111
112         return str.toString();
113     }
114 }
Popular Tags