1 package com.sun.org.apache.xerces.internal.parsers; 2 3 import javax.xml.validation.Schema ; 4 import javax.xml.validation.ValidatorHandler ; 5 6 import com.sun.org.apache.xerces.internal.jaxp.JAXPValidatorComponent; 7 import com.sun.org.apache.xerces.internal.jaxp.validation.InsulatedValidatorComponent; 8 import com.sun.org.apache.xerces.internal.jaxp.validation.XercesSchema; 9 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 10 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentFilter; 11 19 public class JAXPConfiguration extends XIncludeParserConfiguration { 20 21 22 private final Schema fSchema; 23 24 30 public JAXPConfiguration(Schema schema){ 31 this.fSchema = schema; 32 } 33 34 protected void configurePipeline() { 35 super.configurePipeline(); 36 37 if (fSchema != null) { 38 if( isXNICapabaleSchema(fSchema) ) { 39 InsulatedValidatorComponent v = ((XercesSchema)fSchema).newXNIValidator(); 43 addComponent(v); 44 45 fLastComponent.setDocumentHandler(v.getValidator()); 46 v.getValidator().setDocumentSource(fLastComponent); 47 fLastComponent = v.getValidator(); 48 v.getValidator().setDocumentHandler(fDocumentHandler); 49 } else { 50 XMLDocumentFilter validator = null; 52 ValidatorHandler validatorHandler = fSchema.newValidatorHandler(); 53 54 validator = new JAXPValidatorComponent(validatorHandler); 55 addComponent((XMLComponent)validator); 56 57 fLastComponent.setDocumentHandler(validator); 58 validator.setDocumentSource(fLastComponent); 59 fLastComponent = validator; 60 validator.setDocumentHandler(fDocumentHandler); 61 } 62 } 63 } 64 65 68 private static boolean isXNICapabaleSchema( Schema s ) { 69 if(!(s instanceof XercesSchema )) return false; 70 71 try { 72 String v = System.getProperty(JAXPConfiguration.class.getName()+".noSchemaOptimization"); 73 if(v==null) 74 return false; 78 } catch( Throwable t ) { 79 ; 80 } 81 82 return true; 85 } 86 87 public boolean getFeatureDefaultValue(String featureId){ 88 89 int count = fComponents.size(); 91 for (int i = 0; i < count; i++) { 92 XMLComponent c = (XMLComponent) fComponents.get(i); 93 Boolean bo = c.getFeatureDefault(featureId); 94 if(bo != null){ 95 return bo.booleanValue(); 96 } 97 102 } 103 return false; 105 } 106 107 } 108 109 | Popular Tags |