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 ; 13 import org.xml.sax.SAXException ; 14 15 import java.io.IOException ; 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 cause = e.getCauseException(); 33 if (cause instanceof RuntimeException 34 && (e.getMessage() == null || e.getMessage().equals(cause.getMessage()))) 35 throw (RuntimeException )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 in, PropertyMap properties) 46 throws IOException , SAXException , IncorrectSchemaException { 47 try { 48 return new SchemaImpl(vf.compileSchema(in)); 49 } 50 catch (SAXException 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 cause = e.getCauseException(); 59 String message = e.getMessage(); 60 if (cause != null && message != null && message.equals(cause.getMessage())) 61 message = null; if (message == null) { 63 if (cause instanceof RuntimeException ) 64 throw (RuntimeException )cause; 65 if (cause instanceof SAXException ) 66 throw (SAXException )cause; 67 if (cause instanceof IOException ) 68 throw (IOException )cause; 69 if (cause instanceof VerifierConfigurationException) { 70 e = (VerifierConfigurationException)cause; 71 continue; 72 } 73 } 74 throw new SAXException (message, cause); 75 } 76 } 77 78 } 79 80 public Option getOption(String uri) { 81 return null; 82 } 83 } 84 | Popular Tags |