1 19 20 package org.openide.modules; 21 22 import java.io.File ; 23 import java.util.Collection ; 24 import org.openide.util.Lookup; 25 import org.openide.util.LookupEvent; 26 import org.openide.util.LookupListener; 27 28 36 public abstract class InstalledFileLocator { 37 private static final InstalledFileLocator DEFAULT = new InstalledFileLocator() { 38 public File locate(String rp, String cnb, boolean l) { 39 InstalledFileLocator[] ifls = getInstances(); 40 41 for (int i = 0; i < ifls.length; i++) { 42 File f = ifls[i].locate(rp, cnb, l); 43 44 if (f != null) { 45 return f; 46 } 47 } 48 49 return null; 50 } 51 }; 52 53 private static InstalledFileLocator[] instances = null; 54 private static Lookup.Result<InstalledFileLocator> result = null; 55 60 private static final Object LOCK = new String (InstalledFileLocator.class.getName()); 61 62 65 protected InstalledFileLocator() { 66 } 67 68 163 public abstract File locate(String relativePath, String codeNameBase, boolean localized); 164 165 174 public static InstalledFileLocator getDefault() { 175 return DEFAULT; 176 } 177 178 private static InstalledFileLocator[] getInstances() { 179 synchronized (LOCK) { 180 if (instances != null) { 181 return instances; 182 } 183 } 184 185 Lookup.Result<InstalledFileLocator> _result; 186 synchronized (LOCK) { 187 _result = result; 188 } 189 if (_result == null) { 190 _result = Lookup.getDefault().lookupResult(InstalledFileLocator.class); 191 _result.addLookupListener(new LookupListener() { 192 public void resultChanged(LookupEvent e) { 193 synchronized (LOCK) { 194 instances = null; 195 } 196 } 197 }); 198 synchronized (LOCK) { 199 result = _result; 200 } 201 } 202 203 Collection <? extends InstalledFileLocator> c = _result.allInstances(); 204 synchronized (LOCK) { 205 return instances = c.toArray(new InstalledFileLocator[c.size()]); 206 } 207 } 208 209 } 210 | Popular Tags |