KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > validate > jarv > VerifierFactorySchemaReader


1 package com.thaiopensource.validate.jarv;
2
3 import com.thaiopensource.util.PropertyMap;
4 import com.thaiopensource.validate.IncorrectSchemaException;
5 import com.thaiopensource.validate.Schema;
6 import com.thaiopensource.validate.SchemaReader;
7 import com.thaiopensource.validate.Validator;
8 import com.thaiopensource.validate.Option;
9 import com.thaiopensource.validate.AbstractSchema;
10 import org.iso_relax.verifier.VerifierConfigurationException;
11 import org.iso_relax.verifier.VerifierFactory;
12 import org.xml.sax.InputSource JavaDoc;
13 import org.xml.sax.SAXException JavaDoc;
14
15 import java.io.IOException JavaDoc;
16
17 public class VerifierFactorySchemaReader implements SchemaReader {
18   private final VerifierFactory vf;
19
20   static private class SchemaImpl extends AbstractSchema {
21     final org.iso_relax.verifier.Schema schema;
22
23     private SchemaImpl(org.iso_relax.verifier.Schema schema) {
24       this.schema = schema;
25     }
26
27     public Validator createValidator(PropertyMap properties) {
28       try {
29         return new VerifierValidator(schema.newVerifier(), properties);
30       }
31       catch (VerifierConfigurationException e) {
32         Exception JavaDoc cause = e.getCauseException();
33         if (cause instanceof RuntimeException JavaDoc
34             && (e.getMessage() == null || e.getMessage().equals(cause.getMessage())))
35           throw (RuntimeException JavaDoc)cause;
36         throw new JarvConfigurationException(e);
37       }
38     }
39   }
40
41   public VerifierFactorySchemaReader(VerifierFactory vf) {
42     this.vf = vf;
43   }
44
45   public Schema createSchema(InputSource JavaDoc in, PropertyMap properties)
46           throws IOException JavaDoc, SAXException JavaDoc, IncorrectSchemaException {
47     try {
48       return new SchemaImpl(vf.compileSchema(in));
49     }
50     catch (SAXException JavaDoc e) {
51       System.err.println("compileSchema threw a SAXException class " + e.getClass().toString());
52       if (e.getException() != null)
53         System.err.println("cause has class " + e.getException().getClass().toString());
54       throw e;
55     }
56     catch (VerifierConfigurationException e) {
57       for (;;) {
58         Exception JavaDoc cause = e.getCauseException();
59         String JavaDoc message = e.getMessage();
60         if (cause != null && message != null && message.equals(cause.getMessage()))
61           message = null; // don't really have a message
62
if (message == null) {
63           if (cause instanceof RuntimeException JavaDoc)
64             throw (RuntimeException JavaDoc)cause;
65           if (cause instanceof SAXException JavaDoc)
66             throw (SAXException JavaDoc)cause;
67           if (cause instanceof IOException JavaDoc)
68             throw (IOException JavaDoc)cause;
69           if (cause instanceof VerifierConfigurationException) {
70             e = (VerifierConfigurationException)cause;
71             continue;
72           }
73         }
74         throw new SAXException JavaDoc(message, cause);
75       }
76     }
77
78   }
79
80   public Option getOption(String JavaDoc uri) {
81     return null;
82   }
83 }
84
Popular Tags