1 19 20 package org.netbeans.api.java.queries; 21 22 import java.net.URL ; 23 import java.util.Arrays ; 24 import javax.swing.event.ChangeListener ; 25 import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; 26 import org.openide.ErrorManager; 27 import org.openide.filesystems.FileUtil; 28 import org.openide.util.Lookup; 29 30 35 public class JavadocForBinaryQuery { 36 37 private static final ErrorManager ERR = ErrorManager.getDefault().getInstance(JavadocForBinaryQuery.class.getName()); 38 39 private static final Lookup.Result<? extends JavadocForBinaryQueryImplementation> implementations = 40 Lookup.getDefault().lookupResult(JavadocForBinaryQueryImplementation.class); 41 42 private JavadocForBinaryQuery () { 43 } 44 45 55 public static Result findJavadoc(URL binary) { 56 if (FileUtil.isArchiveFile(binary)) { 57 throw new IllegalArgumentException ("File URL pointing to " + "JAR is not valid classpath entry. Use jar: URL. Was: "+binary); } 60 boolean log = ERR.isLoggable(ErrorManager.INFORMATIONAL); 61 if (log) ERR.log("JFBQ.findJavadoc: " + binary); 62 for (JavadocForBinaryQueryImplementation impl : implementations.allInstances()) { 63 Result r = impl.findJavadoc(binary); 64 if (r != null) { 65 if (log) ERR.log(" got result " + Arrays.asList(r.getRoots()) + " from " + impl); 66 return r; 67 } else { 68 if (log) ERR.log(" got no result from " + impl); 69 } 70 } 71 if (log) ERR.log(" got no results from any impl"); 72 return EMPTY_RESULT; 73 } 74 75 79 public interface Result { 80 81 88 URL [] getRoots(); 89 90 94 void addChangeListener(ChangeListener l); 95 96 100 void removeChangeListener(ChangeListener l); 101 102 } 103 104 private static final Result EMPTY_RESULT = new EmptyResult(); 105 private static final class EmptyResult implements Result { 106 private static final URL [] NO_ROOTS = new URL [0]; 107 EmptyResult() {} 108 public URL [] getRoots() { 109 return NO_ROOTS; 110 } 111 public void addChangeListener(ChangeListener l) {} 112 public void removeChangeListener(ChangeListener l) {} 113 } 114 115 } 116 | Popular Tags |