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 *     https://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 */
020package org.apache.directory.api.ldap.codec.api;
021
022
023import org.apache.directory.api.asn1.DecoderException;
024import org.apache.directory.api.asn1.util.Asn1Buffer;
025import org.apache.directory.api.ldap.model.message.Control;
026
027
028/**
029 * Implementors of new codec control extensions must implement a factory using
030 * this factory interface, Factory implementations for specific controls are
031 * then registered with the codec and used by the codec to encode and decode
032 * those controls.
033 *
034 * @param <C> The Control to create
035 *
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 */
038public interface ControlFactory<C extends Control>
039{
040    /**
041     * @return The OID of the Control this factory creates.
042     */
043    String getOid();
044
045
046    /**
047     * Creates and returns a version of the Control.
048     *
049     * @return The {@link CodecControl} decorated version of the Control.
050     */
051    Control newControl();
052
053
054    /**
055     * Encode the value part of the control.
056     *
057     * @param buffer The buffer into which to put the encoded value
058     * @param control The control to encode
059     */
060    void encodeValue( Asn1Buffer buffer, Control control );
061    
062    
063
064
065    /**
066     * Decode a Control's value. It will feed the Control.
067     * 
068     *  @param container The Asn1Container containing the control to feed
069     *  @param control The control to feed
070     *  @param controlBytes The data to decode
071     *  @throws DecoderException If the value can't be decoded
072     */
073    void decodeValue( ControlContainer container, Control control, byte[] controlBytes ) throws DecoderException;
074    
075    
076    /**
077     * Decode a Control's value. It will feed the Control.
078     * 
079     *  @param control The control to feed
080     *  @param controlBytes The data to decode
081     *  @throws DecoderException If the value can't be decoded
082     */
083    void decodeValue( Control control, byte[] controlBytes ) throws DecoderException;
084}