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