1 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 ; 30 31 32 public class AnyBeanActionForm extends FormData 33 { 34 private static final Logger _log = Logger.getInstance( AnyBeanActionForm.class ); 35 36 private Object _bean; 37 38 39 public AnyBeanActionForm() 40 { 41 } 42 43 public AnyBeanActionForm( Object bean ) 44 { 45 _bean = bean; 46 } 47 48 public Object getBean() 49 { 50 return _bean; 51 } 52 53 public void setBean( Object bean ) 54 { 55 _bean = bean; 56 } 57 58 public void reset( ActionMapping mapping, HttpServletRequest request ) 59 { 60 if ( _bean == null ) 61 { 62 assert mapping instanceof PageFlowActionMapping : mapping.getClass().getName(); 63 64 String 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 e ) 74 { 75 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 request ) 86 { 87 assert _bean != null; 88 String beanName = mapping.getAttribute(); 89 return validateBean( _bean, beanName, mapping, request ); 90 } 91 92 public String toString() 93 { 94 return "[AnyBeanActionForm wrapper for " + _bean + ']'; 95 } 96 } 97 | Popular Tags |