< prev index next >

src/java.naming/share/classes/javax/naming/spi/NamingManager.java

Print this page




 142 
 143         // Try to use current class loader
 144         try {
 145              clas = helper.loadClass(factoryName);
 146         } catch (ClassNotFoundException e) {
 147             // ignore and continue
 148             // e.printStackTrace();
 149         }
 150         // All other exceptions are passed up.
 151 
 152         // Not in class path; try to use codebase
 153         String codebase;
 154         if (clas == null &&
 155                 (codebase = ref.getFactoryClassLocation()) != null) {
 156             try {
 157                 clas = helper.loadClass(factoryName, codebase);
 158             } catch (ClassNotFoundException e) {
 159             }
 160         }
 161 
 162         return (clas != null) ? (ObjectFactory) clas.newInstance() : null;


 163     }
 164 
 165 
 166     /**
 167      * Creates an object using the factories specified in the
 168      * {@code Context.OBJECT_FACTORIES} property of the environment
 169      * or of the provider resource file associated with {@code nameCtx}.
 170      *
 171      * @return factory created; null if cannot create
 172      */
 173     private static Object createObjectFromFactories(Object obj, Name name,
 174             Context nameCtx, Hashtable<?,?> environment) throws Exception {
 175 
 176         FactoryEnumeration factories = ResourceManager.getFactories(
 177             Context.OBJECT_FACTORIES, environment, nameCtx);
 178 
 179         if (factories == null)
 180             return null;
 181 
 182         // Try each factory until one succeeds


 693             Iterator<InitialContextFactory> iterator = loader.iterator();
 694             try {
 695                 while (iterator.hasNext()) {
 696                     InitialContextFactory f = iterator.next();
 697                     if (f.getClass().getName().equals(className)) {
 698                         factory = f;
 699                         break;
 700                     }
 701                 }
 702             } catch (ServiceConfigurationError e) {
 703                 NoInitialContextException ne =
 704                         new NoInitialContextException(
 705                                 "Cannot load initial context factory "
 706                                         + "'" + className + "'");
 707                 ne.setRootCause(e);
 708                 throw ne;
 709             }
 710 
 711             if (factory == null) {
 712                 try {
 713                     factory = (InitialContextFactory)
 714                             helper.loadClass(className).newInstance();

 715                 } catch (Exception e) {
 716                     NoInitialContextException ne =
 717                             new NoInitialContextException(
 718                                     "Cannot instantiate class: " + className);
 719                     ne.setRootCause(e);
 720                     throw ne;
 721                 }
 722             }
 723         } else {
 724             factory = builder.createInitialContextFactory(env);
 725         }
 726 
 727         return factory.getInitialContext(env);
 728     }
 729 
 730 
 731     /**
 732      * Sets the InitialContextFactory builder to be builder.
 733      *
 734      *<p>




 142 
 143         // Try to use current class loader
 144         try {
 145              clas = helper.loadClass(factoryName);
 146         } catch (ClassNotFoundException e) {
 147             // ignore and continue
 148             // e.printStackTrace();
 149         }
 150         // All other exceptions are passed up.
 151 
 152         // Not in class path; try to use codebase
 153         String codebase;
 154         if (clas == null &&
 155                 (codebase = ref.getFactoryClassLocation()) != null) {
 156             try {
 157                 clas = helper.loadClass(factoryName, codebase);
 158             } catch (ClassNotFoundException e) {
 159             }
 160         }
 161 
 162         @SuppressWarnings("deprecation") // Class.newInstance
 163         ObjectFactory result = (clas != null) ? (ObjectFactory) clas.newInstance() : null;
 164         return result;
 165     }
 166 
 167 
 168     /**
 169      * Creates an object using the factories specified in the
 170      * {@code Context.OBJECT_FACTORIES} property of the environment
 171      * or of the provider resource file associated with {@code nameCtx}.
 172      *
 173      * @return factory created; null if cannot create
 174      */
 175     private static Object createObjectFromFactories(Object obj, Name name,
 176             Context nameCtx, Hashtable<?,?> environment) throws Exception {
 177 
 178         FactoryEnumeration factories = ResourceManager.getFactories(
 179             Context.OBJECT_FACTORIES, environment, nameCtx);
 180 
 181         if (factories == null)
 182             return null;
 183 
 184         // Try each factory until one succeeds


 695             Iterator<InitialContextFactory> iterator = loader.iterator();
 696             try {
 697                 while (iterator.hasNext()) {
 698                     InitialContextFactory f = iterator.next();
 699                     if (f.getClass().getName().equals(className)) {
 700                         factory = f;
 701                         break;
 702                     }
 703                 }
 704             } catch (ServiceConfigurationError e) {
 705                 NoInitialContextException ne =
 706                         new NoInitialContextException(
 707                                 "Cannot load initial context factory "
 708                                         + "'" + className + "'");
 709                 ne.setRootCause(e);
 710                 throw ne;
 711             }
 712 
 713             if (factory == null) {
 714                 try {
 715                     @SuppressWarnings("deprecation")
 716                     Object o = helper.loadClass(className).newInstance();
 717                     factory = (InitialContextFactory) o;
 718                 } catch (Exception e) {
 719                     NoInitialContextException ne =
 720                             new NoInitialContextException(
 721                                     "Cannot instantiate class: " + className);
 722                     ne.setRootCause(e);
 723                     throw ne;
 724                 }
 725             }
 726         } else {
 727             factory = builder.createInitialContextFactory(env);
 728         }
 729 
 730         return factory.getInitialContext(env);
 731     }
 732 
 733 
 734     /**
 735      * Sets the InitialContextFactory builder to be builder.
 736      *
 737      *<p>


< prev index next >