KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > model > form > FormModelResolver


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.model.form;
8
9
10 import java.util.Map JavaDoc;
11
12 import javax.servlet.http.HttpServletRequest JavaDoc;
13
14 import com.inversoft.beans.BeanException;
15 import com.inversoft.verge.mvc.MVCException;
16 import com.inversoft.verge.mvc.MVCRequest;
17 import com.inversoft.verge.mvc.config.BaseFormConfig;
18 import com.inversoft.verge.mvc.controller.form.config.FormConfigStruct;
19 import com.inversoft.verge.mvc.model.ModelResolution;
20 import com.inversoft.verge.mvc.model.ModelResolver;
21 import com.inversoft.verge.util.WebBean;
22
23
24 /**
25  * <p>
26  * This class is the model resolver for the form based MVC
27  * of the Inversoft verge framework. This class uses the
28  * HttpServletRequest to determine what form the user
29  * submitted and then locates the FormMVC configuraion
30  * objects, which are then used during the process of getting
31  * and setting the model values.
32  * </p>
33  *
34  * @author Brian Pontarelli
35  * @since 2.0
36  * @version 2.0
37  */

38 public class FormModelResolver implements ModelResolver {
39
40
41     /**
42      * Constructor for FormModelResolver.
43      */

44     public FormModelResolver() {
45         super();
46     }
47
48
49     /**
50      * <p>
51      * Using the {@link BaseFormConfig BaseFormConfig} fetched by the controller
52      * setupMVCRequest method, this retrieves the FormBean.
53      * </p>
54      *
55      * @param mvcRequest The MVCRequest used while parsing for the http servlet
56      * request stored inside it as well as other objects.
57      * @param definition The Model definition from the request
58      * @param extraParams The FormConfig is stored in here
59      * @return The ModelResolution for the model object
60      */

61     public ModelResolution resolve(MVCRequest mvcRequest, String JavaDoc definition,
62             Map JavaDoc extraParams)
63     throws MVCException {
64
65         // Check the extraParams first and if it is not there, look it up and
66
// store it
67
HttpServletRequest JavaDoc request = mvcRequest.getRequest();
68         FormConfigStruct struct = (FormConfigStruct) mvcRequest.getConfiguration();
69         BaseFormConfig config = struct.baseFormConfig;
70         FormMetaData md = new FormMetaData(definition);
71         WebBean formBean = config.getFormBean(md.getID());
72         ModelResolution mr = null;
73
74         try {
75             mr = new ModelResolution(formBean.getInstance(request), md);
76         } catch (BeanException be) {
77             throw new MVCException(be);
78         }
79
80         return mr;
81     }
82 }
83
Popular Tags