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