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.core.entry.ClonedServerEntry;
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.InternalDeleteRequest;
028 import org.apache.directory.shared.ldap.name.DN;
029
030
031 /**
032 * A Delete context used for Interceptors. It contains all the informations
033 * needed for the delete 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 DeleteOperationContext extends AbstractChangeOperationContext
039 {
040 /**
041 * An optimization added to prevent redundant lookups of the deleted
042 * entry.
043 */
044 private ClonedServerEntry entry;
045
046
047 /**
048 * Creates a new instance of DeleteOperationContext.
049 */
050 public DeleteOperationContext( CoreSession session )
051 {
052 super( session );
053 }
054
055
056 /**
057 * Creates a new instance of DeleteOperationContext.
058 *
059 * @param deleteDn The entry DN to delete
060 */
061 public DeleteOperationContext( CoreSession session, DN deleteDn )
062 {
063 super( session, deleteDn );
064 }
065
066
067 public DeleteOperationContext( CoreSession session, InternalDeleteRequest deleteRequest )
068 {
069 super( session, deleteRequest.getName() );
070 requestControls = deleteRequest.getControls();
071
072 if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
073 {
074 ignoreReferral();
075 }
076 else
077 {
078 throwReferral();
079 }
080 }
081
082
083 /**
084 * @return the operation name
085 */
086 public String getName()
087 {
088 return MessageTypeEnum.DEL_REQUEST.name();
089 }
090
091
092 /**
093 * @see Object#toString()
094 */
095 public String toString()
096 {
097 return "DeleteContext for DN '" + getDn().getName() + "'";
098 }
099
100
101 /**
102 * @param entry the entry to set
103 */
104 public void setEntry( ClonedServerEntry entry )
105 {
106 this.entry = entry;
107 }
108
109
110 /**
111 * Gets the deleted entry if cached. Must be called before deleting the
112 * entry when the entry member is null or this call will fail.
113 *
114 * @return the entry
115 */
116 public ClonedServerEntry getEntry()
117 {
118 return entry;
119 }
120 }