001 package com.thaiopensource.validate;
002
003 import java.util.Enumeration;
004
005 import javax.xml.transform.sax.SAXTransformerFactory;
006
007 import org.apache.xalan.processor.TransformerFactoryImpl;
008
009 import com.thaiopensource.util.Service;
010 /**
011 * A SchemaReaderFactory that automatically discovers SchemaReader implementations.
012 * For a SchemeaReader implementation to be discoverable by this class, it must have
013 * a factory class with a no-argument constructor implementing SchemaReaderFactory,
014 * and the fully-qualified name of this factory class must be listed in the file
015 * <code>META-INF/services/com.thaiopensource.validate.SchemaReaderFactory</code>.
016 */
017 public class SchemaReaderLoader implements SchemaReaderFactory {
018 private final Service service = new Service(SchemaReaderFactory.class);
019 public SchemaReader createSchemaReader(String namespaceUri) {
020 for (Enumeration en = service.getProviders(); en.hasMoreElements();) {
021 SchemaReaderFactory srf = (SchemaReaderFactory)en.nextElement();
022 SchemaReader sr = srf.createSchemaReader(namespaceUri);
023 if (sr != null)
024 return sr;
025 }
026 return null;
027 }
028
029 public Option getOption(String uri) {
030 for (Enumeration en = service.getProviders(); en.hasMoreElements();) {
031 SchemaReaderFactory srf = (SchemaReaderFactory)en.nextElement();
032 Option option = srf.getOption(uri);
033 if (option != null)
034 return option;
035 }
036 return null;
037 }
038
039 // XXX this does not do proper discovery
040 public SAXTransformerFactory createSAXTransformerFactory() {
041 return new TransformerFactoryImpl();
042 }
043 }