1 57 58 package com.sun.org.apache.xerces.internal.parsers; 59 60 import java.util.Vector ; 61 62 import com.sun.org.apache.xerces.internal.dom.ASModelImpl; 63 import com.sun.org.apache.xerces.internal.dom3.as.ASModel; 64 import com.sun.org.apache.xerces.internal.dom3.as.DOMASBuilder; 65 import com.sun.org.apache.xerces.internal.dom3.as.DOMASException; 66 import com.sun.org.apache.xerces.internal.impl.Constants; 67 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 68 import com.sun.org.apache.xerces.internal.impl.xs.XSGrammarBucket; 69 import com.sun.org.apache.xerces.internal.util.SymbolTable; 70 import com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl; 71 import com.sun.org.apache.xerces.internal.xni.XNIException; 72 import com.sun.org.apache.xerces.internal.xni.grammars.Grammar; 73 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 74 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 75 import org.w3c.dom.ls.LSInput ; 76 77 87 88 public class DOMASBuilderImpl 89 extends DOMParserImpl implements DOMASBuilder { 90 91 95 97 protected static final String SCHEMA_FULL_CHECKING = 98 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; 99 100 102 protected static final String ERROR_REPORTER = 103 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 104 105 protected static final String SYMBOL_TABLE = 106 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 107 108 protected static final String ENTITY_MANAGER = 109 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 110 111 112 116 protected XSGrammarBucket fGrammarBucket; 117 118 protected ASModelImpl fAbstractSchema; 119 120 124 127 public DOMASBuilderImpl() { 128 super(new XMLGrammarCachingConfiguration()); 129 } 131 136 public DOMASBuilderImpl(XMLGrammarCachingConfiguration config) { 137 super(config); 138 } 140 143 public DOMASBuilderImpl(SymbolTable symbolTable) { 144 super(new XMLGrammarCachingConfiguration(symbolTable)); 145 } 147 148 155 public DOMASBuilderImpl(SymbolTable symbolTable, XMLGrammarPool grammarPool) { 156 super(new XMLGrammarCachingConfiguration(symbolTable, grammarPool)); 157 } 158 159 163 170 public ASModel getAbstractSchema() { 171 return fAbstractSchema; 172 } 173 174 181 public void setAbstractSchema(ASModel abstractSchema) { 182 183 fAbstractSchema = (ASModelImpl)abstractSchema; 189 190 XMLGrammarPool grammarPool = (XMLGrammarPool)fConfiguration.getProperty(StandardParserConfiguration.XMLGRAMMAR_POOL); 192 if (grammarPool == null) { 195 grammarPool = new XMLGrammarPoolImpl(); 197 fConfiguration.setProperty(StandardParserConfiguration.XMLGRAMMAR_POOL, 198 grammarPool); 199 } 200 if (fAbstractSchema != null) { 201 initGrammarPool(fAbstractSchema, grammarPool); 202 } 203 } 204 205 228 public ASModel parseASURI(String uri) 229 throws DOMASException, Exception { 230 XMLInputSource source = new XMLInputSource(null, uri, null); 231 return parseASInputSource(source); 232 } 233 234 259 public ASModel parseASInputSource(LSInput is) 260 throws DOMASException, Exception { 261 262 XMLInputSource xis = this.dom2xmlInputSource(is); 264 try { 265 return parseASInputSource(xis); 266 } 267 catch (XNIException e) { 268 Exception ex = e.getException(); 269 throw ex; 270 } 271 } 272 273 ASModel parseASInputSource(XMLInputSource is) throws Exception { 274 275 if (fGrammarBucket == null) { 276 fGrammarBucket = new XSGrammarBucket(); 277 } 278 279 initGrammarBucket(); 280 281 XMLGrammarCachingConfiguration gramConfig = (XMLGrammarCachingConfiguration)fConfiguration; 284 gramConfig.lockGrammarPool(); 286 SchemaGrammar grammar = gramConfig.parseXMLSchema(is); 287 gramConfig.unlockGrammarPool(); 288 289 ASModelImpl newAsModel = null; 290 if (grammar != null) { 291 newAsModel = new ASModelImpl(); 292 fGrammarBucket.putGrammar (grammar, true); 293 addGrammars(newAsModel, fGrammarBucket); 294 } 295 return newAsModel; 296 } 297 298 private void initGrammarBucket() { 300 fGrammarBucket.reset(); 301 if (fAbstractSchema != null) 302 initGrammarBucketRecurse(fAbstractSchema); 303 } 304 private void initGrammarBucketRecurse(ASModelImpl currModel) { 305 if(currModel.getGrammar() != null) { 306 fGrammarBucket.putGrammar(currModel.getGrammar()); 307 } 308 for(int i = 0; i < currModel.getInternalASModels().size(); i++) { 309 ASModelImpl nextModel = (ASModelImpl)(currModel.getInternalASModels().elementAt(i)); 310 initGrammarBucketRecurse(nextModel); 311 } 312 } 313 314 private void addGrammars(ASModelImpl model, XSGrammarBucket grammarBucket) { 315 SchemaGrammar [] grammarList = grammarBucket.getGrammars(); 316 for(int i=0; i<grammarList.length; i++) { 317 ASModelImpl newModel = new ASModelImpl(); 318 newModel.setGrammar(grammarList[i]); 319 model.addASModel(newModel); 320 } 321 } 323 private void initGrammarPool(ASModelImpl currModel, XMLGrammarPool grammarPool) { 324 Grammar[] grammars = new Grammar[1]; 327 if ((grammars[0] = (Grammar)currModel.getGrammar()) != null) { 328 grammarPool.cacheGrammars(grammars[0].getGrammarDescription().getGrammarType(), grammars); 329 } 330 Vector modelStore = currModel.getInternalASModels(); 331 for (int i = 0; i < modelStore.size(); i++) { 332 initGrammarPool((ASModelImpl)modelStore.elementAt(i), grammarPool); 333 } 334 } 335 } | Popular Tags |