ebourg      2004/10/04 13:06:09

  Modified:    configuration/src/java/org/apache/commons/configuration
                        JNDIConfiguration.java
               configuration/xdocs changes.xml
  Log:
  All NamingEnumerations in JNDIConfiguraiton are now properly closed (Suggested by 
Eric Jung)
  
  Revision  Changes    Path
  1.19      +75 -36    
jakarta-commons/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java
  
  Index: JNDIConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/JNDIConfiguration.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- JNDIConfiguration.java    21 Sep 2004 17:18:27 -0000      1.18
  +++ JNDIConfiguration.java    4 Oct 2004 20:06:09 -0000       1.19
  @@ -132,33 +132,47 @@
        */
       private void recursiveGetKeys(Set keys, Context context, String prefix) throws 
NamingException
       {
  -        // iterates through the context's elements
  -        NamingEnumeration elements = context.list("");
  -        while (elements.hasMore())
  -        {
  -            NameClassPair nameClassPair = (NameClassPair) elements.next();
  -            String name = nameClassPair.getName();
  -            Object object = context.lookup(name);
  +        NamingEnumeration elements = null;
   
  -            // build the key
  -            StringBuffer key = new StringBuffer();
  -            key.append(prefix);
  -            if (key.length() > 0)
  -            {
  -                key.append(".");
  -            }
  -            key.append(name);
  +        try
  +        {
  +            elements = context.list("");
   
  -            if (object instanceof Context)
  +            // iterates through the context's elements
  +            while (elements.hasMore())
               {
  -                // add the keys of the sub context
  -                Context subcontext = (Context) object;
  -                recursiveGetKeys(keys, subcontext, key.toString());
  +                NameClassPair nameClassPair = (NameClassPair) elements.next();
  +                String name = nameClassPair.getName();
  +                Object object = context.lookup(name);
  +
  +                // build the key
  +                StringBuffer key = new StringBuffer();
  +                key.append(prefix);
  +                if (key.length() > 0)
  +                {
  +                    key.append(".");
  +                }
  +                key.append(name);
  +
  +                if (object instanceof Context)
  +                {
  +                    // add the keys of the sub context
  +                    Context subcontext = (Context) object;
  +                    recursiveGetKeys(keys, subcontext, key.toString());
  +                }
  +                else
  +                {
  +                    // add the key
  +                    keys.add(key.toString());
  +                }
               }
  -            else
  +        }
  +        finally
  +        {
  +            // close the enumeration
  +            if (elements != null)
               {
  -                // add the key
  -                keys.add(key.toString());
  +                elements.close();
               }
           }
       }
  @@ -232,19 +246,31 @@
           String key = (String) path.get(0);
   
           // search a context matching the key in the context's elements
  -        NamingEnumeration elements = context.list("");
  -        while (elements.hasMore())
  -        {
  -            NameClassPair nameClassPair = (NameClassPair) elements.next();
  -            String name = nameClassPair.getName();
  -            Object object = context.lookup(name);
  +        NamingEnumeration elements = null;
   
  -            if (object instanceof Context && name.equals(key))
  +        try
  +        {
  +            elements = context.list("");
  +            while (elements.hasMore())
               {
  -                Context subcontext = (Context) object;
  +                NameClassPair nameClassPair = (NameClassPair) elements.next();
  +                String name = nameClassPair.getName();
  +                Object object = context.lookup(name);
   
  -                // recursive search in the sub context
  -                return getContext(path.subList(1, path.size()), subcontext);
  +                if (object instanceof Context && name.equals(key))
  +                {
  +                    Context subcontext = (Context) object;
  +
  +                    // recursive search in the sub context
  +                    return getContext(path.subList(1, path.size()), subcontext);
  +                }
  +            }
  +        }
  +        finally
  +        {
  +            if (elements != null)
  +            {
  +                elements.close();
               }
           }
   
  @@ -268,8 +294,21 @@
       {
           try
           {
  -            NamingEnumeration enumeration = getBaseContext().list("");
  -            return !enumeration.hasMore();
  +            NamingEnumeration enumeration = null;
  +
  +            try
  +            {
  +                enumeration = getBaseContext().list("");
  +                return !enumeration.hasMore();
  +            }
  +            finally
  +            {
  +                // close the enumeration
  +                if (enumeration != null)
  +                {
  +                    enumeration.close();
  +                }
  +            }
           }
           catch (NamingException ne)
           {
  
  
  
  1.50      +4 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- changes.xml       4 Oct 2004 19:35:45 -0000       1.49
  +++ changes.xml       4 Oct 2004 20:06:09 -0000       1.50
  @@ -7,6 +7,10 @@
   
     <body>
       <release version="1.0" date="IN CVS">
  +      <action dev="ebourg" type="update">
  +        All NamingEnumerations in JNDIConfiguraiton are now properly closed 
(Suggested
  +        by Eric Jung).
  +      </action>
         <action dev="ebourg" type="fix" issue="30799">
           Properties added to an XMLConfiguration are no longer duplicated in the
           resulting XML file.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to