001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * JavadocSearchEngineImpl.java
044: *
045: * Created on 18. ?erven 2001, 14:55
046: */
047:
048: package org.netbeans.modules.javadoc.search;
049:
050: import java.util.ArrayList;
051: import org.openide.ErrorManager;
052:
053: import org.openide.filesystems.FileObject;
054:
055: /**
056: *
057: * @author Petr Suchomel
058: * @version 0.1
059: */
060: class JavadocSearchEngineImpl extends JavadocSearchEngine {
061:
062: private ArrayList tasks;
063:
064: private IndexSearchThread.DocIndexItemConsumer diiConsumer;
065:
066: /** Used to search for set elements in javadoc repository
067: * @param items to search for
068: * @throws NoJavadocException if no javadoc directory is mounted, nothing can be searched
069: */
070: public void search(String[] items,
071: final SearchEngineCallback callback)
072: throws NoJavadocException {
073: FileObject docRoots[] = JavadocRegistry.getDefault()
074: .getDocRoots();
075: tasks = new ArrayList(docRoots.length);
076:
077: diiConsumer = new IndexSearchThread.DocIndexItemConsumer() {
078: public void addDocIndexItem(final DocIndexItem dii) {
079: callback.addItem(dii);
080: }
081:
082: public void indexSearchThreadFinished(IndexSearchThread t) {
083: tasks.remove(t);
084: if (tasks.isEmpty())
085: callback.finished();
086: }
087: };
088:
089: if (docRoots.length <= 0) {
090: callback.finished();
091: throw new NoJavadocException();
092: }
093: String toFind = items[0];
094:
095: for (int i = 0; i < docRoots.length; i++) {
096:
097: JavadocSearchType st = JavadocRegistry.getDefault()
098: .findSearchType(docRoots[i]);
099: if (st == null) {
100: ErrorManager.getDefault().log(
101: "NO Search type for " + docRoots[i]);
102: continue;
103: }
104: FileObject indexFo = st.getDocFileObject(docRoots[i]);
105: if (indexFo == null) {
106: ErrorManager.getDefault().log(
107: "NO Index files fot " + docRoots[i]);
108: continue;
109: }
110:
111: IndexSearchThread searchThread = st.getSearchThread(toFind,
112: indexFo, diiConsumer);
113:
114: tasks.add(searchThread);
115: searchThread.go();
116: }
117: //callback.finished();
118: }
119:
120: /** Stops execution of Javadoc search thread
121: */
122: public void stop() {
123: for (int i = 0; i < tasks.size(); i++) {
124: SearchThreadJdk12 searchThread = (SearchThreadJdk12) tasks
125: .get(i);
126: searchThread.finish();
127: }
128: }
129: }
|