< prev index next >

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

Print this page




 120      */
 121     private static final
 122         WeakHashMap<ClassLoader, Map<String, WeakReference<Object>>>
 123             urlFactoryCache = new WeakHashMap<>(11);
 124     private static final WeakReference<Object> NO_FACTORY =
 125             new WeakReference<>(null);
 126 
 127     // There should be no instances of this class.
 128     private ResourceManager() {
 129     }
 130 
 131 
 132     // ---------- Public methods ----------
 133 
 134     /**
 135      * Given the environment parameter passed to the initial context
 136      * constructor, returns the full environment for that initial
 137      * context (never null).  This is based on the environment
 138      * parameter, the system properties, and all application resource files.
 139      *
 140      * <p> This method will modify <tt>env</tt> and save
 141      * a reference to it.  The caller may no longer modify it.
 142      *
 143      * @param env       environment passed to initial context constructor.
 144      *                  Null indicates an empty environment.
 145      *
 146      * @throws NamingException if an error occurs while reading a
 147      *          resource file
 148      */
 149     @SuppressWarnings("unchecked")
 150     public static Hashtable<?, ?> getInitialEnvironment(Hashtable<?, ?> env)
 151             throws NamingException
 152     {
 153         String[] props = VersionHelper.PROPS;   // system properties
 154         if (env == null) {
 155             env = new Hashtable<>(11);
 156         }
 157 
 158         // Merge property values from env param, and system properties.
 159         // The first value wins: there's no concatenation of
 160         // colon-separated lists.


 178 
 179         // Return without merging if application resource files lookup
 180         // is disabled.
 181         String disableAppRes = (String)env.get(DISABLE_APP_RESOURCE_FILES);
 182         if (disableAppRes != null && disableAppRes.equalsIgnoreCase("true")) {
 183             return env;
 184         }
 185 
 186         // Merge the above with the values read from all application
 187         // resource files.  Colon-separated lists are concatenated.
 188         mergeTables((Hashtable<Object, Object>)env, getApplicationResources());
 189         return env;
 190     }
 191 
 192     /**
 193       * Retrieves the property from the environment, or from the provider
 194       * resource file associated with the given context.  The environment
 195       * may in turn contain values that come from system properties,
 196       * or application resource files.
 197       *
 198       * If <tt>concat</tt> is true and both the environment and the provider
 199       * resource file contain the property, the two values are concatenated
 200       * (with a ':' separator).
 201       *
 202       * Returns null if no value is found.
 203       *
 204       * @param propName The non-null property name
 205       * @param env      The possibly null environment properties
 206       * @param ctx      The possibly null context
 207       * @param concat   True if multiple values should be concatenated
 208       * @return the property value, or null is there is none.
 209       * @throws NamingException if an error occurs while reading the provider
 210       * resource file.
 211       */
 212     public static String getProperty(String propName, Hashtable<?,?> env,
 213         Context ctx, boolean concat)
 214             throws NamingException {
 215 
 216         String val1 = (env != null) ? (String)env.get(propName) : null;
 217         if ((ctx == null) ||
 218             ((val1 != null) && !concat)) {




 120      */
 121     private static final
 122         WeakHashMap<ClassLoader, Map<String, WeakReference<Object>>>
 123             urlFactoryCache = new WeakHashMap<>(11);
 124     private static final WeakReference<Object> NO_FACTORY =
 125             new WeakReference<>(null);
 126 
 127     // There should be no instances of this class.
 128     private ResourceManager() {
 129     }
 130 
 131 
 132     // ---------- Public methods ----------
 133 
 134     /**
 135      * Given the environment parameter passed to the initial context
 136      * constructor, returns the full environment for that initial
 137      * context (never null).  This is based on the environment
 138      * parameter, the system properties, and all application resource files.
 139      *
 140      * <p> This method will modify {@code env} and save
 141      * a reference to it.  The caller may no longer modify it.
 142      *
 143      * @param env       environment passed to initial context constructor.
 144      *                  Null indicates an empty environment.
 145      *
 146      * @throws NamingException if an error occurs while reading a
 147      *          resource file
 148      */
 149     @SuppressWarnings("unchecked")
 150     public static Hashtable<?, ?> getInitialEnvironment(Hashtable<?, ?> env)
 151             throws NamingException
 152     {
 153         String[] props = VersionHelper.PROPS;   // system properties
 154         if (env == null) {
 155             env = new Hashtable<>(11);
 156         }
 157 
 158         // Merge property values from env param, and system properties.
 159         // The first value wins: there's no concatenation of
 160         // colon-separated lists.


 178 
 179         // Return without merging if application resource files lookup
 180         // is disabled.
 181         String disableAppRes = (String)env.get(DISABLE_APP_RESOURCE_FILES);
 182         if (disableAppRes != null && disableAppRes.equalsIgnoreCase("true")) {
 183             return env;
 184         }
 185 
 186         // Merge the above with the values read from all application
 187         // resource files.  Colon-separated lists are concatenated.
 188         mergeTables((Hashtable<Object, Object>)env, getApplicationResources());
 189         return env;
 190     }
 191 
 192     /**
 193       * Retrieves the property from the environment, or from the provider
 194       * resource file associated with the given context.  The environment
 195       * may in turn contain values that come from system properties,
 196       * or application resource files.
 197       *
 198       * If {@code concat} is true and both the environment and the provider
 199       * resource file contain the property, the two values are concatenated
 200       * (with a ':' separator).
 201       *
 202       * Returns null if no value is found.
 203       *
 204       * @param propName The non-null property name
 205       * @param env      The possibly null environment properties
 206       * @param ctx      The possibly null context
 207       * @param concat   True if multiple values should be concatenated
 208       * @return the property value, or null is there is none.
 209       * @throws NamingException if an error occurs while reading the provider
 210       * resource file.
 211       */
 212     public static String getProperty(String propName, Hashtable<?,?> env,
 213         Context ctx, boolean concat)
 214             throws NamingException {
 215 
 216         String val1 = (env != null) ? (String)env.get(propName) : null;
 217         if ((ctx == null) ||
 218             ((val1 != null) && !concat)) {


< prev index next >