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 org.apache.directory.server.core.interceptor.context.OperationContext;
026    import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
027    import org.apache.directory.shared.ldap.name.DN;
028    import org.apache.directory.shared.ldap.name.RDN;
029    import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
030    
031    
032    public class ModifyDNStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
033    {
034        private boolean deleteOldRn;
035        private DN oldRDN;
036        private RDN newRDN;
037        private DN oldSuperiorDN;
038        private DN newSuperiorDN;
039        private DN oldDN;
040        private DN newDN;
041    
042    
043        public ModifyDNStoredProcedureParameterInjector( OperationContext opContext, boolean deleteOldRn,
044            DN oldRDN, RDN newRDN, DN oldSuperiorDN, DN newSuperiorDN, DN oldDN, DN newDN)
045        {
046            super( opContext );
047            this.deleteOldRn = deleteOldRn;
048            this.oldRDN = oldRDN;
049            this.newRDN = newRDN;
050            this.oldSuperiorDN = oldSuperiorDN;
051            this.newSuperiorDN = newSuperiorDN;
052            this.oldDN = oldDN;
053            this.newDN = newDN;
054            
055            Map<Class<?>, MicroInjector> injectors = super.getInjectors();
056            injectors.put( StoredProcedureParameter.ModifyDN_ENTRY.class, $entryInjector );
057            injectors.put( StoredProcedureParameter.ModifyDN_NEW_RDN.class, $newrdnInjector );
058            injectors.put( StoredProcedureParameter.ModifyDN_DELETE_OLD_RDN.class, $deleteoldrdnInjector );
059            injectors.put( StoredProcedureParameter.ModifyDN_NEW_SUPERIOR.class, $newSuperiorInjector );
060            injectors.put( StoredProcedureParameter.ModifyDN_OLD_RDN.class, $oldRDNInjector );
061            injectors.put( StoredProcedureParameter.ModifyDN_OLD_SUPERIOR_DN.class, $oldSuperiorDNInjector );
062            injectors.put( StoredProcedureParameter.ModifyDN_NEW_DN.class, $newDNInjector );
063            
064        }
065        /**
066         * Injector for 'entry' parameter of ModifyDNRequest as in RFC4511.
067         */
068        MicroInjector $entryInjector = new MicroInjector()
069        {
070            public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
071            {
072                // Return a safe copy constructed with user provided name.
073                return new DN( oldDN.getName() );
074            }
075        };
076    
077        /**
078         * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
079         */
080        MicroInjector $newrdnInjector = new MicroInjector()
081        {
082            public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
083            {
084                // Return a safe copy constructed with user provided name.
085                return new DN( newRDN.getName() );
086            }
087        };
088    
089        /**
090         * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
091         */
092        MicroInjector $deleteoldrdnInjector = new MicroInjector()
093        {
094            public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
095            {
096                // Return a safe copy constructed with user provided name.
097                return deleteOldRn;
098            }
099        };
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 LdapInvalidDnException
107            {
108                // Return a safe copy constructed with user provided name.
109                return new DN( newSuperiorDN.getName() );
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 LdapInvalidDnException
119            {
120                // Return a safe copy constructed with user provided name.
121                return new DN( oldRDN.getName() );
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 LdapInvalidDnException
131            {
132                // Return a safe copy constructed with user provided name.
133                return new DN( oldSuperiorDN.getName() );
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 LdapInvalidDnException
143            {
144                // Return a safe copy constructed with user provided name.
145                return new DN( newDN.getName() );
146            }
147        };
148        
149    }