1 package com.thaiopensource.relaxng; 2 3 import com.thaiopensource.validate.auto.AutoSchemaReader; 4 import com.thaiopensource.util.PropertyMapBuilder; 5 import com.thaiopensource.validate.Flag; 6 import com.thaiopensource.validate.IncorrectSchemaException; 7 import com.thaiopensource.validate.SchemaReader; 8 import com.thaiopensource.xml.sax.XMLReaderCreator; 9 import com.thaiopensource.validate.Schema; 10 import com.thaiopensource.validate.ValidateProperty; 11 import com.thaiopensource.validate.rng.CompactSchemaReader; 12 import com.thaiopensource.validate.rng.RngProperty; 13 import org.relaxng.datatype.DatatypeLibraryFactory; 14 import org.xml.sax.ErrorHandler ; 15 import org.xml.sax.InputSource ; 16 import org.xml.sax.SAXException ; 17 18 import java.io.IOException ; 19 20 32 public class SchemaFactory { 33 private PropertyMapBuilder properties = new PropertyMapBuilder(); 34 private boolean compactSyntax = false; 35 private SchemaReader autoSchemaLanguage = new AutoSchemaReader(); 36 37 40 public SchemaFactory() { 41 } 42 43 69 public Schema createSchema(InputSource in) throws IOException , SAXException , IncorrectSchemaException { 70 SchemaReader r = compactSyntax ? CompactSchemaReader.getInstance() : autoSchemaLanguage; 71 return r.createSchema(in, properties.toPropertyMap()); 72 } 73 74 84 public void setXMLReaderCreator(XMLReaderCreator xrc) { 85 properties.put(ValidateProperty.XML_READER_CREATOR, xrc); 86 } 87 88 98 public XMLReaderCreator getXMLReaderCreator() { 99 return (XMLReaderCreator)properties.get(ValidateProperty.XML_READER_CREATOR); 100 } 101 102 110 public void setErrorHandler(ErrorHandler eh) { 111 properties.put(ValidateProperty.ERROR_HANDLER, eh); 112 } 113 114 123 public ErrorHandler getErrorHandler() { 124 return (ErrorHandler )properties.get(ValidateProperty.ERROR_HANDLER); 125 } 126 127 135 public void setDatatypeLibraryFactory(DatatypeLibraryFactory dlf) { 136 properties.put(RngProperty.DATATYPE_LIBRARY_FACTORY, dlf); 137 } 138 139 148 public DatatypeLibraryFactory getDatatypeLibraryFactory() { 149 return (DatatypeLibraryFactory)properties.get(RngProperty.DATATYPE_LIBRARY_FACTORY); 150 } 151 152 162 public void setCheckIdIdref(boolean checkIdIdref) { 163 properties.put(RngProperty.CHECK_ID_IDREF, checkIdIdref ? Flag.PRESENT : null); 164 } 165 166 177 public boolean getCheckIdIdref() { 178 return properties.contains(RngProperty.CHECK_ID_IDREF); 179 } 180 181 188 public void setCompactSyntax(boolean compactSyntax) { 189 this.compactSyntax = compactSyntax; 190 } 191 192 199 public boolean getCompactSyntax() { 200 return compactSyntax; 201 } 202 203 public void setFeasible(boolean feasible) { 204 properties.put(RngProperty.FEASIBLE, feasible ? Flag.PRESENT : null); 205 } 206 207 public boolean getFeasible() { 208 return properties.contains(RngProperty.FEASIBLE); 209 } 210 } 211 | Popular Tags |