User: dbudworth
  Date: 01/11/28 17:48:48

  Modified:    src/main/org/jboss/naming Util.java
  Log:
  Added unbind(ctx,name), which removed all parents provided they are empty
  after the named node is unbound.
  
  May want to rename this to unbindTree if people get confused with the
  parental removal
  
  Revision  Changes    Path
  1.8       +32 -1     jboss/src/main/org/jboss/naming/Util.java
  
  Index: Util.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/naming/Util.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Util.java 2001/11/07 01:58:21     1.7
  +++ Util.java 2001/11/29 01:48:48     1.8
  @@ -14,7 +14,7 @@
   /** A static utility class for common JNDI operations.
    *
    * @author [EMAIL PROTECTED]
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class Util
   {
  @@ -106,5 +106,36 @@
           String atom = name.get(size-1);
           Context parentCtx = createSubcontext(ctx, name.getPrefix(size-1));
           parentCtx.rebind(atom, value);
  +    }
  +
  +    /** Unbinds a name from ctx, and removes parents if they are empty
  +     @param ctx, the parent JNDI Context under which the name will be unbound
  +     @param name, The name to unbind
  +     */
  +    public static void unbind(Context ctx, String name)
  +        throws NamingException
  +    {
  +        unbind(ctx,ctx.getNameParser("").parse(name));
  +    }
  +    
  +    /** Unbinds a name from ctx, and removes parents if they are empty
  +     @param ctx, the parent JNDI Context under which the name will be unbound
  +     @param name, The name to unbind
  +     */
  +    public static void unbind(Context ctx, Name name)
  +       throws NamingException
  +    {
  +       ctx.unbind(name); //unbind the end node in the name
  +       int sz = name.size();
  +       //walk the list backwards, stopping at the domain since I don't know if
  +       //a domain can be unbound this way.
  +       while (--sz > 0) //walk the tree backwards, stopping at the domain
  +       {
  +          Name pname = name.getPrefix(sz);
  +          if (ctx.listBindings(pname).hasMore()) //if we have more children stop now
  +             break;
  +          else
  +             ctx.unbind(pname); //must be no children, nuke it and continue
  +       }
       }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to