1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.mina.integration.ognl;
18
19 import java.util.Map;
20
21 import ognl.ObjectPropertyAccessor;
22 import ognl.OgnlContext;
23 import ognl.OgnlException;
24 import ognl.OgnlRuntime;
25 import ognl.PropertyAccessor;
26
27
28
29
30
31
32 public abstract class AbstractPropertyAccessor extends ObjectPropertyAccessor {
33
34 static final Object READ_ONLY_MODE = new Object();
35
36 static final Object QUERY = new Object();
37
38 @Override
39 public final boolean hasGetProperty(OgnlContext context, Object target, Object oname) throws OgnlException {
40 if (oname == null) {
41 return false;
42 }
43
44 if (hasGetProperty0(context, target, oname.toString())) {
45 return true;
46 } else {
47 return super.hasGetProperty(context, target, oname);
48 }
49 }
50
51 @Override
52 public final boolean hasSetProperty(OgnlContext context, Object target, Object oname) throws OgnlException {
53 if (context.containsKey(READ_ONLY_MODE)) {
54
55 return true;
56 }
57
58 if (oname == null) {
59 return false;
60 }
61
62 if (hasSetProperty0(context, target, oname.toString())) {
63 return true;
64 } else {
65 return super.hasSetProperty(context, target, oname);
66 }
67 }
68
69 @Override
70 public final Object getPossibleProperty(Map context, Object target, String name) throws OgnlException {
71 Object answer = getProperty0((OgnlContext) context, target, name);
72 if (answer == OgnlRuntime.NotFound) {
73 answer = super.getPossibleProperty(context, target, name);
74 }
75 return answer;
76 }
77
78 @Override
79 public final Object setPossibleProperty(Map context, Object target, String name, Object value) throws OgnlException {
80 if (context.containsKey(READ_ONLY_MODE)) {
81 throw new OgnlException("Expression must be read-only: " + context.get(QUERY));
82 }
83
84 Object answer = setProperty0((OgnlContext) context, target, name, value);
85 if (answer == OgnlRuntime.NotFound) {
86 answer = super.setPossibleProperty(context, target, name, value);
87 }
88 return answer;
89 }
90
91 protected abstract boolean hasGetProperty0(OgnlContext context, Object target, String name) throws OgnlException;
92
93 protected abstract boolean hasSetProperty0(OgnlContext context, Object target, String name) throws OgnlException;
94
95 protected abstract Object getProperty0(OgnlContext context, Object target, String name) throws OgnlException;
96
97 protected abstract Object setProperty0(OgnlContext context, Object target, String name, Object value)
98 throws OgnlException;
99 }