KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > validate > SchemaReaderLoader


1 package com.thaiopensource.validate;
2
3 import com.thaiopensource.validate.SchemaReader;
4 import com.thaiopensource.util.Service;
5
6 import java.util.Enumeration;
7 /**
8  * A SchemaReaderFactory that automatically discovers SchemaReader implementations.
9  * For a SchemeaReader implementation to be discoverable by this class, it must have
10  * a factory class with a no-argument constructor implementing SchemaReaderFactory,
11  * and the fully-qualified name of this factory class must be listed in the file
12  * <code>META-INF/services/com.thaiopensource.validate.SchemaReaderFactory</code>.
13  */

14 public class SchemaReaderLoader implements SchemaReaderFactory {
15   private final Service service = new Service(SchemaReaderFactory.class);
16   public SchemaReader createSchemaReader(String namespaceUri) {
17     for (Enumeration enum = service.getProviders(); enum.hasMoreElements();) {
18       SchemaReaderFactory srf = (SchemaReaderFactory)enum.nextElement();
19       SchemaReader sr = srf.createSchemaReader(namespaceUri);
20       if (sr != null)
21         return sr;
22     }
23     return null;
24   }
25
26   public Option getOption(String uri) {
27     for (Enumeration enum = service.getProviders(); enum.hasMoreElements();) {
28       SchemaReaderFactory srf = (SchemaReaderFactory)enum.nextElement();
29       Option option = srf.getOption(uri);
30       if (option != null)
31         return option;
32     }
33     return null;
34   }
35 }
36
Popular Tags