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.shared.ldap.model.message.controls;
021
022
023
024
025/**
026 * A simple Subentries Control implementation. This control is described in 
027 * RFC 3672 :
028 *    The subentries control MAY be sent with a searchRequest to control
029 *    the visibility of entries and subentries which are within scope.
030 *    Non-visible entries or subentries are not returned in response to the
031 *    request.
032 * 
033 *    The subentries control is an LDAP Control whose controlType is
034 *    1.3.6.1.4.1.4203.1.10.1, criticality is TRUE or FALSE (hence absent),
035 *    and controlValue contains a BER-encoded BOOLEAN indicating
036 *    visibility.  A controlValue containing the value TRUE indicates that
037 *    subentries are visible and normal entries are not.  A controlValue
038 *    containing the value FALSE indicates that normal entries are visible
039 *    and subentries are not.
040 * 
041 *    Note that TRUE visibility has the three octet encoding { 01 01 FF }
042 *    and FALSE visibility has the three octet encoding { 01 01 00 }.
043 * 
044 *    The controlValue SHALL NOT be absent.
045 * 
046 *    In absence of this control, subentries are not visible to singleLevel
047 *    and wholeSubtree scope Search requests but are visible to baseObject
048 *    scope Search requests.
049 * 
050 *    There is no corresponding response control.
051 * 
052 *    This control is not appropriate for non-Search operations.
053 * 
054 * 
055 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
056 */
057public class SubentriesImpl extends AbstractControl implements Subentries
058{
059    private boolean visibility = false;
060
061
062    /**
063     * Default constructor
064     */
065    public SubentriesImpl()
066    {
067        super( OID );
068    }
069
070
071    /**
072     * returns Tells if the Subentry values are visible or not
073     */
074    public boolean isVisible()
075    {
076        return visibility;
077    }
078
079
080    /**
081     * @param visibility Set the visibility flag
082     */
083    public void setVisibility( boolean visibility )
084    {
085        this.visibility = visibility;
086    }
087
088
089    /**
090     * @see Object#hashCode()
091     */
092    @Override
093    public int hashCode()
094    {
095        int h = super.hashCode();
096
097        h = h * 37 + ( visibility ? 1 : 0 );
098
099        return h;
100    }
101
102
103    /**
104     * @see Object#equals(Object)
105     */
106    public boolean equals( Object o )
107    {
108        if ( !super.equals( o ) )
109        {
110            return false;
111        }
112
113        Subentries otherDecorator = ( Subentries ) o;
114
115        return ( visibility == otherDecorator.isVisible() );
116    }
117
118
119    /**
120     * Return a String representing this EntryChangeControl.
121     */
122    public String toString()
123    {
124        StringBuffer sb = new StringBuffer();
125
126        sb.append( "    Subentries Control\n" );
127        sb.append( "        oid : " ).append( getOid() ).append( '\n' );
128        sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
129        sb.append( "        Visibility   : '" ).append( visibility ).append( "'\n" );
130
131        return sb.toString();
132    }
133}