src/share/classes/com/sun/jndi/url/rmi/rmiURLContextFactory.java

Print this page




  46 
  47 public class rmiURLContextFactory implements ObjectFactory {
  48 
  49     public Object getObjectInstance(Object urlInfo, Name name,
  50                                     Context nameCtx, Hashtable<?,?> env)
  51             throws NamingException
  52     {
  53         if (urlInfo == null) {
  54             return (new rmiURLContext(env));
  55         } else if (urlInfo instanceof String) {
  56             return getUsingURL((String)urlInfo, env);
  57         } else if (urlInfo instanceof String[]) {
  58             return getUsingURLs((String[])urlInfo, env);
  59         } else {
  60             throw (new ConfigurationException(
  61                     "rmiURLContextFactory.getObjectInstance: " +
  62                     "argument must be an RMI URL String or an array of them"));
  63         }
  64     }
  65 
  66     private static Object getUsingURL(String url, Hashtable env)
  67             throws NamingException
  68     {
  69         rmiURLContext urlCtx = new rmiURLContext(env);
  70         try {
  71             return urlCtx.lookup(url);
  72         } finally {
  73             urlCtx.close();
  74         }
  75     }
  76 
  77     /*
  78      * Try each URL until lookup() succeeds for one of them.
  79      * If all URLs fail, throw one of the exceptions arbitrarily.
  80      * Not pretty, but potentially more informative than returning null.
  81      */
  82     private static Object getUsingURLs(String[] urls, Hashtable env)
  83             throws NamingException
  84     {
  85         if (urls.length == 0) {
  86             throw (new ConfigurationException(
  87                     "rmiURLContextFactory: empty URL array"));
  88         }
  89         rmiURLContext urlCtx = new rmiURLContext(env);
  90         try {
  91             NamingException ne = null;
  92             for (int i = 0; i < urls.length; i++) {
  93                 try {
  94                     return urlCtx.lookup(urls[i]);
  95                 } catch (NamingException e) {
  96                     ne = e;
  97                 }
  98             }
  99             throw ne;
 100         } finally {
 101             urlCtx.close();
 102         }


  46 
  47 public class rmiURLContextFactory implements ObjectFactory {
  48 
  49     public Object getObjectInstance(Object urlInfo, Name name,
  50                                     Context nameCtx, Hashtable<?,?> env)
  51             throws NamingException
  52     {
  53         if (urlInfo == null) {
  54             return (new rmiURLContext(env));
  55         } else if (urlInfo instanceof String) {
  56             return getUsingURL((String)urlInfo, env);
  57         } else if (urlInfo instanceof String[]) {
  58             return getUsingURLs((String[])urlInfo, env);
  59         } else {
  60             throw (new ConfigurationException(
  61                     "rmiURLContextFactory.getObjectInstance: " +
  62                     "argument must be an RMI URL String or an array of them"));
  63         }
  64     }
  65 
  66     private static Object getUsingURL(String url, Hashtable<?,?> env)
  67             throws NamingException
  68     {
  69         rmiURLContext urlCtx = new rmiURLContext(env);
  70         try {
  71             return urlCtx.lookup(url);
  72         } finally {
  73             urlCtx.close();
  74         }
  75     }
  76 
  77     /*
  78      * Try each URL until lookup() succeeds for one of them.
  79      * If all URLs fail, throw one of the exceptions arbitrarily.
  80      * Not pretty, but potentially more informative than returning null.
  81      */
  82     private static Object getUsingURLs(String[] urls, Hashtable<?,?> env)
  83             throws NamingException
  84     {
  85         if (urls.length == 0) {
  86             throw (new ConfigurationException(
  87                     "rmiURLContextFactory: empty URL array"));
  88         }
  89         rmiURLContext urlCtx = new rmiURLContext(env);
  90         try {
  91             NamingException ne = null;
  92             for (int i = 0; i < urls.length; i++) {
  93                 try {
  94                     return urlCtx.lookup(urls[i]);
  95                 } catch (NamingException e) {
  96                     ne = e;
  97                 }
  98             }
  99             throw ne;
 100         } finally {
 101             urlCtx.close();
 102         }