1 7 package com.inversoft.verge.mvc.controller.actionflow.config; 8 9 10 import java.util.HashMap ; 11 import java.util.Iterator ; 12 import java.util.Map ; 13 14 import javax.servlet.ServletRequest ; 15 16 import com.inversoft.config.ConfigRegistry; 17 import com.inversoft.util.StringTools; 18 19 20 29 public class ActionFlowConfigRegistry implements ConfigRegistry { 30 31 35 public static final String KEY = ActionFlowConfigRegistry.class.getName(); 36 37 42 private static volatile ActionFlowConfigRegistry instance = 43 new ActionFlowConfigRegistry(); 44 45 46 49 private Map namespaces; 50 51 52 55 protected ActionFlowConfigRegistry() { 56 namespaces = new HashMap (); 57 } 58 59 62 ActionFlowConfigRegistry(ActionFlowConfigRegistry orig) { 63 namespaces = new HashMap (); 64 namespaces.putAll(orig.namespaces); 65 } 66 67 68 87 public static ActionFlowConfigRegistry getInstance(ServletRequest request) { 88 assert (instance != null) : "instance == null"; 89 90 ActionFlowConfigRegistry localInstance = null; 91 if (request == null) { 92 localInstance = instance; 93 } else { 94 localInstance = (ActionFlowConfigRegistry) request.getAttribute(KEY); 95 } 96 97 if (localInstance == null && request != null) { 98 request.setAttribute(KEY, instance); 99 localInstance = instance; 100 } 101 102 return localInstance; 103 } 104 105 109 protected static void setInstance(ActionFlowConfigRegistry newStore) { 110 assert (newStore != null) : "newStore == null"; 111 instance = newStore; 112 } 113 114 115 124 protected Namespace register(Namespace namespace) 125 throws IllegalArgumentException { 126 if (namespace == null) { 127 throw new IllegalArgumentException ("The namespace is null"); 128 } 129 130 return (Namespace) namespaces.put(namespace.getName(), namespace); 131 } 132 133 141 public Namespace lookup(String name) throws IllegalArgumentException { 142 if (name == null || StringTools.isEmpty(name)) { 143 throw new IllegalArgumentException ("The name is null or empty"); 144 } 145 146 return (Namespace) namespaces.get(name); 147 } 148 149 157 public Iterator iterator() { 158 Map temp = new HashMap (namespaces); 159 return temp.values().iterator(); 160 } 161 } | Popular Tags |