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 */ 020package org.apache.directory.api.ldap.codec; 021 022 023import java.nio.ByteBuffer; 024 025import org.apache.directory.api.asn1.Asn1Object; 026import org.apache.directory.api.asn1.DecoderException; 027import org.apache.directory.api.asn1.EncoderException; 028import org.apache.directory.api.i18n.I18n; 029import org.apache.directory.api.ldap.codec.api.ControlDecorator; 030import org.apache.directory.api.ldap.codec.api.LdapApiService; 031import org.apache.directory.api.ldap.model.message.Control; 032 033 034/** 035 * A decorator for handling opaque Control objects where we know nothing about 036 * their encoded value. These Controls are generated by default when an 037 * {@link ControlFactory} for them has not been registered with the 038 * {@link LdapApiService}. 039 * 040 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 041 * @version $Rev$, $Date$ 042 */ 043public class BasicControlDecorator<E> extends ControlDecorator<Control> 044{ 045 /** 046 * Creates a new instance of BasicControlDecorator, decorating a 047 * {@link Control}. 048 * 049 * @param codec The LDAP codec service. 050 * @param control The {@link Control} to decorate. 051 */ 052 public BasicControlDecorator( LdapApiService codec, Control control ) 053 { 054 super( codec, control ); 055 } 056 057 058 /** 059 * {@inheritDoc} 060 */ 061 public Asn1Object decode( byte[] controlBytes ) throws DecoderException 062 { 063 return null; 064 } 065 066 067 /** 068 * {@inheritDoc} 069 */ 070 public int computeLength() 071 { 072 // Call the super class to compute the global control length 073 if ( getValue() == null ) 074 { 075 valueLength = 0; 076 } 077 else 078 { 079 valueLength = getValue().length; 080 } 081 082 return valueLength; 083 } 084 085 086 /** 087 * {@inheritDoc} 088 */ 089 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException 090 { 091 if ( buffer == null ) 092 { 093 throw new EncoderException( I18n.err( I18n.ERR_04023 ) ); 094 } 095 096 if ( valueLength != 0 ) 097 { 098 buffer.put( getValue() ); 099 } 100 101 return buffer; 102 } 103}