KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > form > FormWebBeanHandle


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.controller.form;
8
9
10 import java.util.Collections JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13
14 import com.inversoft.beans.BeanException;
15 import com.inversoft.verge.mvc.controller.BeanHandle;
16 import com.inversoft.verge.mvc.controller.WebBeanHandle;
17 import com.inversoft.verge.util.WebBean;
18
19
20 /**
21  * <p>
22  * This class is a sub-class of the WebBeanHandle. This
23  * functions the same as its parent except that the handle
24  * method parameters are changed to by the {@link FormAction
25  * FormAction} class rather than the {@link
26  * com.inversoft.verge.mvc.controller.Action Action} class.
27  * </p>
28  *
29  * @author bpontarelli
30  * @version 2.0
31  * @since 2.0
32  */

33 public class FormWebBeanHandle extends WebBeanHandle {
34
35     /**
36      * The parameters for the handle methods of the framework. This is currently
37      * just the {@link com.inversoft.verge.mvc.controller.Action Action} or a sub-
38      * class
39      */

40     private final static Class JavaDoc [] HANDLE_PARAMS = {FormAction.class};
41
42     /**
43      * Global switch for caching. This does not work yet so it is turned off. The
44      * problem is that the class can have two methods that take two different
45      * parameters, but both are valid handle methods.
46      */

47     static final boolean CACHING = true;
48
49     /**
50      * The cache Map for the BeanProperty objects (unsynchronized)
51      */

52     static Map JavaDoc cache = new HashMap JavaDoc();
53
54
55     //--------------------------------------------------------------------------
56
// Cache Methods
57
//--------------------------------------------------------------------------
58

59
60     /**
61      * Returns an instance of the BeanHandle for the given handleName and
62      * bean Class. This object might be cached, depending on the implementation
63      * of this method. Therefore, you must take into account a cached or non-
64      * cached object.
65      *
66      * @param handleName The handle name of the BeanHandle
67      * @param beanClass The bean Class
68      * @return The BeanHandle and never null
69      * @throws BeanException If the creation of the obejct fails
70      */

71     private static BeanHandle getBeanHandle(String JavaDoc handleName, Class JavaDoc beanClass)
72     throws BeanException {
73
74         // If not caching, just create the objects
75
if (!CACHING) {
76             return new BeanHandle(handleName, beanClass, HANDLE_PARAMS);
77         }
78
79         // Otherwise look for the property Map or create and store
80
Map JavaDoc propMap = null;
81         synchronized (cache) {
82             propMap = (Map JavaDoc) cache.get(beanClass);
83             if (propMap == null) {
84                 propMap = Collections.synchronizedMap(new HashMap JavaDoc());
85                 cache.put(beanClass, propMap);
86             }
87         }
88
89         // Look for the property itself, or create and store
90
BeanHandle bh = null;
91         synchronized (propMap) {
92             bh = (BeanHandle) propMap.get(handleName);
93             if (bh == null) {
94                 bh = new BeanHandle(handleName, beanClass, HANDLE_PARAMS);
95                 propMap.put(handleName, bh);
96             }
97         }
98
99         return bh;
100     }
101
102
103     /**
104      * Constructs a new reference to the bean's handle method given by the
105      * id and handle parameters.
106      *
107      * @param id The id of the bean inside the scope that the bean will be
108      * placed in.
109      * @param handle The String that defines the nested properties of the
110      * bean and finally the handle method on the bean
111      * @param scope The scope that this bean is stored in
112      * @param className The Class of the bean so that it can be created if it does
113      * not exist in the scope
114      * @throws BeanException If the definition or scope are invalid or the Class
115      * is null
116      * @asserts If any parameters are null or the scope int is invalid
117      */

118     public FormWebBeanHandle(String JavaDoc id, String JavaDoc handle, int scope, String JavaDoc className)
119     throws BeanException {
120         super(id, handle, scope, className);
121     }
122
123     /**
124      * Constructs a new reference to the bean's handle method given by the
125      * definition parameter.
126      *
127      * @param definition The String that defines not only the name of the bean
128      * inside the scope, but also nested properties of the bean and
129      * finally the handle method on the bean
130      * @param scope The scope that this bean is stored in
131      * @param className The name of the Class of the bean so that it can be
132      * created if it does not exist in the scope
133      * @throws BeanException If the definition or scope are invalid or the Class
134      * is null
135      * @asserts If any parameters are null or the scope int is invalid
136      */

137     public FormWebBeanHandle(String JavaDoc definition, int scope, String JavaDoc className)
138     throws BeanException {
139         super(definition, scope, className);
140     }
141
142     /**
143      * Constructs a new reference to the bean's handle method given by the
144      * definition parameter.
145      *
146      * @param definition The String that defines not only the name of the bean
147      * inside the scope, but also nested properties of the bean and
148      * finally the handle method on the bean
149      * @param scope The scope that this bean is stored in
150      * @param klass The Class of the bean so that it can be created if it does
151      * not exist in the scope
152      * @throws BeanException If the definition or scope are invalid or the Class
153      * is null
154      * @asserts If any parameters are null or the scope int is invalid
155      */

156     public FormWebBeanHandle(String JavaDoc definition, int scope, Class JavaDoc klass)
157     throws BeanException {
158         super(definition, scope, klass);
159     }
160
161     /**
162      * Constructs a new reference to the bean's handle method given by the
163      * definition parameter.
164      *
165      * @param webBean The WebBean that the handle is defined for
166      * @param handle The String that defines the nested properties of the
167      * bean and finally the handle method on the bean
168      * @throws BeanException If the definition or scope are invalid or the Class
169      * is null
170      * @asserts If any parameters are null or the scope int is invalid
171      */

172     public FormWebBeanHandle(WebBean webBean, String JavaDoc handle) throws BeanException {
173         super(webBean, handle);
174     }
175
176
177     /**
178      * Returns the parameters passed to the handle method.
179      *
180      * @return An array of Class objects which are the parameters to the handle
181      * method
182      */

183     public Class JavaDoc[] getHandleParams() {
184         return HANDLE_PARAMS;
185     }
186
187     /**
188      * Returns a BeanHandle that takes the FormAction as its parameter.
189      *
190      * @param handleName The name of the handle method
191      * @param beanClass The bean class
192      * @return The BeanHandle object found (if any)
193      * @throws BeanException If there was a problem locating the BeanHandle
194      */

195     protected BeanHandle findBeanHandle(String JavaDoc handleName, Class JavaDoc beanClass)
196     throws BeanException {
197         return FormWebBeanHandle.getBeanHandle(handleName, beanClass);
198     }
199 }
Popular Tags