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 public String[] attributeNames() {
46 synchronized (support) {
47 return support.attributeNames();
48 }
49 }
50
51
52
53
54
55 public boolean equals(Object other) {
56 if (this == other) {
57 return true;
58 }
59 AttributeAccessorSupport that;
60 if (other instanceof SynchronizedAttributeAccessor) {
61 that = ((SynchronizedAttributeAccessor) other).support;
62 }
63 else if (other instanceof AttributeAccessorSupport) {
64 that = (AttributeAccessorSupport) other;
65 }
66 else {
67 return false;
68 }
69 synchronized (support) {
70 return support.equals(that);
71 }
72 }
73
74
75
76
77
78 public Object getAttribute(String name) {
79 synchronized (support) {
80 return support.getAttribute(name);
81 }
82 }
83
84
85
86
87
88 public boolean hasAttribute(String name) {
89 synchronized (support) {
90 return support.hasAttribute(name);
91 }
92 }
93
94
95
96
97
98 public int hashCode() {
99 return support.hashCode();
100 }
101
102
103
104
105
106 public Object removeAttribute(String name) {
107 synchronized (support) {
108 return support.removeAttribute(name);
109 }
110 }
111
112
113
114
115
116
117 public void setAttribute(String name, Object value) {
118 synchronized (support) {
119 support.setAttribute(name, value);
120 }
121 }
122
123
124
125
126
127
128
129
130 public Object setAttributeIfAbsent(String name, Object value) {
131 synchronized (support) {
132 Object old = getAttribute(name);
133 if (old != null) {
134 return old;
135 }
136 setAttribute(name, value);
137 }
138 return null;
139 }
140
141
142
143
144
145 public String toString() {
146 StringBuffer buffer = new StringBuffer("SynchronizedAttributeAccessor: [");
147 synchronized (support) {
148 String[] names = attributeNames();
149 for (int i = 0; i < names.length; i++) {
150 String name = names[i];
151 buffer.append(names[i]).append("=").append(getAttribute(name));
152 if (i < names.length - 1) {
153 buffer.append(", ");
154 }
155 }
156 buffer.append("]");
157 return buffer.toString();
158 }
159 }
160
161 }