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 */ 020 021package org.apache.directory.api.ldap.extras.controls.vlv; 022 023 024import java.util.Arrays; 025 026import org.apache.directory.api.ldap.model.message.controls.AbstractControl; 027import org.apache.directory.api.util.Strings; 028 029 030/** 031 * Virtual List View response control as specified in draft-ietf-ldapext-ldapv3-vlv-09. 032 * 033 * VirtualListViewResponse ::= SEQUENCE { 034 * targetPosition INTEGER (0 .. maxInt), 035 * contentCount INTEGER (0 .. maxInt), 036 * virtualListViewResult ENUMERATED { 037 * success (0), 038 * operationsError (1), 039 * protocolError (3), 040 * unwillingToPerform (53), 041 * insufficientAccessRights (50), 042 * timeLimitExceeded (3), 043 * adminLimitExceeded (11), 044 * innapropriateMatching (18), 045 * sortControlMissing (60), 046 * offsetRangeError (61), 047 * other(80), 048 * ... }, 049 * contextID OCTET STRING OPTIONAL } 050 * 051 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 052 */ 053public class VirtualListViewResponseImpl extends AbstractControl implements VirtualListViewResponse 054{ 055 private int targetPosition; 056 private int contentCount; 057 private VirtualListViewResultCode virtualListViewResult; 058 private byte[] contextId; 059 060 /** 061 * Creates a new VirtualListViewResponseImpl instance 062 */ 063 public VirtualListViewResponseImpl() 064 { 065 super( OID ); 066 } 067 068 069 /** 070 * {@inheritDoc} 071 */ 072 @Override 073 public int getTargetPosition() 074 { 075 return targetPosition; 076 } 077 078 079 /** 080 * {@inheritDoc} 081 */ 082 @Override 083 public void setTargetPosition( int targetPosition ) 084 { 085 this.targetPosition = targetPosition; 086 } 087 088 089 /** 090 * {@inheritDoc} 091 */ 092 @Override 093 public int getContentCount() 094 { 095 return contentCount; 096 } 097 098 099 /** 100 * {@inheritDoc} 101 */ 102 @Override 103 public void setContentCount( int contentCount ) 104 { 105 this.contentCount = contentCount; 106 } 107 108 109 /** 110 * {@inheritDoc} 111 */ 112 @Override 113 public VirtualListViewResultCode getVirtualListViewResult() 114 { 115 return virtualListViewResult; 116 } 117 118 119 /** 120 * {@inheritDoc} 121 */ 122 @Override 123 public void setVirtualListViewResult( VirtualListViewResultCode virtualListViewResultCode ) 124 { 125 this.virtualListViewResult = virtualListViewResultCode; 126 } 127 128 129 /** 130 * {@inheritDoc} 131 */ 132 @Override 133 public byte[] getContextId() 134 { 135 return contextId; 136 } 137 138 139 /** 140 * {@inheritDoc} 141 */ 142 @Override 143 public void setContextId( byte[] contextId ) 144 { 145 this.contextId = contextId; 146 } 147 148 149 /** 150 * @see Object#hashCode() 151 */ 152 @Override 153 public int hashCode() 154 { 155 int h = super.hashCode(); 156 157 h = h * 37 + targetPosition; 158 h = h * 37 + contentCount; 159 h = h * 37 + ( ( virtualListViewResult == null ) ? 0 : virtualListViewResult.hashCode() ); 160 161 if ( contextId != null ) 162 { 163 for ( byte b : contextId ) 164 { 165 h = h * 17 + b; 166 } 167 } 168 169 return h; 170 } 171 172 173 /** 174 * @see Object#equals(Object) 175 */ 176 @Override 177 public boolean equals( Object o ) 178 { 179 if ( this == o ) 180 { 181 return true; 182 } 183 184 if ( !( o instanceof VirtualListViewRequest ) ) 185 { 186 return false; 187 } 188 189 VirtualListViewResponse otherControl = ( VirtualListViewResponse ) o; 190 191 return super.equals( o ) 192 && ( targetPosition == otherControl.getTargetPosition() ) 193 && ( contentCount == otherControl.getContentCount() ) 194 && ( virtualListViewResult == otherControl.getVirtualListViewResult() ) 195 && Arrays.equals( contextId, otherControl.getContextId() ); 196 } 197 198 199 /** 200 * Return a String representing this VirtualListViewResponseImpl. 201 */ 202 @Override 203 public String toString() 204 { 205 StringBuilder sb = new StringBuilder(); 206 207 sb.append( " Virtual List View Response Control\n" ); 208 sb.append( " oid : " ).append( getOid() ).append( '\n' ); 209 sb.append( " critical : " ).append( isCritical() ).append( '\n' ); 210 sb.append( " targetPosition : '" ).append( targetPosition ).append( "'\n" ); 211 sb.append( " contentCount : '" ).append( contentCount ).append( "'\n" ); 212 sb.append( " virtualListViewResult : '" ).append( virtualListViewResult ).append( "'\n" ); 213 214 if ( contextId != null ) 215 { 216 sb.append( " contextID : '" ).append( Strings.dumpBytes( contextId ) ).append( "'\n" ); 217 } 218 219 return sb.toString(); 220 } 221}