Example #1
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));
        }
Example #2
0
        /**
         * Sets the receiver's stream handler to one which is appropriate for its
         * protocol. Throws a MalformedURLException if no reasonable handler is
         * available.
         * <p/>
         * Note that this will overwrite any existing stream handler with the new
         * one. Senders must check if the strmHandler is null before calling the
         * method if they do not want this behavior (a speed optimization).
         */
        void setupStreamHandler()
        {
            String className = null;

            // Check for a cached (previously looked up) handler for
            // the requested protocol.
            strmHandler = streamHandlers.get(protocol);
            if (strmHandler != null)
            {
                return;
            }

            // If there is a stream handler factory, then attempt to
            // use it to create the handler.
            if (streamHandlerFactory != null)
            {
                strmHandler = streamHandlerFactory.createURLStreamHandler(protocol);
                if (strmHandler != null)
                {
                    streamHandlers.put(protocol, strmHandler);
                    return;
                }
            }

            // Check if there is a list of packages which can provide handlers.
            // If so, then walk this list looking for an applicable one.
            String packageList = java.security.AccessController
                    .doPrivileged(new PriviAction<String>(
                            "java.protocol.handler.pkgs")); //$NON-NLS-1$
            if (packageList != null)
            {
                java.util.StringTokenizer st = new java.util.StringTokenizer(packageList, "|"); //$NON-NLS-1$
                while (st.hasMoreTokens())
                {
                    className = st.nextToken() + "." + protocol + ".Handler"; //$NON-NLS-1$ //$NON-NLS-2$

                    try
                    {
                        strmHandler = (URLStreamHandler)java.lang.Class.forName(className,
                                true, java.lang.ClassLoader.getSystemClassLoader())
                                .newInstance();
                        if (strmHandler != null)
                        {
                            streamHandlers.put(protocol, strmHandler);
                        }
                        return;
                    }
                    catch (java.lang.IllegalAccessException e)
                    {
                    }
                    catch (java.lang.InstantiationException e)
                    {
                    }
                    catch (java.lang.ClassNotFoundException e)
                    {
                    }
                }
            }

            // No one else has provided a handler, so try our internal one.

            className = "org.apache.harmony.luni.internal.net.www.protocol." + protocol //$NON-NLS-1$
                    + ".Handler"; //$NON-NLS-1$
            try
            {
                strmHandler = (URLStreamHandler)java.lang.Class.forName(className)
                        .newInstance();
            }
            catch (java.lang.IllegalAccessException e)
            {
            }
            catch (java.lang.InstantiationException e)
            {
            }
            catch (java.lang.ClassNotFoundException e)
            {
            }
            if (strmHandler != null)
            {
                streamHandlers.put(protocol, strmHandler);
            }
        }
Example #3
0
        /*
         * Sets the receiver's stream handler to one which is appropriate for its
         * protocol. Throws a MalformedURLException if no reasonable handler is
         * available.
         * <p/>
         * Note that this will overwrite any existing stream handler with the new
         * one. Senders must check if the strmHandler is null before calling the
         * method if they do not want this behavior (a speed optimization).
         */
        void setupStreamHandler()
        {
            String className = null;

            // Check for a cached (previously looked up) handler for
            // the requested protocol.
            strmHandler = streamHandlers.get(protocol);
            if (strmHandler != null)
            {
                return;
            }

            // If there is a stream handler factory, then attempt to
            // use it to create the handler.
            if (streamHandlerFactory != null)
            {
                strmHandler = streamHandlerFactory.createURLStreamHandler(protocol);
                if (strmHandler != null)
                {
                    streamHandlers.put(protocol, strmHandler);
                    return;
                }
            }

            // Check if there is a list of packages which can provide handlers.
            // If so, then walk this list looking for an applicable one.
            String packageList = java.security.AccessController
                                 .doPrivileged(new PriviAction <String>(
                                                   "java.protocol.handler.pkgs")); //$NON-NLS-1$

            if (packageList != null)
            {
                java.util.StringTokenizer st = new java.util.StringTokenizer(packageList, "|"); //$NON-NLS-1$
                while (st.hasMoreTokens())
                {
                    className = st.nextToken() + "." + protocol + ".Handler"; //$NON-NLS-1$ //$NON-NLS-2$

                    try
                    {
                        strmHandler = (URLStreamHandler)java.lang.Class.forName(className,
                                                                                true, java.lang.ClassLoader.getSystemClassLoader())
                                      .newInstance();
                        if (strmHandler != null)
                        {
                            streamHandlers.put(protocol, strmHandler);
                        }
                        return;
                    }
                    catch (java.lang.IllegalAccessException e)
                    {
                    }
                    catch (java.lang.InstantiationException e)
                    {
                    }
                    catch (java.lang.ClassNotFoundException e)
                    {
                    }
                }
            }

            // No one else has provided a handler, so try our internal one.

            className = "org.apache.harmony.luni.internal.net.www.protocol." + protocol //$NON-NLS-1$
                        + ".Handler";                                                   //$NON-NLS-1$
            try
            {
                strmHandler = (URLStreamHandler)java.lang.Class.forName(className)
                              .newInstance();
            }
            catch (java.lang.IllegalAccessException e)
            {
            }
            catch (java.lang.InstantiationException e)
            {
            }
            catch (java.lang.ClassNotFoundException e)
            {
            }
            if (strmHandler != null)
            {
                streamHandlers.put(protocol, strmHandler);
            }
        }