1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.server.core.interceptor.context;
21
22
23 import org.apache.directory.server.core.CoreSession;
24 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
25 import org.apache.directory.shared.ldap.message.ModifyDnRequest;
26 import org.apache.directory.shared.ldap.name.LdapDN;
27
28
29 /**
30 * A Move context used for Interceptors. It contains all the informations
31 * needed for the modify DN operation, and used by all the interceptors
32 *
33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34 * @version $Rev$, $Date$
35 */
36 public class MoveOperationContext extends AbstractChangeOperationContext
37 {
38 /** The parent DN */
39 private LdapDN parent;
40
41
42 /**
43 * Creates a new instance of MoveOperationContext.
44 */
45 public MoveOperationContext( CoreSession session )
46 {
47 super( session );
48 }
49
50
51 /**
52 * Creates a new instance of MoveOperationContext.
53 */
54 public MoveOperationContext( CoreSession session, LdapDN oldDn, LdapDN parent )
55 {
56 super( session, oldDn );
57 this.parent = parent;
58 }
59
60
61 public MoveOperationContext( CoreSession session, ModifyDnRequest modifyDnRequest )
62 {
63 super( session, modifyDnRequest.getName() );
64 this.parent = modifyDnRequest.getNewSuperior();
65
66 if ( parent == null )
67 {
68 throw new IllegalArgumentException( "The new superior cannot be null for " + modifyDnRequest );
69 }
70
71 this.requestControls = modifyDnRequest.getControls();
72 if ( modifyDnRequest.getNewRdn() != null )
73 {
74 throw new IllegalArgumentException( modifyDnRequest + " represents a move and rename operation." );
75 }
76 }
77
78
79 /**
80 * @return The parent DN
81 */
82 public LdapDN getParent()
83 {
84 return parent;
85 }
86
87
88 /**
89 * Set the parent DN
90 *
91 * @param parent The parent
92 */
93 public void setParent( LdapDN parent )
94 {
95 this.parent = parent;
96 }
97
98
99 /**
100 * @return the operation name
101 */
102 public String getName()
103 {
104 return MessageTypeEnum.MOD_DN_REQUEST.name();
105 }
106
107
108 /**
109 * @see Object#toString()
110 */
111 public String toString()
112 {
113 return "ReplaceContext for old DN '" + getDn().getUpName() + "'" +
114 ", parent '" + parent + "'";
115 }
116 }