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 @SuppressWarnings("unchecked")
33 public abstract class AbstractPropertyAccessor extends ObjectPropertyAccessor {
34
35 static final Object READ_ONLY_MODE = new Object();
36
37 static final Object QUERY = new Object();
38
39 @Override
40 public final boolean hasGetProperty(OgnlContext context, Object target, Object oname) throws OgnlException {
41 if (oname == null) {
42 return false;
43 }
44
45 if (hasGetProperty0(context, target, oname.toString())) {
46 return true;
47 } else {
48 return super.hasGetProperty(context, target, oname);
49 }
50 }
51
52 @Override
53 public final boolean hasSetProperty(OgnlContext context, Object target, Object oname) throws OgnlException {
54 if (context.containsKey(READ_ONLY_MODE)) {
55
56 return true;
57 }
58
59 if (oname == null) {
60 return false;
61 }
62
63 if (hasSetProperty0(context, target, oname.toString())) {
64 return true;
65 } else {
66 return super.hasSetProperty(context, target, oname);
67 }
68 }
69
70 @Override
71 public final Object getPossibleProperty(Map context, Object target, String name) throws OgnlException {
72 Object answer = getProperty0((OgnlContext) context, target, name);
73 if (answer == OgnlRuntime.NotFound) {
74 answer = super.getPossibleProperty(context, target, name);
75 }
76 return answer;
77 }
78
79 @Override
80 public final Object setPossibleProperty(Map context, Object target, String name, Object value) throws OgnlException {
81 if (context.containsKey(READ_ONLY_MODE)) {
82 throw new OgnlException("Expression must be read-only: " + context.get(QUERY));
83 }
84
85 Object answer = setProperty0((OgnlContext) context, target, name, value);
86 if (answer == OgnlRuntime.NotFound) {
87 answer = super.setPossibleProperty(context, target, name, value);
88 }
89 return answer;
90 }
91
92 protected abstract boolean hasGetProperty0(OgnlContext context, Object target, String name) throws OgnlException;
93
94 protected abstract boolean hasSetProperty0(OgnlContext context, Object target, String name) throws OgnlException;
95
96 protected abstract Object getProperty0(OgnlContext context, Object target, String name) throws OgnlException;
97
98 protected abstract Object setProperty0(OgnlContext context, Object target, String name, Object value)
99 throws OgnlException;
100
101
102
103
104 @Override
105 public final Object getProperty(Map context, Object target, Object oname) throws OgnlException {
106 return super.getProperty(context, target, oname);
107 }
108
109 @Override
110 public final boolean hasGetProperty(Map context, Object target, Object oname) throws OgnlException {
111 return super.hasGetProperty(context, target, oname);
112 }
113
114 @Override
115 public final boolean hasSetProperty(Map context, Object target, Object oname) throws OgnlException {
116 return super.hasSetProperty(context, target, oname);
117 }
118
119 @Override
120 public final void setProperty(Map context, Object target, Object oname, Object value) throws OgnlException {
121 super.setProperty(context, target, oname, value);
122 }
123 }