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