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.ldap;
021    
022    
023    import org.apache.directory.server.core.interceptor.context.OperationContext;
024    import org.apache.directory.shared.ldap.message.internal.InternalRequest;
025    import org.apache.directory.shared.ldap.message.internal.InternalResponse;
026    
027    
028    /**
029     * Utility methods used by the LDAP protocol service.
030     *
031     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032     * @version $Rev$, $Date$
033     */
034    public class LdapProtocolUtils implements LdapProtocolConstants
035    {
036        /**
037         * Extracts request controls from a request to populate into an
038         * OperationContext.
039         *  
040         * @param opContext the context to populate with request controls
041         * @param request the request to extract controls from
042         */
043        public static void setRequestControls( OperationContext opContext, InternalRequest request ) throws Exception
044        {
045            if ( request.getControls() != null )
046            {
047                request.addAll( request.getControls().values().toArray( EMPTY_CONTROLS ) );
048            }
049        }
050    
051    
052        /**
053         * Extracts response controls from a an OperationContext to populate into 
054         * a Response object.
055         *  
056         * @param opContext the context to extract controls from
057         * @param response the response to populate with response controls
058         */
059        public static void setResponseControls( OperationContext opContext, InternalResponse response ) throws Exception
060        {
061            opContext.addRequestControls( opContext.getResponseControls() );
062        }
063    }