01: /*
02: * Created on 16 Jul 2007
03: */
04: package uk.org.ponder.rsf.swf.beans;
05:
06: import java.util.Map;
07:
08: import org.springframework.validation.Errors;
09: import org.springframework.web.bind.WebDataBinder;
10: import org.springframework.webflow.action.FormObjectAccessor;
11:
12: import uk.org.ponder.beanutil.BeanLocator;
13: import uk.org.ponder.beanutil.BeanModelAlterer;
14: import uk.org.ponder.mapping.DARList;
15: import uk.org.ponder.mapping.DARReceiver;
16: import uk.org.ponder.mapping.DataAlterationRequest;
17: import uk.org.ponder.rsf.swf.util.RSFSWFUtil;
18:
19: /** The universal target for all bindings which are destined for a
20: * SWF-managed bean. These are merely queued up here, and then converted
21: * into the equivalent request map as if they had been applied using the
22: * WebDataBinder.
23: * @author Antranig Basman (antranig@caret.cam.ac.uk)
24: */
25:
26: public class SWFBindingBean implements DARReceiver, BeanLocator {
27:
28: private BeanLocator rbl;
29: private BeanModelAlterer alterer;
30:
31: public void setRootBeanLocator(BeanLocator rbl) {
32: this .rbl = rbl;
33: }
34:
35: public void setBeanModelAlterer(BeanModelAlterer alterer) {
36: this .alterer = alterer;
37: }
38:
39: private DARList darlist = new DARList();
40: // TODO: if we really wanted to acquire this, the best method would probably
41: // have to be to subclass FormAction - all useful configuration is protected,
42: // including this and the formObjectAccessor.
43: private WebDataBinder webDataBinder;
44:
45: public boolean addDataAlterationRequest(DataAlterationRequest toadd) {
46: darlist.add(toadd);
47: return true;
48: }
49:
50: // NB: "unbinding" will be performed by the following line:
51: // binder.bind(new MutablePropertyValues(context.getRequestParameters().asMap()));
52:
53: public Map getEquivalentMap() {
54: return RSFSWFUtil.getEquivalentBinderMap(darlist,
55: webDataBinder, alterer);
56: }
57:
58: // Used during the render cycle to locate current form object settings.
59: public Object locateBean(String name) {
60: Errors errors = getErrorsObject();
61: if (errors != null) {
62: return errors.getFieldValue(name);
63: } else {
64: Object formObject = getFormObject();
65: // Spring has already done security checks here
66: return alterer.getBeanValue(name, formObject, null);
67: }
68: }
69:
70: protected Object getFormObject() {
71: return rbl.locateBean(FormObjectAccessor
72: .getCurrentFormObjectName());
73: }
74:
75: protected Errors getErrorsObject() {
76: return (Errors) rbl.locateBean(FormObjectAccessor
77: .getCurrentFormErrorsName());
78: }
79:
80: }
|