KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > gsf > Index


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.gsf;
21
22 import java.io.IOException JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.Set JavaDoc;
26
27 /**
28  * This class represents an index that is provided by the IDE to a language
29  * plugin for storage and retrieval. Language plugins should not subclass this class.
30  *
31  * @author Tor Norbye
32  */

33 public abstract class Index {
34     
35     public Index() {
36     }
37     
38     /**
39      * Encodes a type of the name kind used by
40      * {@link ClassIndex#getDeclaredTypes} method.
41      *
42      */

43     public enum NameKind {
44         /**
45          * The name parameter of the {@link ClassIndex#getDeclaredTypes}
46          * is an exact simple name of the package or declared type.
47          * @todo Rename to EXACT_NAME
48          */

49         EXACT_NAME,
50         
51         /**
52          * The name parameter of the {@link ClassIndex#getDeclaredTypes}
53          * is an case sensitive prefix of the package or declared type name.
54          */

55         PREFIX,
56         
57         /**
58          * The name parameter of the {@link ClassIndex#getDeclaredTypes} is
59          * an case insensitive prefix of the declared type name.
60          */

61         CASE_INSENSITIVE_PREFIX,
62         
63         /**
64          * The name parameter of the {@link ClassIndex#getDeclaredTypes} is
65          * an camel case of the declared type name.
66          */

67         CAMEL_CASE,
68         
69         
70         /**
71          * The name parameter of the {@link ClassIndex#getDeclaredTypes} is
72          * an regular expression of the declared type name.
73          */

74         REGEXP,
75         
76         /**
77          * The name parameter of the {@link ClassIndex#getDeclaredTypes} is
78          * an case insensitive regular expression of the declared type name.
79          */

80         CASE_INSENSITIVE_REGEXP
81     };
82     
83     
84     /**
85      * Encodes a reference type,
86      * used by {@link ClassIndex#getElements} and {@link ClassIndex#getResources}
87      * to restrict the search.
88      */

89     public enum SearchKind {
90         
91         /**
92          * The returned class has to extend or implement given element
93          */

94         IMPLEMENTORS,
95         
96         /**
97          * The returned class has to call method on given element
98          */

99         METHOD_REFERENCES,
100         
101         /**
102          * The returned class has to access a field on given element
103          */

104         FIELD_REFERENCES,
105         
106         /**
107          * The returned class contains references to the element type
108          */

109         TYPE_REFERENCES,
110     };
111     
112     /**
113      * Scope used by {@link ClassIndex} to search in
114      */

115     public enum SearchScope {
116         /**
117          * Search is done in source path
118          */

119         SOURCE,
120         /**
121          * Search is done in compile and boot path
122          */

123         DEPENDENCIES
124     };
125
126     /**
127      * Result corresponding to a "document" in the
128      * index. Each document contains name,value pairs.
129      * Some pairs are unique (a single key and value)
130      * whereas others have many values for a single key.
131      * Call getValues() on the latter.
132      *
133      * @todo There's some asymmetry between gsfStore and
134      * gsfSearch now, in that the store operation
135      * takes a set of maps, whereas the result is a
136      * set of SearchResults (which are map-like). Originally
137      * I returned a set of maps, but the maps aren't
138      * really maps since they wrap Lucene documents,
139      * which don't support all the map operations.
140      * Possibly I could offer some kind of SearchDocument
141      * interface here to be passed in instead for better
142      * symmetry, as long as it's convenient to use.
143      */

144     public interface SearchResult {
145         String JavaDoc getValue(String JavaDoc key);
146         String JavaDoc[] getValues(String JavaDoc key);
147         
148         // For index browser (development/debugging aid) only
149
Object JavaDoc getIndex(); // GSF Index
150
Object JavaDoc getDocument(); // Lucene Document
151
Object JavaDoc getIndexReader(); // Lucene IndexReader
152
java.io.File JavaDoc getSegment(); // Segment directory
153
//String[] getKeys(); // Set of field
154
int getDocumentNumber();
155     }
156     
157     // TODO: Find a way to communicate which fields should not be tokenized or indexed...
158

159     // Store map of class names, where each entry has a map of fields and values (fields might be "name", "fqn", "case insensitive name", etc.
160
// The same fields can be looked up later.
161
// TODO: The first key is redundant here (it's repeated as part of the fields; just make this a List<Map> instead!
162
public abstract void gsfStore(Set JavaDoc<Map JavaDoc<String JavaDoc,String JavaDoc>> fieldToData, Set JavaDoc<Map JavaDoc<String JavaDoc,String JavaDoc>> noIndexData, Map JavaDoc<String JavaDoc,String JavaDoc> toDelete) throws IOException JavaDoc;
163     public abstract void gsfSearch(final String JavaDoc primaryField, final String JavaDoc name, final NameKind kind,
164             final Set JavaDoc<SearchScope> scope, final Set JavaDoc<SearchResult> result) throws IOException JavaDoc;
165 }
166
Popular Tags