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.mitosis.operation;
21  
22  
23  import org.apache.directory.mitosis.common.CSN;
24  import org.apache.directory.server.core.CoreSession;
25  import org.apache.directory.server.core.DirectoryService;
26  import org.apache.directory.server.core.entry.ServerAttribute;
27  import org.apache.directory.server.core.entry.ServerEntry;
28  import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
29  import org.apache.directory.server.core.partition.PartitionNexus;
30  import org.apache.directory.server.schema.registries.Registries;
31  import org.apache.directory.shared.ldap.entry.EntryAttribute;
32  import org.apache.directory.shared.ldap.entry.Modification;
33  import org.apache.directory.shared.ldap.entry.ModificationOperation;
34  import org.apache.directory.shared.ldap.name.LdapDN;
35  
36  import java.util.List;
37  
38  
39  /**
40   * An {@link Operation} that deletes an attribute from an entry.
41   *
42   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43   */
44  public class DeleteAttributeOperation extends AttributeOperation
45  {
46      /**
47       * Declares the Serial Version Uid.
48       *
49       * @see <a
50       *      href="http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid">Always
51       *      Declare Serial Version Uid</a>
52       */
53      private static final long serialVersionUID = -131557844165710365L;
54  
55  
56      /**
57       * Creates a new operation that deletes the specified attribute. This 
58       * constructor will not be visible out of this package, as it is 
59       * only used for the deserialization process.
60       * 
61       * @param attribute an attribute to delete
62       */
63      /** No qualifier*/ DeleteAttributeOperation( Registries registries )
64      {
65          super( registries, OperationType.DELETE_ATTRIBUTE );
66      }
67  
68      
69      /**
70       * Creates a new operation that deletes the specified attribute.
71       * 
72       * @param attribute an attribute to delete
73       */
74      public DeleteAttributeOperation( Registries registries, CSN csn, LdapDN name, ServerAttribute attribute )
75      {
76          super( registries, OperationType.DELETE_ATTRIBUTE, csn, name, attribute );
77      }
78  
79  
80      /**
81       * Inject the modified attribute into the server.
82       * 
83       * @param nexus the partition which will be modified
84       * @param coreSession the current session
85       */
86      protected void execute1( PartitionNexus nexus, CoreSession coreSession ) throws Exception
87      {
88          DirectoryService ds = coreSession.getDirectoryService();
89          ServerEntry serverEntry = ds.newEntry( LdapDN.EMPTY_LDAPDN );
90          EntryAttribute attribute = getAttribute();
91          serverEntry.put( attribute );
92          List<Modification> items = ModifyOperationContext.createModItems( serverEntry, 
93              ModificationOperation.REMOVE_ATTRIBUTE );
94  
95          nexus.modify( new ModifyOperationContext( coreSession, getDn(), items ) );
96      }
97  
98  
99      /**
100      * @see Object#toString()
101      */
102     public String toString()
103     {
104         return super.toString() + ".delete( " + getAttribute() + " )";
105     }
106 }