KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > internal > AnyBeanActionForm


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.internal;
19
20 import org.apache.beehive.netui.pageflow.FormData;
21 import org.apache.beehive.netui.pageflow.Validatable;
22 import org.apache.beehive.netui.pageflow.handler.ReloadableClassHandler;
23 import org.apache.beehive.netui.pageflow.handler.Handlers;
24 import org.apache.beehive.netui.pageflow.config.PageFlowActionMapping;
25 import org.apache.beehive.netui.util.logging.Logger;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionErrors;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30
31
32 public class AnyBeanActionForm extends FormData
33 {
34     private static final Logger _log = Logger.getInstance( AnyBeanActionForm.class );
35     
36     private Object JavaDoc _bean;
37
38     
39     public AnyBeanActionForm()
40     {
41     }
42     
43     public AnyBeanActionForm( Object JavaDoc bean )
44     {
45         _bean = bean;
46     }
47     
48     public Object JavaDoc getBean()
49     {
50         return _bean;
51     }
52
53     public void setBean( Object JavaDoc bean )
54     {
55         _bean = bean;
56     }
57     
58     public void reset( ActionMapping mapping, HttpServletRequest JavaDoc request )
59     {
60         if ( _bean == null )
61         {
62             assert mapping instanceof PageFlowActionMapping : mapping.getClass().getName();
63             
64             String JavaDoc formClass = ( ( PageFlowActionMapping ) mapping ).getFormClass();
65             assert formClass != null;
66             
67             try
68             {
69                 ReloadableClassHandler reloadableHandler =
70                         Handlers.get( getServlet().getServletContext() ).getReloadableClassHandler();
71                 _bean = reloadableHandler.newInstance( formClass );
72             }
73             catch ( Exception JavaDoc e )
74             {
75                 // Can be any exception -- not just the reflection-related exceptions...
76
// because the exception could be thrown from the bean's constructor.
77
if ( _log.isErrorEnabled() )
78                 {
79                     _log.error( "Error while creating form-bean object of type " + formClass, e );
80                 }
81             }
82         }
83     }
84
85     public ActionErrors validate( ActionMapping mapping, HttpServletRequest JavaDoc request )
86     {
87         assert _bean != null;
88         String JavaDoc beanName = mapping.getAttribute();
89         return validateBean( _bean, beanName, mapping, request );
90     }
91     
92     public String JavaDoc toString()
93     {
94         return "[AnyBeanActionForm wrapper for " + _bean + ']';
95     }
96 }
97
Popular Tags