1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.api.interceptor.context;
21
22
23 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
24 import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
25 import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
26 import org.apache.directory.api.ldap.model.message.controls.ManageDsaIT;
27 import org.apache.directory.api.ldap.model.name.Dn;
28 import org.apache.directory.api.ldap.model.name.Rdn;
29 import org.apache.directory.server.core.api.CoreSession;
30 import org.apache.directory.server.core.api.OperationEnum;
31 import org.apache.directory.server.i18n.I18n;
32
33
34
35
36
37
38
39
40 public class MoveOperationContext extends AbstractChangeOperationContext
41 {
42
43 private Dn oldSuperior;
44
45
46 private Rdn rdn;
47
48
49 private Dn newSuperior;
50
51
52 private Dn newDn;
53
54
55
56
57
58
59
60 public MoveOperationContext( CoreSession session )
61 {
62 super( session );
63
64 if ( session != null )
65 {
66 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.MOVE ) );
67 }
68 }
69
70
71
72
73
74
75
76
77
78 public MoveOperationContext( CoreSession session, Dn oldDn, Dn newSuperior )
79 {
80 super( session, oldDn );
81 this.newSuperior = newSuperior;
82 oldSuperior = oldDn.getParent();
83 rdn = oldDn.getRdn().clone();
84
85 if ( session != null )
86 {
87 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.MOVE ) );
88 }
89
90 try
91 {
92 newDn = newSuperior.add( rdn );
93 }
94 catch ( LdapInvalidDnException lide )
95 {
96 throw new IllegalArgumentException( lide.getMessage(), lide );
97 }
98 }
99
100
101
102
103
104
105
106
107 public MoveOperationContext( CoreSession session, ModifyDnRequest modifyDnRequest )
108 {
109 super( session, modifyDnRequest.getName() );
110 this.newSuperior = modifyDnRequest.getNewSuperior();
111
112 if ( session != null )
113 {
114 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.MOVE ) );
115 }
116
117 if ( newSuperior == null )
118 {
119 throw new IllegalArgumentException( I18n.err( I18n.ERR_326_NEW_SUPERIROR_CANNOT_BE_NULL, modifyDnRequest ) );
120 }
121
122 this.requestControls = modifyDnRequest.getControls();
123
124 if ( modifyDnRequest.getNewRdn() != null )
125 {
126 throw new IllegalArgumentException( I18n.err( I18n.ERR_327_MOVE_AND_RENAME_OPERATION, modifyDnRequest ) );
127 }
128
129 if ( requestControls.containsKey( ManageDsaIT.OID ) )
130 {
131 ignoreReferral();
132 }
133 else
134 {
135 throwReferral();
136 }
137
138 oldSuperior = modifyDnRequest.getName().getParent();
139 rdn = modifyDnRequest.getName().getRdn().clone();
140
141 try
142 {
143 newDn = newSuperior.add( rdn );
144 }
145 catch ( LdapInvalidDnException lide )
146 {
147 throw new IllegalArgumentException( lide.getMessage(), lide );
148 }
149 }
150
151
152
153
154
155 public Dn getOldSuperior()
156 {
157 return oldSuperior;
158 }
159
160
161
162
163
164 public void setOldSuperior( Dn oldSuperior )
165 {
166 this.oldSuperior = oldSuperior;
167 }
168
169
170
171
172
173 public Dn getNewSuperior()
174 {
175 return newSuperior;
176 }
177
178
179
180
181
182 public void setNewSuperior( Dn newSuperior )
183 {
184 this.newSuperior = newSuperior;
185 }
186
187
188
189
190
191 public Rdn getRdn()
192 {
193 return rdn;
194 }
195
196
197
198
199
200 public void setRdn( Rdn rdn )
201 {
202 this.rdn = rdn;
203 }
204
205
206
207
208
209 public Dn getNewDn()
210 {
211 return newDn;
212 }
213
214
215
216
217
218 public void setNewDn( Dn newDn )
219 {
220 this.newDn = newDn;
221 }
222
223
224
225
226
227 @Override
228 public String getName()
229 {
230 return MessageTypeEnum.MODIFYDN_REQUEST.name();
231 }
232
233
234
235
236
237 @Override
238 public String toString()
239 {
240 return "ReplaceContext for old Dn '" + getDn().getName() + "'" + ", newSuperior '" + newSuperior + "'";
241 }
242 }