/** * Pull the grammar out of the bucket simply using * its TNS as a key */ SchemaGrammar getGrammar(String tns) { return fGrammarBucket.getGrammar(tns); }
private void getGlobalElements() { globals = new ArrayList(); SchemaGrammar[] sgs = gb.getGrammars(); for (int i = 0; i < sgs.length; i++) { addGlobals(sgs[i]); } }
SchemaGrammar sg = getGrammar(grammar.fTargetNamespace); if (sg != null) { putGrammar(grammar); return true; putGrammar(grammar); return true; sg2 = getGrammar(sg1.fTargetNamespace); if (sg2 == null) { putGrammar(grammar); for (int i = grammars.size() - 1; i >= 0; i--) putGrammar((SchemaGrammar)grammars.elementAt(i));
ASModel parseASInputSource(XMLInputSource is) throws Exception { if (fGrammarBucket == null) { fGrammarBucket = new XSGrammarBucket(); } initGrammarBucket(); // actually do the parse: // save some casting XMLGrammarCachingConfiguration gramConfig = (XMLGrammarCachingConfiguration)fConfiguration; // ensure grammarPool doesn't absorb grammars while it's parsing gramConfig.lockGrammarPool(); SchemaGrammar grammar = gramConfig.parseXMLSchema(is); gramConfig.unlockGrammarPool(); ASModelImpl newAsModel = null; if (grammar != null) { newAsModel = new ASModelImpl(); fGrammarBucket.putGrammar (grammar, true); addGrammars(newAsModel, fGrammarBucket); } return newAsModel; }
private void initGrammarBucket(){ if(fGrammarPool != null) { Grammar [] initialGrammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA); final int length = (initialGrammars != null) ? initialGrammars.length : 0; for (int i = 0; i < length; ++i) { // put this grammar into the bucket, along with grammars // imported by it (directly or indirectly) if (!fGrammarBucket.putGrammar((SchemaGrammar)(initialGrammars[i]), true)) { // REVISIT: a conflict between new grammar(s) and grammars // in the bucket. What to do? A warning? An exception? fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "GrammarConflict", null, XMLErrorReporter.SEVERITY_WARNING); } } } }
private void initGrammarBucket() { fGrammarBucket.reset(); if (fAbstractSchema != null) initGrammarBucketRecurse(fAbstractSchema); } private void initGrammarBucketRecurse(ASModelImpl currModel) {
grammarBucket = new XSGrammarBucket();
private void initGrammarBucketRecurse(ASModelImpl currModel) { if(currModel.getGrammar() != null) { fGrammarBucket.putGrammar(currModel.getGrammar()); } for(int i = 0; i < currModel.getInternalASModels().size(); i++) { ASModelImpl nextModel = (ASModelImpl)(currModel.getInternalASModels().elementAt(i)); initGrammarBucketRecurse(nextModel); } }
public void reset(XMLComponentManager componentManager) throws XMLConfigurationException { fGrammarBucket.reset();
private void addImportList(SchemaGrammar sg, Vector importedGrammars, Vector namespaceList) { final int size = namespaceList.size(); SchemaGrammar isg; for (int i=0; i<size; i++) { isg = fGrammarBucket.getGrammar((String)namespaceList.elementAt(i)); if (isg != null) { importedGrammars.add(isg); } else { //REVIST: report an error message } } }
return putGrammar(grammar, deep); SchemaGrammar sg = getGrammar(grammar.fTargetNamespace); if (sg == null) { putGrammar(grammar); sg2 = getGrammar(sg1.fTargetNamespace); if (sg2 == null) { putGrammar((SchemaGrammar)grammars.elementAt(i));
private void addGrammars(ASModelImpl model, XSGrammarBucket grammarBucket) { SchemaGrammar [] grammarList = grammarBucket.getGrammars(); for(int i=0; i<grammarList.length; i++) { ASModelImpl newModel = new ASModelImpl(); newModel.setGrammar(grammarList[i]); model.addASModel(newModel); } } // addGrammars
private SchemaGrammar createGrammarFrom(SchemaGrammar grammar) { SchemaGrammar newGrammar = new SchemaGrammar(grammar); fGrammarBucket.putGrammar(newGrammar); // update all the grammars in the bucket to point to the new grammar. updateImportListWith(newGrammar); // update import list of the new grammar updateImportListFor(newGrammar); return newGrammar; }
public XSElementDecl getGlobalElementDecl(QName element) { SchemaGrammar sGrammar = fGrammarBucket.getGrammar(element.uri); if (sGrammar != null) { return sGrammar.getGlobalElementDecl(element.localpart); } return null; }
/** * First try to find a grammar in the bucket, if failed, consult the * grammar pool. If a grammar is found in the pool, then add it (and all * imported ones) into the bucket. */ protected SchemaGrammar findGrammar(XSDDescription desc, boolean ignoreConflict) { SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace()); if (sg == null) { if (fGrammarPool != null) { sg = (SchemaGrammar)fGrammarPool.retrieveGrammar(desc); if (sg != null) { // put this grammar into the bucket, along with grammars // imported by it (directly or indirectly) if (!fGrammarBucket.putGrammar(sg, true, ignoreConflict)) { // REVISIT: a conflict between new grammar(s) and grammars // in the bucket. What to do? A warning? An exception? reportSchemaWarning("GrammarConflict", null, null); sg = null; } } } } return sg; }
public Grammar[] retrieveInitialGrammarSet(String grammarType) { if (grammarType == XMLGrammarDescription.XML_SCHEMA) { if (fInitialGrammarSet == null) { if (fGrammarBucket == null) { fInitialGrammarSet = new Grammar [] {SchemaGrammar.Schema4Annotations.getSchema4Annotations(fSchemaVersion)}; } else { SchemaGrammar [] schemaGrammars = fGrammarBucket.getGrammars(); /** * If the grammar bucket already contains the schema for schemas * then we already have the definitions for the parts relevant * to annotations. */ for (int i = 0; i < schemaGrammars.length; ++i) { if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(schemaGrammars[i].getTargetNamespace())) { fInitialGrammarSet = schemaGrammars; return fInitialGrammarSet; } } Grammar [] grammars = new Grammar[schemaGrammars.length + 1]; System.arraycopy(schemaGrammars, 0, grammars, 0, schemaGrammars.length); grammars[grammars.length - 1] = SchemaGrammar.Schema4Annotations.getSchema4Annotations(fSchemaVersion); fInitialGrammarSet = grammars; } } return fInitialGrammarSet; } return new Grammar[0]; }
private SchemaGrammar getSchemaGrammar(XSDDescription desc) { SchemaGrammar sg = findGrammar(desc, fNamespaceGrowth); if (sg == null) { sg = new SchemaGrammar(desc.getNamespace(), desc.makeClone(), fSymbolTable); fGrammarBucket.putGrammar(sg); } else if (sg.isImmutable()){ sg = createGrammarFrom(sg); } return sg; }
public XSElementDecl getGlobalElementDecl(QName name) { SchemaGrammar sg = gb.getGrammar(name.uri); return sg != null ? sg.getGlobalElementDecl(name.localpart) : null; }
SchemaGrammar sg2 = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace); if (sg2.isImmutable()) { sg = new SchemaGrammar(sg2); fGrammarBucket.putGrammar(sg); referType == XSDDescription.CONTEXT_REDEFINE || referType == XSDDescription.CONTEXT_OVERRIDE) { sg = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace); if(sg == null) { sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable, fSchemaVersion); fGrammarBucket.putGrammar(sg); fGrammarBucket.putGrammar(sg);
/** * Namespace growth * * Go throuth the grammar bucket, and for each grammar in the bucket * check the import list. If there exists a grammar in import list * that has the same namespace as newGrammar, but a different instance, * then update the import list and replace the old grammar instance with * the new one */ private void updateImportListWith(SchemaGrammar newGrammar) { SchemaGrammar[] schemaGrammars = fGrammarBucket.getGrammars(); for (int i = 0; i < schemaGrammars.length; ++i) { SchemaGrammar sg = schemaGrammars[i]; if (sg != newGrammar) { Vector importedGrammars = sg.getImportedGrammars(); if (importedGrammars != null) { for (int j=0; j<importedGrammars.size(); j++) { SchemaGrammar isg = (SchemaGrammar) importedGrammars.elementAt(j); if (null2EmptyString(isg.getTargetNamespace()).equals(null2EmptyString(newGrammar.getTargetNamespace()))) { if (isg != newGrammar) { importedGrammars.set(j, newGrammar); } break; } } } } } }