1 22 package org.objectweb.petals.classloader; 23 24 import java.io.IOException ; 25 import java.net.URL ; 26 import java.net.URLClassLoader ; 27 import java.util.List ; 28 29 import org.objectweb.petals.PetalsException; 30 31 37 public class LoaderManagerImpl implements LoaderManager { 38 39 42 public LoaderManagerImpl() { 43 super(); 44 } 45 46 50 57 public URLClassLoader createClassLoader(URL [] baseUrls, List <String > classpathLocations, boolean useParentFirst) throws PetalsException { 58 59 PetalsClassLoader cl = null; 61 62 Loaders loaders = Loaders.getInstance(); 63 64 try { 65 cl = new PetalsClassLoader(baseUrls, classpathLocations, loaders.getSharedLibrariesClassLoader()); 66 67 cl.setParentFirst(useParentFirst); 68 } 69 catch (IOException e) { 70 throw new PetalsException("Error while creating a class loader", e); 71 } 72 return cl; 73 } 74 75 81 public void deleteClassLoader(String classLoaderId) { 82 83 Loaders loaders = Loaders.getInstance(); 84 85 if (!containsClassLoader(classLoaderId)) { 86 return; 87 } 88 89 loaders.remove(classLoaderId); 91 loaders.getSharedLibrariesClassLoader().removeSharedLibrariesClassLoader(classLoaderId); 92 } 93 94 97 public boolean containsClassLoader(String classLoaderId) { 98 99 Loaders loaders = Loaders.getInstance(); 100 101 return loaders.contains(classLoaderId); 102 } 103 104 108 public URLClassLoader createComponentClassLoader(String classLoaderId, URL [] baseUrls, List <String > classpathUrls, boolean useParentFirst, List <String > sharedLibrariesNameList) 109 throws PetalsException { 110 111 PetalsClassLoader cl = null; 113 114 Loaders loaders = Loaders.getInstance(); 115 116 try { 117 cl = new ComponentClassLoader(baseUrls, classpathUrls, loaders.getSharedLibrariesClassLoader(), sharedLibrariesNameList); 118 119 cl.setParentFirst(useParentFirst); 120 } 121 catch (IOException e) { 122 throw new PetalsException("Error while creating a class loader", e); 123 } 124 125 loaders.put(classLoaderId, cl); 127 128 return cl; 129 } 130 131 138 public URLClassLoader createSharedLibrariesClassLoader(String classLoaderId, URL [] baseUrls, List <String > classpathUrls, boolean useParentFirst) throws PetalsException { 139 140 PetalsClassLoader cl = null; 142 143 try { 144 cl = new PetalsClassLoader(baseUrls, classpathUrls); 145 cl.setParentFirst(useParentFirst); 146 } 147 catch (IOException e) { 148 throw new PetalsException("Error while creating a class loader", e); 149 } 150 151 Loaders loaders = Loaders.getInstance(); 153 154 loaders.put(classLoaderId, cl); 155 loaders.getSharedLibrariesClassLoader().addSharedLibrariesClassLoader(classLoaderId, cl); 156 157 return cl; 158 } 159 160 } 161 | Popular Tags |