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.exception.LdapInvalidDnException;
26  import org.apache.directory.api.ldap.model.name.Dn;
27  import org.apache.directory.api.ldap.model.name.Rdn;
28  import org.apache.directory.api.ldap.trigger.StoredProcedureParameter;
29  import org.apache.directory.server.core.api.interceptor.context.OperationContext;
30  
31  
32  public class ModifyDNStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
33  {
34      private boolean deleteOldRn;
35      private Rdn oldRdn;
36      private Rdn newRdn;
37      private Dn oldSuperiorDn;
38      private Dn newSuperiorDn;
39      private Dn oldDn;
40      private Dn newDn;
41  
42  
43      public ModifyDNStoredProcedureParameterInjector( OperationContext opContext, boolean deleteOldRn,
44          Rdn oldRDN, Rdn newRdn, Dn oldSuperiorDn, Dn newSuperiorDn, Dn oldDn, Dn newDn )
45      {
46          super( opContext );
47          this.deleteOldRn = deleteOldRn;
48          this.oldRdn = oldRDN.clone();
49          this.newRdn = newRdn.clone();
50          this.oldSuperiorDn = oldSuperiorDn;
51          this.newSuperiorDn = newSuperiorDn;
52          this.oldDn = oldDn;
53          this.newDn = newDn;
54  
55          Map<Class<?>, MicroInjector> injectors = super.getInjectors();
56          injectors.put( StoredProcedureParameter.ModifyDN_ENTRY.class, entryInjector );
57          injectors.put( StoredProcedureParameter.ModifyDN_NEW_RDN.class, newrdnInjector );
58          injectors.put( StoredProcedureParameter.ModifyDN_DELETE_OLD_RDN.class, deleteoldrdnInjector );
59          injectors.put( StoredProcedureParameter.ModifyDN_NEW_SUPERIOR.class, newSuperiorInjector );
60          injectors.put( StoredProcedureParameter.ModifyDN_OLD_RDN.class, oldRDNInjector );
61          injectors.put( StoredProcedureParameter.ModifyDN_OLD_SUPERIOR_DN.class, oldSuperiorDNInjector );
62          injectors.put( StoredProcedureParameter.ModifyDN_NEW_DN.class, newDNInjector );
63  
64      }
65  
66      /**
67       * Injector for 'entry' parameter of ModifyDNRequest as in RFC4511.
68       */
69      MicroInjector entryInjector = new MicroInjector()
70      {
71          public Object inject( OperationContext opContext, StoredProcedureParameter param )
72              throws LdapInvalidDnException
73          {
74              // Return a safe copy constructed with user provided name.
75              return opContext.getSession().getDirectoryService().getDnFactory().create( oldDn.getName() );
76          }
77      };
78  
79      /**
80       * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
81       */
82      MicroInjector newrdnInjector = new MicroInjector()
83      {
84          public Object inject( OperationContext opContext, StoredProcedureParameter param )
85              throws LdapInvalidDnException
86          {
87              // Return a safe copy constructed with user provided name.
88              return opContext.getSession().getDirectoryService().getDnFactory().create( newRdn.getName() );
89          }
90      };
91  
92      /**
93       * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
94       */
95      MicroInjector deleteoldrdnInjector = new MicroInjector()
96      {
97          public Object inject( OperationContext opContext, StoredProcedureParameter param )
98              throws LdapInvalidDnException
99          {
100             // Return a safe copy constructed with user provided name.
101             return deleteOldRn;
102         }
103     };
104 
105     /**
106      * Injector for 'newSuperior' parameter of ModifyDNRequest as in RFC4511.
107      */
108     MicroInjector newSuperiorInjector = new MicroInjector()
109     {
110         public Object inject( OperationContext opContext, StoredProcedureParameter param )
111             throws LdapInvalidDnException
112         {
113             // Return a safe copy constructed with user provided name.
114             return opContext.getSession().getDirectoryService().getDnFactory().create( newSuperiorDn.getName() );
115         }
116     };
117 
118     /**
119      * Extra injector for 'oldRdn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
120      */
121     MicroInjector oldRDNInjector = new MicroInjector()
122     {
123         public Object inject( OperationContext opContext, StoredProcedureParameter param )
124             throws LdapInvalidDnException
125         {
126             // Return a safe copy constructed with user provided name.
127             return opContext.getSession().getDirectoryService().getDnFactory().create( oldRdn.getName() );
128         }
129     };
130 
131     /**
132      * Extra injector for 'oldRdn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
133      */
134     MicroInjector oldSuperiorDNInjector = new MicroInjector()
135     {
136         public Object inject( OperationContext opContext, StoredProcedureParameter param )
137             throws LdapInvalidDnException
138         {
139             // Return a safe copy constructed with user provided name.
140             return opContext.getSession().getDirectoryService().getDnFactory().create( oldSuperiorDn.getName() );
141         }
142     };
143 
144     /**
145      * Extra injector for 'newDn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
146      */
147     MicroInjector newDNInjector = new MicroInjector()
148     {
149         public Object inject( OperationContext opContext, StoredProcedureParameter param )
150             throws LdapInvalidDnException
151         {
152             // Return a safe copy constructed with user provided name.
153             return opContext.getSession().getDirectoryService().getDnFactory().create( newDn.getName() );
154         }
155     };
156 
157 }