KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > relaxng > impl > SchemaReceiverImpl


1 package com.thaiopensource.relaxng.impl;
2
3 import com.thaiopensource.validate.IncorrectSchemaException;
4 import com.thaiopensource.validate.auto.SchemaReceiver;
5 import com.thaiopensource.validate.Schema;
6 import com.thaiopensource.validate.ValidateProperty;
7 import com.thaiopensource.validate.rng.RngProperty;
8 import com.thaiopensource.validate.nrl.NrlSchemaReceiverFactory;
9 import com.thaiopensource.validate.nrl.NrlProperty;
10 import com.thaiopensource.validate.auto.SchemaFuture;
11 import com.thaiopensource.relaxng.parse.ParseReceiver;
12 import com.thaiopensource.relaxng.parse.BuildException;
13 import com.thaiopensource.util.PropertyMap;
14 import org.relaxng.datatype.DatatypeLibraryFactory;
15 import org.relaxng.datatype.helpers.DatatypeLibraryLoader;
16 import org.xml.sax.ErrorHandler JavaDoc;
17 import org.xml.sax.SAXException JavaDoc;
18 import org.xml.sax.XMLReader JavaDoc;
19
20 import java.io.IOException JavaDoc;
21
22 public class SchemaReceiverImpl implements SchemaReceiver {
23   private final ParseReceiver parser;
24   private final PropertyMap properties;
25
26   public SchemaReceiverImpl(ParseReceiver parser, PropertyMap properties) {
27     this.parser = parser;
28     this.properties = properties;
29   }
30
31   public SchemaFuture installHandlers(XMLReader JavaDoc xr) throws SAXException JavaDoc {
32     final SchemaPatternBuilder pb = new SchemaPatternBuilder();
33     ErrorHandler JavaDoc eh = ValidateProperty.ERROR_HANDLER.get(properties);
34     DatatypeLibraryFactory dlf = RngProperty.DATATYPE_LIBRARY_FACTORY.get(properties);
35     if (dlf == null)
36       dlf = new DatatypeLibraryLoader();
37     final PatternFuture pf = SchemaBuilderImpl.installHandlers(parser, xr, eh, dlf, pb);
38     return new SchemaFuture() {
39       public Schema getSchema() throws IncorrectSchemaException, SAXException JavaDoc, IOException JavaDoc {
40         return SchemaReaderImpl.wrapPattern(pf.getPattern(properties.contains(NrlProperty.ATTRIBUTES_SCHEMA)),
41                                             pb, properties);
42       }
43       public RuntimeException JavaDoc unwrapException(RuntimeException JavaDoc e) throws SAXException JavaDoc, IOException JavaDoc, IncorrectSchemaException {
44         if (e instanceof BuildException)
45           return SchemaBuilderImpl.unwrapBuildException((BuildException)e);
46         return e;
47       }
48     };
49   }
50 }
51
Popular Tags