You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/03/14 02:17:28 UTC

cvs commit: db-ojb/src/ejb/org/apache/ojb/ejb ContextHelper.java PBClient.java StressTestClient.java PersonArticleClientODMG.java PersonArticleClient.java ODMGClient.java

arminw      2003/03/13 17:17:28

  Modified:    src/ejb/org/apache/ojb/ejb PBClient.java
                        StressTestClient.java PersonArticleClientODMG.java
                        PersonArticleClient.java ODMGClient.java
  Added:       src/ejb/org/apache/ojb/ejb ContextHelper.java
  Log:
  do JNDI context lookup for
  client in a helper class
  
  Revision  Changes    Path
  1.9       +2 -22     db-ojb/src/ejb/org/apache/ojb/ejb/PBClient.java
  
  Index: PBClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/PBClient.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PBClient.java	13 Mar 2003 23:39:03 -0000	1.8
  +++ PBClient.java	14 Mar 2003 01:17:27 -0000	1.9
  @@ -76,7 +76,6 @@
    */
   public class PBClient extends TestCase
   {
  -    Context ctx;
       PBSessionRemote bean;
       static int loops = 500;
   
  @@ -121,26 +120,7 @@
   
       protected void init()
       {
  -        Properties prop = null;
  -        prop = System.getProperties();
  -        // id jndi-properties not set as system properties, take jboss jndi
  -        // properties as default
  -        if (prop.getProperty("java.naming.factory.initial") == null)
  -        {
  -            prop = new Properties();
  -            prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  -            prop.setProperty("java.naming.provider.url", "jnp://localhost:1099/");
  -            prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  -        }
  -        try
  -        {
  -            ctx = new InitialContext(prop);
  -        }
  -        catch (NamingException e)
  -        {
  -            e.printStackTrace();
  -        }
  -
  +        Context ctx = ContextHelper.getContext();
           try
           {
   //            System.err.println("## "+ctx.getEnvironment());
  
  
  
  1.8       +1 -22     db-ojb/src/ejb/org/apache/ojb/ejb/StressTestClient.java
  
  Index: StressTestClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/StressTestClient.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StressTestClient.java	14 Mar 2003 00:56:25 -0000	1.7
  +++ StressTestClient.java	14 Mar 2003 01:17:27 -0000	1.8
  @@ -149,30 +149,9 @@
        */
       public void init() throws Exception
       {
  -        Context ctx = null;
  +        Context ctx = ContextHelper.getContext();
           times = new long[4];
           threadCount = concurrentThreads;
  -
  -        Properties prop = null;
  -        prop = System.getProperties();
  -        // if jndi-properties not set as system properties, take jboss jndi
  -        // properties as default
  -        if (prop.getProperty("java.naming.factory.initial") == null)
  -        {
  -            prop = new Properties();
  -            prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  -            prop.setProperty("java.naming.provider.url", "jnp://localhost:1099/");
  -            prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  -        }
  -        try
  -        {
  -            ctx = new InitialContext(prop);
  -        }
  -        catch (NamingException e)
  -        {
  -            e.printStackTrace();
  -        }
  -
           try
           {
               Object object = PortableRemoteObject.narrow(ctx.lookup(PBSessionHome.JNDI_NAME), EJBHome.class);
  
  
  
  1.4       +2 -23     db-ojb/src/ejb/org/apache/ojb/ejb/PersonArticleClientODMG.java
  
  Index: PersonArticleClientODMG.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/PersonArticleClientODMG.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PersonArticleClientODMG.java	10 Jan 2003 11:33:10 -0000	1.3
  +++ PersonArticleClientODMG.java	14 Mar 2003 01:17:27 -0000	1.4
  @@ -73,7 +73,6 @@
    */
   public class PersonArticleClientODMG extends TestCase
   {
  -    Context ctx;
       PersonArticleManagerODMGRemote bean;
   
       public PersonArticleClientODMG(String s)
  @@ -189,30 +188,10 @@
   
       protected void init() throws Exception
       {
  -        Properties prop = null;
  -        prop = System.getProperties();
  -        // id jndi-properties not set as system properties, take jboss jndi
  -        // properties as default
  -        if (prop.getProperty("java.naming.factory.initial") == null)
  -        {
  -            prop = new Properties();
  -            prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  -            prop.setProperty("java.naming.provider.url", "jnp://localhost:1099/");
  -            prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  -        }
  -        try
  -        {
  -            ctx = new InitialContext(prop);
  -        }
  -        catch (NamingException e)
  -        {
  -            e.printStackTrace();
  -        }
  -
           try
           {
               Object object = PortableRemoteObject.narrow(
  -                    ctx.lookup(PersonArticleManagerODMGHome.JNDI_NAME), EJBHome.class);
  +            ContextHelper.getContext().lookup(PersonArticleManagerODMGHome.JNDI_NAME), EJBHome.class);
               bean = (PersonArticleManagerODMGRemote) ((PersonArticleManagerODMGHome) object).create();
               System.out.println("Bean found: " + bean);
           }
  
  
  
  1.4       +2 -23     db-ojb/src/ejb/org/apache/ojb/ejb/PersonArticleClient.java
  
  Index: PersonArticleClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/PersonArticleClient.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PersonArticleClient.java	10 Jan 2003 11:33:10 -0000	1.3
  +++ PersonArticleClient.java	14 Mar 2003 01:17:27 -0000	1.4
  @@ -73,7 +73,6 @@
    */
   public class PersonArticleClient extends TestCase
   {
  -    Context ctx;
       PersonArticleManagerPBRemote bean;
   
       public PersonArticleClient(String s)
  @@ -189,30 +188,10 @@
   
       protected void init() throws Exception
       {
  -        Properties prop = null;
  -        prop = System.getProperties();
  -        // id jndi-properties not set as system properties, take jboss jndi
  -        // properties as default
  -        if (prop.getProperty("java.naming.factory.initial") == null)
  -        {
  -            prop = new Properties();
  -            prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  -            prop.setProperty("java.naming.provider.url", "jnp://localhost:1099/");
  -            prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  -        }
  -        try
  -        {
  -            ctx = new InitialContext(prop);
  -        }
  -        catch (NamingException e)
  -        {
  -            e.printStackTrace();
  -        }
  -
           try
           {
               Object object = PortableRemoteObject.narrow(
  -                    ctx.lookup(PersonArticleManagerPBHome.JNDI_NAME), EJBHome.class);
  +            ContextHelper.getContext().lookup(PersonArticleManagerPBHome.JNDI_NAME), EJBHome.class);
               bean = (PersonArticleManagerPBRemote) ((PersonArticleManagerPBHome) object).create();
               System.out.println("Bean found: " + bean);
           }
  
  
  
  1.10      +2 -27     db-ojb/src/ejb/org/apache/ojb/ejb/ODMGClient.java
  
  Index: ODMGClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/ODMGClient.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ODMGClient.java	13 Mar 2003 23:39:03 -0000	1.9
  +++ ODMGClient.java	14 Mar 2003 01:17:27 -0000	1.10
  @@ -76,7 +76,6 @@
    */
   public class ODMGClient extends TestCase
   {
  -    Context ctx;
       ODMGSessionRemote sampleBean;
       static int loops = 500;
   
  @@ -127,32 +126,9 @@
   //        }
   //    }
   
  -
       protected void init()
       {
  -        Properties prop = null;
  -        prop = System.getProperties();
  -        // id jndi-properties not set as system properties, take jboss jndi
  -        // properties as default
  -        String namingFactoryName = prop.getProperty("java.naming.factory.initial");
  -        if (namingFactoryName == null || namingFactoryName == "")
  -        {
  -            System.out.println("Use default naming properties");
  -            prop = new Properties();
  -            prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  -            prop.setProperty("java.naming.provider.url", "jnp://localhost:1099");
  -            prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  -            System.out.println("Naming properties: " + prop);
  -        }
  -        try
  -        {
  -            ctx = new InitialContext(prop);
  -        }
  -        catch (NamingException e)
  -        {
  -            e.printStackTrace();
  -        }
  -
  +        Context ctx = ContextHelper.getContext();
           try
           {
               Object object = PortableRemoteObject.narrow(ctx.lookup(ODMGSessionHome.JNDI_NAME), EJBHome.class);
  @@ -164,7 +140,6 @@
               e.printStackTrace();
           }
       }
  -
   
       public void testInsertDelete() throws RemoteException
       {
  
  
  
  1.1                  db-ojb/src/ejb/org/apache/ojb/ejb/ContextHelper.java
  
  Index: ContextHelper.java
  ===================================================================
  package org.apache.ojb.ejb;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import java.util.Properties;
  
  /**
   * Helper class for JNDI context lookup.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: ContextHelper.java,v 1.1 2003/03/14 01:17:27 arminw Exp $
   */
  public class ContextHelper
  {
      public static Context getContext()
      {
          Context ctx = null;
          Properties prop = null;
          prop = System.getProperties();
          // if jndi-properties not set as system properties, take jboss jndi
          // properties as default
          if (prop.getProperty("java.naming.factory.initial") == null)
          {
              prop = new Properties();
              prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
              prop.setProperty("java.naming.provider.url", "jnp://localhost:1099/");
              prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
          }
          try
          {
              ctx = new InitialContext(prop);
          }
          catch (NamingException e)
          {
              e.printStackTrace();
          }
          return ctx;
      }
  }