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.ModifyDnRequest;
25 import org.apache.directory.shared.ldap.name.LdapDN;
26 import org.apache.directory.shared.ldap.name.Rdn;
27
28
29 /**
30 * A Move And Rename 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 MoveAndRenameOperationContext extends RenameOperationContext
37 {
38 /** The parent DN */
39 private LdapDN parent;
40
41 /** Cached calculated new DN after move and rename */
42 private LdapDN newDn;
43
44 /**
45 * Creates a new instance of MoveAndRenameOperationContext.
46 */
47 public MoveAndRenameOperationContext( CoreSession session )
48 {
49 super( session );
50 }
51
52
53 /**
54 * Creates a new instance of MoveAndRenameOperationContext.
55 *
56 * @param oldDn the original source entry DN to be moved and renamed
57 * @param parent the new entry superior of the target after the move
58 * @param newRdn the new rdn to use for the target once renamed
59 * @param delOldRdn true if the old rdn value is deleted, false otherwise
60 */
61 public MoveAndRenameOperationContext( CoreSession session, LdapDN oldDn, LdapDN parent, Rdn newRdn, boolean delOldRdn )
62 {
63 super( session, oldDn, newRdn, delOldRdn );
64 this.parent = parent;
65 }
66
67
68 public MoveAndRenameOperationContext( CoreSession session, ModifyDnRequest modifyDnRequest )
69 {
70 // super sets the newRdn and the delOldRdn members and tests
71 super( session, modifyDnRequest );
72 this.parent = modifyDnRequest.getNewSuperior();
73
74 if ( parent == null )
75 {
76 throw new IllegalStateException( "NewSuperior must not be null: " + modifyDnRequest );
77 }
78 }
79
80
81 /**
82 * @return The parent DN
83 */
84 public LdapDN getParent()
85 {
86 return parent;
87 }
88
89
90 /**
91 * Set the parent DN
92 *
93 * @param parent The parent
94 */
95 public void setParent( LdapDN parent )
96 {
97 this.parent = parent;
98 }
99
100
101 /**
102 * Gets cached copy of already computed new name or creates it if not
103 *
104 * @return the normalized new name after move and rename
105 * @throws Exception if the name cannot be normalized
106 */
107 public LdapDN getNewDn() throws Exception
108 {
109 if ( newDn == null )
110 {
111 newDn = new LdapDN( getParent().getUpName() );
112 newDn.add( getNewRdn().getUpName() );
113 newDn.normalize( session.getDirectoryService()
114 .getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
115 }
116
117 return newDn;
118 }
119
120
121 /**
122 * @see Object#toString()
123 */
124 public String toString()
125 {
126 return "ReplaceContext for old DN '" + getDn().getUpName() + "'" +
127 ", parent '" + parent + "'";
128 }
129 }