/** * Gets the unique instance of this class. This is only allowed in * very limited situations. */ public static Unsafe getUnsafe() { /* * Only code on the bootclasspath is allowed to get at the * Unsafe instance. */ ClassLoader calling = VMStack.getCallingClassLoader(); if ((calling != null) && (calling != Unsafe.class.getClassLoader())) { throw new SecurityException("Unsafe access denied"); } return THE_ONE; }
/** * Returns a {@code Class} object which represents the class with the * given name. The name should be the name of a non-primitive class, as described in * the {@link Class class definition}. * Primitive types can not be found using this method; use {@code int.class} or {@code Integer.TYPE} instead. * * <p>If the class has not yet been loaded, it is loaded and initialized * first. This is done through either the class loader of the calling class * or one of its parent class loaders. It is possible that a static initializer is run as * a result of this call. * * @param className * the name of the non-primitive-type class to find. * @return the named {@code Class} instance. * @throws ClassNotFoundException * if the requested class can not be found. * @throws LinkageError * if an error occurs during linkage * @throws ExceptionInInitializerError * if an exception occurs during static initialization of a * class. */ public static Class<?> forName(String className) throws ClassNotFoundException { return forName(className, true, VMStack.getCallingClassLoader()); }
/** * Loads and links the dynamic library that is identified through the * specified path. This method is similar to {@link #loadLibrary(String)}, * but it accepts a full path specification whereas {@code loadLibrary} just * accepts the name of the library to load. * * @param pathName * the path of the file to be loaded. */ public static void load(String pathName) { Runtime.getRuntime().load(pathName, VMStack.getCallingClassLoader()); }
/** * Loads and links the library with the specified name. The mapping of the * specified library name to the full path for loading the library is * implementation-dependent. * * @param libName * the name of the library to load. * @throws UnsatisfiedLinkError * if the library could not be loaded. */ public static void loadLibrary(String libName) { Runtime.getRuntime().loadLibrary(libName, VMStack.getCallingClassLoader()); }
/** * Loads and links the library with the specified name. The mapping of the * specified library name to the full path for loading the library is * implementation-dependent. * * @param libName * the name of the library to load. * @throws UnsatisfiedLinkError * if the library can not be loaded. */ public void loadLibrary(String libName) { loadLibrary(libName, VMStack.getCallingClassLoader()); }
/** * Returns all the packages known to the caller's class loader. * * @return all the packages known to the caller's class loader. * @see ClassLoader#getPackages */ public static Package[] getPackages() { ClassLoader classloader = VMStack.getCallingClassLoader(); if (classloader == null) { classloader = ClassLoader.getSystemClassLoader(); } return classloader.getPackages(); }
/** * Loads and links the dynamic library that is identified through the * specified path. This method is similar to {@link #loadLibrary(String)}, * but it accepts a full path specification whereas {@code loadLibrary} just * accepts the name of the library to load. * * @param pathName * the absolute (platform dependent) path to the library to load. * @throws UnsatisfiedLinkError * if the library can not be loaded. */ public void load(String pathName) { load(pathName, VMStack.getCallingClassLoader()); }
/** * Attempts to locate the requested package in the caller's class loader. If * no package information can be located, {@code null} is returned. * * @param packageName * the name of the package to find. * @return the requested package, or {@code null}. * @see ClassLoader#getPackage(java.lang.String) */ public static Package getPackage(String packageName) { ClassLoader classloader = VMStack.getCallingClassLoader(); if (classloader == null) { classloader = ClassLoader.getSystemClassLoader(); } return classloader.getPackage(packageName); }
/** * Finds the named resource bundle for the default {@code Locale} and the caller's * {@code ClassLoader}. * * @param bundleName * the name of the {@code ResourceBundle}. * @return the requested {@code ResourceBundle}. * @throws MissingResourceException * if the {@code ResourceBundle} cannot be found. */ public static ResourceBundle getBundle(String bundleName) throws MissingResourceException { ClassLoader classLoader = VMStack.getCallingClassLoader(); if (classLoader == null) { classLoader = getLoader(); } return getBundle(bundleName, Locale.getDefault(), classLoader); }
/** * Finds the named {@code ResourceBundle} for the specified {@code Locale} and the caller * {@code ClassLoader}. * * @param bundleName * the name of the {@code ResourceBundle}. * @param locale * the {@code Locale}. * @return the requested resource bundle. * @throws MissingResourceException * if the resource bundle cannot be found. */ public static ResourceBundle getBundle(String bundleName, Locale locale) { ClassLoader classLoader = VMStack.getCallingClassLoader(); if (classLoader == null) { classLoader = getLoader(); } return getBundle(bundleName, locale, classLoader); }
try { rb = ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), VMStack.getCallingClassLoader()); } catch (MissingResourceException e) { rb = null;
/** * Returns an {@code Enumeration} that contains all of the loaded JDBC * drivers that the current caller can access. * * @return An {@code Enumeration} containing all the currently loaded JDBC * {@code Drivers}. */ public static Enumeration<Driver> getDrivers() { /* * Synchronize to avoid clashes with additions and removals of drivers * in the DriverSet */ ClassLoader callerClassLoader = VMStack.getCallingClassLoader(); synchronized (theDrivers) { ArrayList<Driver> result = new ArrayList<Driver>(); for (Driver driver : theDrivers) { if (DriverManager.isClassFromClassLoader(driver, callerClassLoader)) { result.add(driver); } } return Collections.enumeration(result); } }
/** * Removes a driver from the {@code DriverManager}'s registered driver list. * This will only succeed when the caller's class loader loaded the driver * that is to be removed. If the driver was loaded by a different class * loader, the removal of the driver fails silently. * <p> * If the removal succeeds, the {@code DriverManager} will not use this * driver in the future when asked to get a {@code Connection}. * * @param driver * the JDBC driver to remove. * @throws SQLException * if there is a problem interfering with accessing the * database. */ public static void deregisterDriver(Driver driver) throws SQLException { if (driver == null) { return; } ClassLoader callerClassLoader = VMStack.getCallingClassLoader(); if (!DriverManager.isClassFromClassLoader(driver, callerClassLoader)) { throw new SecurityException("calling class not authorized to deregister JDBC driver"); } synchronized (theDrivers) { theDrivers.remove(driver); } }
/** * Tries to find a driver that can interpret the supplied URL. * * @param url * the URL of a database. * @return a {@code Driver} that matches the provided URL. {@code null} if * no {@code Driver} understands the URL * @throws SQLException * if there is any kind of problem accessing the database. */ public static Driver getDriver(String url) throws SQLException { ClassLoader callerClassLoader = VMStack.getCallingClassLoader(); synchronized (theDrivers) { /* * Loop over the drivers in the DriverSet checking to see if one * does understand the supplied URL - return the first driver which * does understand the URL */ for (Driver driver : theDrivers) { if (driver.acceptsURL(url) && DriverManager.isClassFromClassLoader(driver, callerClassLoader)) { return driver; } } } // If no drivers understand the URL, throw an SQLException // SQLState: 08 - connection exception // 001 - SQL-client unable to establish SQL-connection throw new SQLException("No suitable driver", "08001"); }
/** * Loads and links the dynamic library that is identified through the * specified path. This method is similar to {@link #loadLibrary(String)}, * but it accepts a full path specification whereas {@code loadLibrary} just * accepts the name of the library to load. * * @param pathName * the path of the file to be loaded. */ public static void load(String pathName) { Runtime.getRuntime().load(pathName, VMStack.getCallingClassLoader()); }
/** * Loads and links the dynamic library that is identified through the * specified path. This method is similar to {@link #loadLibrary(String)}, * but it accepts a full path specification whereas {@code loadLibrary} just * accepts the name of the library to load. * * @param pathName * the path of the file to be loaded. */ public static void load(String pathName) { Runtime.getRuntime().load(pathName, VMStack.getCallingClassLoader()); }
/** * Loads and links the dynamic library that is identified through the * specified path. This method is similar to {@link #loadLibrary(String)}, * but it accepts a full path specification whereas {@code loadLibrary} just * accepts the name of the library to load. * * @param pathName * the path of the file to be loaded. */ public static void load(String pathName) { Runtime.getRuntime().load(pathName, VMStack.getCallingClassLoader()); }
/** * Returns all the packages known to the caller's class loader. * * @return all the packages known to the caller's class loader. * @see ClassLoader#getPackages */ public static Package[] getPackages() { ClassLoader classloader = VMStack.getCallingClassLoader(); if (classloader == null) { classloader = ClassLoader.getSystemClassLoader(); } return classloader.getPackages(); }
/** * Loads and links the library with the specified name. The mapping of the * specified library name to the full path for loading the library is * implementation-dependent. * * @param libName * the name of the library to load. * @throws UnsatisfiedLinkError * if the library can not be loaded. */ public void loadLibrary(String libName) { loadLibrary(libName, VMStack.getCallingClassLoader()); }
/** * Loads and links the library with the specified name. The mapping of the * specified library name to the full path for loading the library is * implementation-dependent. * * @param libName * the name of the library to load. * @throws UnsatisfiedLinkError * if the library could not be loaded. */ public static void loadLibrary(String libName) { Runtime.getRuntime().loadLibrary(libName, VMStack.getCallingClassLoader()); }