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.ServerEntry;
28  import org.apache.directory.server.core.interceptor.context.OperationContext;
29  import org.apache.directory.shared.ldap.name.LdapDN;
30  import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
31  
32  
33  public class AddStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
34  {
35      private LdapDN addedEntryName;
36      private ServerEntry addedEntry;
37      
38      
39      public AddStoredProcedureParameterInjector( OperationContext opContext, LdapDN addedEntryName, 
40          ServerEntry 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      
51      MicroInjector $entryInjector = new MicroInjector()
52      {
53          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
54          {
55              // Return a safe copy constructed with user provided name.
56              return new LdapDN( addedEntryName.getUpName() );
57          }
58      };
59      
60      
61      MicroInjector $attributesInjector = new MicroInjector()
62      {
63          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
64          {
65              return addedEntry.clone();
66          }
67      };
68  
69  }