< prev index next >

src/java.xml/share/classes/org/w3c/dom/bootstrap/DOMImplementationRegistry.java

Print this page




 196         }
 197         return new DOMImplementationRegistry(sources);
 198     }
 199 
 200     /**
 201      * Return the first implementation that has the desired
 202      * features, or <code>null</code> if none is found.
 203      *
 204      * @param features
 205      *            A string that specifies which features are required. This is
 206      *            a space separated list in which each feature is specified by
 207      *            its name optionally followed by a space and a version number.
 208      *            This is something like: "XML 1.0 Traversal +Events 2.0"
 209      * @return An implementation that has the desired features,
 210      *         or <code>null</code> if none found.
 211      */
 212     public DOMImplementation getDOMImplementation(final String features) {
 213         int size = sources.size();
 214         String name = null;
 215         for (int i = 0; i < size; i++) {
 216             DOMImplementationSource source =
 217                 (DOMImplementationSource) sources.get(i);
 218             DOMImplementation impl = source.getDOMImplementation(features);
 219             if (impl != null) {
 220                 return impl;
 221             }
 222         }
 223         return null;
 224     }
 225 
 226     /**
 227      * Return a list of implementations that support the
 228      * desired features.
 229      *
 230      * @param features
 231      *            A string that specifies which features are required. This is
 232      *            a space separated list in which each feature is specified by
 233      *            its name optionally followed by a space and a version number.
 234      *            This is something like: "XML 1.0 Traversal +Events 2.0"
 235      * @return A list of DOMImplementations that support the desired features.
 236      */
 237     public DOMImplementationList getDOMImplementationList(final String features) {
 238         final List<DOMImplementation> implementations = new ArrayList<>();
 239         int size = sources.size();
 240         for (int i = 0; i < size; i++) {
 241             DOMImplementationSource source =
 242                 (DOMImplementationSource) sources.get(i);
 243             DOMImplementationList impls =
 244                 source.getDOMImplementationList(features);
 245             for (int j = 0; j < impls.getLength(); j++) {
 246                 DOMImplementation impl = impls.item(j);
 247                 implementations.add(impl);
 248             }
 249         }
 250         return new DOMImplementationList() {
 251                 public DOMImplementation item(final int index) {
 252                     if (index >= 0 && index < implementations.size()) {
 253                         try {
 254                             return (DOMImplementation)
 255                                 implementations.get(index);
 256                         } catch (IndexOutOfBoundsException e) {
 257                             return null;
 258                         }
 259                     }
 260                     return null;
 261                 }
 262 
 263                 public int getLength() {
 264                     return implementations.size();
 265                 }
 266             };
 267     }
 268 
 269     /**
 270      * Register an implementation.
 271      *
 272      * @param s The source to be registered, may not be <code>null</code>
 273      */
 274     public void addSource(final DOMImplementationSource s) {
 275         if (s == null) {




 196         }
 197         return new DOMImplementationRegistry(sources);
 198     }
 199 
 200     /**
 201      * Return the first implementation that has the desired
 202      * features, or <code>null</code> if none is found.
 203      *
 204      * @param features
 205      *            A string that specifies which features are required. This is
 206      *            a space separated list in which each feature is specified by
 207      *            its name optionally followed by a space and a version number.
 208      *            This is something like: "XML 1.0 Traversal +Events 2.0"
 209      * @return An implementation that has the desired features,
 210      *         or <code>null</code> if none found.
 211      */
 212     public DOMImplementation getDOMImplementation(final String features) {
 213         int size = sources.size();
 214         String name = null;
 215         for (int i = 0; i < size; i++) {
 216             DOMImplementationSource source = sources.get(i);

 217             DOMImplementation impl = source.getDOMImplementation(features);
 218             if (impl != null) {
 219                 return impl;
 220             }
 221         }
 222         return null;
 223     }
 224 
 225     /**
 226      * Return a list of implementations that support the
 227      * desired features.
 228      *
 229      * @param features
 230      *            A string that specifies which features are required. This is
 231      *            a space separated list in which each feature is specified by
 232      *            its name optionally followed by a space and a version number.
 233      *            This is something like: "XML 1.0 Traversal +Events 2.0"
 234      * @return A list of DOMImplementations that support the desired features.
 235      */
 236     public DOMImplementationList getDOMImplementationList(final String features) {
 237         final List<DOMImplementation> implementations = new ArrayList<>();
 238         int size = sources.size();
 239         for (int i = 0; i < size; i++) {
 240             DOMImplementationSource source = sources.get(i);

 241             DOMImplementationList impls =
 242                 source.getDOMImplementationList(features);
 243             for (int j = 0; j < impls.getLength(); j++) {
 244                 DOMImplementation impl = impls.item(j);
 245                 implementations.add(impl);
 246             }
 247         }
 248         return new DOMImplementationList() {
 249                 public DOMImplementation item(final int index) {
 250                     if (index >= 0 && index < implementations.size()) {
 251                         try {
 252                             return implementations.get(index);

 253                         } catch (IndexOutOfBoundsException e) {
 254                             return null;
 255                         }
 256                     }
 257                     return null;
 258                 }
 259 
 260                 public int getLength() {
 261                     return implementations.size();
 262                 }
 263             };
 264     }
 265 
 266     /**
 267      * Register an implementation.
 268      *
 269      * @param s The source to be registered, may not be <code>null</code>
 270      */
 271     public void addSource(final DOMImplementationSource s) {
 272         if (s == null) {


< prev index next >