KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jnp > interfaces > NamingContext


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jnp.interfaces;
23
24 import java.io.BufferedInputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.lang.ref.WeakReference JavaDoc;
28 import java.lang.reflect.Constructor JavaDoc;
29 import java.lang.reflect.InvocationTargetException JavaDoc;
30 import java.net.DatagramPacket JavaDoc;
31 import java.net.InetAddress JavaDoc;
32 import java.net.MulticastSocket JavaDoc;
33 import java.net.Socket JavaDoc;
34 import java.net.InetSocketAddress JavaDoc;
35 import java.rmi.ConnectException JavaDoc;
36 import java.rmi.MarshalledObject JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Arrays JavaDoc;
39 import java.util.Collection JavaDoc;
40 import java.util.Enumeration JavaDoc;
41 import java.util.HashMap JavaDoc;
42 import java.util.Hashtable JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.StringTokenizer JavaDoc;
45 import javax.naming.Binding JavaDoc;
46 import javax.naming.CannotProceedException JavaDoc;
47 import javax.naming.CommunicationException JavaDoc;
48 import javax.naming.ConfigurationException JavaDoc;
49 import javax.naming.Context JavaDoc;
50 import javax.naming.InitialContext JavaDoc;
51 import javax.naming.InvalidNameException JavaDoc;
52 import javax.naming.LinkRef JavaDoc;
53 import javax.naming.Name JavaDoc;
54 import javax.naming.NameParser JavaDoc;
55 import javax.naming.NamingEnumeration JavaDoc;
56 import javax.naming.NamingException JavaDoc;
57 import javax.naming.NotContextException JavaDoc;
58 import javax.naming.ContextNotEmptyException JavaDoc;
59 import javax.naming.OperationNotSupportedException JavaDoc;
60 import javax.naming.Reference JavaDoc;
61 import javax.naming.Referenceable JavaDoc;
62 import javax.naming.ServiceUnavailableException JavaDoc;
63 import javax.naming.event.EventContext JavaDoc;
64 import javax.naming.event.NamingListener JavaDoc;
65 import javax.naming.spi.NamingManager JavaDoc;
66 import javax.naming.spi.ResolveResult JavaDoc;
67 import javax.net.SocketFactory;
68
69 import org.jboss.logging.Logger;
70
71 /**
72  * This class provides the jnp provider Context implementation. It is a Context
73  * interface wrapper for a RMI Naming instance that is obtained from either the
74  * local server instance or by locating the server given by the
75  * Context.PROVIDER_URL value.
76  *
77  * This class also serves as the jnp url resolution context. jnp style urls
78  * passed to the
79  * @author oberg
80  * @author scott.stark@jboss.org
81  * @version $Revision: 58348 $
82  */

