KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > model > web > WebModelResolver


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.web;
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.model.ModelResolution;
18 import com.inversoft.verge.mvc.model.ModelResolver;
19 import com.inversoft.verge.util.WebBean;
20
21
22 /**
23  * <p>
24  * This class is the model resolver for web base model
25  * objects. This uses data stored in the extra params to
26  * locate model objects. The model objects that this classes
27  * returns are actually WebBean objects.
28  * </p>
29  *
30  * @author Brian Pontarelli
31  * @since 2.0
32  * @version 2.0
33  */

34 public class WebModelResolver implements ModelResolver {
35
36     /**
37      * Constructor for WebModelResolver.
38      */

39     public WebModelResolver() {
40         super();
41     }
42
43
44     /**
45      * This constructs a new {@link WebMetaData WebMetaData} using the
46      * extraParams map and the definition. This meta data is used to determine
47      * the id, scope and class of the model object. This then creates a new
48      * WebBean, instantiates it and returns the resolution.
49      *
50      * @param mvcRequest Used to get the web model object.
51      * @param definition Used to determine the id of the WebBean
52      * @param extraParams The stores the scope and class of the bean
53      * @return The ModelResolution for the model object
54      * @throws com.inversoft.verge.mvc.MVCException If the extraParams does not contain the correct
55      * information, if the scope that the bean is stored in already
56      * contains a bean of a different type, etc.
57      * @asserts If the definition is malformed
58      */

59     public ModelResolution resolve(MVCRequest mvcRequest, String JavaDoc definition,
60             Map JavaDoc extraParams)
61     throws MVCException {
62         HttpServletRequest JavaDoc request = mvcRequest.getRequest();
63         WebMetaData md = new WebMetaData(definition, extraParams);
64
65         try {
66             WebBean wb = md.createWebBean();
67             return new ModelResolution(wb.getInstance(request), md);
68         } catch (BeanException be) {
69             throw new MVCException(be);
70         }
71     }
72 }
Popular Tags