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.SourceForBinaryQueryImplementation; 26 import org.openide.ErrorManager; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileUtil; 29 import org.openide.util.Lookup; 30 31 42 public class SourceForBinaryQuery { 43 44 private static final ErrorManager ERR = ErrorManager.getDefault().getInstance(SourceForBinaryQuery.class.getName()); 45 46 private static final Lookup.Result<? extends SourceForBinaryQueryImplementation> implementations = 47 Lookup.getDefault().lookupResult (SourceForBinaryQueryImplementation.class); 48 49 private SourceForBinaryQuery () { 50 } 51 52 57 public static Result findSourceRoots (URL binaryRoot) { 58 if (FileUtil.isArchiveFile(binaryRoot)) { 59 throw new IllegalArgumentException ("File URL pointing to " + "JAR is not valid classpath entry. Use jar: URL. Was: "+binaryRoot); } 62 if (!binaryRoot.toExternalForm().endsWith("/")) { 63 throw new IllegalArgumentException ("Folder URL must end with '/'. Was: "+binaryRoot); 64 } 65 boolean log = ERR.isLoggable(ErrorManager.INFORMATIONAL); 66 if (log) ERR.log("SFBQ.findSourceRoots: " + binaryRoot); 67 for (SourceForBinaryQueryImplementation impl : implementations.allInstances()) { 68 Result result = impl.findSourceRoots(binaryRoot); 69 if (result != null) { 70 if (log) ERR.log(" got result " + Arrays.asList(result.getRoots()) + " from " + impl); 71 return result; 72 } 73 } 74 return EMPTY_RESULT; 75 } 76 77 81 public interface Result { 82 83 87 FileObject[] getRoots(); 88 89 93 void addChangeListener(ChangeListener l); 94 95 99 void removeChangeListener(ChangeListener l); 100 101 } 102 103 private static final Result EMPTY_RESULT = new EmptyResult(); 104 private static final class EmptyResult implements Result { 105 private static final FileObject[] NO_ROOTS = new FileObject[0]; 106 EmptyResult() {} 107 public FileObject[] getRoots() { 108 return NO_ROOTS; 109 } 110 public void addChangeListener(ChangeListener l) {} 111 public void removeChangeListener(ChangeListener l) {} 112 } 113 114 } 115 | Popular Tags |