1 7 package com.inversoft.verge.mvc.controller.form.config; 8 9 10 import java.util.ArrayList ; 11 import java.util.HashMap ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 import javax.servlet.ServletRequest ; 16 17 import com.inversoft.config.ConfigRegistry; 18 import com.inversoft.verge.mvc.config.BaseFormConfig; 19 import com.inversoft.verge.mvc.config.FormConfigRegistry; 20 21 22 34 public class FormMVCConfigRegistry implements ConfigRegistry, FormConfigRegistry { 35 36 40 public static final String KEY = FormMVCConfigRegistry.class.getName(); 41 42 47 private static volatile FormMVCConfigRegistry instance = new FormMVCConfigRegistry(); 48 49 private Map forms; 50 private Map actions; 51 private Map mappings; 52 53 54 57 protected FormMVCConfigRegistry() { 58 forms = new HashMap (); 59 actions = new HashMap (); 60 mappings = new HashMap (); 61 } 62 63 64 83 public static FormMVCConfigRegistry getInstance(ServletRequest request) { 84 assert (instance != null) : "instance == null"; 85 86 FormMVCConfigRegistry localInstance = null; 87 if (request == null) { 88 localInstance = instance; 89 } else { 90 localInstance = (FormMVCConfigRegistry) request.getAttribute(KEY); 91 } 92 93 if (localInstance == null && request != null) { 94 request.setAttribute(KEY, instance); 95 localInstance = instance; 96 } 97 98 return localInstance; 99 } 100 101 106 protected static void setInstance(FormMVCConfigRegistry newInstance) { 107 assert (newInstance != null) : "newInstance == null"; 108 instance = newInstance; 109 } 110 111 112 121 public BaseFormConfig lookupForm(String name) { 122 return (FormConfig) forms.get(name); 123 } 124 125 132 protected void register(String name, FormConfig config) { 133 134 assert (name != null) : "name == null"; 135 assert (config != null) : "config == null"; 136 137 forms.put(name, config); 138 } 139 140 150 public ActionConfig lookupAction(String name, FormConfig formConfig) { 151 152 ActionConfig config = null; 153 154 if (formConfig != null) { 155 config = formConfig.getActionConfig(name); 156 } 157 158 if (config == null) { 159 config = (ActionConfig) actions.get(name); 160 } 161 162 return config; 163 } 164 165 172 public ActionConfig lookupAction(String name) { 173 return (ActionConfig) actions.get(name); 174 } 175 176 182 protected void register(String name, ActionConfig config) { 183 assert (name != null) : "name == null"; 184 assert (config != null) : "config == null"; 185 186 actions.put(name, config); 187 } 188 189 199 public MappingConfig lookupMapping(String name, FormConfig formConfig) { 200 201 MappingConfig config = null; 202 203 if (formConfig != null) { 204 config = formConfig.getMappingConfig(name); 205 } 206 207 if (config == null) { 208 config = (MappingConfig) mappings.get(name); 209 } 210 211 return config; 212 } 213 214 221 public MappingConfig lookupMapping(String name) { 222 return (MappingConfig) mappings.get(name); 223 } 224 225 231 protected void register(String name, MappingConfig config) { 232 assert (name != null) : "name == null"; 233 assert (config != null) : "config == null"; 234 235 mappings.put(name, config); 236 } 237 238 243 public List getAllConfigs() { 244 List list = new ArrayList (actions.values()); 245 list.addAll(forms.values()); 246 247 return list; 248 } 249 } 250 | Popular Tags |