1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.message.controls; 21 22 23 /** 24 * A simple Subentries Control implementation. This control is described in 25 * RFC 3672 : 26 * The subentries control MAY be sent with a searchRequest to control 27 * the visibility of entries and subentries which are within scope. 28 * Non-visible entries or subentries are not returned in response to the 29 * request. 30 * 31 * The subentries control is an LDAP Control whose controlType is 32 * 1.3.6.1.4.1.4203.1.10.1, criticality is TRUE or FALSE (hence absent), 33 * and controlValue contains a BER-encoded BOOLEAN indicating 34 * visibility. A controlValue containing the value TRUE indicates that 35 * subentries are visible and normal entries are not. A controlValue 36 * containing the value FALSE indicates that normal entries are visible 37 * and subentries are not. 38 * 39 * Note that TRUE visibility has the three octet encoding { 01 01 FF } 40 * and FALSE visibility has the three octet encoding { 01 01 00 }. 41 * 42 * The controlValue SHALL NOT be absent. 43 * 44 * In absence of this control, subentries are not visible to singleLevel 45 * and wholeSubtree scope Search requests but are visible to baseObject 46 * scope Search requests. 47 * 48 * There is no corresponding response control. 49 * 50 * This control is not appropriate for non-Search operations. 51 * 52 * 53 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 54 */ 55 public class SubentriesImpl extends AbstractControl implements Subentries 56 { 57 private boolean visibility = false; 58 59 60 /** 61 * Default constructor 62 */ 63 public SubentriesImpl() 64 { 65 super( OID ); 66 } 67 68 69 /** 70 * returns Tells if the Subentry values are visible or not 71 */ 72 @Override 73 public boolean isVisible() 74 { 75 return visibility; 76 } 77 78 79 /** 80 * @param visibility Set the visibility flag 81 */ 82 @Override 83 public void setVisibility( boolean visibility ) 84 { 85 this.visibility = visibility; 86 } 87 88 89 /** 90 * @see Object#hashCode() 91 */ 92 @Override 93 public int hashCode() 94 { 95 int h = super.hashCode(); 96 97 h = h * 37 + ( visibility ? 1 : 0 ); 98 99 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 }