1 package net.myvietnam.mvncore.configuration; 2 3 56 57 import java.io.FileNotFoundException ; 58 import java.io.IOException ; 59 import java.io.InputStream ; 60 61 import org.apache.commons.lang.StringUtils; 62 63 77 public class ClassPropertiesConfiguration 78 extends BasePropertiesConfiguration 79 implements Configuration 80 { 81 82 private Class baseClass = null; 83 84 85 private ClassLoader classLoader = null; 86 87 95 public ClassPropertiesConfiguration(Class baseClass, String resource) 96 throws IOException 97 { 98 this.baseClass = baseClass; 99 classLoader = (baseClass.getClassLoader() == null) 103 ? ClassLoader.getSystemClassLoader() 104 : baseClass.getClassLoader(); 105 106 setIncludesAllowed(true); 107 108 load(getPropertyStream(resource)); 109 } 110 111 120 public ClassPropertiesConfiguration(Class baseClass, String resource, 121 Configuration defaults) 122 throws IOException 123 { 124 this(baseClass, resource); 125 this.defaults = defaults; 126 } 127 128 137 public ClassPropertiesConfiguration(Class baseClass, String resource, 138 String defaultFile) 139 throws IOException 140 { 141 this(baseClass, resource); 142 143 if (StringUtils.isNotEmpty(defaultFile)) 144 { 145 this.defaults = 146 new ClassPropertiesConfiguration(baseClass, defaultFile); 147 } 148 } 149 150 158 public InputStream getPropertyStream(String resourceName) 159 throws IOException 160 { 161 InputStream resource = null; 162 if (resourceName.startsWith("./")) 165 { 166 } 168 169 resource = baseClass.getResourceAsStream(resourceName); 171 172 if (resource == null) 173 { 174 resource = classLoader.getResourceAsStream(resourceName); 175 } 176 177 if (resource == null) 178 { 179 throw new FileNotFoundException ("Could not open Resource " 180 + resourceName); 181 } 182 183 return resource; 184 } 185 } 186 187 188 189 190 | Popular Tags |