View Javadoc
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  
21  package org.apache.directory.api.ldap.extras.controls.vlv;
22  
23  
24  import java.util.Arrays;
25  
26  import org.apache.directory.api.ldap.model.message.controls.AbstractControl;
27  import org.apache.directory.api.util.Strings;
28  
29  
30  /**
31   * Virtual List View response control as specified in draft-ietf-ldapext-ldapv3-vlv-09.
32   * 
33   *  VirtualListViewResponse ::= SEQUENCE {
34   *         targetPosition    INTEGER (0 .. maxInt),
35   *         contentCount     INTEGER (0 .. maxInt),
36   *         virtualListViewResult ENUMERATED {
37   *              success (0),
38   *              operationsError (1),
39   *              protocolError (3),
40   *              unwillingToPerform (53),
41   *              insufficientAccessRights (50),
42   *              timeLimitExceeded (3),
43   *              adminLimitExceeded (11),
44   *              innapropriateMatching (18),
45   *              sortControlMissing (60),
46   *              offsetRangeError (61),
47   *              other(80),
48   *              ... },
49   *         contextID     OCTET STRING OPTIONAL }
50   *
51   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
52   */
53  public class VirtualListViewResponseImpl extends AbstractControl implements VirtualListViewResponse
54  {
55  
56      private int targetPosition;
57      private int contentCount;
58      private VirtualListViewResultCode virtualListViewResult;
59      private byte[] contextId;
60  
61  
62      public VirtualListViewResponseImpl()
63      {
64          super( OID );
65      }
66  
67  
68      @Override
69      public int getTargetPosition()
70      {
71          return targetPosition;
72      }
73  
74  
75      @Override
76      public void setTargetPosition( int targetPosition )
77      {
78          this.targetPosition = targetPosition;
79      }
80  
81  
82      @Override
83      public int getContentCount()
84      {
85          return contentCount;
86      }
87  
88  
89      @Override
90      public void setContentCount( int contentCount )
91      {
92          this.contentCount = contentCount;
93      }
94  
95  
96      @Override
97      public VirtualListViewResultCode getVirtualListViewResult()
98      {
99          return virtualListViewResult;
100     }
101 
102 
103     @Override
104     public void setVirtualListViewResult( VirtualListViewResultCode virtualListViewResultCode )
105     {
106         this.virtualListViewResult = virtualListViewResultCode;
107     }
108 
109 
110     @Override
111     public byte[] getContextId()
112     {
113         return contextId;
114     }
115 
116 
117     @Override
118     public void setContextId( byte[] contextId )
119     {
120         this.contextId = contextId;
121     }
122 
123 
124     /**
125      * @see Object#hashCode()
126      */
127     @Override
128     public int hashCode()
129     {
130         int h = super.hashCode();
131 
132         h = h * 37 + targetPosition;
133         h = h * 37 + contentCount;
134         h = h * 37 + ( ( virtualListViewResult == null ) ? 0 : virtualListViewResult.hashCode() );
135 
136         if ( contextId != null )
137         {
138             for ( byte b : contextId )
139             {
140                 h = h * 17 + b;
141             }
142         }
143 
144         return h;
145     }
146 
147 
148     /**
149      * @see Object#equals(Object)
150      */
151     @Override
152     public boolean equals( Object o )
153     {
154         if ( !super.equals( o ) )
155         {
156             return false;
157         }
158 
159         VirtualListViewResponseImpl otherControl = ( VirtualListViewResponseImpl ) o;
160 
161         return ( targetPosition == otherControl.getTargetPosition() ) &&
162             ( contentCount == otherControl.getContentCount() ) &&
163             ( virtualListViewResult == otherControl.getVirtualListViewResult() ) &&
164             Arrays.equals( contextId, otherControl.getContextId() );
165     }
166 
167 
168     /**
169      * Return a String representing this VirtualListViewResponseImpl.
170      */
171     public String toString()
172     {
173         StringBuffer sb = new StringBuffer();
174 
175         sb.append( "    Virtual List View Response Control\n" );
176         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
177         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
178         sb.append( "        targetPosition   : '" ).append( targetPosition ).append( "'\n" );
179         sb.append( "        contentCount   : '" ).append( contentCount ).append( "'\n" );
180         sb.append( "        virtualListViewResult   : '" ).append( virtualListViewResult ).append( "'\n" );
181 
182         if ( contextId != null )
183         {
184             sb.append( "        contextID   : '" ).append( Strings.dumpBytes( contextId ) ).append( "'\n" );
185         }
186 
187         return sb.toString();
188     }
189 }