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.interceptor.context;
21  
22  
23  import org.apache.directory.server.core.CoreSession;
24  import org.apache.directory.server.core.entry.ClonedServerEntry;
25  import org.apache.directory.server.core.entry.DefaultServerEntry;
26  import org.apache.directory.server.core.entry.ServerEntry;
27  import org.apache.directory.shared.ldap.message.AddRequest;
28  import org.apache.directory.shared.ldap.message.MessageTypeEnum;
29  import org.apache.directory.shared.ldap.name.LdapDN;
30  
31  
32  /**
33   * A Add context used for Interceptors. It contains all the informations
34   * needed for the add operation, and used by all the interceptors
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   * @version $Rev$, $Date$
38   */
39  public class AddOperationContext extends AbstractChangeOperationContext
40  {
41      /**
42       * Creates a new instance of AddOperationContext.
43       * 
44       * @param session the current Session 
45       */
46      public AddOperationContext( CoreSession session )
47      {
48          super( session );
49      }
50  
51  
52      /**
53       * Creates a new instance of AddOperationContext.
54       * 
55       * @param session the current Session 
56       * @param dn the name of the entry being added
57       */
58      public AddOperationContext( CoreSession session, LdapDN dn )
59      {
60          super( session, dn );
61      }
62  
63  
64      /**
65       * Creates a new instance of AddOperationContext.
66       * 
67       * @param session the current Session 
68       * @param entry the entry being added
69       */
70      public AddOperationContext( CoreSession session, ServerEntry entry )
71      {
72          super( session, entry.getDn() );
73          this.entry = new ClonedServerEntry( entry );
74      }
75  
76  
77      /**
78       * Creates a new instance of ModifyOperationContext.
79       *
80       * @param session the current Session 
81       * @param dn the name of the entry being added
82       * @param entry the entry being added
83       */
84      public AddOperationContext( CoreSession session, LdapDN dn, ServerEntry entry )
85      {
86          super( session, dn );
87          this.entry = new ClonedServerEntry( entry );
88      }
89  
90  
91      public AddOperationContext( CoreSession session, AddRequest addRequest ) throws Exception
92      {
93          super( session );
94          this.entry = new ClonedServerEntry( 
95              new DefaultServerEntry( session.getDirectoryService().getRegistries(), addRequest.getEntry() ) );
96          this.dn = addRequest.getEntry().getDn();
97          this.requestControls = addRequest.getControls();
98      }
99  
100 
101     /**
102      * @return the operation name
103      */
104     public String getName()
105     {
106         return MessageTypeEnum.ADD_REQUEST.name();
107     }
108 
109     
110     /**
111      * @see Object#toString()
112      */
113     public String toString()
114     {
115         return "AddContext for DN '" + getDn().getUpName() + "'" + ", added entry: " + entry;
116     }
117 }