83 public class NamingContext
84    implements EventContext JavaDoc, java.io.Serializable JavaDoc
85 {
86    // Constants -----------------------------------------------------
87
/**
88     * @since 1.7
89     */

90    static final long serialVersionUID = 8906455608484282128L;
91    /**
92     * The javax.net.SocketFactory impl to use for the bootstrap socket
93     */

94    public static final String JavaDoc JNP_SOCKET_FACTORY = "jnp.socketFactory";
95    /**
96     * The local address to bind the connected bootstrap socket to
97     */

98    public static final String JavaDoc JNP_LOCAL_ADDRESS = "jnp.localAddress";
99    /**
100     * The local port to bind the connected bootstrap socket to
101     */

102    public static final String JavaDoc JNP_LOCAL_PORT = "jnp.localPort";
103    /**
104     * A flag to disable the broadcast discovery queries
105     */

106    public static final String JavaDoc JNP_DISABLE_DISCOVERY = "jnp.disableDiscovery";
107    /**
108     * The cluster partition discovery should be restricted to
109     */

110    public static final String JavaDoc JNP_PARTITION_NAME = "jnp.partitionName";
111    /**
112     * The multicast IP/address to which the discovery query is sent
113     */

114    public static final String JavaDoc JNP_DISCOVERY_GROUP = "jnp.discoveryGroup";
115    /**
116     * The port to which the discovery query is sent
117     */

118    public static final String JavaDoc JNP_DISCOVERY_PORT = "jnp.discoveryPort";
119
120    /** The time-to-live for the multicast discovery packets */
121    public static final String JavaDoc JNP_DISCOVERY_TTL = "jnp.discoveryTTL";
122
123    /**
124     * The time in MS to wait for a discovery query response
125     */

126    public static final String JavaDoc JNP_DISCOVERY_TIMEOUT = "jnp.discoveryTimeout";
127    /**
128     * An internal property added by parseNameForScheme if the input name uses a
129     * url prefix that was removed during cannonicalization. This is needed to
130     * avoid modification of the incoming Name.
131     */

132    public static final String JavaDoc JNP_PARSED_NAME = "jnp.parsedName";
133    /**
134     * A flag indicating the style of names passed to NamingManager method.
135     * True for api expected relative names, false for absolute names as used
136     * historically by the jboss naming implementation.
137     */

138    public static final String JavaDoc JNP_USE_RELATIVE_NAME = "jnp.useRelativeName";
139    /**
140     * An integer that controls the number of connection retry attempts will
141     * be made on the initial connection to the naming server. This only applies
142     * to ConnectException failures. A value <= 1 means that only one attempt
143     * will be made.
144     */

145    public static final String JavaDoc JNP_MAX_RETRIES = "jnp.maxRetries";
146
147    /**
148     * The default discovery multicast information
149     */

150    public final static String JavaDoc DEFAULT_DISCOVERY_GROUP_ADDRESS = "230.0.0.4";
151    public final static int DEFAULT_DISCOVERY_GROUP_PORT = 1102;
152    public final static int DEFAULT_DISCOVERY_TIMEOUT = 5000;
153
154    /**
155     * An obsolete constant replaced by the JNP_MAX_RETRIES value
156     */

157    public static int MAX_RETRIES = 1;
158    /**
159     * The JBoss logging interface
160     */

161    private static Logger log = Logger.getLogger(NamingContext.class);
162
163    // Static --------------------------------------------------------
164

165    public static Hashtable JavaDoc haServers = new Hashtable JavaDoc();
166
167    public static void setHANamingServerForPartition(String JavaDoc partitionName, Naming haServer)
168    {
169       haServers.put(partitionName, haServer);
170    }
171
172    public static void removeHANamingServerForPartition(String JavaDoc partitionName)
173    {
174       haServers.remove(partitionName);
175    }
176
177    public static Naming getHANamingServerForPartition(String JavaDoc partitionName)
178    {
179       return (Naming) haServers.get(partitionName);
180    }
181
182    public static Naming localServer;
183
184    // Attributes ----------------------------------------------------
185
Naming naming;
186    Hashtable JavaDoc env;
187    Name JavaDoc prefix;
188
189    NameParser JavaDoc parser = new NamingParser();
190    
191    // Static --------------------------------------------------------
192

193    // Cache of naming server stubs
194
// This is a critical optimization in the case where new InitialContext
195
// is performed often. The server stub will be shared between all those
196
// calls, which will improve performance.
197
// Weak references are used so if no contexts use a particular server
198
// it will be removed from the cache.
199
static HashMap JavaDoc cachedServers = new HashMap JavaDoc();
200
201    static void addServer(String JavaDoc name, Naming server)
202    {
203       // Add server to map
204
synchronized (NamingContext.class)
205       {
206          cachedServers.put(name, new WeakReference JavaDoc(server));
207       }
208    }
209
210    static Naming getServer(String JavaDoc host, int port, Hashtable JavaDoc serverEnv)
211       throws NamingException JavaDoc
212    {
213       // Check the server cache for a host:port entry
214
String JavaDoc hostKey = host + ":" + port;
215       WeakReference JavaDoc ref = (WeakReference JavaDoc) cachedServers.get(hostKey);
216       Naming server;
217       if (ref != null)
218       {
219          server = (Naming) ref.get();
220          if (server != null)
221          {
222             return server;
223          }
224       }
225
226       // Server not found; add it to cache
227
try
228       {
229          SocketFactory factory = loadSocketFactory(serverEnv);
230          Socket JavaDoc s;
231
232          try
233          {
234             InetAddress JavaDoc localAddr = null;
235             int localPort = 0;
236             String JavaDoc localAddrStr = (String JavaDoc) serverEnv.get(JNP_LOCAL_ADDRESS);
237             String JavaDoc localPortStr = (String JavaDoc) serverEnv.get(JNP_LOCAL_PORT);
238             if (localAddrStr != null)
239                localAddr = InetAddress.getByName(localAddrStr);
240             if (localPortStr != null)
241                localPort = Integer.parseInt(localPortStr);
242             s = factory.createSocket(host, port, localAddr, localPort);
243          }
244          catch (IOException JavaDoc e)
245          {
246             NamingException JavaDoc ex = new ServiceUnavailableException JavaDoc("Failed to connect to server " + hostKey);
247             ex.setRootCause(e);
248             throw ex;
249          }
250
251          // Get stub from naming server
252
BufferedInputStream JavaDoc bis = new BufferedInputStream JavaDoc(s.getInputStream());
253          ObjectInputStream JavaDoc in = new ObjectInputStream JavaDoc(bis);
254          MarshalledObject JavaDoc stub = (MarshalledObject JavaDoc) in.readObject();
255          server = (Naming) stub.get();
256          s.close();
257
258          // Add it to cache
259
addServer(hostKey, server);
260          serverEnv.put("hostKey", hostKey);
261
262          return server;
263       }
264       catch (IOException JavaDoc e)
265       {
266          NamingException JavaDoc ex = new CommunicationException JavaDoc("Failed to retrieve stub from server " + hostKey);
267          ex.setRootCause(e);
268          throw ex;
269       }
270       catch (Exception JavaDoc e)
271       {
272          NamingException JavaDoc ex = new CommunicationException JavaDoc("Failed to connect to server " + hostKey);
273          ex.setRootCause(e);
274          throw ex;
275       }
276    }
277
278    /**
279     * Create a SocketFactory based on the JNP_SOCKET_FACTORY property in the
280     * given env. If JNP_SOCKET_FACTORY is not specified default to the
281     * TimedSocketFactory.
282     */

283    static SocketFactory loadSocketFactory(Hashtable JavaDoc serverEnv)
284       throws ClassNotFoundException JavaDoc, IllegalAccessException JavaDoc,
285       InstantiationException JavaDoc, InvocationTargetException JavaDoc
286    {
287       SocketFactory factory = null;
288
289       // Get the socket factory classname
290
String JavaDoc socketFactoryName = (String JavaDoc) serverEnv.get(JNP_SOCKET_FACTORY);
291       if (socketFactoryName == null ||
292          socketFactoryName.equals(TimedSocketFactory.class.getName()))
293       {
294          factory = new TimedSocketFactory(serverEnv);
295          return factory;
296       }
297
298       /* Create the socket factory. Look for a ctor that accepts a
299        Hashtable and if not found use the default ctor.
300        */

301       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
302       Class JavaDoc factoryClass = loader.loadClass(socketFactoryName);
303       try
304       {
305          Class JavaDoc[] ctorSig = {Hashtable JavaDoc.class};
306          Constructor JavaDoc ctor = factoryClass.getConstructor(ctorSig);
307          Object JavaDoc[] ctorArgs = {serverEnv};
308          factory = (SocketFactory) ctor.newInstance(ctorArgs);
309       }
310       catch (NoSuchMethodException JavaDoc e)
311       {
312          // Use the default ctor
313
factory = (SocketFactory) factoryClass.newInstance();
314       }
315       return factory;
316    }
317
318    static void removeServer(Hashtable JavaDoc serverEnv)
319    {
320       String JavaDoc host = "localhost";
321       int port = 1099;
322       
323       // Locate naming service
324
if (serverEnv.get(Context.PROVIDER_URL) != null)
325       {
326          String JavaDoc providerURL = (String JavaDoc) serverEnv.get(Context.PROVIDER_URL);
327
328          StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(providerURL, ", ");
329          while (tokenizer.hasMoreElements())
330          {
331             String JavaDoc url = tokenizer.nextToken();
332
333             try
334             {
335                // Parse the url into a host:port form, stripping any protocol
336
Name JavaDoc urlAsName = new NamingParser().parse(url);
337                String JavaDoc server = parseNameForScheme(urlAsName, null);
338                if (server != null)
339                   url = server;
340                int colon = url.indexOf(':');
341                if (colon < 0)
342                {
343                   host = url.trim();
344                }
345                else
346                {
347                   host = url.substring(0, colon).trim();
348                   try
349                   {
350                      port = Integer.parseInt(url.substring(colon + 1).trim());
351                   }
352                   catch (Exception JavaDoc ex)
353                   {
354                      // Use default;
355
}
356                }
357
358                // Remove server from map
359
synchronized (NamingContext.class)
360                {
361                   cachedServers.remove(host + ":" + port);
362                }
363             }
364             catch (NamingException JavaDoc ignored)
365             {
366             }
367          }
368          Object JavaDoc hostKey = serverEnv.remove("hostKey");
369          if (hostKey != null)
370          {
371             synchronized (NamingContext.class)
372             {
373                cachedServers.remove(hostKey);
374             }
375          }
376       }
377       else
378       {
379          // Don't do anything for local server
380
}
381    }
382
383    /**
384     * Called to remove any url scheme atoms and extract the naming service
385     * hostname:port information.
386     * @param n the name component to the parsed. After returning n will have all
387     * scheme related atoms removed.
388     * @return the naming service hostname:port information string if name
389     * contained the host information.
390     */

391    static String JavaDoc parseNameForScheme(Name JavaDoc n, Hashtable JavaDoc nameEnv)
392       throws InvalidNameException JavaDoc
393    {
394       String JavaDoc serverInfo = null;
395       if (n.size() > 0)
396       {
397          String JavaDoc scheme = n.get(0);
398          int schemeLength = 0;
399          if (scheme.startsWith("java:"))
400             schemeLength = 5;
401          else if (scheme.startsWith("jnp:"))
402             schemeLength = 4;
403          else if (scheme.startsWith("jnps:"))
404             schemeLength = 5;
405          else if (scheme.startsWith("jnp-http:"))
406             schemeLength = 9;
407          else if (scheme.startsWith("jnp-https:"))
408             schemeLength = 10;
409          if (schemeLength > 0)
410          {
411             // Make a copy of the name to avoid
412
n = (Name JavaDoc) n.clone();
413             String JavaDoc suffix = scheme.substring(schemeLength);
414             if (suffix.length() == 0)
415             {
416                // Scheme was "url:/..."
417
n.remove(0);
418                if (n.size() > 1 && n.get(0).equals(""))
419                {
420                   // Scheme was "url://hostname:port/..."
421
// Get hostname:port value for the naming server
422
serverInfo = n.get(1);
423                   n.remove(0);
424                   n.remove(0);
425                   // If n is a empty atom remove it or else a '/' will result
426
if (n.size() == 1 && n.get(0).length() == 0)
427                      n.remove(0);
428                }
429             }
430             else
431             {
432                // Scheme was "url:foo" -> reinsert "foo"
433
n.remove(0);
434                n.add(0, suffix);
435             }
436             if (nameEnv != null)
437                nameEnv.put(JNP_PARSED_NAME, n);
438          }
439       }
440       return serverInfo;
441    }
442
443    public static void setLocal(Naming server)
444    {
445       localServer = server;
446    }
447
448    // Constructors --------------------------------------------------
449
public NamingContext(Hashtable JavaDoc e, Name JavaDoc baseName, Naming server)
450       throws NamingException JavaDoc
451    {
452       if (baseName == null)
453          this.prefix = parser.parse("");
454       else
455          this.prefix = baseName;
456
457       if (e != null)
458          this.env = (Hashtable JavaDoc) e.clone();
459       else
460          this.env = new Hashtable JavaDoc();
461
462       this.naming = server;
463    }
464
465    // Public --------------------------------------------------------
466
public Naming getNaming()
467    {
468       return this.naming;
469    }
470
471    public void setNaming(Naming server)
472    {
473       this.naming = server;
474    }
475
476    // Context implementation ----------------------------------------
477
public void rebind(String JavaDoc name, Object JavaDoc obj)
478       throws NamingException JavaDoc
479    {
480       rebind(getNameParser(name).parse(name), obj);
481    }
482
483    public void rebind(Name JavaDoc name, Object JavaDoc obj)
484       throws NamingException JavaDoc
485    {
486       Hashtable JavaDoc refEnv = getEnv(name);
487       checkRef(refEnv);
488       Name JavaDoc parsedName = (Name JavaDoc) refEnv.get(JNP_PARSED_NAME);
489       if (parsedName != null)
490          name = parsedName;
491
492       // Allow state factories to change the stored object
493
obj = getStateToBind(obj, name, refEnv);
494
495       try
496       {
497          String JavaDoc className;
498          
499          // Referenceable
500
if (obj instanceof Referenceable JavaDoc)
501             obj = ((Referenceable JavaDoc) obj).getReference();
502
503          if (!(obj instanceof Reference JavaDoc))
504          {
505             className = obj.getClass().getName();
506             // Normal object - serialize using a MarshalledValuePair
507
obj = new MarshalledValuePair(obj);
508          }
509          else
510          {
511             className = ((Reference JavaDoc) obj).getClassName();
512          }
513          naming.rebind(getAbsoluteName(name), obj, className);
514       }
515       catch (CannotProceedException JavaDoc cpe)
516       {
517          cpe.setEnvironment(refEnv);
518          Context JavaDoc cctx = NamingManager.getContinuationContext(cpe);
519          cctx.rebind(cpe.getRemainingName(), obj);
520       }
521       catch (IOException JavaDoc e)
522       {
523          naming = null;
524          removeServer(refEnv);
525          NamingException JavaDoc ex = new CommunicationException JavaDoc();
526          ex.setRootCause(e);
527          throw ex;
528       }
529    }
530
531    public void bind(String JavaDoc name, Object JavaDoc obj)
532       throws NamingException JavaDoc
533    {
534       bind(getNameParser(name).parse(name), obj);
535    }
536
537    public void bind(Name JavaDoc name, Object JavaDoc obj)
538       throws NamingException JavaDoc
539    {
540       Hashtable JavaDoc refEnv = getEnv(name);
541       checkRef(refEnv);
542       Name JavaDoc parsedName = (Name JavaDoc) refEnv.get(JNP_PARSED_NAME);
543       if (parsedName != null)
544          name = parsedName;
545
546       // Allow state factories to change the stored object
547
obj = getStateToBind(obj, name, refEnv);
548
549       try
550       {
551          String JavaDoc className;
552          
553          // Referenceable
554
if (obj instanceof Referenceable JavaDoc)
555             obj = ((Referenceable JavaDoc) obj).getReference();
556
557          if (!(obj instanceof Reference JavaDoc))
558          {
559             className = obj.getClass().getName();
560             
561             // Normal object - serialize using a MarshalledValuePair
562
obj = new MarshalledValuePair(obj);
563          }
564          else
565          {
566             className = ((Reference JavaDoc) obj).getClassName();
567          }
568          name = getAbsoluteName(name);
569          naming.bind(name, obj, className);
570       }
571       catch (CannotProceedException JavaDoc cpe)
572       {
573          cpe.setEnvironment(refEnv);
574          Context JavaDoc cctx = NamingManager.getContinuationContext(cpe);
575          cctx.bind(cpe.getRemainingName(), obj);
576       }
577       catch (IOException JavaDoc e)
578       {
579          naming = null;
580          removeServer(refEnv);
581          NamingException JavaDoc ex = new CommunicationException JavaDoc();
582          ex.setRootCause(e);
583          throw ex;
584       }
585    }
586
587    public Object JavaDoc lookup(String JavaDoc name)
588       throws NamingException JavaDoc
589    {
590       return lookup(getNameParser(name).parse(name));
591    }
592
593    public Object JavaDoc lookup(Name JavaDoc name)
594       throws NamingException JavaDoc
595    {
596       Hashtable JavaDoc refEnv = getEnv(name);
597       checkRef(refEnv);
598       Name JavaDoc parsedName = (Name JavaDoc) refEnv.get(JNP_PARSED_NAME);
599       if (parsedName != null)
600          name = parsedName;
601
602       // Empty?
603
if (name.isEmpty())
604          return new NamingContext(refEnv, prefix, naming);
605
606       try
607       {
608          int maxTries = 1;
609          try
610          {
611             String JavaDoc n = (String JavaDoc) refEnv.get(JNP_MAX_RETRIES);
612             if( n != null )
613                maxTries = Integer.parseInt(n);
614             if( maxTries <= 0 )
615                maxTries = 1;
616          }
617          catch(Exception JavaDoc e)
618          {
619             log.debug("Failed to get JNP_MAX_RETRIES, using 1", e);
620          }
621          Name JavaDoc n = getAbsoluteName(name);
622          Object JavaDoc res = null;
623          boolean trace = log.isTraceEnabled();
624          for (int i = 0; i < maxTries; i++)
625          {
626             try
627             {
628                res = naming.lookup(n);
629                break;
630             }
631             catch (ConnectException JavaDoc ce)
632             {
633                int retries = maxTries - i - 1;
634                if( trace )
635                   log.trace("Connect failed, retry count: "+retries, ce);
636                // We may overload server so sleep and retry
637
if (retries > 0)
638                {
639                   try
640                   {
641                      Thread.sleep(1);
642                   }
643                   catch (InterruptedException JavaDoc ignored)
644                   {
645                   }
646                   continue;
647                }
648                // Throw the exception to flush the bad server
649
throw ce;
650             }
651          }
652          if (res instanceof MarshalledValuePair)
653          {
654             MarshalledValuePair mvp = (MarshalledValuePair) res;
655             Object JavaDoc storedObj = mvp.get();
656             return getObjectInstanceWrapFailure(storedObj, name, refEnv);
657          }
658          else if (res instanceof MarshalledObject JavaDoc)
659          {
660             MarshalledObject JavaDoc mo = (MarshalledObject JavaDoc) res;
661             return mo.get();
662          }
663          else if (res instanceof Context JavaDoc)
664          {
665             // Add env
666
Enumeration JavaDoc keys = refEnv.keys();
667             while (keys.hasMoreElements())
668             {
669                String JavaDoc key = (String JavaDoc) keys.nextElement();
670                ((Context JavaDoc) res).addToEnvironment(key, refEnv.get(key));
671             }
672             return res;
673          }
674          else if (res instanceof ResolveResult JavaDoc)
675          {
676             // Dereference partial result
677
ResolveResult JavaDoc rr = (ResolveResult JavaDoc) res;
678             Object JavaDoc resolveRes = rr.getResolvedObj();
679             Object JavaDoc context;
680             Object JavaDoc instanceID;
681
682             if (resolveRes instanceof LinkRef JavaDoc)
683             {
684                context = resolveLink(resolveRes, null);
685                instanceID = ((LinkRef JavaDoc) resolveRes).getLinkName();
686             }
687             else
688             {
689                context = getObjectInstanceWrapFailure(resolveRes, name, refEnv);
690                instanceID = context;
691             }
692
693             if ((context instanceof Context JavaDoc) == false)
694             {
695                throw new NotContextException JavaDoc(instanceID + " is not a Context");
696             }
697             Context JavaDoc ncontext = (Context JavaDoc) context;
698             return ncontext.lookup(rr.getRemainingName());
699          }
700          else if (res instanceof LinkRef JavaDoc)
701          {
702             // Dereference link
703
res = resolveLink(res, refEnv);
704          }
705          else if (res instanceof Reference JavaDoc)
706          {
707             // Dereference object
708
res = getObjectInstanceWrapFailure(res, name, refEnv);
709             if (res instanceof LinkRef JavaDoc)
710                res = resolveLink(res, refEnv);
711          }
712
713          return res;
714       }
715       catch (CannotProceedException JavaDoc cpe)
716       {
717          cpe.setEnvironment(refEnv);
718          Context JavaDoc cctx = NamingManager.getContinuationContext(cpe);
719          return cctx.lookup(cpe.getRemainingName());
720       }
721       catch (IOException JavaDoc e)
722       {
723          naming = null;
724          removeServer(refEnv);
725          NamingException JavaDoc ex = new CommunicationException JavaDoc();
726          ex.setRootCause(e);
727          throw ex;
728       }
729     &nbs