User: oberg   
  Date: 00/05/18 07:32:20

  Modified:    src/main/org/jboss/jdbc DataSourceImpl.java
  Log:
  Can now bind hierarchical JNDI-names
  
  Revision  Changes    Path
  1.3       +26 -2     jboss/src/main/org/jboss/jdbc/DataSourceImpl.java
  
  Index: DataSourceImpl.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/jdbc/DataSourceImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DataSourceImpl.java       2000/05/12 10:17:27     1.2
  +++ DataSourceImpl.java       2000/05/18 14:32:19     1.3
  @@ -26,6 +26,7 @@
   import javax.naming.InitialContext;
   import javax.naming.Name;
   import javax.naming.NamingException;
  +import javax.naming.NameNotFoundException;
   import javax.sql.DataSource;
   
   import org.jboss.logging.Log;
  @@ -40,7 +41,7 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.2 $
  + *   @version $Revision: 1.3 $
    */
   public class DataSourceImpl
      extends ServiceMBeanSupport
  @@ -95,7 +96,7 @@
         throws Exception
      {
         // Bind in JNDI
  -      new InitialContext().bind(jndiName, this);
  +      bind(new InitialContext(), jndiName, this);
         
   //DEBUG      log.log("Connection pool for "+url+" bound to "+jndiName);
         
  @@ -202,6 +203,28 @@
         }
      }
      
  +     // Private -------------------------------------------------------
  +   private void bind(Context ctx, String name, Object val)
  +      throws NamingException
  +   {
  +      // Bind val to name in ctx, and make sure that all intermediate contexts exist
  +      
  +      Name n = ctx.getNameParser("").parse(name);
  +      while (n.size() > 1)
  +      {
  +         String ctxName = n.get(0);
  +         try
  +         {
  +            ctx = (Context)ctx.lookup(ctxName);
  +         } catch (NameNotFoundException e)
  +         {
  +            ctx = ctx.createSubcontext(ctxName);
  +         }
  +         n = n.getSuffix(1);
  +      }
  +      
  +      ctx.bind(n.get(0), val);
  +   }
   }
   
   class ConnectionProxy
  @@ -244,6 +267,7 @@
         }
      }
      
  +   // Package protected  --------------------------------------------
      void close()
      {
         try
  
  
  

Reply via email to