1 17 18 21 package org.quartz.simpl; 22 23 import java.util.Iterator ; 24 import java.util.LinkedList ; 25 import java.net.URL ; 26 import java.io.InputStream ; 27 28 import org.quartz.spi.ClassLoadHelper; 29 30 53 public class CascadingClassLoadHelper implements ClassLoadHelper { 54 55 56 63 64 private LinkedList loadHelpers; 65 66 private ClassLoadHelper bestCandidate; 67 68 75 76 81 public void initialize() { 82 loadHelpers = new LinkedList (); 83 84 loadHelpers.add(new LoadingLoaderClassLoadHelper()); 85 loadHelpers.add(new SimpleClassLoadHelper()); 86 loadHelpers.add(new ThreadContextClassLoadHelper()); 87 loadHelpers.add(new InitThreadContextClassLoadHelper()); 88 89 Iterator iter = loadHelpers.iterator(); 90 while (iter.hasNext()) { 91 ClassLoadHelper loadHelper = (ClassLoadHelper) iter.next(); 92 loadHelper.initialize(); 93 } 94 } 95 96 99 public Class loadClass(String name) throws ClassNotFoundException { 100 101 if (bestCandidate != null) { 102 try { 103 return bestCandidate.loadClass(name); 104 } catch (Exception e) { 105 bestCandidate = null; 106 } 107 } 108 109 ClassNotFoundException cnfe = null; 110 Class clazz = null; 111 ClassLoadHelper loadHelper = null; 112 113 Iterator iter = loadHelpers.iterator(); 114 while (iter.hasNext()) { 115 loadHelper = (ClassLoadHelper) iter.next(); 116 117 try { 118 clazz = loadHelper.loadClass(name); 119 break; 120 } catch (ClassNotFoundException e) { 121 cnfe = e; 122 } 123 } 124 125 if (clazz == null) { 126 throw cnfe; 127 } 128 129 bestCandidate = loadHelper; 130 131 return clazz; 132 } 133 134 140 public URL getResource(String name) { 141 142 if (bestCandidate != null) { 143 try { 144 return bestCandidate.getResource(name); 145 } catch (Exception e) { 146 bestCandidate = null; 147 } 148 } 149 150 URL result = null; 151 ClassLoadHelper loadHelper = null; 152 153 Iterator iter = loadHelpers.iterator(); 154 while (iter.hasNext()) { 155 loadHelper = (ClassLoadHelper) iter.next(); 156 157 result = loadHelper.getResource(name); 158 if (result != null) { 159 break; 160 } 161 } 162 163 bestCandidate = loadHelper; 164 return result; 165 166 } 167 168 174 public InputStream getResourceAsStream(String name) { 175 176 if (bestCandidate != null) { 177 try { 178 return bestCandidate.getResourceAsStream(name); 179 } catch (Exception e) { 180 bestCandidate = null; 181 } 182 } 183 184 InputStream result = null; 185 ClassLoadHelper loadHelper = null; 186 187 Iterator iter = loadHelpers.iterator(); 188 while (iter.hasNext()) { 189 loadHelper = (ClassLoadHelper) iter.next(); 190 191 result = loadHelper.getResourceAsStream(name); 192 if (result != null) { 193 break; 194 } 195 } 196 197 bestCandidate = loadHelper; 198 return result; 199 200 } 201 202 } 203 | Popular Tags |