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