1 24 25 package com.rift.coad.lib.loader; 27 28 import org.apache.log4j.Logger; 30 31 32 import java.lang.ClassLoader ; 34 import java.net.URLClassLoader ; 35 import java.net.URL ; 36 import java.io.File ; 37 38 import com.rift.coad.BaseClassLoader; 40 41 47 public class MasterClassLoader { 48 49 private static MasterClassLoader singleton = null; 51 52 protected Logger log = 54 Logger.getLogger(MasterClassLoader.class.getName()); 55 56 private URLClassLoader classLoader = null; 58 59 60 65 private MasterClassLoader() throws LoaderException { 66 try { 67 classLoader = (URLClassLoader )this.getClass().getClassLoader(); 68 } catch (Exception ex) { 69 throw new LoaderException( 70 "Failed to retrieve the parent class loader : " + 71 ex.getMessage(),ex); 72 } 73 } 74 75 78 public static synchronized MasterClassLoader init() throws 79 LoaderException { 80 if (singleton == null) { 81 singleton = new MasterClassLoader(); 82 } 83 return singleton; 84 } 85 86 87 90 public static synchronized MasterClassLoader getInstance() throws 91 LoaderException { 92 if (singleton == null) { 93 singleton = new MasterClassLoader(); 94 } 95 return singleton; 96 } 97 98 99 102 public void addLib(String path) throws LoaderException { 103 try { 104 if (classLoader instanceof BaseClassLoader) { 105 ((BaseClassLoader)classLoader).addLib(path); 106 } else { 107 log.error( 108 "This object has not been loaded by a BaseClassLoader"); 109 } 110 } catch (Exception ex) { 111 throw new LoaderException("Failed to add the library [" + path + 112 "] because : " + ex.getMessage(),ex); 113 } 114 } 115 116 117 122 public ClassLoader getLoader() { 123 return classLoader; 124 } 125 } 126 | Popular Tags |