KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > core > ShareType


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.core;
18
19 /**
20  * <p>
21  * Available shared resource types.
22  */

23 public class ShareType
24 {
25     // Disk share resource type.
26

27     public static final int DISK = 0;
28
29     // Printer share resource type.
30

31     public static final int PRINTER = 1;
32
33     // Named pipe/IPC share resource type.
34

35     public static final int NAMEDPIPE = 2;
36
37     // Remote administration named pipe, IPC$
38

39     public static final int ADMINPIPE = 3;
40
41     // Unknown share type
42

43     public static final int UNKNOWN = -1;
44
45     /**
46      * Return the share type as a share information type.
47      *
48      * @return int
49      * @param typ int
50      */

51     public final static int asShareInfoType(int typ)
52     {
53
54         // Convert the share type value to a valid share information structure share type
55
// value.
56

57         int shrTyp = 0;
58
59         switch (typ)
60         {
61         case DISK:
62             shrTyp = 0;
63             break;
64         case PRINTER:
65             shrTyp = 1;
66             break;
67         case NAMEDPIPE:
68         case ADMINPIPE:
69             shrTyp = 3;
70             break;
71         }
72         return shrTyp;
73     }
74
75     /**
76      * Return the SMB service name as a shared device type.
77      *
78      * @return int
79      * @param srvName java.lang.String
80      */

81     public final static int ServiceAsType(String JavaDoc srvName)
82     {
83
84         // Check the service name
85

86         if (srvName.compareTo("A:") == 0)
87             return DISK;
88         else if (srvName.compareTo("LPT1:") == 0)
89             return PRINTER;
90         else if (srvName.compareTo("IPC") == 0)
91             return NAMEDPIPE;
92
93         // Unknown service name string
94

95         return UNKNOWN;
96     }
97
98     /**
99      * Return the share type as a service string.
100      *
101      * @return java.lang.String
102      * @param typ int
103      */

104     public final static String JavaDoc TypeAsService(int typ)
105     {
106
107         if (typ == DISK)
108             return "A:";
109         else if (typ == PRINTER)
110             return "LPT1:";
111         else if (typ == NAMEDPIPE || typ == ADMINPIPE)
112             return "IPC";
113         return "";
114     }
115
116     /**
117      * Return the share type as a string.
118      *
119      * @return java.lang.String
120      * @param typ int
121      */

122     public final static String JavaDoc TypeAsString(int typ)
123     {
124
125         if (typ == DISK)
126             return "DISK";
127         else if (typ == PRINTER)
128             return "PRINT";
129         else if (typ == NAMEDPIPE)
130             return "PIPE";
131         else if (typ == ADMINPIPE)
132             return "IPC$";
133         return "<Unknown>";
134     }
135 }
Popular Tags