1 7 package com.inversoft.verge.config; 8 9 10 import java.net.MalformedURLException ; 11 import java.net.URL ; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 import java.util.StringTokenizer ; 15 import java.util.ResourceBundle ; 16 17 import javax.servlet.ServletContext ; 18 19 import org.apache.log4j.Logger; 20 import org.jdom.Document; 21 22 import com.inversoft.config.ConfigFactoryRegistry; 23 import com.inversoft.config.ConfigMediator; 24 import com.inversoft.config.ConfigurationException; 25 import com.inversoft.config.ConfigFactory; 26 import com.inversoft.error.ErrorList; 27 import com.inversoft.util.StringTools; 28 29 30 53 public class VergeConfigMediator extends ConfigMediator { 54 55 58 private static final Logger logger = Logger.getLogger(VergeConfigMediator.class); 59 60 63 public static final String VERGE_FACTORIES_BUNDLE = 64 "com.inversoft.verge.config.ConfigFactories"; 65 66 67 73 public VergeConfigMediator() { 74 ConfigFactoryRegistry.load(ResourceBundle.getBundle(VERGE_FACTORIES_BUNDLE)); 75 } 76 77 78 86 public void mediate(ServletContext context) throws ConfigurationException { 87 88 System.out.println("================== Initializing Verge configuration =================="); 89 90 ErrorList errors = new ErrorList(); 92 String configFiles = context.getInitParameter(VergeConfigConstants.CONTEXT_PARAM); 93 if (StringTools.isEmpty(configFiles)) { 94 logger.warn("No config file(s) specified"); 95 return; 96 } 97 98 StringTokenizer st = new StringTokenizer (configFiles, " ,\t\n\r\f"); 100 List urls = new ArrayList (st.countTokens()); 101 String file; 102 URL url = null; 103 104 while(st.hasMoreTokens()) { 105 file = st.nextToken().trim(); 106 107 try { 108 logger.info("Parsing file: " + file); 109 url = context.getResource(file); 110 if (url == null) { 111 logger.error("Configuration file: " + file + " does not exist"); 112 errors.addError("Configuration file: " + file + " does not exist"); 113 continue; 114 } 115 } catch (MalformedURLException murle) { 116 logger.error(murle.toString()); 117 errors.addError(murle.toString()); 118 } 119 120 urls.add(url); 121 } 122 123 if (urls.size() > 0) { 125 try { 126 super.mediate((URL []) urls.toArray(new URL [urls.size()])); 127 } catch (ConfigurationException ce) { 128 errors.addErrorList(ce.getErrors()); 129 } 130 } 131 132 if (!errors.isEmpty()) { 133 throw new ConfigurationException(errors); 134 } 135 136 System.gc(); 138 } 139 } | Popular Tags |