Beispiel #1
0
 /**
  * Register an implementation.
  *
  * @param s The source to be registered, may not be <code>null</code>
  */
 public void addSource(DOMImplementationSource s)
 {
     if (s == null)
     {
         throw new java.lang.NullPointerException();
     }
     if (!sources.contains(s))
     {
         sources.addElement(s);
     }
 }
Beispiel #2
0
        /**
         * Return the first implementation that has the desired
         * features, or <code>null</code> if none is found.
         *
         * @param features
         *            A string that specifies which features are required. This is
         *            a space separated list in which each feature is specified by
         *            its name optionally followed by a space and a version number.
         *            This is something like: "XML 1.0 Traversal +Events 2.0"
         * @return An implementation that has the desired features,
         *         or <code>null</code> if none found.
         */
        public DOMImplementation getDOMImplementation(String features)
        {
            int size = sources.size();

            //String name = null; Basties Note: unused...
            for (int i = 0; i < size; i++)
            {
                DOMImplementationSource source =
                    (DOMImplementationSource)sources.elementAt(i);
                DOMImplementation impl = source.getDOMImplementation(features);
                if (impl != null)
                {
                    return(impl);
                }
            }
            return(null);
        }
Beispiel #3
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));
        }
Beispiel #4
0
        /**
         * Return a list of implementations that support the
         * desired features.
         *
         * @param features
         *            A string that specifies which features are required. This is
         *            a space separated list in which each feature is specified by
         *            its name optionally followed by a space and a version number.
         *            This is something like: "XML 1.0 Traversal +Events 2.0"
         * @return A list of DOMImplementations that support the desired features.
         */
        public DOMImplementationList getDOMImplementationList(String features)
        {
            java.util.Vector <Object> implementations = new java.util.Vector <Object>();
            int size = sources.size();

            for (int i = 0; i < size; i++)
            {
                DOMImplementationSource source =
                    (DOMImplementationSource)sources.elementAt(i);
                DOMImplementationList impls =
                    source.getDOMImplementationList(features);
                for (int j = 0; j < impls.getLength(); j++)
                {
                    DOMImplementation impl = impls.item(j);
                    implementations.addElement(impl);
                }
            }
            return(new IAC_DOMImplementationList(implementations));
        }