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      /**
63       * Creates a new VirtualListViewResponseImpl instance
64       */
65      public VirtualListViewResponseImpl()
66      {
67          super( OID );
68      }
69  
70  
71      @Override
72      public int getTargetPosition()
73      {
74          return targetPosition;
75      }
76  
77  
78      @Override
79      public void setTargetPosition( int targetPosition )
80      {
81          this.targetPosition = targetPosition;
82      }
83  
84  
85      @Override
86      public int getContentCount()
87      {
88          return contentCount;
89      }
90  
91  
92      @Override
93      public void setContentCount( int contentCount )
94      {
95          this.contentCount = contentCount;
96      }
97  
98  
99      @Override
100     public VirtualListViewResultCode getVirtualListViewResult()
101     {
102         return virtualListViewResult;
103     }
104 
105 
106     @Override
107     public void setVirtualListViewResult( VirtualListViewResultCode virtualListViewResultCode )
108     {
109         this.virtualListViewResult = virtualListViewResultCode;
110     }
111 
112 
113     @Override
114     public byte[] getContextId()
115     {
116         return contextId;
117     }
118 
119 
120     @Override
121     public void setContextId( byte[] contextId )
122     {
123         this.contextId = contextId;
124     }
125 
126 
127     /**
128      * @see Object#hashCode()
129      */
130     @Override
131     public int hashCode()
132     {
133         int h = super.hashCode();
134 
135         h = h * 37 + targetPosition;
136         h = h * 37 + contentCount;
137         h = h * 37 + ( ( virtualListViewResult == null ) ? 0 : virtualListViewResult.hashCode() );
138 
139         if ( contextId != null )
140         {
141             for ( byte b : contextId )
142             {
143                 h = h * 17 + b;
144             }
145         }
146 
147         return h;
148     }
149 
150 
151     /**
152      * @see Object#equals(Object)
153      */
154     @Override
155     public boolean equals( Object o )
156     {
157         if ( !super.equals( o ) )
158         {
159             return false;
160         }
161 
162         VirtualListViewResponseImpl otherControl = ( VirtualListViewResponseImpl ) o;
163 
164         return ( targetPosition == otherControl.getTargetPosition() )
165             && ( contentCount == otherControl.getContentCount() )
166             && ( virtualListViewResult == otherControl.getVirtualListViewResult() )
167             && Arrays.equals( contextId, otherControl.getContextId() );
168     }
169 
170 
171     /**
172      * Return a String representing this VirtualListViewResponseImpl.
173      */
174     @Override
175     public String toString()
176     {
177         StringBuilder sb = new StringBuilder();
178 
179         sb.append( "    Virtual List View Response Control\n" );
180         sb.append( "        oid : " ).append( getOid() ).append( '\n' );
181         sb.append( "        critical : " ).append( isCritical() ).append( '\n' );
182         sb.append( "        targetPosition   : '" ).append( targetPosition ).append( "'\n" );
183         sb.append( "        contentCount   : '" ).append( contentCount ).append( "'\n" );
184         sb.append( "        virtualListViewResult   : '" ).append( virtualListViewResult ).append( "'\n" );
185 
186         if ( contextId != null )
187         {
188             sb.append( "        contextID   : '" ).append( Strings.dumpBytes( contextId ) ).append( "'\n" );
189         }
190 
191         return sb.toString();
192     }
193 }