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.trigger;
21  
22  
23  import java.util.Map;
24  
25  import org.apache.directory.api.ldap.model.constants.SchemaConstants;
26  import org.apache.directory.api.ldap.model.entry.Entry;
27  import org.apache.directory.api.ldap.model.exception.LdapException;
28  import org.apache.directory.api.ldap.model.name.Dn;
29  import org.apache.directory.api.ldap.trigger.StoredProcedureParameter;
30  import org.apache.directory.server.core.api.CoreSession;
31  import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
32  import org.apache.directory.server.core.api.interceptor.context.OperationContext;
33  
34  
35  public class DeleteStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
36  {
37      private Dn deletedEntryName;
38      private Entry deletedEntry;
39  
40  
41      public DeleteStoredProcedureParameterInjector( OperationContext opContext, Dn deletedEntryName )
42          throws LdapException
43      {
44          super( opContext );
45          this.deletedEntryName = deletedEntryName;
46          this.deletedEntry = getDeletedEntry( opContext );
47          Map<Class<?>, MicroInjector> injectors = super.getInjectors();
48          injectors.put( StoredProcedureParameter.Delete_NAME.class, nameInjector );
49          injectors.put( StoredProcedureParameter.Delete_DELETED_ENTRY.class, deletedEntryInjector );
50      }
51  
52      MicroInjector nameInjector = new MicroInjector()
53      {
54          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
55          {
56              // Return a safe copy constructed with user provided name.
57              return opContext.getSession().getDirectoryService().getDnFactory().create( deletedEntryName.getName() );
58          }
59      };
60  
61      MicroInjector deletedEntryInjector = new MicroInjector()
62      {
63          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
64          {
65              return deletedEntry;
66          }
67      };
68  
69  
70      private Entry getDeletedEntry( OperationContext opContext ) throws LdapException
71      {
72          /**
73           * Using LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS here to exclude operational attributes
74           * especially subentry related ones like "triggerExecutionSubentries".
75           */
76          CoreSession session = opContext.getSession();
77          LookupOperationContexttor/context/LookupOperationContext.html#LookupOperationContext">LookupOperationContext lookupContext = new LookupOperationContext( session, deletedEntryName,
78              SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY );
79          lookupContext.setPartition( opContext.getPartition() );
80          lookupContext.setTransaction( opContext.getTransaction() );
81          
82          return session.getDirectoryService().getPartitionNexus().lookup( lookupContext );
83      }
84  }