KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > DialectSelector


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;
18
19 import java.util.BitSet JavaDoc;
20
21 /**
22  * SMB dialect selector class.
23  */

24 public class DialectSelector
25 {
26
27     // Bit set of selected SMB dialects.
28

29     private BitSet JavaDoc dialects;
30
31     /**
32      * Construct a new SMB dialect selector with the SMB core protocol selected.
33      */

34
35     public DialectSelector()
36     {
37         dialects = new BitSet JavaDoc(Dialect.Max);
38
39         // Select only the core protocol by default
40

41         ClearAll();
42         AddDialect(Dialect.Core);
43     }
44
45     /**
46      * Add a dialect to the list of available SMB dialects.
47      *
48      * @param idx Index of the dialect to add to the available dialects.
49      * @exception java.lang.ArrayIndexOutOfBoundsException Invalid dialect index.
50      */

51
52     public void AddDialect(int d) throws java.lang.ArrayIndexOutOfBoundsException JavaDoc
53     {
54         dialects.set(d);
55     }
56
57     /**
58      * Clear all the dialect bits.
59      */

60
61     public void ClearAll()
62     {
63         for (int i = 0; i < dialects.size(); dialects.clear(i++))
64             ;
65     }
66
67     /**
68      * Copy the SMB dialect selector settings.
69      *
70      * @param dsel DialectSelector
71      */

72     public void copyFrom(DialectSelector dsel)
73     {
74
75         // Clear all current settings
76

77         ClearAll();
78
79         // Copy the settings
80

81         for (int i = 0; i < Dialect.Max; i++)
82         {
83
84             // Check if the dialect is enabled
85

86             if (dsel.hasDialect(i))
87                 AddDialect(i);
88         }
89     }
90
91     /**
92      * Determine if the specified SMB dialect is selected/available.
93      *
94      * @param idx Index of the dialect to test for.
95      * @return true if the SMB dialect is available, else false.
96      * @exception java.lang.ArrayIndexOutOfBoundsException Invalid dialect index.
97      */

98
99     public boolean hasDialect(int d) throws java.lang.ArrayIndexOutOfBoundsException JavaDoc
100     {
101         return dialects.get(d);
102     }
103
104     /**
105      * Determine if the core SMB dialect is enabled
106      *
107      * @return boolean
108      */

109     public boolean hasCore()
110     {
111         if (hasDialect(Dialect.Core) || hasDialect(Dialect.CorePlus))
112             return true;
113         return false;
114     }
115
116     /**
117      * Determine if the LanMan SMB dialect is enabled
118      *
119      * @return boolean
120      */

121     public boolean hasLanMan()
122     {
123         if (hasDialect(Dialect.DOSLanMan1) || hasDialect(Dialect.DOSLanMan2) || hasDialect(Dialect.LanMan1)
124                 || hasDialect(Dialect.LanMan2) || hasDialect(Dialect.LanMan2_1))
125             return true;
126         return false;
127     }
128
129     /**
130      * Determine if the NT SMB dialect is enabled
131      *
132      * @return boolean
133      */

134     public boolean hasNT()
135     {
136         if (hasDialect(Dialect.NT))
137             return true;
138         return false;
139     }
140
141     /**
142      * Remove an SMB dialect from the list of available dialects.
143      *
144      * @param idx Index of the dialect to remove.
145      * @exception java.lang.ArrayIndexOutOfBoundsException Invalid dialect index.
146      */

147
148     public void RemoveDialect(int d) throws java.lang.ArrayIndexOutOfBoundsException JavaDoc
149     {
150         dialects.clear(d);
151     }
152
153     /**
154      * Return the dialect selector list as a string.
155      *
156      * @return java.lang.String
157      */

158     public String JavaDoc toString()
159     {
160
161         // Create a string buffer to build the return string
162

163         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
164         str.append("[");
165
166         for (int i = 0; i < dialects.size(); i++)
167         {
168             if (hasDialect(i))
169             {
170                 str.append(Dialect.DialectTypeString(i));
171                 str.append(",");
172             }
173         }
174
175         // Trim the last comma and return the string
176

177         if (str.length() > 1)
178             str.setLength(str.length() - 1);
179         str.append("]");
180         return str.toString();
181     }
182 }
Popular Tags