1 17 package org.sape.carbon.services.config.classloader; 18 19 import java.io.InputStream ; 20 import java.net.URL ; 21 import java.net.URLClassLoader ; 22 23 import org.sape.carbon.core.exception.InvalidParameterException; 24 25 34 public class ConfigurationSource { 35 36 private URL [] sourceURLs = null; 37 private ClassLoader sourceLoader; 38 39 43 public ConfigurationSource() { 44 this.sourceLoader = this.getClass().getClassLoader(); 45 } 46 47 55 public ConfigurationSource(URL [] sourceURLs) { 56 if (sourceURLs == null) { 57 throw new InvalidParameterException ( 58 this.getClass(), 59 "sourceURLs cannot be null"); 60 } 61 62 this.sourceURLs = sourceURLs; 63 this.sourceLoader = new URLClassLoader (sourceURLs); 64 } 65 66 72 public void refresh() { 73 if (this.sourceURLs != null) { 74 synchronized (this) { 75 this.sourceLoader = new URLClassLoader (sourceURLs); 76 } 77 } 78 } 79 80 88 public InputStream getResourceAsStream(String resourcePath) { 89 if (this.sourceURLs != null) { 90 synchronized (this) { 92 return this.sourceLoader.getResourceAsStream(resourcePath); 93 } 94 } else { 95 return this.sourceLoader.getResourceAsStream(resourcePath); 96 } 97 } 98 99 107 public URL getResource(String resourcePath) { 108 if (this.sourceURLs != null) { 109 synchronized (this) { 111 return this.sourceLoader.getResource(resourcePath); 112 } 113 } else { 114 return this.sourceLoader.getResource(resourcePath); 115 } 116 } 117 } 118 | Popular Tags |