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 public boolean isVisible() 073 { 074 return visibility; 075 } 076 077 078 /** 079 * @param visibility Set the visibility flag 080 */ 081 public void setVisibility( boolean visibility ) 082 { 083 this.visibility = visibility; 084 } 085 086 087 /** 088 * @see Object#hashCode() 089 */ 090 @Override 091 public int hashCode() 092 { 093 int h = super.hashCode(); 094 095 h = h * 37 + ( visibility ? 1 : 0 ); 096 097 return h; 098 } 099 100 101 /** 102 * @see Object#equals(Object) 103 */ 104 public boolean equals( Object o ) 105 { 106 if ( !super.equals( o ) ) 107 { 108 return false; 109 } 110 111 Subentries otherDecorator = ( Subentries ) o; 112 113 return ( visibility == otherDecorator.isVisible() ); 114 } 115 116 117 /** 118 * Return a String representing this EntryChangeControl. 119 */ 120 public String toString() 121 { 122 StringBuffer sb = new StringBuffer(); 123 124 sb.append( " Subentries Control\n" ); 125 sb.append( " oid : " ).append( getOid() ).append( '\n' ); 126 sb.append( " critical : " ).append( isCritical() ).append( '\n' ); 127 sb.append( " Visibility : '" ).append( visibility ).append( "'\n" ); 128 129 return sb.toString(); 130 } 131}