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 public void setActualLocationOfNode( Location actual ) {
111 checkNotFrozen();
112 CheckArg.isNotNull(actual, "actual");
113 if (!actual.hasPath()) {
114 throw new IllegalArgumentException(GraphI18n.actualLocationMustHavePath.text(actual));
115 }
116 this.actualLocation = actual;
117 }
118
119
120
121
122
123
124 public Location getActualLocationOfNode() {
125 return actualLocation;
126 }
127
128
129
130
131
132
133 @Override
134 public boolean changes( String workspace,
135 Path path ) {
136 return this.workspaceName.equals(workspace) && from.hasPath() && from.getPath().isAtOrBelow(path);
137 }
138
139
140
141
142
143
144 @Override
145 public void cancel() {
146 super.cancel();
147 this.actualLocation = null;
148 }
149
150
151
152
153
154
155 @Override
156 public int hashCode() {
157 return HashCode.compute(from, workspaceName, propertyName);
158 }
159
160
161
162
163
164
165 @Override
166 public boolean equals( Object obj ) {
167 if (obj == this) return true;
168 if (this.getClass().isInstance(obj)) {
169 RemovePropertyRequest that = (RemovePropertyRequest)obj;
170 if (!this.from().isSame(that.from())) return false;
171 if (!this.propertyName().equals(that.propertyName())) return false;
172 if (!this.inWorkspace().equals(that.inWorkspace())) return false;
173 return true;
174 }
175 return false;
176 }
177
178
179
180
181
182
183 @Override
184 public Location changedLocation() {
185 return actualLocation != null ? actualLocation : from;
186 }
187
188
189
190
191
192
193 @Override
194 public String changedWorkspace() {
195 return workspaceName;
196 }
197
198
199
200
201
202
203 @Override
204 public String toString() {
205 return "remove property " + propertyName() + " from " + from() + " in the \"" + workspaceName + "\" workspace";
206 }
207
208
209
210
211
212
213
214
215
216 @Override
217 public RemovePropertyRequest clone() {
218 RemovePropertyRequest request = new RemovePropertyRequest(actualLocation != null ? actualLocation : from, workspaceName,
219 propertyName);
220 request.setActualLocationOfNode(actualLocation);
221 return request;
222 }
223
224 @Override
225 public RequestType getType() {
226 return RequestType.REMOVE_PROPERTY;
227 }
228 }