1 4 package org.javabb.infra; 5 6 7 import java.io.File ; 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 import org.springframework.context.ApplicationContext; 14 import org.springframework.context.support.ClassPathXmlApplicationContext; 15 16 17 26 public final class ApplicationContextFactory { 27 28 private static Log log = LogFactory.getLog(ApplicationContextFactory.class); 29 30 private boolean init; 31 32 private List locations = new ArrayList (); 33 34 38 public ApplicationContextFactory addLocation( String location ) { 39 40 if ((location != null) && !locations.contains(location)) { 41 42 locations.add(location); 43 44 } 45 46 return this; 47 48 } 49 50 54 public ApplicationContextFactory addLocation( File location ) { 55 56 return addLocation(location.getPath()); 57 58 } 59 60 64 public boolean containsLocation( File location ) { 65 66 return containsLocation(location.getPath()); 67 } 68 69 73 public boolean containsLocation( String path ) { 74 75 return locations.contains(path); 76 77 } 78 79 82 public ApplicationContext init() { 83 84 if (init) { 85 86 String msg = "ApplicationContextFactory already initialized."; 87 88 log.debug(msg); 89 throw new RuntimeException (msg); 90 91 } 92 93 String [] locals = new String [locations.size()]; 94 95 locations.toArray(locals); 96 97 ApplicationContext context; 98 context = new ClassPathXmlApplicationContext(locals); 99 100 init = true; 101 102 return context; 103 104 } 105 106 } 107 | Popular Tags |