001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.core.interceptor.context;
021
022
023 import org.apache.directory.server.core.CoreSession;
024 import org.apache.directory.server.i18n.I18n;
025 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
026 import org.apache.directory.shared.ldap.codec.controls.ManageDsaITControl;
027 import org.apache.directory.shared.ldap.message.internal.InternalModifyDnRequest;
028 import org.apache.directory.shared.ldap.name.DN;
029
030
031 /**
032 * A Move context used for Interceptors. It contains all the informations
033 * needed for the modify DN operation, and used by all the interceptors
034 *
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 * @version $Rev$, $Date$
037 */
038 public class MoveOperationContext extends AbstractChangeOperationContext
039 {
040 /** The parent DN */
041 private DN parent;
042
043
044 /**
045 * Creates a new instance of MoveOperationContext.
046 */
047 public MoveOperationContext( CoreSession session )
048 {
049 super( session );
050 }
051
052
053 /**
054 * Creates a new instance of MoveOperationContext.
055 */
056 public MoveOperationContext( CoreSession session, DN oldDn, DN parent )
057 {
058 super( session, oldDn );
059 this.parent = parent;
060 }
061
062
063 public MoveOperationContext( CoreSession session, InternalModifyDnRequest modifyDnRequest )
064 {
065 super( session, modifyDnRequest.getName() );
066 this.parent = modifyDnRequest.getNewSuperior();
067
068 if ( parent == null )
069 {
070 throw new IllegalArgumentException( I18n.err( I18n.ERR_326, modifyDnRequest ) );
071 }
072
073 this.requestControls = modifyDnRequest.getControls();
074
075 if ( modifyDnRequest.getNewRdn() != null )
076 {
077 throw new IllegalArgumentException( I18n.err( I18n.ERR_327, modifyDnRequest ) );
078 }
079
080 if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
081 {
082 ignoreReferral();
083 }
084 else
085 {
086 throwReferral();
087 }
088 }
089
090
091 /**
092 * @return The parent DN
093 */
094 public DN getParent()
095 {
096 return parent;
097 }
098
099
100 /**
101 * Set the parent DN
102 *
103 * @param parent The parent
104 */
105 public void setParent( DN parent )
106 {
107 this.parent = parent;
108 }
109
110
111 /**
112 * @return the operation name
113 */
114 public String getName()
115 {
116 return MessageTypeEnum.MODIFYDN_REQUEST.name();
117 }
118
119
120 /**
121 * @see Object#toString()
122 */
123 public String toString()
124 {
125 return "ReplaceContext for old DN '" + getDn().getName() + "'" +
126 ", parent '" + parent + "'";
127 }
128 }