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.shared.ldap.codec.search.controls.subEntry;
021    
022    
023    import java.nio.ByteBuffer;
024    
025    import org.apache.directory.shared.asn1.AbstractAsn1Object;
026    import org.apache.directory.shared.asn1.ber.tlv.Value;
027    import org.apache.directory.shared.asn1.codec.EncoderException;
028    
029    
030    /**
031     * A searchRequest control : SubEntry
032     * 
033     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034     * @version $Rev: 764131 $
035     */
036    public class SubEntryControlCodec extends AbstractAsn1Object
037    {
038        private boolean visibility = false;
039    
040        /**
041         * Default constructor
042         *
043         */
044        public SubEntryControlCodec()
045        {
046            super();
047        }
048    
049        /**
050         * Check if the subEntry is visible
051         * 
052         * @return true or false.
053         */
054        public boolean isVisible()
055        {
056            return visibility;
057        }
058    
059    
060        /**
061         * Set the visibility flag
062         * 
063         * @param visibility The visibility flag : true or false
064         */
065        public void setVisibility( boolean visibility )
066        {
067            this.visibility = visibility;
068        }
069    
070    
071        /**
072         * Compute the SubEntryControl length 0x01 0x01 [0x00|0xFF]
073         */
074        public int computeLength()
075        {
076            return 1 + 1 + 1;
077        }
078    
079    
080        /**
081         * Encodes the subEntry control.
082         * 
083         * @param buffer The encoded sink
084         * @return A ByteBuffer that contains the encoded PDU
085         * @throws EncoderException If anything goes wrong.
086         */
087        public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
088        {
089            // Allocate the bytes buffer.
090            ByteBuffer bb = ByteBuffer.allocate( computeLength() );
091            Value.encode( bb, visibility );
092    
093            return bb;
094        }
095    
096    
097        /**
098         * Return a String representing this EntryChangeControl.
099         */
100        public String toString()
101        {
102            StringBuffer sb = new StringBuffer();
103    
104            sb.append( "    SubEntry Control\n" );
105            sb.append( "        Visibility   : '" ).append( visibility ).append( "'\n" );
106    
107            return sb.toString();
108        }
109    }