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  package org.apache.directory.server.xdbm;
20  
21  
22  import java.io.IOException;
23  
24  import org.apache.directory.api.ldap.model.constants.Loggers;
25  import org.apache.directory.api.ldap.model.cursor.CursorException;
26  import org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException;
27  import org.apache.directory.api.ldap.model.exception.LdapException;
28  import org.apache.directory.server.i18n.I18n;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  
32  
33  /**
34   * An empty Cursor implementation.
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   */
38  public class EmptyIndexCursor<K> extends AbstractIndexCursor<K>
39  {
40      /** A dedicated log for cursors */
41      private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() );
42  
43      /** Speedup for logs */
44      private static final boolean IS_DEBUG = LOG_CURSOR.isDebugEnabled();
45  
46  
47      public EmptyIndexCursor()
48      {
49          if ( IS_DEBUG )
50          {
51              LOG_CURSOR.debug( "Creating EmptyIndexCursor {}", this );
52          }
53      }
54  
55  
56      /**
57       * {@inheritDoc}
58       */
59      public void before( IndexEntry<K, String> element ) throws LdapException, CursorException, IOException
60      {
61          checkNotClosed( "before()" );
62      }
63  
64  
65      /**
66       * {@inheritDoc}
67       */
68      protected String getUnsupportedMessage()
69      {
70          return UNSUPPORTED_MSG;
71      }
72  
73  
74      /**
75       * {@inheritDoc}
76       */
77      public void after( IndexEntry<K, String> element ) throws LdapException, CursorException, IOException
78      {
79          checkNotClosed( "after()" );
80      }
81  
82  
83      /**
84       * {@inheritDoc}
85       */
86      public void beforeFirst() throws LdapException, CursorException, IOException
87      {
88          checkNotClosed( "beforeFirst()" );
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      public void afterLast() throws LdapException, CursorException, IOException
96      {
97          checkNotClosed( "afterLast()" );
98      }
99  
100 
101     /**
102      * {@inheritDoc}
103      */
104     public boolean first() throws LdapException, CursorException, IOException
105     {
106         checkNotClosed( "first()" );
107         return false;
108     }
109 
110 
111     /**
112      * {@inheritDoc}
113      */
114     public boolean last() throws LdapException, CursorException, IOException
115     {
116         checkNotClosed( "last()" );
117         return false;
118     }
119 
120 
121     /**
122      * {@inheritDoc}
123      */
124     public boolean previous() throws LdapException, CursorException, IOException
125     {
126         checkNotClosed( "previous()" );
127         return false;
128     }
129 
130 
131     /**
132      * {@inheritDoc}
133      */
134     public boolean next() throws LdapException, CursorException, IOException
135     {
136         checkNotClosed( "next()" );
137         return false;
138     }
139 
140 
141     /**
142      * {@inheritDoc}
143      */
144     public IndexEntry<K, String> get() throws CursorException, IOException
145     {
146         checkNotClosed( "get()" );
147         throw new InvalidCursorPositionException( I18n.err( I18n.ERR_703 ) );
148     }
149 
150 
151     /**
152      * {@inheritDoc}
153      */
154     public void afterValue( String id, K indexValue ) throws Exception
155     {
156         checkNotClosed( "after()" );
157     }
158 
159 
160     /**
161      * {@inheritDoc}
162      */
163     public void beforeValue( String id, K indexValue ) throws Exception
164     {
165         checkNotClosed( "after()" );
166     }
167 
168 
169     /**
170      * {@inheritDoc}
171      */
172     public void close()
173     {
174         if ( IS_DEBUG )
175         {
176             LOG_CURSOR.debug( "Closing EmptyIndexCursor {}", this );
177         }
178 
179         super.close();
180     }
181 
182 
183     /**
184      * {@inheritDoc}
185      */
186     public void close( Exception cause )
187     {
188         if ( IS_DEBUG )
189         {
190             LOG_CURSOR.debug( "Closing EmptyIndexCursor {}", this );
191         }
192 
193         super.close( cause );
194     }
195 }