1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.batch.repeat.context;
18
19 import org.springframework.core.AttributeAccessor;
20 import org.springframework.core.AttributeAccessorSupport;
21
22
23
24
25
26
27
28
29 public class SynchronizedAttributeAccessor implements AttributeAccessor {
30
31
32
33
34 AttributeAccessorSupport support = new AttributeAccessorSupport() {
35
36
37
38 private static final long serialVersionUID = -7664290016506582290L;
39 };
40
41
42
43
44
45 @Override
46 public String[] attributeNames() {
47 synchronized (support) {
48 return support.attributeNames();
49 }
50 }
51
52
53
54
55
56 @Override
57 public boolean equals(Object other) {
58 if (this == other) {
59 return true;
60 }
61 AttributeAccessorSupport that;
62 if (other instanceof SynchronizedAttributeAccessor) {
63 that = ((SynchronizedAttributeAccessor) other).support;
64 }
65 else if (other instanceof AttributeAccessorSupport) {
66 that = (AttributeAccessorSupport) other;
67 }
68 else {
69 return false;
70 }
71 synchronized (support) {
72 return support.equals(that);
73 }
74 }
75
76
77
78
79
80 @Override
81 public Object getAttribute(String name) {
82 synchronized (support) {
83 return support.getAttribute(name);
84 }
85 }
86
87
88
89
90
91 @Override
92 public boolean hasAttribute(String name) {
93 synchronized (support) {
94 return support.hasAttribute(name);
95 }
96 }
97
98
99
100
101
102 @Override
103 public int hashCode() {
104 return support.hashCode();
105 }
106
107
108
109
110
111 @Override
112 public Object removeAttribute(String name) {
113 synchronized (support) {
114 return support.removeAttribute(name);
115 }
116 }
117
118
119
120
121
122
123 @Override
124 public void setAttribute(String name, Object value) {
125 synchronized (support) {
126 support.setAttribute(name, value);
127 }
128 }
129
130
131
132
133
134
135
136
137 public Object setAttributeIfAbsent(String name, Object value) {
138 synchronized (support) {
139 Object old = getAttribute(name);
140 if (old != null) {
141 return old;
142 }
143 setAttribute(name, value);
144 }
145 return null;
146 }
147
148
149
150
151
152 @Override
153 public String toString() {
154 StringBuffer buffer = new StringBuffer("SynchronizedAttributeAccessor: [");
155 synchronized (support) {
156 String[] names = attributeNames();
157 for (int i = 0; i < names.length; i++) {
158 String name = names[i];
159 buffer.append(names[i]).append("=").append(getAttribute(name));
160 if (i < names.length - 1) {
161 buffer.append(", ");
162 }
163 }
164 buffer.append("]");
165 return buffer.toString();
166 }
167 }
168
169 }