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.entry.Entry;
26  import org.apache.directory.api.ldap.model.exception.LdapException;
27  import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
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.interceptor.context.OperationContext;
31  
32  
33  public class AddStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
34  {
35      private Dn addedEntryName;
36      private Entry addedEntry;
37  
38  
39      public AddStoredProcedureParameterInjector( OperationContext opContext, Dn addedEntryName,
40          Entry addedEntry )
41      {
42          super( opContext );
43          this.addedEntryName = addedEntryName;
44          this.addedEntry = addedEntry;
45          Map<Class<?>, MicroInjector> injectors = super.getInjectors();
46          injectors.put( StoredProcedureParameter.Add_ENTRY.class, entryInjector );
47          injectors.put( StoredProcedureParameter.Add_ATTRIBUTES.class, attributesInjector );
48      }
49  
50      MicroInjector entryInjector = new MicroInjector()
51      {
52          @Override
53          public Object inject( OperationContext opContext, StoredProcedureParameter param )
54              throws LdapInvalidDnException
55          {
56              // Return a safe copy constructed with user provided name.
57              return opContext.getSession().getDirectoryService().getDnFactory().create( addedEntryName.getName() );
58          }
59      };
60  
61      MicroInjector attributesInjector = new MicroInjector()
62      {
63          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
64          {
65              return addedEntry.clone();
66          }
67      };
68  
69  }