unico       2004/03/22 05:42:01

  Modified:    src/blocks/repository/java/org/apache/cocoon/generation
                        TraversableGenerator.java
  Log:
  proper releasing of ancestor- and child Sources
  
  Revision  Changes    Path
  1.10      +82 -65    
cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/generation/TraversableGenerator.java
  
  Index: TraversableGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/repository/java/org/apache/cocoon/generation/TraversableGenerator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TraversableGenerator.java 5 Mar 2004 13:02:22 -0000       1.9
  +++ TraversableGenerator.java 22 Mar 2004 13:42:01 -0000      1.10
  @@ -37,6 +37,8 @@
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Date;
  +import java.util.Enumeration;
  +import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   import java.util.Stack;
  @@ -283,13 +285,15 @@
        *                              the source hierarchy 
        */
       public void generate() throws SAXException, ProcessingException {
  -        TraversableSource inputSource = null;
  +             Source src = null;
  +             Stack ancestors = null;
           try {
  -            Source src = this.resolver.resolveURI(this.source);
  +            src = this.resolver.resolveURI(this.source);
               if (!(src instanceof TraversableSource)) {
                   throw new SourceException(this.source + " is not a 
traversable source");
               }
  -            inputSource = (TraversableSource) 
this.resolver.resolveURI(this.source);
  +                     TraversableSource inputSource = 
  +                             (TraversableSource) 
this.resolver.resolveURI(this.source);
   
               if (!inputSource.exists()) {
                   throw new ResourceNotFoundException(this.source + " does not 
exist.");
  @@ -298,7 +302,7 @@
               this.contentHandler.startDocument();
               this.contentHandler.startPrefixMapping(PREFIX, URI);
   
  -            Stack ancestors = getAncestors(inputSource);
  +            ancestors = getAncestors(inputSource);
               addAncestorPath(inputSource, ancestors);
   
               this.contentHandler.endPrefixMapping(PREFIX);
  @@ -312,7 +316,11 @@
               throw new ResourceNotFoundException("Could not read collection "
                                                   + this.source, ioe);
           } finally {
  -            this.resolver.release(inputSource);
  +            this.resolver.release(src);
  +            Enumeration enum = ancestors.elements();
  +            while (enum.hasMoreElements()) {
  +             resolver.release((Source) enum.nextElement());
  +            }
           }
       }
   
  @@ -380,66 +388,75 @@
               if (depth > 0) {
   
                   Collection contents = null;
  -                try {
  -                    contents = source.getChildren();
  -                } catch (SourceException e) {
  -                    throw new ProcessingException("Error adding paths", e);
  -                }
  -
  -                if (sort.equals("name")) {
  -                    Arrays.sort(contents.toArray(), new Comparator() {
  -                        public int compare(Object o1, Object o2) {
  -                            if (reverse) {
  -                                return ((TraversableSource) 
o2).getName().compareTo(((TraversableSource) o1).getName());
  -                            }
  -                            return ((TraversableSource) 
o1).getName().compareTo(((TraversableSource) o2).getName());
  -                        }
  -                    });
  -                } else if (sort.equals("size")) {
  -                    Arrays.sort(contents.toArray(), new Comparator() {
  -                        public int compare(Object o1, Object o2) {
  -                            if (reverse) {
  -                                return new Long(((TraversableSource) 
o2).getContentLength()).compareTo(new Long(((TraversableSource) 
o1).getContentLength()));
  -                            }
  -                            return new Long(((TraversableSource) 
o1).getContentLength()).compareTo(new Long(((TraversableSource) 
o2).getContentLength()));
  -                        }
  -                    });
  -                } else if (sort.equals("lastmodified")) {
  -                    Arrays.sort(contents.toArray(), new Comparator() {
  -                        public int compare(Object o1, Object o2) {
  -                            if (reverse) {
  -                                return new Long(((TraversableSource) 
o2).getLastModified()).compareTo(new Long(((TraversableSource) 
o1).getLastModified()));
  -                            }
  -                            return new Long(((TraversableSource) 
o1).getLastModified()).compareTo(new Long(((TraversableSource) 
o2).getLastModified()));
  -                        }
  -                    });
  -                } else if (sort.equals("collection")) {
  -                    Arrays.sort(contents.toArray(), new Comparator() {
  -                        public int compare(Object o1, Object o2) {
  -                            TraversableSource ts1 = (TraversableSource) o1;
  -                            TraversableSource ts2 = (TraversableSource) o2;
  -
  -                            if (reverse) {
  -                                if (ts2.isCollection() && 
!ts1.isCollection())
  -                                    return -1;
  -                                if (!ts2.isCollection() && 
ts1.isCollection())
  -                                    return 1;
  -                                return 
ts2.getName().compareTo(ts1.getName());
  -                            }
  -                            if (ts2.isCollection() && !ts1.isCollection())
  -                                return 1;
  -                            if (!ts2.isCollection() && ts1.isCollection())
  -                                return -1;
  -                            return ts1.getName().compareTo(ts2.getName());
  -                        }
  -                    });
  -                }
                   
  -                for (int i = 0; i < contents.size(); i++) {
  -                    if (isIncluded((TraversableSource) 
contents.toArray()[i]) && !isExcluded((TraversableSource) 
contents.toArray()[i])) {
  -                        addPath((TraversableSource) contents.toArray()[i], 
depth - 1);
  -                    }
  -                }
  +                             try {
  +                                     contents = source.getChildren();
  +                                     if (sort.equals("name")) {
  +                                         Arrays.sort(contents.toArray(), new 
Comparator() {
  +                                             public int compare(Object o1, 
Object o2) {
  +                                                 if (reverse) {
  +                                                     return 
((TraversableSource) o2).getName().compareTo(((TraversableSource) 
o1).getName());
  +                                                 }
  +                                                 return ((TraversableSource) 
o1).getName().compareTo(((TraversableSource) o2).getName());
  +                                             }
  +                                         });
  +                                     } else if (sort.equals("size")) {
  +                                         Arrays.sort(contents.toArray(), new 
Comparator() {
  +                                             public int compare(Object o1, 
Object o2) {
  +                                                 if (reverse) {
  +                                                     return new 
Long(((TraversableSource) o2).getContentLength()).compareTo(new 
Long(((TraversableSource) o1).getContentLength()));
  +                                                 }
  +                                                 return new 
Long(((TraversableSource) o1).getContentLength()).compareTo(new 
Long(((TraversableSource) o2).getContentLength()));
  +                                             }
  +                                         });
  +                                     } else if (sort.equals("lastmodified")) 
{
  +                                         Arrays.sort(contents.toArray(), new 
Comparator() {
  +                                             public int compare(Object o1, 
Object o2) {
  +                                                 if (reverse) {
  +                                                     return new 
Long(((TraversableSource) o2).getLastModified()).compareTo(new 
Long(((TraversableSource) o1).getLastModified()));
  +                                                 }
  +                                                 return new 
Long(((TraversableSource) o1).getLastModified()).compareTo(new 
Long(((TraversableSource) o2).getLastModified()));
  +                                             }
  +                                         });
  +                                     } else if (sort.equals("collection")) {
  +                                         Arrays.sort(contents.toArray(), new 
Comparator() {
  +                                             public int compare(Object o1, 
Object o2) {
  +                                                 TraversableSource ts1 = 
(TraversableSource) o1;
  +                                                 TraversableSource ts2 = 
(TraversableSource) o2;
  +                                     
  +                                                 if (reverse) {
  +                                                     if (ts2.isCollection() 
&& !ts1.isCollection())
  +                                                         return -1;
  +                                                     if (!ts2.isCollection() 
&& ts1.isCollection())
  +                                                         return 1;
  +                                                     return 
ts2.getName().compareTo(ts1.getName());
  +                                                 }
  +                                                 if (ts2.isCollection() && 
!ts1.isCollection())
  +                                                     return 1;
  +                                                 if (!ts2.isCollection() && 
ts1.isCollection())
  +                                                     return -1;
  +                                                 return 
ts1.getName().compareTo(ts2.getName());
  +                                             }
  +                                         });
  +                                     }
  +                                     
  +                                     for (int i = 0; i < contents.size(); 
i++) {
  +                                         if (isIncluded((TraversableSource) 
contents.toArray()[i]) && !isExcluded((TraversableSource) 
contents.toArray()[i])) {
  +                                             addPath((TraversableSource) 
contents.toArray()[i], depth - 1);
  +                                         }
  +                                     }
  +                             }
  +                             catch (SourceException e) {
  +                                     throw new ProcessingException("Error 
adding paths", e);
  +                             }
  +                             finally {
  +                                     if (contents != null) {
  +                                             Iterator iter = 
contents.iterator();
  +                                             while (iter.hasNext()) {
  +                                                     
resolver.release((Source) iter.next());
  +                                             }
  +                                     }
  +                             }
               }
               endNode(COL_NODE_NAME);
           } else {
  
  
  

Reply via email to