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 javax.naming.NamingException;
26  
27  import org.apache.directory.server.core.entry.ClonedServerEntry;
28  import org.apache.directory.server.core.entry.ServerEntry;
29  import org.apache.directory.server.core.interceptor.context.OperationContext;
30  import org.apache.directory.server.core.partition.ByPassConstants;
31  import org.apache.directory.shared.ldap.name.LdapDN;
32  import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
33  
34  
35  public class DeleteStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
36  {
37      private LdapDN deletedEntryName;
38      private ServerEntry deletedEntry;
39  
40      
41      public DeleteStoredProcedureParameterInjector( OperationContext opContext, LdapDN deletedEntryName ) 
42          throws Exception
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 Exception
55          {
56              // Return a safe copy constructed with user provided name.
57              return new LdapDN( deletedEntryName.getUpName() );
58          }
59      };
60      
61      MicroInjector $deletedEntryInjector = new MicroInjector()
62      {
63          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
64          {
65              return deletedEntry;
66          }
67      };
68      
69  
70      private ClonedServerEntry getDeletedEntry( OperationContext opContext ) throws Exception
71      {
72          /**
73           * Using LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS here to exclude operational attributes
74           * especially subentry related ones like "triggerExecutionSubentries".
75           */
76          return opContext.lookup( deletedEntryName, ByPassConstants.LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS );
77      }
78  }