1 7 package com.inversoft.verge.mvc.model; 8 9 10 import javax.servlet.http.HttpServletRequest ; 11 12 import org.apache.log4j.Logger; 13 14 import com.inversoft.util.StringTools; 15 import com.inversoft.verge.mvc.MVCException; 16 import com.inversoft.verge.mvc.MVCRegistry; 17 import com.inversoft.verge.mvc.MVCRequest; 18 19 20 62 public class DefaultModelParser implements ModelParser { 63 64 67 private static final Logger logger = Logger.getLogger(DefaultModelParser.class); 68 69 73 public static final String INPUT_PARAMETER = "_vi_"; 74 75 76 79 public DefaultModelParser() { 80 } 81 82 83 86 public void preExecute(MVCRequest mvcRequest) throws MVCException { 87 } 89 90 103 public void execute(MVCRequest mvcRequest) throws MVCException { 104 105 if (!mvcRequest.isModelEnabled()) { 107 logger.debug("Model is disabled"); 108 return; 109 } 110 111 HttpServletRequest request = mvcRequest.getRequest(); 112 String [] inputs = request.getParameterValues(INPUT_PARAMETER); 113 if (inputs == null || inputs.length == 0) { 114 logger.debug("No model parameters"); 115 return; 116 } 117 118 ModelMVCInfo modelInfo = new ModelMVCInfo(); 119 String [] modelValues; 120 ModelResolution resolution; 121 ModelResolver resolver; 122 ModelHandler handler; 123 124 for (int i = 0; i < inputs.length; i++) { 125 modelInfo.decode(inputs[i]); 126 127 modelValues = request.getParameterValues(modelInfo.getInputName()); 129 130 modelValues = StringTools.convertEmpty(modelValues); 132 133 resolver = MVCRegistry.lookupModelResolver(modelInfo.getModelSystem()); 135 if (resolver == null) { 136 logger.error("Invalid modelResolver: " + modelInfo.getModelSystem() + 137 ". No ModelResolver registered under that name"); 138 throw new MVCException("Invalid modelResolver: " + 139 modelInfo.getModelSystem() + ". No ModelResolver" + 140 " registered under that name"); 141 } 142 143 resolution = resolver.resolve(mvcRequest, modelInfo.getModelDefinition(), 144 modelInfo.getExtraParams()); 145 146 if (resolution == null) { 148 logger.error("Model does exist for definition: " + 149 modelInfo.getModelDefinition()); 150 throw new MVCException("Model does exist for definition: " + 151 modelInfo.getModelDefinition()); 152 } 153 154 mvcRequest.putModelObject(resolution.getMetaData().getID(), 157 resolution.getModel()); 158 159 handler = MVCRegistry.lookupModelHandler(modelInfo.getModelSystem()); 160 if (handler == null) { 161 logger.error("Invalid modelHandler: " + modelInfo.getModelSystem() + 162 ". No ModelHandler registered under that name"); 163 throw new MVCException("Invalid modelHandler: " + 164 modelInfo.getModelSystem() + ". No ModelHandler" + 165 " registered under that name"); 166 } 167 handler.setValue(mvcRequest, modelInfo.getModelDefinition(), resolution, 168 modelValues, modelInfo.getExtraParams()); 169 } 170 } 171 } | Popular Tags |