01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.pageflow.config;
20:
21: import org.apache.struts.config.FormBeanConfig;
22: import org.apache.struts.action.ActionFormBean;
23: import org.apache.struts.action.ActionForm;
24: import org.apache.struts.action.ActionServlet;
25: import org.apache.beehive.netui.pageflow.handler.ReloadableClassHandler;
26: import org.apache.beehive.netui.pageflow.handler.Handlers;
27: import org.apache.beehive.netui.util.logging.Logger;
28:
29: /**
30: * Class to handle our extensions to the Struts <form-bean> element.
31: */
32: public class PageFlowActionFormBean extends ActionFormBean {
33: private static final Logger _log = Logger
34: .getInstance(PageFlowActionFormBean.class);
35:
36: private String _actualType; // applicable for non-ActionForm-derived form types
37:
38: public String getActualType() {
39: return _actualType;
40: }
41:
42: public void setActualType(String actualType) {
43: _actualType = actualType;
44: }
45:
46: /**
47: * <p>
48: * Create and return an <code>ActionForm</code> instance appropriate
49: * to the information in this <code>FormBeanConfig</code>.
50: * </p>
51: * <p>
52: * This is different than the base implementation in that it uses our ReloadableClassHandler
53: * to load the form bean class.
54: * </p>
55: *
56: * @param servlet The action servlet
57: * @return ActionForm instance
58: * @exception IllegalAccessException if the Class or the appropriate
59: * constructor is not accessible
60: * @exception InstantiationException if this Class represents an abstract
61: * class, an array class, a primitive type, or void; or if instantiation
62: * fails for some other reason
63: */
64: public ActionForm createActionForm(ActionServlet servlet)
65: throws IllegalAccessException, InstantiationException {
66:
67: // Create a new form bean instance
68: if (getDynamic()) {
69: return super .createActionForm(servlet);
70: }
71:
72: try {
73: ReloadableClassHandler rch = Handlers.get(
74: servlet.getServletContext())
75: .getReloadableClassHandler();
76: Object obj = rch.newInstance(getType());
77: assert obj instanceof ActionForm : obj.getClass().getName();
78: ActionForm form = (ActionForm) obj;
79: form.setServlet(servlet);
80: return form;
81: } catch (ClassNotFoundException e) {
82: _log
83: .error("Could not find form bean class "
84: + getType(), e);
85: return null;
86: }
87: }
88: }
|