View Javadoc
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.api.interceptor.context;
21  
22  
23  import org.apache.directory.api.ldap.model.entry.Entry;
24  import org.apache.directory.api.ldap.model.message.DeleteRequest;
25  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
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.server.core.api.CoreSession;
29  import org.apache.directory.server.core.api.OperationEnum;
30  
31  
32  /**
33   * A Delete context used for Interceptors. It contains all the informations
34   * needed for the delete operation, and used by all the interceptors
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public class DeleteOperationContext extends AbstractChangeOperationContext
39  {
40      /**
41       * Creates a new instance of DeleteOperationContext.
42       * 
43       * @param session The session to use
44       */
45      public DeleteOperationContext( CoreSession session )
46      {
47          super( session );
48  
49          if ( session != null )
50          {
51              setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.DELETE ) );
52          }
53      }
54  
55  
56      /**
57       * Creates a new instance of DeleteOperationContext.
58       *
59       * @param session The session to use
60       * @param deleteDn The entry Dn to delete
61       */
62      public DeleteOperationContext( CoreSession session, Dn deleteDn )
63      {
64          super( session, deleteDn );
65  
66          if ( session != null )
67          {
68              setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.DELETE ) );
69          }
70      }
71  
72  
73      /**
74       * Creates a new instance of DeleteOperationContext.
75       * 
76       * @param session The session to use
77       * @param deleteRequest The Delete operation to process
78       */
79      public DeleteOperationContext( CoreSession session, DeleteRequest deleteRequest )
80      {
81          super( session, deleteRequest.getName() );
82  
83          if ( session != null )
84          {
85              setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.DELETE ) );
86          }
87  
88          requestControls = deleteRequest.getControls();
89  
90          if ( requestControls.containsKey( ManageDsaIT.OID ) )
91          {
92              ignoreReferral();
93          }
94          else
95          {
96              throwReferral();
97          }
98      }
99  
100 
101     /**
102      * @return the operation name
103      */
104     public String getName()
105     {
106         return MessageTypeEnum.DEL_REQUEST.name();
107     }
108 
109 
110     /**
111      * @see Object#toString()
112      */
113     public String toString()
114     {
115         return "DeleteContext for Dn '" + getDn().getName() + "'";
116     }
117 
118 
119     /**
120      * @param entry the entry to set
121      */
122     public void setEntry( Entry entry )
123     {
124         this.entry = entry;
125     }
126 }