1 7 package com.inversoft.verge.mvc; 8 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 13 import org.apache.log4j.Logger; 14 15 import com.inversoft.util.ReflectionException; 16 import com.inversoft.util.ReflectionTools; 17 import com.inversoft.verge.mvc.controller.ControllerHandler; 18 import com.inversoft.verge.mvc.controller.ControllerParser; 19 import com.inversoft.verge.mvc.controller.DefaultControllerParser; 20 import com.inversoft.verge.mvc.model.DefaultModelParser; 21 import com.inversoft.verge.mvc.model.ModelHandler; 22 import com.inversoft.verge.mvc.model.ModelParser; 23 import com.inversoft.verge.mvc.model.ModelResolver; 24 import com.inversoft.verge.mvc.validator.DefaultValidatorParser; 25 import com.inversoft.verge.mvc.validator.ValidatorHandler; 26 import com.inversoft.verge.mvc.validator.ValidatorParser; 27 28 29 66 public class MVCRegistry { 67 68 71 private static final Logger logger = Logger.getLogger(MVCRegistry.class); 72 73 76 private static Map controllerParsers = new HashMap (); 77 78 81 private static Map controllerHandlers = new HashMap (); 82 83 86 private static Map modelParsers = new HashMap (); 87 88 91 private static Map modelResolvers = new HashMap (); 92 93 96 private static Map modelHandlers = new HashMap (); 97 98 101 private static Map validatorParsers = new HashMap (); 102 103 106 private static Map validatorHandlers = new HashMap (); 107 108 109 114 static { 115 controllerParsers.put(MVCConstants.DEFAULT_NAME, new DefaultControllerParser()); 116 modelParsers.put(MVCConstants.DEFAULT_NAME, new DefaultModelParser()); 117 validatorParsers.put(MVCConstants.DEFAULT_NAME, new DefaultValidatorParser()); 118 119 try { 120 controllerHandlers.put(MVCConstants.ACTIONFLOW_NAME, 121 ReflectionTools.instantiate( 122 "com.inversoft.verge.mvc.controller.actionflow.ActionFlowControllerHandler")); 123 modelHandlers.put(MVCConstants.ACTIONFLOW_NAME, 124 ReflectionTools.instantiate( 125 "com.inversoft.verge.mvc.model.DefaultModelHandler")); 126 modelResolvers.put(MVCConstants.ACTIONFLOW_NAME, 127 ReflectionTools.instantiate( 128 "com.inversoft.verge.mvc.model.actionflow.ActionFlowModelResolver")); 129 validatorHandlers.put(MVCConstants.ACTIONFLOW_NAME, 130 ReflectionTools.instantiate( 131 "com.inversoft.verge.mvc.validator.actionflow.ActionFlowValidatorHandler")); 132 } catch (ReflectionException re) { 133 logger.info("ActionFlow system disabled (see REASON)"); 134 logger.info("[REASON] " + re.toString()); 135 } 136 137 try { 138 controllerHandlers.put(MVCConstants.FORM_NAME, 139 ReflectionTools.instantiate( 140 "com.inversoft.verge.mvc.controller.form.FormControllerHandler")); 141 modelHandlers.put(MVCConstants.FORM_NAME, 142 ReflectionTools.instantiate( 143 "com.inversoft.verge.mvc.model.DefaultModelHandler")); 144 modelResolvers.put(MVCConstants.FORM_NAME, 145 ReflectionTools.instantiate( 146 "com.inversoft.verge.mvc.model.form.FormModelResolver")); 147 validatorHandlers.put(MVCConstants.FORM_NAME, 148 ReflectionTools.instantiate( 149 "com.inversoft.verge.mvc.validator.form.FormValidatorHandler")); 150 } catch (ReflectionException re) { 151 logger.info("Form-Based MVC system disabled (see REASON)"); 152 logger.info("[REASON] " + re.toString()); 153 } 154 155 try { 156 modelHandlers.put(MVCConstants.REPOSITORY_NAME, 157 ReflectionTools.instantiate( 158 "com.inversoft.verge.mvc.model.repository.RepositoryModelHandler")); 159 modelResolvers.put(MVCConstants.REPOSITORY_NAME, 160 ReflectionTools.instantiate( 161 "com.inversoft.verge.mvc.model.repository.RepositoryModelResolver")); 162 } catch (ReflectionException re) { 163 logger.info("Repository system disabled (see REASON)"); 164 logger.info("[REASON] " + re.toString()); 165 } 166 167 try { 168 modelHandlers.put(MVCConstants.WEB_NAME, 169 ReflectionTools.instantiate("com.inversoft.verge.mvc.model.web.WebModelHandler")); 170 modelResolvers.put(MVCConstants.WEB_NAME, 171 ReflectionTools.instantiate("com.inversoft.verge.mvc.model.web.WebModelResolver")); 172 } catch (ReflectionException re) { 173 logger.info("Web MVC system disabled (see REASON)"); 174 logger.info("[REASON] " + re.toString()); 175 } 176 } 177 178 179 182 private MVCRegistry() { 183 } 185 186 187 193 public static void register(String name, ControllerParser parser) { 194 controllerParsers.put(name, parser); 195 } 196 197 203 public static ControllerParser lookupControllerParser(String name) { 204 return (ControllerParser) controllerParsers.get(name); 205 } 206 207 213 public static void register(String name, ControllerHandler handler) { 214 controllerHandlers.put(name, handler); 215 } 216 217 223 public static ControllerHandler lookupControllerHandler(String name) { 224 return (ControllerHandler) controllerHandlers.get(name); 225 } 226 227 233 public static void register(String name, ModelParser parser) { 234 modelParsers.put(name, parser); 235 } 236 237 243 public static ModelParser lookupModelParser(String name) { 244 return (ModelParser) modelParsers.get(name); 245 } 246 247 253 public static void register(String name, ModelResolver resolver) { 254 modelResolvers.put(name, resolver); 255 } 256 257 263 public static ModelResolver lookupModelResolver(String name) { 264 return (ModelResolver) modelResolvers.get(name); 265 } 266 267 273 public static void register(String name, ModelHandler handler) { 274 modelHandlers.put(name, handler); 275 } 276 277 283 public static ModelHandler lookupModelHandler(String name) { 284 return (ModelHandler) modelHandlers.get(name); 285 } 286 287 293 public static void register(String name, ValidatorParser parser) { 294 validatorParsers.put(name, parser); 295 } 296 297 303 public static ValidatorParser lookupValidatorParser(String name) { 304 return (ValidatorParser) validatorParsers.get(name); 305 } 306 307 313 public static void register(String name, ValidatorHandler handler) { 314 validatorHandlers.put(name, handler); 315 } 316 317 324 public static ValidatorHandler lookupValidatorHandler(String name) { 325 return (ValidatorHandler) validatorHandlers.get(name); 326 } 327 } | Popular Tags |