KickJava   Java API By Example, From Geeks To Geeks.

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


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 search context represents the state of an active search by a disk interface based class. The
22  * context is used to continue a search across multiple requests.
23  */

24 public abstract class SearchContext
25 {
26
27     // Maximum number of files to return per search request.
28

29     private int m_maxFiles;
30
31     // Tree identifier that this search is associated with
32

33     private int m_treeId;
34
35     // Search string
36

37     private String JavaDoc m_searchStr;
38
39     // Flags
40

41     private int m_flags;
42
43     /**
44      * Default constructor.
45      */

46     public SearchContext()
47     {
48     }
49
50     /**
51      * Construct a new search context.
52      *
53      * @param maxFiles int
54      * @param treeId int
55      */

56     protected SearchContext(int maxFiles, int treeId)
57     {
58         m_maxFiles = maxFiles;
59         m_treeId = treeId;
60     }
61
62     /**
63      * Close the search.
64      */

65     public void closeSearch()
66     {
67     }
68
69     /**
70      * Return the search context flags.
71      *
72      * @return int
73      */

74     public final int getFlags()
75     {
76         return m_flags;
77     }
78
79     /**
80      * Return the maximum number of files that should be returned per search request.
81      *
82      * @return int
83      */

84     public final int getMaximumFiles()
85     {
86         return m_maxFiles;
87     }
88
89     /**
90      * Return the resume id for the current file/directory in the search.
91      *
92      * @return int
93      */

94     public abstract int getResumeId();
95
96     /**
97      * Return the search string, used for resume keys in some SMB dialects.
98      *
99      * @return java.lang.String
100      */

101     public final String JavaDoc getSearchString()
102     {
103         return m_searchStr != null ? m_searchStr : "";
104     }
105
106     /**
107      * Return the tree identifier of the tree connection that this search is associated with.
108      *
109      * @return int
110      */

111     public final int getTreeId()
112     {
113         return m_treeId;
114     }
115
116     /**
117      * Determine if there are more files for the active search.
118      *
119      * @return boolean
120      */

121     public abstract boolean hasMoreFiles();
122
123     /**
124      * Return file information for the next file in the active search. Returns false if the search
125      * is complete.
126      *
127      * @param info FileInfo to return the file information.
128      * @return true if the file information is valid, else false
129      */

130     public abstract boolean nextFileInfo(FileInfo info);
131
132     /**
133      * Return the file name of the next file in the active search. Returns null is the search is
134      * complete.
135      *
136      * @return java.lang.String
137      */

138     public abstract String JavaDoc nextFileName();
139
140     /**
141      * Return the total number of file entries for this search if known, else return -1
142      *
143      * @return int
144      */

145     public int numberOfEntries()
146     {
147         return -1;
148     }
149
150     /**
151      * Restart a search at the specified resume point.
152      *
153      * @param resumeId Resume point id.
154      * @return true if the search can be restarted, else false.
155      */

156     public abstract boolean restartAt(int resumeId);
157
158     /**
159      * Restart the current search at the specified file.
160      *
161      * @param info File to restart the search at.
162      * @return true if the search can be restarted, else false.
163      */

164     public abstract boolean restartAt(FileInfo info);
165
166     /**
167      * Set the search context flags.
168      *
169      * @param flg int
170      */

171     public final void setFlags(int flg)
172     {
173         m_flags = flg;
174     }
175
176     /**
177      * Set the maximum files to return per request packet.
178      *
179      * @param maxFiles int
180      */

181     public final void setMaximumFiles(int maxFiles)
182     {
183         m_maxFiles = maxFiles;
184     }
185
186     /**
187      * Set the search string.
188      *
189      * @param str java.lang.String
190      */

191     public final void setSearchString(String JavaDoc str)
192     {
193         m_searchStr = str;
194     }
195
196     /**
197      * Set the tree connection id that the search is associated with.
198      *
199      * @param id int
200      */

201     public final void setTreeId(int id)
202     {
203         m_treeId = id;
204     }
205
206     /**
207      * Return the search context as a string.
208      *
209      * @return java.lang.String
210      */

211     public String JavaDoc toString()
212     {
213         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
214         str.append("[");
215         str.append(getSearchString());
216         str.append(":");
217         str.append(getMaximumFiles());
218         str.append(",");
219         str.append("0x");
220         str.append(Integer.toHexString(getFlags()));
221         str.append("]");
222
223         return str.toString();
224     }
225 }
Popular Tags