001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.directory.api.ldap.model.cursor; 020 021 022import org.apache.directory.api.i18n.I18n; 023import org.apache.directory.api.ldap.model.constants.Loggers; 024import org.apache.directory.api.ldap.model.exception.LdapException; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028 029/** 030 * An empty Cursor implementation. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 * @param <E> The type of element on which this cursor will iterate 034 */ 035public class EmptyCursor<E> extends AbstractCursor<E> 036{ 037 /** A dedicated log for cursors */ 038 private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() ); 039 040 /** Speedup for logs */ 041 private static final boolean IS_DEBUG = LOG_CURSOR.isDebugEnabled(); 042 043 044 public EmptyCursor() 045 { 046 if ( IS_DEBUG ) 047 { 048 LOG_CURSOR.debug( "Creating EmptyCursor : {}", this ); 049 } 050 } 051 052 053 /** 054 * {@inheritDoc} 055 */ 056 public boolean available() 057 { 058 return false; 059 } 060 061 062 /** 063 * {@inheritDoc} 064 */ 065 public void before( E element ) throws LdapException, CursorException 066 { 067 checkNotClosed( "before()" ); 068 } 069 070 071 /** 072 * {@inheritDoc} 073 */ 074 public void after( E element ) throws LdapException, CursorException 075 { 076 checkNotClosed( "after()" ); 077 } 078 079 080 /** 081 * {@inheritDoc} 082 */ 083 public void beforeFirst() throws LdapException, CursorException 084 { 085 checkNotClosed( "beforeFirst()" ); 086 } 087 088 089 /** 090 * {@inheritDoc} 091 */ 092 public void afterLast() throws LdapException, CursorException 093 { 094 checkNotClosed( "afterLast()" ); 095 } 096 097 098 /** 099 * {@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}