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 org.apache.directory.server.core.interceptor.context.OperationContext;
24  import org.apache.directory.shared.ldap.name.LdapDN;
25  import org.apache.directory.shared.ldap.name.Rdn;
26  import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
27  
28  import javax.naming.NamingException;
29  import java.util.Map;
30  
31  
32  public class ModifyDNStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
33  {
34      private boolean deleteOldRn;
35      private LdapDN oldRDN;
36      private Rdn newRDN;
37      private LdapDN oldSuperiorDN;
38      private LdapDN newSuperiorDN;
39      private LdapDN oldDN;
40      private LdapDN newDN;
41  
42  
43      public ModifyDNStoredProcedureParameterInjector( OperationContext opContext, boolean deleteOldRn,
44          LdapDN oldRDN, Rdn newRDN, LdapDN oldSuperiorDN, LdapDN newSuperiorDN, LdapDN oldDN, LdapDN newDN)
45      {
46          super( opContext );
47          this.deleteOldRn = deleteOldRn;
48          this.oldRDN = oldRDN;
49          this.newRDN = newRDN;
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       * Injector for 'entry' parameter of ModifyDNRequest as in RFC4511.
67       */
68      MicroInjector $entryInjector = new MicroInjector()
69      {
70          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
71          {
72              // Return a safe copy constructed with user provided name.
73              return new LdapDN( oldDN.getUpName() );
74          }
75      };
76  
77      /**
78       * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
79       */
80      MicroInjector $newrdnInjector = new MicroInjector()
81      {
82          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
83          {
84              // Return a safe copy constructed with user provided name.
85              return new LdapDN( newRDN.getUpName() );
86          }
87      };
88  
89      /**
90       * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
91       */
92      MicroInjector $deleteoldrdnInjector = new MicroInjector()
93      {
94          public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
95          {
96              // Return a safe copy constructed with user provided name.
97              return deleteOldRn;
98          }
99      };
100 
101     /**
102      * Injector for 'newSuperior' parameter of ModifyDNRequest as in RFC4511.
103      */
104     MicroInjector $newSuperiorInjector = new MicroInjector()
105     {
106         public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
107         {
108             // Return a safe copy constructed with user provided name.
109             return new LdapDN( newSuperiorDN.getUpName() );
110         }
111     };
112     
113     /**
114      * Extra injector for 'oldRDN' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
115      */
116     MicroInjector $oldRDNInjector = new MicroInjector()
117     {
118         public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
119         {
120             // Return a safe copy constructed with user provided name.
121             return new LdapDN( oldRDN.getUpName() );
122         }
123     };
124     
125     /**
126      * Extra injector for 'oldRDN' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
127      */
128     MicroInjector $oldSuperiorDNInjector = new MicroInjector()
129     {
130         public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
131         {
132             // Return a safe copy constructed with user provided name.
133             return new LdapDN( oldSuperiorDN.getUpName() );
134         }
135     };
136     
137     /**
138      * Extra injector for 'newDN' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
139      */
140     MicroInjector $newDNInjector = new MicroInjector()
141     {
142         public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws NamingException
143         {
144             // Return a safe copy constructed with user provided name.
145             return new LdapDN( newDN.getUpName() );
146         }
147     };
148     
149 }