1 16 17 package org.springframework.context.support; 18 19 import org.springframework.beans.BeansException; 20 import org.springframework.context.ApplicationContext; 21 import org.springframework.core.io.ClassPathResource; 22 import org.springframework.core.io.Resource; 23 import org.springframework.util.Assert; 24 25 51 public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext { 52 53 private Resource[] configResources; 54 55 private String [] configLocations; 56 57 58 64 public ClassPathXmlApplicationContext(String configLocation) throws BeansException { 65 this(new String [] {configLocation}); 66 } 67 68 74 public ClassPathXmlApplicationContext(String [] configLocations) throws BeansException { 75 this(configLocations, (ApplicationContext) null); 76 } 77 78 86 public ClassPathXmlApplicationContext(String [] configLocations, ApplicationContext parent) 87 throws BeansException { 88 89 super(parent); 90 this.configLocations = configLocations; 91 refresh(); 92 } 93 94 95 105 public ClassPathXmlApplicationContext(String [] configLocations, boolean refresh) throws BeansException { 106 this(configLocations, refresh, null); 107 } 108 109 120 public ClassPathXmlApplicationContext(String [] configLocations, boolean refresh, ApplicationContext parent) 121 throws BeansException { 122 123 super(parent); 124 this.configLocations = configLocations; 125 if (refresh) { 126 refresh(); 127 } 128 } 129 130 131 144 public ClassPathXmlApplicationContext(String path, Class clazz) throws BeansException { 145 this(new String [] {path}, clazz); 146 } 147 148 158 public ClassPathXmlApplicationContext(String [] paths, Class clazz) throws BeansException { 159 this(paths, clazz, null); 160 } 161 162 174 public ClassPathXmlApplicationContext(String [] paths, Class clazz, ApplicationContext parent) 175 throws BeansException { 176 177 super(parent); 178 Assert.notNull(paths, "Path array must not be null"); 179 Assert.notNull(clazz, "Class argument must not be null"); 180 this.configResources = new Resource[paths.length]; 181 for (int i = 0; i < paths.length; i++) { 182 this.configResources[i] = new ClassPathResource(paths[i], clazz); 183 } 184 refresh(); 185 } 186 187 188 protected Resource[] getConfigResources() { 189 return this.configResources; 190 } 191 192 protected String [] getConfigLocations() { 193 return this.configLocations; 194 } 195 196 } 197 | Popular Tags |