< prev index next >

src/java.naming/share/classes/com/sun/naming/internal/ResourceManager.java

Print this page




 382         synchronized (perLoaderCache) {
 383             Object factory = null;
 384 
 385             WeakReference<Object> factoryRef = perLoaderCache.get(key);
 386             if (factoryRef == NO_FACTORY) {
 387                 return null;
 388             } else if (factoryRef != null) {
 389                 factory = factoryRef.get();
 390                 if (factory != null) {  // check if weak ref has been cleared
 391                     return factory;
 392                 }
 393             }
 394 
 395             // Not cached; find first factory and cache
 396             StringTokenizer parser = new StringTokenizer(facProp, ":");
 397             String className;
 398             while (factory == null && parser.hasMoreTokens()) {
 399                 className = parser.nextToken() + classSuffix;
 400                 try {
 401                     // System.out.println("loading " + className);
 402                     factory = helper.loadClass(className, loader).newInstance();


 403                 } catch (InstantiationException e) {
 404                     NamingException ne =
 405                         new NamingException("Cannot instantiate " + className);
 406                     ne.setRootCause(e);
 407                     throw ne;
 408                 } catch (IllegalAccessException e) {
 409                     NamingException ne =
 410                         new NamingException("Cannot access " + className);
 411                     ne.setRootCause(e);
 412                     throw ne;
 413                 } catch (Exception e) {
 414                     // ignore ClassNotFoundException, IllegalArgumentException,
 415                     // etc.
 416                 }
 417             }
 418 
 419             // Cache it.
 420             perLoaderCache.put(key, (factory != null)
 421                                         ? new WeakReference<>(factory)
 422                                         : NO_FACTORY);




 382         synchronized (perLoaderCache) {
 383             Object factory = null;
 384 
 385             WeakReference<Object> factoryRef = perLoaderCache.get(key);
 386             if (factoryRef == NO_FACTORY) {
 387                 return null;
 388             } else if (factoryRef != null) {
 389                 factory = factoryRef.get();
 390                 if (factory != null) {  // check if weak ref has been cleared
 391                     return factory;
 392                 }
 393             }
 394 
 395             // Not cached; find first factory and cache
 396             StringTokenizer parser = new StringTokenizer(facProp, ":");
 397             String className;
 398             while (factory == null && parser.hasMoreTokens()) {
 399                 className = parser.nextToken() + classSuffix;
 400                 try {
 401                     // System.out.println("loading " + className);
 402                     @SuppressWarnings("deprecation") // Class.newInstance
 403                     Object tmp = helper.loadClass(className, loader).newInstance();
 404                     factory = tmp;
 405                 } catch (InstantiationException e) {
 406                     NamingException ne =
 407                         new NamingException("Cannot instantiate " + className);
 408                     ne.setRootCause(e);
 409                     throw ne;
 410                 } catch (IllegalAccessException e) {
 411                     NamingException ne =
 412                         new NamingException("Cannot access " + className);
 413                     ne.setRootCause(e);
 414                     throw ne;
 415                 } catch (Exception e) {
 416                     // ignore ClassNotFoundException, IllegalArgumentException,
 417                     // etc.
 418                 }
 419             }
 420 
 421             // Cache it.
 422             perLoaderCache.put(key, (factory != null)
 423                                         ? new WeakReference<>(factory)
 424                                         : NO_FACTORY);


< prev index next >