001 package com.thaiopensource.relaxng.impl;
002
003 import java.io.IOException;
004
005 import org.relaxng.datatype.DatatypeLibraryFactory;
006 import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
007 import org.xml.sax.ErrorHandler;
008 import org.xml.sax.SAXException;
009 import org.xml.sax.XMLReader;
010
011 import com.oxygenxml.validate.nvdl.NvdlProperty;
012 import com.thaiopensource.relaxng.parse.BuildException;
013 import com.thaiopensource.relaxng.parse.ParseReceiver;
014 import com.thaiopensource.util.PropertyMap;
015 import com.thaiopensource.validate.IncorrectSchemaException;
016 import com.thaiopensource.validate.Schema;
017 import com.thaiopensource.validate.ValidateProperty;
018 import com.thaiopensource.validate.auto.SchemaFuture;
019 import com.thaiopensource.validate.auto.SchemaReceiver;
020 import com.thaiopensource.validate.nrl.NrlProperty;
021 import com.thaiopensource.validate.rng.RngProperty;
022
023 public class SchemaReceiverImpl implements SchemaReceiver {
024 private final ParseReceiver parser;
025 private final PropertyMap properties;
026
027 public SchemaReceiverImpl(ParseReceiver parser, PropertyMap properties) {
028 this.parser = parser;
029 this.properties = properties;
030 }
031
032 public SchemaFuture installHandlers(XMLReader xr) throws SAXException {
033 final SchemaPatternBuilder pb = new SchemaPatternBuilder();
034 ErrorHandler eh = ValidateProperty.ERROR_HANDLER.get(properties);
035 DatatypeLibraryFactory dlf = RngProperty.DATATYPE_LIBRARY_FACTORY.get(properties);
036 if (dlf == null)
037 dlf = new DatatypeLibraryLoader();
038 final PatternFuture pf = SchemaBuilderImpl.installHandlers(parser, xr, eh, dlf, pb);
039 return new SchemaFuture() {
040 public Schema getSchema() throws IncorrectSchemaException, SAXException, IOException {
041 return SchemaReaderImpl.wrapPattern(pf.getPattern(
042 properties.contains(NrlProperty.ATTRIBUTES_SCHEMA) ||
043 properties.contains(NvdlProperty.ATTRIBUTES_SCHEMA)),
044 pb, properties);
045 }
046 public RuntimeException unwrapException(RuntimeException e) throws SAXException, IOException, IncorrectSchemaException {
047 if (e instanceof BuildException)
048 return SchemaBuilderImpl.unwrapBuildException((BuildException)e);
049 return e;
050 }
051 };
052 }
053 }