Esempio n. 1
0
        /**
         * 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 java.util.Enumeration <Driver> getDrivers()
        {
            java.lang.ClassLoader callerClassLoader = java.lang.Runtime.getRuntime().getClass().getClassLoader();// Basties note: sometime do the same as VM.callerClassLoader();

            /*
             * Synchronize to avoid clashes with additions and removals of drivers
             * in the DriverSet
             */
            lock (theDrivers)
            {
                /*
                 * Create the Enumeration by building a Vector from the elements of
                 * the DriverSet
                 */
                java.util.Vector <Driver>   theVector   = new java.util.Vector <Driver>();
                java.util.Iterator <Driver> theIterator = theDrivers.iterator();
                while (theIterator.hasNext())
                {
                    Driver theDriver = theIterator.next();
                    if (DriverManager.isClassFromClassLoader(theDriver,
                                                             callerClassLoader))
                    {
                        theVector.add(theDriver);
                    }
                }
                return(theVector.elements());
            }
        }
Esempio n. 2
0
        /**
         * This method returns an Inputstream for the reading resource
         * META_INF/services/org.w3c.dom.DOMImplementationSourceList after checking
         * access control privileges. For a JRE 1.1, this check is not done.
         *
         * @param classLoader classLoader
         * @param name the resource
         * @return an Inputstream for the resource specified
         */
        private static java.io.InputStream getResourceAsStream(java.lang.ClassLoader classLoader,
                                                               String name)
        {
            java.io.InputStream input = null == classLoader?java.lang.ClassLoader.getSystemResourceAsStream(name) : classLoader.getResourceAsStream(name);

            return(input);

            /*
             * if (isJRE11()) {
             * InputStream ris;
             * if (classLoader == null) {
             * ris = ClassLoader.getSystemResourceAsStream(name);
             * } else {
             * ris = classLoader.getResourceAsStream(name);
             * }
             * return ris;
             * } else {
             * return (InputStream)
             * AccessController.doPrivileged(new PrivilegedAction() {
             *  public Object run() {
             *      InputStream ris;
             *      if (classLoader == null) {
             *      ris =
             *          ClassLoader.getSystemResourceAsStream(name);
             *      } else {
             *      ris = classLoader.getResourceAsStream(name);
             *      }
             *      return ris;
             *  }
             *  });*/
        }
Esempio n. 3
0
        /**
         * Determines whether the supplied object was loaded by the given {@code ClassLoader}.
         *
         * @param theObject
         *            the object to check.
         * @param theClassLoader
         *            the {@code ClassLoader}.
         * @return {@code true} if the Object does belong to the {@code ClassLoader}
         *         , {@code false} otherwise
         */
        private static bool isClassFromClassLoader(Object theObject,
                                                   java.lang.ClassLoader theClassLoader)
        {
            if ((theObject == null) || (theClassLoader == null))
            {
                return(false);
            }

            java.lang.Class objectClass = theObject.getClass();

            try
            {
                java.lang.Class checkClass = java.lang.Class.forName(objectClass.getName(), true,
                                                                     theClassLoader);
                if (checkClass == objectClass)
                {
                    return(true);
                }
            }
            catch (Exception /*Throwable*/)
            {
                // Empty
            }
            return(false);
        }
Esempio n. 4
0
        // Load statically registered providers and init Services Info
        private static void loadProviders()
        {
            String providerClassName = null;
            int    i = 1;

            java.lang.ClassLoader  cl = java.lang.ClassLoader.getSystemClassLoader();
            java.security.Provider p;

            while ((providerClassName = java.security.Security.getProperty("security.provider." //$NON-NLS-1$
                                                                           + i++)) != null)
            {
                try
                {
                    p = (java.security.Provider)java.lang.Class
                        .forName(providerClassName.trim(), true, cl)
                        .newInstance();
                    providers.add(p);
                    providersNames.put(p.getName(), p);
                    initServiceInfo(p);
                }
                catch (java.lang.ClassNotFoundException)
                { // ignore Exceptions
                }
                catch (java.lang.IllegalAccessException)
                {
                }
                catch (java.lang.InstantiationException)
                {
                }
            }
            Engine.door.renumProviders();
        }
