Java Resource Get getResource(String name)

Here you can find the source of getResource(String name)

Description

Determines the url of the indicated resource using the currently set class loader.

License

Apache License

Parameter

Parameter Description
name The resource name

Return

The resource's url

Declaration

public static URL getResource(String name) 

Method Source Code

//package com.java2s;
/* Copyright 2002-2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.//from w  w w .j  a  va 2  s .c o m
 */

import java.net.URL;

public class Main {
    /** The class loader currently used by OJB */
    private static ClassLoader _classLoader = null;

    /**
     * Determines the url of the indicated resource using the currently set class loader.
     * 
     * @param name The resource name
     * @return The resource's url
     */
    public static URL getResource(String name) {
        return getClassLoader().getResource(name);
    }

    /**
     * Returns the class loader currently used by OJB. Defaults to the class loader of
     * the current thread (<code>Thread.currentThread().getContextClassLoader()</code>)
     * if not set differently. If class loader is not explicitly set and the loader for
     * the current thread context is null, the JVM default class loader will be used.
     * 
     * @return The classloader used by OJB
     * @see #setClassLoader(ClassLoader)
     */
    public static ClassLoader getClassLoader() {
        final ClassLoader ojbClassLoader;
        if (_classLoader != null) {
            ojbClassLoader = _classLoader;
        } else {
            final ClassLoader threadCtxtClassLoader;
            threadCtxtClassLoader = Thread.currentThread().getContextClassLoader();
            if (threadCtxtClassLoader == null) {
                // mkalen: happens only in "obscure" situations using JNI, revert to system CL
                ojbClassLoader = ClassLoader.getSystemClassLoader();
            } else {
                ojbClassLoader = threadCtxtClassLoader;
            }
        }
        return ojbClassLoader;
    }
}

Related

  1. getResource(String key, String bundleName, Locale locale)
  2. getResource(String name)
  3. getResource(String name)
  4. getResource(String name)
  5. getResource(String name)
  6. getResource(String name)
  7. getResource(String name)
  8. getResource(String name)
  9. getResource(String name, Class neighbor)