User: patriot1burke
  Date: 01/09/13 20:48:14

  Modified:    src/main/org/jnp/interfaces NamingContext.java
  Log:
  made member variables protected so inherited classes can access them
  
  Revision  Changes    Path
  1.12      +239 -228  jnp/src/main/org/jnp/interfaces/NamingContext.java
  
  Index: NamingContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/jnp/src/main/org/jnp/interfaces/NamingContext.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- NamingContext.java        2001/09/07 03:12:44     1.11
  +++ NamingContext.java        2001/09/14 03:48:13     1.12
  @@ -37,22 +37,22 @@
   
    *   @author oberg
    *   @author [EMAIL PROTECTED]
  - *   @version $Revision: 1.11 $
  + *   @version $Revision: 1.12 $
    */
   public class NamingContext
      implements Context, java.io.Serializable
   {
  -    // Constants -----------------------------------------------------
  -    /** @since 1.7 */
  -    static final long serialVersionUID = 8906455608484282128L;
  -    static Naming localServer;
  +   // Constants -----------------------------------------------------
  +   /** @since 1.7 */
  +   static final long serialVersionUID = 8906455608484282128L;
  +   static Naming localServer;
   
       // Attributes ----------------------------------------------------
  -    Naming naming;
  -    Hashtable env;
  -    Name prefix;
  +   Naming naming;
  +   Hashtable env;
  +   Name prefix;
   
  -    NameParser parser = new NamingParser();
  +   NameParser parser = new NamingParser();
   
       // Static --------------------------------------------------------
        
  @@ -62,157 +62,157 @@
       // calls, which will improve performance.
       // Weak references are used so if no contexts use a particular server
       // it will be removed from the cache.
  -    static HashMap cachedServers = new HashMap();
  +   static HashMap cachedServers = new HashMap();
   
  -    static void addServer(String name, Naming server)
  -    {
  -        // Add server to map
  -        // Clone and synchronize to minimize delay for readers of the map
  -        synchronized (NamingContext.class)
  -        {
  -            HashMap newServers = (HashMap)cachedServers.clone();
  -            newServers.put(name, new WeakReference(server));
  -            cachedServers = newServers;
  -        }
  -    }
  +   static void addServer(String name, Naming server)
  +   {
  +      // Add server to map
  +      // Clone and synchronize to minimize delay for readers of the map
  +      synchronized (NamingContext.class)
  +      {
  +         HashMap newServers = (HashMap)cachedServers.clone();
  +         newServers.put(name, new WeakReference(server));
  +         cachedServers = newServers;
  +      }
  +   }
      
      static Naming getServer(String host, int port)
  -             throws NamingException
  +      throws NamingException
      {
  -        WeakReference ref = (WeakReference)cachedServers.get(host+":"+port);
  +      WeakReference ref = (WeakReference)cachedServers.get(host+":"+port);
   
  -        Naming server;
  -        if (ref != null)
  -        {
  -            server = (Naming)ref.get();
  -            if (server != null)
  -            {
  -//DEBUG             System.out.println("Using cached naming server");
  -                return server;
  -            }
  -        }
  +      Naming server;
  +      if (ref != null)
  +      {
  +         server = (Naming)ref.get();
  +         if (server != null)
  +         {
  +            //DEBUG             System.out.println("Using cached naming server");
  +            return server;
  +         }
  +      }
   
  -        // Server not found; add it to cache
  -        try
  -        {
  -            Socket s;
  +      // Server not found; add it to cache
  +      try
  +      {
  +         Socket s;
   
  -            try
  -            {
  -                    s = new Socket(host,port);
  -            } catch (IOException e2)
  -            {
  -               NamingException ex = new 
ServiceUnavailableException(e2.getMessage());
  -               ex.setRootCause(e2);
  -               throw ex;
  -            }
  +         try
  +         {
  +            s = new Socket(host,port);
  +         } catch (IOException e2)
  +         {
  +            NamingException ex = new ServiceUnavailableException(e2.getMessage());
  +            ex.setRootCause(e2);
  +            throw ex;
  +         }
   
  -                    // Get stub from naming server
  -        ObjectInputStream in = new ObjectInputStream(new 
BufferedInputStream(s.getInputStream()));
  -        server = ((Naming)((MarshalledObject)in.readObject()).get());
  -        s.close();
  +         // Get stub from naming server
  +         ObjectInputStream in = new ObjectInputStream(new 
BufferedInputStream(s.getInputStream()));
  +         server = ((Naming)((MarshalledObject)in.readObject()).get());
  +         s.close();
   
  -            // Add it to cache
  -            addServer(host+":"+port, server);
  +         // Add it to cache
  +         addServer(host+":"+port, server);
   
  -            return server;
  -     } catch (IOException e)
  -     {
  -        NamingException ex = new CommunicationException(e.getMessage());
  -        ex.setRootCause(e);
  -        throw ex;
  -     } catch (ClassNotFoundException e)
  -     {
  -        NamingException ex = new CommunicationException(e.getMessage());
  -        ex.setRootCause(e);
  -        throw ex;
  -     }
  +         return server;
  +      } catch (IOException e)
  +      {
  +         NamingException ex = new CommunicationException(e.getMessage());
  +         ex.setRootCause(e);
  +         throw ex;
  +      } catch (ClassNotFoundException e)
  +      {
  +         NamingException ex = new CommunicationException(e.getMessage());
  +         ex.setRootCause(e);
  +         throw ex;
  +      }
      }
        
      static void removeServer(Hashtable env)
      {
  -     String host = "localhost";
  -     int port = 1099;
  +      String host = "localhost";
  +      int port = 1099;
        
  -     // Locate naming service
  -     if (env.get(Context.PROVIDER_URL) != null)
  -     {
  -        StringTokenizer tkn = new 
StringTokenizer((String)env.get(Context.PROVIDER_URL),":");
  -        host = tkn.nextToken();
  -        try
  -        {
  -           port = Integer.parseInt(tkn.nextToken());
  -        } catch (Exception ex)
  -        {
  -           // Use default;
  -        }
  -             // Remove server from map
  -             // Clone and synchronize to minimize delay for readers of the map
  -             synchronized (NamingContext.class)
  -             {
  -                     HashMap newServers = (HashMap)cachedServers.clone();
  -                     newServers.remove(host+":"+port);
  -                     cachedServers = newServers;
  -             }
  -     } else
  -     {
  -             // Don't do anything for local server
  -     }
  +      // Locate naming service
  +      if (env.get(Context.PROVIDER_URL) != null)
  +      {
  +         StringTokenizer tkn = new 
StringTokenizer((String)env.get(Context.PROVIDER_URL),":");
  +         host = tkn.nextToken();
  +         try
  +         {
  +            port = Integer.parseInt(tkn.nextToken());
  +         } catch (Exception ex)
  +         {
  +            // Use default;
  +         }
  +         // Remove server from map
  +         // Clone and synchronize to minimize delay for readers of the map
  +         synchronized (NamingContext.class)
  +         {
  +            HashMap newServers = (HashMap)cachedServers.clone();
  +            newServers.remove(host+":"+port);
  +            cachedServers = newServers;
  +         }
  +      } else
  +      {
  +         // Don't do anything for local server
  +      }
                
      }
   
  -    /** Called to remove any url scheme atoms and extract the naming
  +   /** Called to remove any url scheme atoms and extract the naming
           service hostname:port information.
       @param n, the name component to the parsed. After returning n will
           have all scheme related atoms removed.
       @return the naming service hostname:port information string if name
           contained the host information.
       */
  -    static String parseNameForScheme(Name n) throws InvalidNameException
  -    {
  -        String serverInfo = null;
  -        if( n.size() > 0 )
  -        {
  -            String scheme = n.get(0);
  -            int schemeLength = 0;
  -            if( scheme.startsWith("java:") )
  -                schemeLength = 5;
  -            else if( scheme.startsWith("jnp:") )
  -                schemeLength = 4;
  -            if( schemeLength > 0 )
  -            {
  -                String suffix = scheme.substring(schemeLength);
  -                if( suffix.length() == 0 )
  -                {
  -                    // Scheme was "url:/..."
  -                    n.remove(0);
  -                    if( n.size() > 1 && n.get(0).equals("") )
  -                    {
  -                        // Scheme was "url://hostname:port/..."
  -                        // Get hostname:port value for the naming server
  -                        serverInfo = n.get(1);
  -                        n.remove(0);
  -                        n.remove(0);
  -                        // If n is a empty atom remove it or else a '/' will result
  -                        if( n.size() == 1 && n.get(0).length() == 0 )
  -                            n.remove(0);
  -                    }
  -                }
  -                else
  -                {
  -                    // Scheme was "url:foo" -> reinsert "foo"
  -                    n.remove(0);
  -                    n.add(0, suffix);
  -                }
  +   static String parseNameForScheme(Name n) throws InvalidNameException
  +   {
  +      String serverInfo = null;
  +      if( n.size() > 0 )
  +      {
  +         String scheme = n.get(0);
  +         int schemeLength = 0;
  +         if( scheme.startsWith("java:") )
  +            schemeLength = 5;
  +         else if( scheme.startsWith("jnp:") )
  +            schemeLength = 4;
  +         if( schemeLength > 0 )
  +         {
  +            String suffix = scheme.substring(schemeLength);
  +            if( suffix.length() == 0 )
  +            {
  +               // Scheme was "url:/..."
  +               n.remove(0);
  +               if( n.size() > 1 && n.get(0).equals("") )
  +               {
  +                  // Scheme was "url://hostname:port/..."
  +                  // Get hostname:port value for the naming server
  +                  serverInfo = n.get(1);
  +                  n.remove(0);
  +                  n.remove(0);
  +                  // If n is a empty atom remove it or else a '/' will result
  +                  if( n.size() == 1 && n.get(0).length() == 0 )
  +                     n.remove(0);
  +               }
               }
  -        }
  -        return serverInfo;
  -    }
  -
  -    public static void setLocal(Naming server)
  -    {
  -        localServer = server;
  -    }
  +            else
  +            {
  +               // Scheme was "url:foo" -> reinsert "foo"
  +               n.remove(0);
  +               n.add(0, suffix);
  +            }
  +         }
  +      }
  +      return serverInfo;
  +   }
  +
  +   public static void setLocal(Naming server)
  +   {
  +      localServer = server;
  +   }
   
      // Constructors --------------------------------------------------
      public NamingContext(Hashtable e, Name baseName, Naming server)
  @@ -272,7 +272,7 @@
            cctx.rebind(cpe.getRemainingName(), obj);
         } catch (IOException e)
         {
  -                     naming = null;
  +         naming = null;
            removeServer(env);
            NamingException ex = new CommunicationException();
            ex.setRootCause(e);
  @@ -320,7 +320,7 @@
         } catch (IOException e)
         {
            naming = null;
  -                     removeServer(env);
  +         removeServer(env);
            NamingException ex = new CommunicationException();
            ex.setRootCause(e);
            throw ex;
  @@ -345,7 +345,7 @@
            
         try
         {
  -     Name n = getAbsoluteName(name);
  +         Name n = getAbsoluteName(name);
            Object res = naming.lookup(n);
            
            if (res instanceof MarshalledObject)
  @@ -390,9 +390,9 @@
                     try
                     {
                        Context ctx = 
(Context)NamingManager.getObjectInstance(resolveRes,
  -                                                            getAbsoluteName(name),
  -                                                            this,
  -                                                            env);
  +                                                                            
getAbsoluteName(name),
  +                                                                            this,
  +                                                                            env);
                        return ctx.lookup(((ResolveResult)res).getRemainingName());
                     } catch (ClassCastException e)
                     {
  @@ -634,34 +634,34 @@
         return createSubcontext(getNameParser(name).parse(name));
      }
   
  -    public Context createSubcontext(Name name)
  +   public Context createSubcontext(Name name)
         throws NamingException 
  -    {
  -       if( name.size() == 0 )
  -          throw new InvalidNameException("Cannot pass an empty name to 
createSubcontext");
  -
  -        Hashtable env = getEnv(name);
  -        checkRef(env);
  -        try
  -        {
  -            name = getAbsoluteName(name);
  -            return naming.createSubcontext(name);
  -        }
  -        catch (CannotProceedException cpe)
  -        {
  -            cpe.setEnvironment(env);
  -            Context cctx = NamingManager.getContinuationContext(cpe);
  -            return cctx.createSubcontext(cpe.getRemainingName());
  -        }
  -        catch (IOException e)
  -        {
  -            naming = null;
  -            removeServer(env);
  -            NamingException ex = new CommunicationException();
  -            ex.setRootCause(e);
  -            throw ex;
  -        }
  -    }
  +   {
  +      if( name.size() == 0 )
  +         throw new InvalidNameException("Cannot pass an empty name to 
createSubcontext");
  +
  +      Hashtable env = getEnv(name);
  +      checkRef(env);
  +      try
  +      {
  +         name = getAbsoluteName(name);
  +         return naming.createSubcontext(name);
  +      }
  +      catch (CannotProceedException cpe)
  +      {
  +         cpe.setEnvironment(env);
  +         Context cctx = NamingManager.getContinuationContext(cpe);
  +         return cctx.createSubcontext(cpe.getRemainingName());
  +      }
  +      catch (IOException e)
  +      {
  +         naming = null;
  +         removeServer(env);
  +         NamingException ex = new CommunicationException();
  +         ex.setRootCause(e);
  +         throw ex;
  +      }
  +   }
   
      public Object addToEnvironment(String propName, Object propVal)
         throws NamingException 
  @@ -722,25 +722,25 @@
      public Object lookupLink(Name name)
         throws NamingException 
      {
  -       if( name.isEmpty() )
  -           return lookup(name);
  +      if( name.isEmpty() )
  +         return lookup(name);
   
  -       Object link = null;
  -       try
  -       {
  -           Name n = getAbsoluteName(name);
  -           link = naming.lookup(n);
  -       }
  -       catch(IOException e)
  -       {
  -            naming = null;
  -            removeServer(env);
  -            NamingException ex = new CommunicationException();
  -            ex.setRootCause(e);
  -            throw ex;
  -       }
  -       return link;
  -  }
  +      Object link = null;
  +      try
  +      {
  +         Name n = getAbsoluteName(name);
  +         link = naming.lookup(n);
  +      }
  +      catch(IOException e)
  +      {
  +         naming = null;
  +         removeServer(env);
  +         NamingException ex = new CommunicationException();
  +         ex.setRootCause(e);
  +         throw ex;
  +      }
  +      return link;
  +   }
   
      // Private -------------------------------------------------------
      private void checkRef(Hashtable env)
  @@ -752,32 +752,43 @@
            int port = 1099;
            
            // Locate naming service
  -         String url = (String) env.get(Context.PROVIDER_URL);
  -         if( url != null && url.length() > 0 )
  +         String urls = (String) env.get(Context.PROVIDER_URL);
  +         if (urls != null && urls.length() > 0)
            {
  -            int colon = url.indexOf(':');
  -            if( colon < 0 )
  +            StringTokenizer tokenizer = new StringTokenizer(urls, ",");
  +            while (tokenizer.hasMoreElements())
               {
  -               host = url;
  -            }
  -            else
  -            {
  -               host = url.substring(0, colon);
  -               try
  +               String url = tokenizer.nextToken();
  +               int colon = url.indexOf(':');
  +               if( colon < 0 )
  +               {
  +                  host = url;
  +               }
  +               else
                  {
  -                  port = Integer.parseInt(url.substring(colon+1));
  +                  host = url.substring(0, colon);
  +                  try
  +                  {
  +                     port = Integer.parseInt(url.substring(colon+1));
  +                  }
  +                  catch (Exception ex)
  +                  {
  +                     // Use default;
  +                  }
                  }
  -               catch (Exception ex)
  +               try
                  {
  -                  // Use default;
  +                  // Get server from cache
  +                  naming = getServer(host, port);
                  }
  -            }
  -              // Get server from cache
  -              naming = getServer(host, port);
  -         } else
  +               catch (Exception ignored) {}
  +            } 
  +            if (naming == null) throw new CommunicationException("Could not obtain 
connection to any of these urls: " + urls);
  +         }
  +         else
            {
  -             // Use server in same JVM
  -                             naming = localServer;
  +            // Use server in same JVM
  +            naming = localServer;
               
               if (naming == null)
               {
  @@ -788,30 +799,30 @@
         }
      }
   
  -    private Name getAbsoluteName(Name n)
  +   private Name getAbsoluteName(Name n)
         throws NamingException
  -    {
  -        if (n.isEmpty())
  -            return composeName(n,prefix);
  -        else if (n.get(0).toString().equals("")) // Absolute name
  -            return n.getSuffix(1);
  -        else // Add prefix
  -            return composeName(n,prefix);
  -    }
  -
  -    private Hashtable getEnv(Name n)
  -        throws InvalidNameException
  -    {
  -        Hashtable nameEnv = env;
  -        String serverInfo = parseNameForScheme(n);
  -        if( serverInfo != null )
  -        {
  -           // Set hostname:port value for the naming server
  -           nameEnv = (Hashtable)env.clone();
  -           nameEnv.put(Context.PROVIDER_URL, serverInfo);
  -        }
  -        return nameEnv;
  -    }
  +   {
  +      if (n.isEmpty())
  +         return composeName(n,prefix);
  +      else if (n.get(0).toString().equals("")) // Absolute name
  +         return n.getSuffix(1);
  +      else // Add prefix
  +         return composeName(n,prefix);
  +   }
  +
  +   private Hashtable getEnv(Name n)
  +      throws InvalidNameException
  +   {
  +      Hashtable nameEnv = env;
  +      String serverInfo = parseNameForScheme(n);
  +      if( serverInfo != null )
  +      {
  +         // Set hostname:port value for the naming server
  +         nameEnv = (Hashtable)env.clone();
  +         nameEnv.put(Context.PROVIDER_URL, serverInfo);
  +      }
  +      return nameEnv;
  +   }
   
      // Inner classes -------------------------------------------------
   }
  
  
  

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

Reply via email to