1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.request;
25
26 import org.modeshape.common.util.CheckArg;
27 import org.modeshape.common.util.HashCode;
28 import org.modeshape.graph.GraphI18n;
29 import org.modeshape.graph.Location;
30 import org.modeshape.graph.property.Name;
31 import org.modeshape.graph.property.Path;
32
33
34
35
36
37 public class RemovePropertyRequest extends ChangeRequest {
38
39 private static final long serialVersionUID = 1L;
40
41 private final Location from;
42 private final String workspaceName;
43 private final Name propertyName;
44 private Location actualLocation;
45
46
47
48
49
50
51
52
53
54 public RemovePropertyRequest( Location from,
55 String workspaceName,
56 Name propertyName ) {
57 CheckArg.isNotNull(from, "from");
58 CheckArg.isNotNull(propertyName, "propertyName");
59 CheckArg.isNotNull(workspaceName, "workspaceName");
60 this.workspaceName = workspaceName;
61 this.from = from;
62 this.propertyName = propertyName;
63 }
64
65
66
67
68
69
70 @Override
71 public boolean isReadOnly() {
72 return false;
73 }
74
75
76
77
78
79
80 public Location from() {
81 return from;
82 }
83
84
85
86
87
88
89 public String inWorkspace() {
90 return workspaceName;
91 }
92
93
94
95
96
97
98 public Name propertyName() {
99 return propertyName;
100 }
101
102
103
104
105
106
107
108
109
110
111 public void setActualLocationOfNode( Location actual ) {
112 checkNotFrozen();
113 if (!from.equals(actual)) {
114 throw new IllegalArgumentException(GraphI18n.actualLocationNotEqualToInputLocation.text(actual, from));
115 }
116 assert actual != null;
117 if (!actual.hasPath()) {
118 throw new IllegalArgumentException(GraphI18n.actualLocationMustHavePath.text(actual));
119 }
120 this.actualLocation = actual;
121 }
122
123
124
125
126
127
128 public Location getActualLocationOfNode() {
129 return actualLocation;
130 }
131
132
133
134
135
136
137 @Override
138 public boolean changes( String workspace,
139 Path path ) {
140 return this.workspaceName.equals(workspace) && from.hasPath() && from.getPath().isAtOrBelow(path);
141 }
142
143
144
145
146
147
148 @Override
149 public void cancel() {
150 super.cancel();
151 this.actualLocation = null;
152 }
153
154
155
156
157
158
159 @Override
160 public int hashCode() {
161 return HashCode.compute(from, workspaceName, propertyName);
162 }
163
164
165
166
167
168
169 @Override
170 public boolean equals( Object obj ) {
171 if (obj == this) return true;
172 if (this.getClass().isInstance(obj)) {
173 RemovePropertyRequest that = (RemovePropertyRequest)obj;
174 if (!this.from().isSame(that.from())) return false;
175 if (!this.propertyName().equals(that.propertyName())) return false;
176 if (!this.inWorkspace().equals(that.inWorkspace())) return false;
177 return true;
178 }
179 return false;
180 }
181
182
183
184
185
186
187 @Override
188 public Location changedLocation() {
189 return actualLocation != null ? actualLocation : from;
190 }
191
192
193
194
195
196
197 @Override
198 public String changedWorkspace() {
199 return workspaceName;
200 }
201
202
203
204
205
206
207 @Override
208 public String toString() {
209 return "remove property " + propertyName() + " from " + from() + " in the \"" + workspaceName + "\" workspace";
210 }
211
212
213
214
215
216
217
218
219
220 @Override
221 public RemovePropertyRequest clone() {
222 RemovePropertyRequest request = new RemovePropertyRequest(actualLocation != null ? actualLocation : from, workspaceName,
223 propertyName);
224 request.setActualLocationOfNode(actualLocation);
225 return request;
226 }
227
228 @Override
229 public RequestType getType() {
230 return RequestType.REMOVE_PROPERTY;
231 }
232 }