cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: cocoon-2.0/src/java/org/apache/cocoon/components/store JispFilesystemStore.java
Date Thu, 31 Jul 2003 02:55:15 GMT
vgritsenko    2003/07/30 19:55:15

  Modified:    src/java/org/apache/cocoon/components/store
                        JispFilesystemStore.java
  Log:
  Fix eternal loop in the iterator (fix backported from excalibur).
  
  Revision  Changes    Path
  1.3       +38 -31    cocoon-2.0/src/java/org/apache/cocoon/components/store/JispFilesystemStore.java
  
  Index: JispFilesystemStore.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/components/store/JispFilesystemStore.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JispFilesystemStore.java	29 Jul 2003 17:41:30 -0000	1.2
  +++ JispFilesystemStore.java	31 Jul 2003 02:55:15 -0000	1.3
  @@ -74,6 +74,7 @@
   import java.io.Serializable;
   import java.util.Collections;
   import java.util.Enumeration;
  +import java.util.NoSuchElementException;
   import java.util.Vector;
   
   /**
  @@ -415,6 +416,7 @@
       
       class BTreeObjectEnumeration implements Enumeration
       {
  +        private Object m_Next;
           private BTreeIterator m_Iterator;
           private JispFilesystemStore m_Store;
   
  @@ -422,54 +424,59 @@
           {
               m_Iterator = iterator;
               m_Store = store;
  +
  +            // Obtain first element. If any.
  +            try
  +            {
  +                m_Next = m_Iterator.getKey();
  +            }
  +            catch (IOException ioe)
  +            {
  +                m_Store.getLogger().error("store(..): Exception", ioe);
  +                m_Next = null;
  +            }
           }
   
           public boolean hasMoreElements() 
           {
  -            boolean hasMore = false;
  -            Object tmp = null;
  +            return (m_Next != null);
  +        }
   
  -            try 
  +        public Object nextElement() throws NoSuchElementException
  +        {
  +            if (m_Next == null)
               {
  -                tmp = m_Iterator.getKey();
  +                throw new NoSuchElementException();
  +            }
  +
  +            // Save current element
  +            Object tmp = m_Next;
   
  -                if(m_Iterator.moveNext()) 
  +            // Advance to the next element
  +            try
  +            {
  +                if (m_Iterator.moveNext())
                   {
  -                    hasMore = true;
  +                    m_Next = m_Iterator.getKey();
                   }
  -    
  -                /* resets iterator to the old state **/
  -                m_Iterator.moveTo((KeyObject)tmp);
  -            } 
  +                else
  +                {
  +                    // Can't move to the next element - no more elements.
  +                    m_Next = null;
  +                }
  +            }
               catch (IOException ioe) 
               {
                   m_Store.getLogger().error("store(..): Exception", ioe);
  +                m_Next = null;
               }
               catch (ClassNotFoundException cnfe) 
               {
                   m_Store.getLogger().error("store(..): Exception", cnfe);
  +                m_Next = null;
               }
  -            return hasMore;
  -        }
   
  -        public Object nextElement() 
  -        {
  -            Object tmp = null;
  -
  -            try 
  -            {
  -                tmp = m_Iterator.getKey();
  -                m_Iterator.moveNext();
  -            } 
  -            catch (IOException ioe) 
  -            {
  -                m_Store.getLogger().error("store(..): Exception", ioe);
  -            } 
  -            catch (ClassNotFoundException cnfe) 
  -            {
  -                m_Store.getLogger().error("store(..): Exception", cnfe);
  -            }
  -            // return the real key
  +            // Return the real key
               return tmp.toString();
           }
       }
  
  
  

Mime
View raw message