001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.server.core.trigger; 021 022 023 import java.util.Map; 024 025 import javax.naming.NamingException; 026 027 import org.apache.directory.server.core.entry.ClonedServerEntry; 028 import org.apache.directory.server.core.interceptor.context.OperationContext; 029 import org.apache.directory.server.core.partition.ByPassConstants; 030 import org.apache.directory.shared.ldap.entry.ServerEntry; 031 import org.apache.directory.shared.ldap.name.DN; 032 import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter; 033 034 035 public class DeleteStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector 036 { 037 private DN deletedEntryName; 038 private ServerEntry deletedEntry; 039 040 041 public DeleteStoredProcedureParameterInjector( OperationContext opContext, DN deletedEntryName ) 042 throws Exception 043 { 044 super( opContext ); 045 this.deletedEntryName = deletedEntryName; 046 this.deletedEntry = getDeletedEntry( opContext ); 047 Map<Class<?>, MicroInjector> injectors = super.getInjectors(); 048 injectors.put( StoredProcedureParameter.Delete_NAME.class, $nameInjector ); 049 injectors.put( StoredProcedureParameter.Delete_DELETED_ENTRY.class, $deletedEntryInjector ); 050 } 051 052 MicroInjector $nameInjector = new MicroInjector() 053 { 054 public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws Exception 055 { 056 // Return a safe copy constructed with user provided name. 057 return new DN( deletedEntryName.getName() ); 058 } 059 }; 060 061 MicroInjector $deletedEntryInjector = new MicroInjector() 062 { 063 public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException 064 { 065 return deletedEntry; 066 } 067 }; 068 069 070 private ClonedServerEntry getDeletedEntry( OperationContext opContext ) throws Exception 071 { 072 /** 073 * Using LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS here to exclude operational attributes 074 * especially subentry related ones like "triggerExecutionSubentries". 075 */ 076 return opContext.lookup( deletedEntryName, ByPassConstants.LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS ); 077 } 078 }