Esempio n. 5
0
        /**
         * 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 {
            java.lang.ClassLoader callerClassLoader = java.lang.Runtime.getRuntime().getClass().getClassLoader(); // Basties note: sometime do the same as VM.callerClassLoader();

            lock (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
                 */
                java.util.Iterator <Driver> theIterator = theDrivers.iterator();
                while (theIterator.hasNext())
                {
                    Driver theDriver = theIterator.next();
                    if (theDriver.acceptsURL(url) &&
                        DriverManager.isClassFromClassLoader(theDriver,
                                                             callerClassLoader))
                    {
                        return(theDriver);
                    }
                }
            }
            // If no drivers understand the URL, throw an SQLException
            // sql.6=No suitable driver
            // SQLState: 08 - connection exception
            // 001 - SQL-client unable to establish SQL-connection
            throw new SQLException("No suitable driver", "08001"); //$NON-NLS-1$ //$NON-NLS-2$
        }
Esempio n. 6
0
 internal static java.lang.ClassLoader getContextClassLoader()
 {
     java.lang.ClassLoader cl = null;
     try {
         cl = java.lang.Thread.currentThread().getContextClassLoader();
     } catch (java.lang.SecurityException ex) {
     }
     return(cl);
 }
Esempio n. 7
0
        /*
         * Create an instance of a class using the specified ClassLoader and
         * optionally fall back to the current ClassLoader if not found.
         *
         * @param className Name of the concrete class corresponding to the
         * service provider
         *
         * @param cl ClassLoader to use to load the class, null means to use
         * the bootstrap ClassLoader
         *
         * @param doFallback true if the current ClassLoader should be tried as
         * a fallback if the class is not found using cl
         */
        internal static Object newInstance(String className, java.lang.ClassLoader cl,
                                           bool doFallback)
        //throws ConfigurationError
        {
            // assert(className != null);

            try {
                java.lang.Class providerClass;
                if (cl == null)
                {
                    // If classloader is null Use the bootstrap ClassLoader.
                    // Thus Class.forName(String) will use the current
                    // ClassLoader which will be the bootstrap ClassLoader.
                    providerClass = java.lang.Class.forName(className);
                }
                else
                {
                    try {
                        providerClass = cl.loadClass(className);
                    } catch (java.lang.ClassNotFoundException x) {
                        if (doFallback)
                        {
                            // Fall back to current classloader
                            cl = typeof(FactoryFinder).getClass().getClassLoader();
                            if (cl != null)
                            {
                                providerClass = cl.loadClass(className);
                            }
                            else
                            {
                                providerClass = java.lang.Class.forName(className);
                            }
                        }
                        else
                        {
                            throw x;
                        }
                    }
                }

                Object instance = providerClass.newInstance();
                if (debug)
                {
                    dPrint("created new instance of " + providerClass +
                           " using ClassLoader: " + cl);
                }
                return(instance);
            } catch (java.lang.ClassNotFoundException x) {
                throw new ConfigurationError(
                          "Provider " + className + " not found", x);
            } catch (java.lang.Exception x) {
                throw new ConfigurationError(
                          "Provider " + className + " could not be instantiated: " + x,
                          x);
            }
        }
Esempio n. 8
0
 internal static java.io.InputStream getResourceAsStream(java.lang.ClassLoader cl,
                                                         String name)
 {
     java.io.InputStream ris;
     if (cl == null)
     {
         ris = java.lang.ClassLoader.getSystemResourceAsStream(name);
     }
     else
     {
         ris = cl.getResourceAsStream(name);
     }
     return(ris);
 }
Esempio n. 9
0
 /**
  * Creates a new instance of the specified class name
  *
  * Package private so this code is not exposed at the API level.
  */
 internal static Object newInstance(java.lang.ClassLoader classLoader, String className)
 //throws ClassNotFoundException, IllegalAccessException,
 //    InstantiationException
 {
     java.lang.Class driverClass;
     if (classLoader == null)
     {
         driverClass = java.lang.Class.forName(className);
     }
     else
     {
         driverClass = classLoader.loadClass(className);
     }
     return(driverClass.newInstance());
 }
