1 7 package com.inversoft.verge.repository.config; 8 9 10 import java.util.Collection ; 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 import javax.servlet.ServletRequest ; 15 16 import com.inversoft.config.ConfigRegistry; 17 18 19 29 public class RepositoryConfigRegistry implements ConfigRegistry { 30 31 35 public static final String KEY = RepositoryConfigRegistry.class.getName(); 36 37 42 private static volatile RepositoryConfigRegistry instance = 43 new RepositoryConfigRegistry(); 44 45 46 49 private Map configurations = new HashMap (); 50 51 52 55 protected RepositoryConfigRegistry() { 56 } 57 58 59 78 public static RepositoryConfigRegistry getInstance(ServletRequest request) { 79 assert (instance != null) : "instance == null"; 80 81 RepositoryConfigRegistry localInstance = null; 82 if (request == null) { 83 localInstance = instance; 84 } else { 85 localInstance = (RepositoryConfigRegistry) request.getAttribute(KEY); 86 } 87 88 if (localInstance == null && request != null) { 89 request.setAttribute(KEY, instance); 90 localInstance = instance; 91 } 92 93 return localInstance; 94 } 95 96 101 protected static RepositoryConfigRegistry setInstance( 102 RepositoryConfigRegistry instance) { 103 RepositoryConfigRegistry old = RepositoryConfigRegistry.instance; 104 RepositoryConfigRegistry.instance = instance; 105 return old; 106 } 107 108 116 protected void register(String id, Config config) { 117 assert (id != null) : "id == null"; 118 assert (config != null) : "config == null"; 119 120 configurations.put(id, config); 121 } 122 123 130 public Config lookup(String id) { 131 return (Config) configurations.get(id); 132 } 133 134 139 public Collection getConfigurations() { 140 return configurations.values(); 141 } 142 } 143 | Popular Tags |