View Javadoc
1   /*
2    * GenericResourceIterator.java
3    *
4    * Created on December 21, 2004, 1:31 PM
5    */
6   
7   package gov.noaa.eds.xapi.generic;
8   
9   import java.util.Iterator;
10  import java.util.NoSuchElementException;
11  import org.xmldb.api.base.ErrorCodes;
12  import org.xmldb.api.base.Resource;
13  import org.xmldb.api.base.ResourceIterator;
14  import org.xmldb.api.base.XMLDBException;
15  
16  /***
17   * A simple iterator for Resource objects.
18   * @version $Id: GenericResourceIterator.java,v 1.2 2004/12/23 22:26:01 mrxtravis Exp $
19   * @author tns
20   */
21  public class GenericResourceIterator implements ResourceIterator {
22      
23      private Iterator iterator = null;
24      
25      /*** Creates a new instance of GenericResourceIterator */
26      public GenericResourceIterator(Iterator iterator) {
27          this.iterator = iterator;
28      }
29      
30      /***Returns the next resource or throws an XMLDBException if one does not exist.
31       *@return The next resource in this iteration
32       */
33      public Resource nextResource() throws XMLDBException {
34          try {
35              return (Resource) this.iterator.next();
36          } catch (NoSuchElementException e){
37              throw new XMLDBException(ErrorCodes.NO_SUCH_RESOURCE);
38          }
39      }
40      
41      /***
42       * Determines if this iterations has any more resources to iterate through
43       * @return true if there are more resource, false otherwise
44       */
45      public boolean hasMoreResources() throws XMLDBException {
46          return this.iterator.hasNext();
47      }
48      
49  }