1 7 package com.inversoft.verge.util.url.config; 8 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 13 import javax.servlet.ServletRequest ; 14 15 import com.inversoft.config.ConfigRegistry; 16 17 18 28 public class URLConfigRegistry implements ConfigRegistry { 29 30 34 public static final String KEY = URLConfigRegistry.class.getName(); 35 36 41 private static volatile URLConfigRegistry instance = new URLConfigRegistry(); 42 43 44 private Map categories; 45 46 47 50 protected URLConfigRegistry() { 51 categories = new HashMap (); 52 } 53 54 55 74 public static URLConfigRegistry getInstance(ServletRequest request) { 75 assert (instance != null) : "instance == null"; 76 77 URLConfigRegistry localInstance = null; 78 if (request == null) { 79 localInstance = instance; 80 } else { 81 localInstance = (URLConfigRegistry) request.getAttribute(KEY); 82 } 83 84 if (localInstance == null && request != null) { 85 request.setAttribute(KEY, instance); 86 localInstance = instance; 87 } 88 89 return localInstance; 90 } 91 92 97 protected static void setInstance(URLConfigRegistry newInstance) { 98 instance = newInstance; 99 } 100 101 102 107 protected void register(CategoryConfig cc) { 108 categories.put(cc.getName(), cc); 109 } 110 111 117 public CategoryConfig lookupCategory(String name) { 118 return (CategoryConfig) categories.get(name); 119 } 120 } | Popular Tags |