01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05:
06: package com.opensymphony.xwork.util;
07:
08: import ognl.OgnlException;
09: import ognl.OgnlRuntime;
10: import ognl.PropertyAccessor;
11:
12: import java.util.Map;
13:
14: /**
15: * Is able to access (set/get) properties on a given object.
16: * <p/>
17: * Uses Ognl internal.
18: *
19: * @author Gabe
20: */
21: public class ObjectProxyPropertyAccessor implements PropertyAccessor {
22: public Object getProperty(Map context, Object target, Object name)
23: throws OgnlException {
24: ObjectProxy proxy = (ObjectProxy) target;
25: setupContext(context, proxy);
26:
27: return OgnlRuntime.getPropertyAccessor(
28: proxy.getValue().getClass()).getProperty(context,
29: target, name);
30:
31: }
32:
33: public void setProperty(Map context, Object target, Object name,
34: Object value) throws OgnlException {
35: ObjectProxy proxy = (ObjectProxy) target;
36: setupContext(context, proxy);
37:
38: OgnlRuntime.getPropertyAccessor(proxy.getValue().getClass())
39: .setProperty(context, target, name, value);
40: }
41:
42: /**
43: * Sets up the context with the last property and last class
44: * accessed.
45: *
46: * @param context
47: * @param proxy
48: */
49: private void setupContext(Map context, ObjectProxy proxy) {
50: OgnlContextState.setLastBeanClassAccessed(context, proxy
51: .getLastClassAccessed());
52: OgnlContextState.setLastBeanPropertyAccessed(context, proxy
53: .getLastPropertyAccessed());
54: }
55: }
|