1 19 package org.openide.filesystems; 20 21 import java.util.logging.Level ; 22 import java.util.logging.Logger ; 23 import org.openide.util.Exceptions; 24 import org.openide.util.Lookup; 25 26 27 32 final class ExternalUtil extends Object { 33 34 private static Repository repository; 35 36 39 public static Repository getRepository() { 40 initialize(); 41 42 return repository; 43 } 44 45 47 public static void exception(Exception ex) { 48 Logger.getLogger(ExternalUtil.class.getName()).log(Level.WARNING, null, ex); 49 } 50 51 56 public static Throwable copyAnnotation(Throwable newEx, Throwable oldEx) { 57 return newEx.initCause(oldEx); 58 } 59 60 62 public static void annotate(Throwable ex, String msg) { 63 Exceptions.attachLocalizedMessage(ex, msg); 64 } 65 66 68 public static Throwable annotate(Throwable ex, Throwable stack) { 69 Throwable orig = ex; 70 while (ex.getCause() != null) { 71 ex = ex.getCause(); 72 } 73 ex.initCause(stack); 74 return orig; 75 } 76 77 private static Logger LOG = Logger.getLogger("org.openide.filesystems"); 80 public static void log(String msg) { 81 LOG.fine(msg); 82 } 83 84 89 public static Class findClass(String name) throws ClassNotFoundException { 90 initialize(); 91 92 ClassLoader c = Lookup.getDefault().lookup(ClassLoader .class); 93 94 if (c == null) { 95 return Class.forName(name); 96 } else { 97 return Class.forName(name, true, c); 98 } 99 } 100 101 103 private static void initialize() { 104 if (!isInitialized()) { 105 Lookup l = Lookup.getDefault(); 106 Repository rep = l.lookup(org.openide.filesystems.Repository.class); 107 setRepository(rep); 108 } 109 } 110 111 private static synchronized boolean isInitialized() { 112 return repository != null; 113 } 114 115 118 private static synchronized void setRepository(Repository rep) { 119 repository = rep; 120 121 if (repository == null) { 122 repository = new Repository(FileUtil.createMemoryFileSystem()); 124 } 125 } 126 } 127 | Popular Tags |