Esempio n. 10
0
        private static String readProviderFromFile()
        {//throws InternalError {
            java.lang.ClassLoader systemLoader = java.lang.ClassLoader.getSystemClassLoader();

            if (systemLoader != null)
            {
                java.io.InputStream inJ = systemLoader.getResourceAsStream("META-INF/services/java.util.prefs.PreferencesFactory"); //$NON-NLS-1$
                if (inJ != null)
                {
                    java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(inJ));
                    String line = null;
                    try
                    {
                        while ((line = reader.readLine()) != null)
                        {
                            int index = line.indexOf("#"); //$NON-NLS-1$
                            // Trim comments
                            if (index != -1)
                            {
                                line = line.substring(0, index);
                            }
                            String trimedName = line.trim();
                            if (!"".equals(trimedName))
                            { //$NON-NLS-1$
                                return(trimedName);
                            }
                        }
                    }
                    catch (java.io.IOException e)
                    {
                        // prefs.11=Load provider configuration file faild: {0}
                        throw new java.lang.InternalError("Load provider configuration file faild: " + e);   //$NON-NLS-1$
                    }
                    finally
                    {
                        try
                        {
                            reader.close();
                        }
                        catch (java.io.IOException e)
                        {
                            // ignore
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 11
0
 /*
  * @return New instance of a <code>DocumentBuilderFactory</code>
  *
  * @exception FactoryConfigurationError if the implementation is not
  * available or cannot be instantiated.
  */
 public static DocumentBuilderFactory newInstance(String factoryClassName,
                                                  java.lang.ClassLoader classLoader)
 {
     if (factoryClassName == null)
     {
         throw new FactoryConfigurationError("factoryClassName cannot be null.");
     }
     if (classLoader == null)
     {
         classLoader = SecuritySupport.getContextClassLoader();
     }
     try {
         return((DocumentBuilderFactory)FactoryFinder.newInstance(factoryClassName, classLoader, false));
     } catch (FactoryFinder.ConfigurationError e) {
         throw new FactoryConfigurationError(e.getException(), e.getMessage());
     }
 }
Esempio n. 12
0
        /**
         * Obtain a new instance of a <code>DOMImplementationRegistry</code>.
         *
         *
         * The <code>DOMImplementationRegistry</code> is initialized by the
         * application or the implementation, depending on the context, by
         * first checking the value of the Java system property
         * <code>org.w3c.dom.DOMImplementationSourceList</code> and
         * the the service provider whose contents are at
         * "<code>META_INF/services/org.w3c.dom.DOMImplementationSourceList</code>"
         * The value of this property is a white-space separated list of
         * names of availables classes implementing the
         * <code>DOMImplementationSource</code> interface. Each class listed
         * in the class name list is instantiated and any exceptions
         * encountered are thrown to the application.
         *
         * @return an initialized instance of DOMImplementationRegistry
         * @throws ClassNotFoundException
         *     If any specified class can not be found
         * @throws InstantiationException
         *     If any specified class is an interface or abstract class
         * @throws IllegalAccessException
         *     If the default constructor of a specified class is not accessible
         * @throws ClassCastException
         *     If any specified class does not implement
         * <code>DOMImplementationSource</code>
         */
        public static DOMImplementationRegistry newInstance()
        {
            //throws     ClassNotFoundException,     InstantiationException,     IllegalAccessException,     ClassCastException {
            java.util.Vector <Object> sources = new java.util.Vector <Object>();

            java.lang.ClassLoader classLoader = getClassLoader();
            // fetch system property:
            String p = getSystemProperty(PROPERTY);

            //
            // if property is not specified then use contents of
            // META_INF/org.w3c.dom.DOMImplementationSourceList from classpath
            if (p == null)
            {
                p = getServiceValue(classLoader);
            }
            if (p == null)
            {
                //
                // DOM Implementations can modify here to add *additional* fallback
                // mechanisms to access a list of default DOMImplementationSources.
            }
            if (p != null)
            {
                java.util.StringTokenizer st = new java.util.StringTokenizer(p);
                while (st.hasMoreTokens())
                {
                    String sourceName = st.nextToken();
                    // Use context class loader, falling back to Class.forName
                    // if and only if this fails...
                    java.lang.Class sourceClass = null;
                    if (classLoader != null)
                    {
                        sourceClass = classLoader.loadClass(sourceName);
                    }
                    else
                    {
                        sourceClass = java.lang.Class.forName(sourceName);
                    }
                    DOMImplementationSource source =
                        (DOMImplementationSource)sourceClass.newInstance();
                    sources.addElement(source);
                }
            }
            return(new DOMImplementationRegistry(sources));
        }
Esempio n. 13
0
        /**
         *
         * Gets a class loader.
         *
         * @return A class loader, possibly <code>null</code>
         */
        private static java.lang.ClassLoader getClassLoader()
        {
            try
            {
                java.lang.ClassLoader contextClassLoader = getContextClassLoader();

                if (contextClassLoader != null)
                {
                    return(contextClassLoader);
                }
            }
            catch (Exception)
            {
                // Assume that the DOM application is in a JRE 1.1, use the
                // current ClassLoader
                return(typeof(DOMImplementationRegistry).getClass().getClassLoader());
            }
            return(typeof(DOMImplementationRegistry).getClass().getClassLoader());
        }
Esempio n. 14
0
        /**
         * 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;
            }
            java.lang.ClassLoader callerClassLoader = java.lang.Runtime.getRuntime().getClass().getClassLoader();// Basties note: sometime do the same as VM.callerClassLoader();

            if (!DriverManager.isClassFromClassLoader(driver, callerClassLoader))
            {
                // sql.1=DriverManager: calling class not authorized to deregister
                // JDBC driver
                throw new java.lang.SecurityException("DriverManager: calling class not authorized to deregister JDBC driver"); //$NON-NLS-1$
            } // end if
            lock (theDrivers)
            {
                theDrivers.remove(driver);
            }
        }
Esempio n. 15
0
        private const String DEFAULT_FACTORY_NAME_UNIX = "java.util.prefs.FilePreferencesFactoryImpl"; //$NON-NLS-1$

        static Preferences()
        {
            String factoryClassName = java.lang.SystemJ.getProperty("java.util.prefs.PreferencesFactory"); //$NON-NLS-1$

            if (factoryClassName == null)
            {
                factoryClassName = readProviderFromFile();
            }

            // set default provider
            if (factoryClassName == null)
            {
                String osName = java.lang.SystemJ.getProperty("os.name");

                // only comparing ASCII, so assume english locale
                osName = (osName == null ? null : osName.toLowerCase(Locale.ENGLISH));

                if (osName != null && osName.startsWith("windows"))
                { //$NON-NLS-1$
                    factoryClassName = DEFAULT_FACTORY_NAME_WIN;
                }
                else
                {
                    factoryClassName = DEFAULT_FACTORY_NAME_UNIX;
                }
            }
            try
            {
                java.lang.ClassLoader loader = java.lang.Thread.currentThread().getContextClassLoader();
                if (loader == null)
                {
                    loader = java.lang.ClassLoader.getSystemClassLoader();
                }
                java.lang.Class factoryClass = loader.loadClass(factoryClassName);
                factory = (PreferencesFactory)factoryClass.newInstance();
            }
            catch (Exception e)
            {
                // prefs.10=Cannot initiate PreferencesFactory: {0}. Caused by {1}
                throw new java.lang.InternalError("Cannot initiate PreferencesFactory: " + factoryClassName + ". Caused by " + e);   //$NON-NLS-1$
            }
        }
Esempio n. 16
0
 private static XMLReader loadClass(java.lang.ClassLoader loader, String className)
 //throws SAXException
 {
     try {
         return((XMLReader)NewInstance.newInstance(loader, className));
     } catch (java.lang.ClassNotFoundException e1) {
         throw new SAXException("SAX2 driver class " + className +
                                " not found", e1);
     } catch (java.lang.IllegalAccessException e2) {
         throw new SAXException("SAX2 driver class " + className +
                                " found but cannot be loaded", e2);
     } catch (java.lang.InstantiationException e3) {
         throw new SAXException("SAX2 driver class " + className +
                                " loaded but cannot be instantiated (no empty public constructor?)",
                                e3);
     } catch (java.lang.ClassCastException e4) {
         throw new SAXException("SAX2 driver class " + className +
                                " does not implement XMLReader", e4);
     }
 }
Esempio n. 17
0
            public LookupProvidersIterator(java.lang.Class providerClass, java.lang.ClassLoader loader)
            {
                this.loader = loader;

                java.util.Enumeration <java.net.URL> e = null;
                try
                {
                    e = loader.getResources("META-INF/services/" + providerClass.getName()); //$NON-NLS-1$
                    while (e.hasMoreElements())
                    {
                        java.util.Set <String> names = parse((java.net.URL)e.nextElement());
                        providerNames.addAll(names);
                    }
                }
                catch (java.io.IOException e1)
                {
                    // Ignored
                }

                it = providerNames.iterator();
            }
Esempio n. 18
0
        /**
         * This method attempts to return the first line of the resource
         * META_INF/services/org.w3c.dom.DOMImplementationSourceList
         * from the provided ClassLoader.
         *
         * @param classLoader classLoader, may not be <code>null</code>.
         * @return first line of resource, or <code>null</code>
         */
        private static String getServiceValue(java.lang.ClassLoader classLoader)
        {
            String serviceId = "META-INF/services/" + PROPERTY;

            // try to find services in CLASSPATH
            try
            {
                java.io.InputStream input = getResourceAsStream(classLoader, serviceId);

                if (input != null)
                {
                    java.io.BufferedReader rd;
                    try
                    {
                        rd =
                            new java.io.BufferedReader(new java.io.InputStreamReader(input, "UTF-8"),
                                                       DEFAULT_LINE_LENGTH);
                    }
                    catch (java.io.UnsupportedEncodingException)
                    {
                        rd =
                            new java.io.BufferedReader(new java.io.InputStreamReader(input),
                                                       DEFAULT_LINE_LENGTH);
                    }
                    String serviceValue = rd.readLine();
                    rd.close();
                    if (serviceValue != null && serviceValue.length() > 0)
                    {
                        return(serviceValue);
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(null);
        }
Esempio n. 19
0
        /*
         * Attempt to create an XMLReader from system defaults.
         * In environments which can support it, the name of the XMLReader
         * class is determined by trying each these options in order, and
         * using the first one which succeeds:<p/> <ul>
         *
         * <li>If the system property <code>org.xml.sax.driver</code>
         * has a value, that is used as an XMLReader class name. </li>
         *
         * <li>The JAR "Services API" is used to look for a class name
         * in the <em>META-INF/services/org.xml.sax.driver</em> file in
         * jarfiles available to the runtime.</li>
         *
         * <li> SAX parser distributions are strongly encouraged to provide
         * a default XMLReader class name that will take effect only when
         * previous options (on this list) are not successful.</li>
         *
         * <li>Finally, if {@link ParserFactory#makeParser()} can
         * return a system default SAX1 parser, that parser is wrapped in
         * a {@link ParserAdapter}.  (This is a migration aid for SAX1
         * environments, where the <code>org.xml.sax.parser</code> system
         * property will often be usable.) </li>
         *
         * </ul>
         *
         * <p> In environments such as small embedded systems, which can not
         * support that flexibility, other mechanisms to determine the default
         * may be used. </p>
         *
         * <p>Note that many Java environments allow system properties to be
         * initialized on a command line.  This means that <em>in most cases</em>
         * setting a good value for that property ensures that calls to this
         * method will succeed, except when security policies intervene.
         * This will also maximize application portability to older SAX
         * environments, with less robust implementations of this method.
         * </p>
         *
         * @return A new XMLReader.
         * @exception org.xml.sax.SAXException If no default XMLReader class
         *            can be identified and instantiated.
         * @see #createXMLReader(java.lang.String)
         */
        public static XMLReader createXMLReader()
        //throws SAXException
        {
            String className = null;

            java.lang.ClassLoader loader = NewInstance.getClassLoader();

            // 1. try the JVM-instance-wide system property
            try { className = java.lang.SystemJ.getProperty(property); }
            catch (java.lang.RuntimeException e) { /* normally fails for applets */ }

            // 2. if that fails, try META-INF/services/
            if (className == null)
            {
                try {
                    String service = "META-INF/services/" + property;
                    java.io.InputStream    input;
                    java.io.BufferedReader reader;

                    if (loader == null)
                    {
                        input = java.lang.ClassLoader.getSystemResourceAsStream(service);
                    }
                    else
                    {
                        input = loader.getResourceAsStream(service);
                    }

                    if (input != null)
                    {
                        reader = new java.io.BufferedReader(
                            new java.io.InputStreamReader(input, "UTF8"));
                        className = reader.readLine();
                        input.close();
                    }
                } catch (Exception e) {
                }
            }

            // 3. Distro-specific fallback
            if (className == null)
            {
// BEGIN DISTRIBUTION-SPECIFIC

                // EXAMPLE:
                // className = "com.example.sax.XmlReader";
                // or a $JAVA_HOME/jre/lib/*properties setting...

                //Take a look in Java 7 shows: className = "com.sun.org.apache.xerces.internal.parsers.SAXParser";

// END DISTRIBUTION-SPECIFIC
            }

            // do we know the XMLReader implementation class yet?
            if (className != null)
            {
                return(loadClass(loader, className));
            }

            // 4. panic -- adapt any SAX1 parser
            try {
                return(new ParserAdapter(ParserFactory.makeParser()));
            } catch (java.lang.Exception e) {
                throw new SAXException("Can't create default XMLReader; "
                                       + "is system property org.xml.sax.driver set?");
            }
        }
Esempio n. 20
0
            /*
             * Creates and returns a new instance of the implementation described by
             * this {@code Service}.
             *
             * @param constructorParameter
             *            the parameter that is used by the constructor, or {@code
             *            null} if the implementation does not declare a constructor
             *            parameter.
             * @return a new instance of the implementation described by this
             *         {@code Service}.
             * @throws NoSuchAlgorithmException
             *             if the instance could not be constructed.
             * @throws InvalidParameterException
             *             if the implementation does not support the specified
             *             {@code constructorParameter}.
             */
            public Object newInstance(Object constructorParameter)
            {//throws NoSuchAlgorithmException {
                if (implementation == null || !className.equals(lastClassName))
                {
                    java.lang.ClassLoader cl = provider.getClass()
                                               .getClassLoader();
                    if (cl == null)
                    {
                        cl = java.lang.ClassLoader.getSystemClassLoader();
                    }
                    try
                    {
                        implementation = java.lang.Class.forName(className,
                                                                 true, cl);
                    }
                    catch (Exception e)
                    {
                        return(new NoSuchAlgorithmException(
                                   type + " " + algorithm + " implementation not found: " + e));
                    }
                    lastClassName = className;
                }

                java.lang.Class[] parameterTypes = new java.lang.Class[1];

                if (constructorParameter != null &&
                    !supportsParameter(constructorParameter))
                {
                    throw new InvalidParameterException(type + ": service cannot use the parameter"); //$NON-NLS-1$
                }
                Object[] initargs = { constructorParameter };

                try
                {
                    if (type.equalsIgnoreCase("CertStore"))
                    {                                                                           //$NON-NLS-1$
                        parameterTypes[0] = java.lang.Class
                                            .forName("java.security.cert.CertStoreParameters"); //$NON-NLS-1$
                    }
                    else if (type.equalsIgnoreCase("Configuration"))
                    {
                        parameterTypes[0] = java.lang.Class
                                            .forName("javax.security.auth.login.Configuration$Parameters");
                    }

                    if (parameterTypes[0] == null)
                    {
                        if (constructorParameter == null)
                        {
                            return(implementation.newInstance());
                        }
                        else
                        {
                            parameterTypes[0] = constructorParameter.getClass();
                        }
                    }
                    return(implementation.getConstructor(parameterTypes)
                           .newInstance(initargs));
                }
                catch (java.lang.Exception e)
                {
                    throw new NoSuchAlgorithmException(type + " " + algorithm + " implementation not found: ", e);
                }
            }
Esempio n. 21
0
 public static java.util.Iterator <T> lookupProviders <T>(java.lang.Class providerClass, java.lang.ClassLoader loader)
 {
     return(new LookupProvidersIterator <T>(providerClass, loader));
 }
Esempio n. 22
0
 public URLClassLoader(java.net.URL[] newURLs, java.lang.ClassLoader parent)
 {
     this.urls = newURLs;
 }
Esempio n. 23
0
        /*
         * Finds the implementation Class object in the specified order.  Main
         * entry point.
         * @return Class object of factory, never null
         *
         * @param factoryId             Name of the factory to find, same as
         *                              a property name
         * @param fallbackClassName     Implementation class name, if nothing else
         *                              is found.  Use null to mean no fallback.
         *
         * Package private so this code can be shared.
         */
        internal static Object find(String factoryId, String fallbackClassName)
        // throws ConfigurationError
        {
            // Figure out which ClassLoader to use for loading the provider
            // class.  If there is a Context ClassLoader then use it.

            java.lang.ClassLoader classLoader = SecuritySupport.getContextClassLoader();

            if (classLoader == null)
            {
                // if we have no Context ClassLoader
                // so use the current ClassLoader
                classLoader = typeof(FactoryFinder).getClass().getClassLoader();
            }

            if (debug)
            {
                dPrint("find factoryId =" + factoryId);
            }

            // Use the system property first
            try {
                String systemProp = SecuritySupport.getSystemProperty(factoryId);
                if (systemProp != null && systemProp.length() > 0)
                {
                    if (debug)
                    {
                        dPrint("found system property, value=" + systemProp);
                    }
                    return(newInstance(systemProp, classLoader, true));
                }
            } catch (java.lang.SecurityException se) {
                //if first option fails due to any reason we should try next option in the
                //look up algorithm.
            }

            // try to read from $java.home/lib/jaxp.properties
            try {
                String javah      = SecuritySupport.getSystemProperty("java.home");
                String configFile = javah + java.io.File.separator +
                                    "lib" + java.io.File.separator + "jaxp.properties";
                String factoryClassName = null;
                if (firstTime)
                {
                    lock (cacheProps) {
                        if (firstTime)
                        {
                            java.io.File f = new java.io.File(configFile);
                            firstTime = false;
                            if (SecuritySupport.doesFileExist(f))
                            {
                                if (debug)
                                {
                                    dPrint("Read properties file " + f);
                                }
                                //cacheProps.load( new FileInputStream(f));
                                cacheProps.load(SecuritySupport.getFileInputStream(f));
                            }
                        }
                    }
                }
                factoryClassName = cacheProps.getProperty(factoryId);

                if (factoryClassName != null)
                {
                    if (debug)
                    {
                        dPrint("found in $java.home/jaxp.properties, value=" + factoryClassName);
                    }
                    return(newInstance(factoryClassName, classLoader, true));
                }
            } catch (java.lang.Exception ex) {
                if (debug)
                {
                    ex.printStackTrace();
                }
            }

            // Try Jar Service Provider Mechanism
            Object provider = findJarServiceProvider(factoryId);

            if (provider != null)
            {
                return(provider);
            }
            if (fallbackClassName == null)
            {
                throw new ConfigurationError(
                          "Provider for " + factoryId + " cannot be found", null);
            }

            if (debug)
            {
                dPrint("loaded from fallback value: " + fallbackClassName);
            }
            return(newInstance(fallbackClassName, classLoader, true));
        }
Esempio n. 24
0
 protected internal SecureClassLoader(java.lang.ClassLoader parent) : base(parent)
 {
 }
Esempio n. 25
0
 /**
  * Create a new PrivilegedSetTccl using the given classloader
  * @param cl ClassLoader to use
  */
 internal PrivilegedSetTccl(java.lang.ClassLoader cl)
 {
     this.cl = cl;
 }
Esempio n. 26
0
 public static ResourceBundle getBundle(String name, Locale locale, java.lang.ClassLoader classLoader)
 {
     throw new java.lang.UnsupportedOperationException("Not yet implemented");
 }
Esempio n. 27
0
        /*
         * Try to find provider using Jar Service Provider Mechanism
         *
         * @return instance of provider class if found or null
         */
        private static Object findJarServiceProvider(String factoryId)
        //throws ConfigurationError
        {
            String serviceId = "META-INF/services/" + factoryId;

            java.io.InputStream isJ = null;

            // First try the Context ClassLoader
            java.lang.ClassLoader cl = SecuritySupport.getContextClassLoader();
            if (cl != null)
            {
                isJ = SecuritySupport.getResourceAsStream(cl, serviceId);

                // If no provider found then try the current ClassLoader
                if (isJ == null)
                {
                    cl  = typeof(FactoryFinder).getClass().getClassLoader();
                    isJ = SecuritySupport.getResourceAsStream(cl, serviceId);
                }
            }
            else
            {
                // No Context ClassLoader, try the current
                // ClassLoader
                cl  = typeof(FactoryFinder).getClass().getClassLoader();
                isJ = SecuritySupport.getResourceAsStream(cl, serviceId);
            }

            if (isJ == null)
            {
                // No provider found
                return(null);
            }

            if (debug)
            {
                dPrint("found jar resource=" + serviceId +
                       " using ClassLoader: " + cl);
            }

            // Read the service provider name in UTF-8 as specified in
            // the jar spec.  Unfortunately this fails in Microsoft
            // VJ++, which does not implement the UTF-8
            // encoding. Theoretically, we should simply let it fail in
            // that case, since the JVM is obviously broken if it
            // doesn't support such a basic standard.  But since there
            // are still some users attempting to use VJ++ for
            // development, we have dropped in a fallback which makes a
            // second attempt using the platform's default encoding. In
            // VJ++ this is apparently ASCII, which is a subset of
            // UTF-8... and since the strings we'll be reading here are
            // also primarily limited to the 7-bit ASCII range (at
            // least, in English versions), this should work well
            // enough to keep us on the air until we're ready to
            // officially decommit from VJ++. [Edited comment from
            // jkesselm]
            java.io.BufferedReader rd;
            try {
                rd = new java.io.BufferedReader(new java.io.InputStreamReader(isJ, "UTF-8"), DEFAULT_LINE_LENGTH);
            } catch (java.io.UnsupportedEncodingException e) {
                rd = new java.io.BufferedReader(new java.io.InputStreamReader(isJ), DEFAULT_LINE_LENGTH);
            }

            String factoryClassName = null;

            try {
                // XXX Does not handle all possible input as specified by the
                // Jar Service Provider specification
                factoryClassName = rd.readLine();
            } catch (java.io.IOException x) {
                // No provider found
                return(null);
            } finally {
                try {
                    // try to close the reader.
                    rd.close();
                }
                // Ignore the exception.
                catch (java.io.IOException exc) {
                }
            }

            if (factoryClassName != null &&
                !"".equals(factoryClassName))
            {
                if (debug)
                {
                    dPrint("found in resource, value="
                           + factoryClassName);
                }

                // Note: here we do not want to fall back to the current
                // ClassLoader because we want to avoid the case where the
                // resource file was found using one ClassLoader and the
                // provider class was instantiated using a different one.
                return(newInstance(factoryClassName, cl, false));
            }

            // No provider found
            return(null);
        }