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 * https://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 * A persistence search object 024 * 025 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 026 */ 027public class PersistentSearchImpl extends AbstractControl implements PersistentSearch 028{ 029 030 /** 031 * If changesOnly is TRUE, the server MUST NOT return any existing entries 032 * that match the search criteria. Entries are only returned when they are 033 * changed (added, modified, deleted, or subject to a modifyDN operation). 034 */ 035 private boolean changesOnly = true; 036 037 /** 038 * If returnECs is TRUE, the server MUST return an Entry Change Notification 039 * control with each entry returned as the result of changes. 040 */ 041 private boolean returnECs = false; 042 043 /** 044 * As changes are made to the server, the effected entries MUST be returned 045 * to the client if they match the standard search criteria and if the 046 * operation that caused the change is included in the changeTypes field. 047 * The changeTypes field is the logical OR of one or more of these values: 048 * add (1), 049 * delete (2), 050 * modify (4), 051 * modDN (8). 052 */ 053 private int changeTypes = CHANGE_TYPES_MAX; 054 055 056 /** 057 * Default constructor 058 * 059 */ 060 public PersistentSearchImpl() 061 { 062 super( OID ); 063 } 064 065 066 /** 067 * {@inheritDoc} 068 */ 069 @Override 070 public void setChangesOnly( boolean changesOnly ) 071 { 072 this.changesOnly = changesOnly; 073 } 074 075 076 /** 077 * {@inheritDoc} 078 */ 079 @Override 080 public boolean isChangesOnly() 081 { 082 return changesOnly; 083 } 084 085 086 /** 087 * {@inheritDoc} 088 */ 089 @Override 090 public void setReturnECs( boolean returnECs ) 091 { 092 this.returnECs = returnECs; 093 } 094 095 096 /** 097 * {@inheritDoc} 098 */ 099 @Override 100 public boolean isReturnECs() 101 { 102 return returnECs; 103 } 104 105 106 /** 107 * {@inheritDoc} 108 */ 109 @Override 110 public void setChangeTypes( int changeTypes ) 111 { 112 this.changeTypes = changeTypes; 113 } 114 115 116 /** 117 * {@inheritDoc} 118 */ 119 @Override 120 public int getChangeTypes() 121 { 122 return changeTypes; 123 } 124 125 126 /** 127 * {@inheritDoc} 128 */ 129 @Override 130 public boolean isNotificationEnabled( ChangeType changeType ) 131 { 132 return ( changeType.getValue() & changeTypes ) > 0; 133 } 134 135 136 /** 137 * {@inheritDoc} 138 */ 139 @Override 140 public void enableNotification( ChangeType changeType ) 141 { 142 changeTypes |= changeType.getValue(); 143 } 144 145 146 /** 147 * {@inheritDoc} 148 */ 149 @Override 150 public void disableNotification( ChangeType changeType ) 151 { 152 changeTypes &= ~changeType.getValue(); 153 } 154 155 156 /** 157 * @see Object#hashCode() 158 */ 159 @Override 160 public int hashCode() 161 { 162 int h = super.hashCode(); 163 164 h = h * 37 + ( changesOnly ? 1 : 0 ); 165 h = h * 37 + ( returnECs ? 1 : 0 ); 166 h = h * 37 + changeTypes; 167 168 return h; 169 } 170 171 172 /** 173 * @see Object#equals(Object) 174 */ 175 @Override 176 public boolean equals( Object other ) 177 { 178 if ( this == other ) 179 { 180 return true; 181 } 182 183 if ( !( other instanceof PersistentSearch ) ) 184 { 185 return false; 186 } 187 188 PersistentSearch otherControl = ( PersistentSearch ) other; 189 190 return super.equals( other ) 191 && ( changesOnly == otherControl.isChangesOnly() ) 192 && ( returnECs == otherControl.isReturnECs() ) 193 && ( changeTypes == otherControl.getChangeTypes() ); 194 } 195 196 197 /** 198 * Return a String representing this PSearchControl. 199 */ 200 @Override 201 public String toString() 202 { 203 StringBuilder sb = new StringBuilder(); 204 205 sb.append( " Persistant Search Control\n" ); 206 sb.append( " oid : " ).append( getOid() ).append( '\n' ); 207 sb.append( " critical : " ).append( isCritical() ).append( '\n' ); 208 sb.append( " changeTypes : '" ).append( changeTypes ).append( "'\n" ); 209 sb.append( " changesOnly : '" ).append( changesOnly ).append( "'\n" ); 210 sb.append( " returnECs : '" ).append( returnECs ).append( "'\n" ); 211 212 return sb.toString(); 213 } 214}