1 23 24 package com.sun.enterprise.config; 25 26 import java.util.Map ; 27 import java.util.Hashtable ; 28 import org.xml.sax.helpers.DefaultHandler ; 29 import com.sun.enterprise.config.impl.ConfigContextImpl; 30 import com.sun.enterprise.config.pluggable.EnvironmentFactory; 31 import com.sun.enterprise.config.pluggable.ConfigEnvironment; 32 33 37 public class ConfigContextFactory { 38 39 private static Hashtable _ctxCache = new Hashtable (); 40 41 42 58 public ConfigContext createConfigContext(String url, String rootClass) { 59 ConfigEnvironment ce = getConfigEnvironment(); 60 ce.setUrl(url); 61 ce.setRootClass(rootClass); 62 return createConfigContext(ce); 63 } 64 65 68 public static ConfigContext createConfigContext(ConfigEnvironment ce) { 69 70 if(!ce.isCachingEnabled()) { 71 return newConfigContext(ce); 73 } 74 75 ConfigContext context = getConfigContextFromCache(ce.getUrl()); 76 77 if(context == null) { 78 context = newConfigContext(ce); 79 addConfigContextToCache(ce.getUrl(), context); 80 } else { 82 } 84 return context; 85 } 86 87 public static void removeConfigContext(ConfigContext ctx) { 88 String url = ctx.getUrl(); 89 removeConfigContext(url); 90 } 91 92 public static synchronized void removeConfigContext(String url) { 93 Object obj = _ctxCache.remove(url); 94 invalidateConfigContext(obj); 95 } 96 97 120 public static synchronized void replaceConfigContext( 121 ConfigContext oldCtx, 122 ConfigContext newCtx) 123 throws ConfigException { 124 125 assert (oldCtx != null); 126 assert (newCtx != null); 127 128 String url = oldCtx.getUrl(); 129 130 if(_ctxCache.containsKey(url)) { 131 _ctxCache.put(url, newCtx); 132 } else { 133 throw new ConfigException 134 ("Old ConfigContext is not found. Cannot replace with new one"); 135 } 137 } 138 139 153 public static boolean enableLastModifiedCheck(ConfigContext ctx, boolean value) { 154 return ((ConfigContextImpl)ctx).enableLastModifiedCheck(value); 155 } 156 157 private static ConfigEnvironment getConfigEnvironment() { 158 ConfigEnvironment ce = null; 159 try { 160 ce = EnvironmentFactory. 161 getEnvironmentFactory(). 162 getConfigEnvironment(); 163 } catch(Exception e) { 164 throw new ConfigRuntimeException 165 ("err_getting_config_env", 166 "err_getting_config_env", 167 e); } 169 return ce; 170 } 171 172 public static ConfigContext getConfigContextFromCache(String url) { 173 return (ConfigContext) _ctxCache.get(url); 174 } 175 176 private static ConfigContext newConfigContext(ConfigEnvironment ce) { 177 return new ConfigContextImpl(ce); 178 } 179 180 private static void addConfigContextToCache(String url, ConfigContext ctx) { 181 _ctxCache.put(url, ctx); 182 } 183 184 private static void invalidateConfigContext(Object obj) { 185 try { 186 if(obj != null) 187 ((ConfigContextImpl)obj).cleanup(); } catch(Exception e) { 189 } 192 } 193 } 194 | Popular Tags |