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