KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > search > JavadocSearchEngineImpl


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 /*
21  * JavadocSearchEngineImpl.java
22  *
23  * Created on 18. ?erven 2001, 14:55
24  */

25
26 package org.netbeans.modules.javadoc.search;
27
28 import java.util.ArrayList JavaDoc;
29 import org.openide.ErrorManager;
30
31 import org.openide.filesystems.FileObject;
32
33 /**
34  *
35  * @author Petr Suchomel
36  * @version 0.1
37  */

38 class JavadocSearchEngineImpl extends JavadocSearchEngine {
39
40     private ArrayList JavaDoc tasks;
41
42     private IndexSearchThread.DocIndexItemConsumer diiConsumer;
43
44     /** Used to search for set elements in javadoc repository
45      * @param items to search for
46      * @throws NoJavadocException if no javadoc directory is mounted, nothing can be searched
47      */

48     public void search(String JavaDoc[] items, final SearchEngineCallback callback) throws NoJavadocException {
49         FileObject docRoots[] = JavadocRegistry.getDefault().getDocRoots();
50         tasks = new ArrayList JavaDoc( docRoots.length );
51
52         diiConsumer = new IndexSearchThread.DocIndexItemConsumer() {
53                           public void addDocIndexItem( final DocIndexItem dii ) {
54                               callback.addItem(dii);
55                           }
56
57                           public void indexSearchThreadFinished( IndexSearchThread t ) {
58                               tasks.remove( t );
59                               if ( tasks.isEmpty() )
60                                   callback.finished();
61                           }
62                       };
63                       
64         if ( docRoots.length <= 0 ) {
65             callback.finished();
66             throw new NoJavadocException();
67         }
68         String JavaDoc toFind = items[0];
69         
70         for( int i = 0; i < docRoots.length; i++ ) {
71             
72             JavadocSearchType st = JavadocRegistry.getDefault().findSearchType( docRoots[i] );
73             if (st == null) {
74                 ErrorManager.getDefault().log ("NO Search type for " + docRoots[i]);
75                 continue;
76             }
77             FileObject indexFo = st.getDocFileObject( docRoots[i] );
78             if (indexFo == null) {
79                 ErrorManager.getDefault().log ("NO Index files fot " + docRoots[i] );
80                 continue;
81             }
82             
83             IndexSearchThread searchThread = st.getSearchThread( toFind, indexFo, diiConsumer );
84
85             tasks.add( searchThread );
86             searchThread.go();
87         }
88         //callback.finished();
89
}
90     
91     /** Stops execution of Javadoc search thread
92      */

93     public void stop() {
94         for( int i = 0; i < tasks.size(); i++ ) {
95             SearchThreadJdk12 searchThread = (SearchThreadJdk12)tasks.get( i );
96             searchThread.finish();
97         }
98     }
99 }
100
Popular Tags