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  package org.apache.directory.server.xdbm;
21  
22  
23  import org.apache.directory.api.ldap.model.cursor.AbstractCursor;
24  import org.apache.directory.api.ldap.model.cursor.CursorException;
25  import org.apache.directory.api.ldap.model.exception.LdapException;
26  import org.apache.directory.server.core.api.partition.PartitionTxn;
27  
28  
29  /**
30   * An abstract Cursor used by the index cursors.
31   *
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public abstract class AbstractIndexCursor<V> extends AbstractCursor<IndexEntry<V, String>>
35  {
36      /** Tells if there are some element available in the cursor */
37      private boolean available = false;
38      
39      /** A transaction associated with this cursor */
40      protected PartitionTxn partitionTxn;
41  
42      /** The message used for unsupported operations */
43      protected static final String UNSUPPORTED_MSG = "Unsupported operation";
44  
45  
46      /**
47       * {@inheritDoc}
48       */
49      public boolean available()
50      {
51          return available;
52      }
53  
54  
55      /**
56       * Gets the message to return for operations that are not supported
57       * 
58       * @return The Unsupported message
59       */
60      protected abstract String getUnsupportedMessage();
61  
62  
63      /**
64       * {@inheritDoc}
65       */
66      public void after( IndexEntry<V, String> element ) throws LdapException, CursorException
67      {
68          throw new UnsupportedOperationException( getUnsupportedMessage() );
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      public void before( IndexEntry<V, String> element ) throws LdapException, CursorException
76      {
77          throw new UnsupportedOperationException( getUnsupportedMessage() );
78      }
79  
80  
81      /**
82       * {@inheritDoc}
83       */
84      protected boolean setAvailable( boolean available )
85      {
86          this.available = available;
87          return available;
88      }
89      
90  
91  
92      @Override
93      public boolean previous() throws LdapException, CursorException
94      {
95          return false;
96      }
97  
98  
99      @Override
100     public boolean next() throws LdapException, CursorException
101     {
102         return false;
103     }
104 }