User: starksm 
  Date: 01/05/09 20:21:30

  Modified:    src/main/org/jboss/naming Util.java
  Log:
  Add createSubcontext utility methods
  
  Revision  Changes    Path
  1.2       +37 -10    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Util.java 2001/05/09 08:15:02     1.1
  +++ Util.java 2001/05/10 03:21:30     1.2
  @@ -9,30 +9,57 @@
   
   /** A static utility class for common JNDI operations.
    *
  - * @author  [EMAIL PROTECTED]
  - * @version 
  + * @author [EMAIL PROTECTED]
  + * @version $Revision: 1.2 $
    */
   public class Util
   {
   
  -    /** Bind val to name in ctx, and make sure that all intermediate contexts exist
  +    /** Create a subcontext including any intermediate contexts.
  +    @param ctx, the parent JNDI Context under which value will be bound
  +    @param name, the name relative to ctx of the subcontext.
  +    @return The new or existing JNDI subcontext
  +    @throws NamingException, on any JNDI failure
       */
  -    public static void bind(Context ctx, String name, Object value) throws 
NamingException
  +    public static Context createSubcontext(Context ctx, String name) throws 
NamingException
       {
           Name n = ctx.getNameParser("").parse(name);
  -        while( n.size() > 1 )
  +        return createSubcontext(ctx, n);
  +    }
  +    /** Create a subcontext including any intermediate contexts.
  +    @param ctx, the parent JNDI Context under which value will be bound
  +    @param name, the name relative to ctx of the subcontext.
  +    @return The new or existing JNDI subcontext
  +    @throws NamingException, on any JNDI failure
  +    */
  +    public static Context createSubcontext(Context ctx, Name name) throws 
NamingException
  +    {
  +        Context subctx = ctx;
  +        for(int pos = 0; pos < name.size(); pos ++)
           {
  -            String ctxName = n.get(0);
  +            String ctxName = name.get(pos);
               try
               {
  -                ctx = (Context) ctx.lookup(ctxName);
  +                subctx = (Context) ctx.lookup(ctxName);
               }
               catch(NameNotFoundException e)
               {
  -                ctx = ctx.createSubcontext(ctxName);
  +                subctx = ctx.createSubcontext(ctxName);
               }
  -            n = n.getSuffix(1);
           }
  -        ctx.bind(n.get(0), value);
  +        return subctx;
  +    }
  +
  +    /** Bind val to name in ctx, and make sure that all intermediate contexts exist
  +    @param ctx, the parent JNDI Context under which value will be bound
  +    @param name, the name relative to ctx where value will be bound
  +    @param value, the value to bind.
  +    */
  +    public static void bind(Context ctx, String name, Object value) throws 
NamingException
  +    {
  +        Name n = ctx.getNameParser("").parse(name);
  +        String atom = n.get(n.size()-1);
  +        Context parentCtx = createSubcontext(ctx, n.getPrefix(n.size()-1));
  +        parentCtx.bind(atom, value);
       }
   }
  
  
  

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

Reply via email to