KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > model > repository > RepositoryModelHandler


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.repository;
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.util.typeconverter.TypeConversionException;
16 import com.inversoft.verge.mvc.MVCException;
17 import com.inversoft.verge.mvc.MVCRequest;
18 import com.inversoft.verge.mvc.model.ModelHandler;
19 import com.inversoft.verge.mvc.model.ModelResolution;
20 import com.inversoft.verge.repository.RepositoryBeanProperty;
21
22
23 /**
24  * <p>
25  * This class is the handler for repository model objects.
26  * </p>
27  *
28  * @author Brian Pontarelli
29  * @since 2.0
30  * @version 2.0
31  */

32 public class RepositoryModelHandler implements ModelHandler {
33
34     /**
35      * Constructs a new <code>RepositoryModelHandler</code>
36      */

37     public RepositoryModelHandler() {
38     }
39
40     /**
41      * Using the RepositoryBean passed in as the model object from the resolver,
42      * this method creates a new RepositoryBeanProperty using the property from
43      * the RepositoryMetaData store in the extraParams by the resolver. This is
44      * used to get the value from the bean.
45      *
46      * @param mvcRequest Used to retrieve the value from the repository bean
47      * @param definition Not used
48      * @param resolution The ModelResolution for the model object
49      * @param extraParams Used to retrieve the meta data that the resolver
50      * stored previously
51      * @return The value of the property
52      * @throws com.inversoft.verge.mvc.MVCException If there were any problems retrieving the value
53      */

54     public Object JavaDoc getValue(MVCRequest mvcRequest, String JavaDoc definition,
55         ModelResolution resolution, Map JavaDoc extraParams)
56     throws MVCException {
57
58         RepositoryMetaData md = (RepositoryMetaData) resolution.getMetaData();
59         if (md == null) {
60             md = new RepositoryMetaData(definition);
61         }
62
63         try {
64             HttpServletRequest JavaDoc request = mvcRequest.getRequest();
65             RepositoryBeanProperty rbp = md.createRepositoryBeanProperty(request);
66             return rbp.getPropertyValue(request);
67         } catch (BeanException be) {
68             throw new MVCException(be);
69         }
70     }
71
72     /**
73      * Using the RepositoryBean passed in as the model object from the resolver,
74      * this method creates a new RepositoryBeanProperty using the property from
75      * the RepositoryMetaData store in the extraParams by the resolver. This is
76      * used to set the value from the bean.
77      *
78      * @param mvcRequest Used to set the value into the repository bean
79      * @param definition Not used
80      * @param resolution The ModelResolution for the model object
81      * @param value The value to set
82      * @param extraParams Used to retrieve the meta data that the resolver
83      * stored previously
84      * @throws com.inversoft.verge.mvc.MVCException If there were any problems retrieving the value
85      */

86     public void setValue(MVCRequest mvcRequest, String JavaDoc definition,
87         ModelResolution resolution, Object JavaDoc value, Map JavaDoc extraParams)
88     throws MVCException {
89
90         RepositoryMetaData md = (RepositoryMetaData) resolution.getMetaData();
91         if (md == null) {
92             md = new RepositoryMetaData(definition);
93         }
94
95         HttpServletRequest JavaDoc request = mvcRequest.getRequest();
96         RepositoryBeanProperty rbp = null;
97         try {
98             rbp = md.createRepositoryBeanProperty(request);
99             rbp.setPropertyValue(request, value); // converts
100
} catch (BeanException be) {
101             throw new MVCException(be);
102         } catch (TypeConversionException tce) {
103
104             assert (rbp != null) : "rbp == null";
105             
106             // The conversion failed, so, we let the ValidatorParser handle it
107
mvcRequest.getValidatorParser().executeHandle(mvcRequest, tce,
108                 resolution.getModel(), rbp);
109         }
110     }
111 }
112
Popular Tags