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 java.io.IOException; 023 024import org.apache.directory.api.i18n.I18n; 025import org.apache.directory.api.ldap.model.constants.Loggers; 026import org.apache.directory.api.ldap.model.exception.LdapException; 027import org.slf4j.Logger; 028import org.slf4j.LoggerFactory; 029 030 031/** 032 * An empty Cursor implementation. 033 * 034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 035 * @param <E> The type of element on which this cursor will iterate 036 */ 037public class EmptyCursor<E> extends AbstractCursor<E> 038{ 039 /** A dedicated log for cursors */ 040 private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() ); 041 042 /** 043 * Creates a new EmptyCursor instance 044 */ 045 public EmptyCursor() 046 { 047 if ( LOG_CURSOR.isDebugEnabled() ) 048 { 049 LOG_CURSOR.debug( I18n.msg( I18n.MSG_13103_CREATING_EMPTY_CURSOR, this ) ); 050 } 051 } 052 053 054 /** 055 * {@inheritDoc} 056 */ 057 @Override 058 public boolean available() 059 { 060 return false; 061 } 062 063 064 /** 065 * {@inheritDoc} 066 */ 067 @Override 068 public void before( E element ) throws LdapException, CursorException 069 { 070 checkNotClosed(); 071 } 072 073 074 /** 075 * {@inheritDoc} 076 */ 077 @Override 078 public void after( E element ) throws LdapException, CursorException 079 { 080 checkNotClosed(); 081 } 082 083 084 /** 085 * {@inheritDoc} 086 */ 087 @Override 088 public void beforeFirst() throws LdapException, CursorException 089 { 090 checkNotClosed(); 091 } 092 093 094 /** 095 * {@inheritDoc} 096 */ 097 @Override 098 public void afterLast() throws LdapException, CursorException 099 { 100 checkNotClosed(); 101 } 102 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 public boolean first() throws LdapException, CursorException 109 { 110 checkNotClosed(); 111 return false; 112 } 113 114 115 /** 116 * {@inheritDoc} 117 */ 118 @Override 119 public boolean last() throws LdapException, CursorException 120 { 121 checkNotClosed(); 122 return false; 123 } 124 125 126 /** 127 * {@inheritDoc} 128 */ 129 @Override 130 public boolean previous() throws LdapException, CursorException 131 { 132 checkNotClosed(); 133 return false; 134 } 135 136 137 /** 138 * {@inheritDoc} 139 */ 140 @Override 141 public boolean next() throws LdapException, CursorException 142 { 143 checkNotClosed(); 144 return false; 145 } 146 147 148 /** 149 * {@inheritDoc} 150 */ 151 @Override 152 public E get() throws CursorException 153 { 154 checkNotClosed(); 155 throw new InvalidCursorPositionException( I18n.err( I18n.ERR_13104_EMPTY_CURSOR ) ); 156 } 157 158 159 /** 160 * {@inheritDoc} 161 */ 162 @Override 163 public void close() throws IOException 164 { 165 if ( LOG_CURSOR.isDebugEnabled() ) 166 { 167 LOG_CURSOR.debug( I18n.msg( I18n.MSG_13100_CLOSING_EMPTY_CURSOR, this ) ); 168 } 169 170 super.close(); 171 } 172 173 174 /** 175 * {@inheritDoc} 176 */ 177 @Override 178 public void close( Exception cause ) throws IOException 179 { 180 if ( LOG_CURSOR.isDebugEnabled() ) 181 { 182 LOG_CURSOR.debug( I18n.msg( I18n.MSG_13100_CLOSING_EMPTY_CURSOR, this ) ); 183 } 184 185 super.close( cause ); 186 } 187}