1 16 17 package org.apache.xerces.impl.xs; 18 19 import java.util.Hashtable ; 20 import java.util.Enumeration ; 21 import java.util.Vector ; 22 23 31 public class XSGrammarBucket { 32 33 35 38 Hashtable fGrammarRegistry = new Hashtable (); 39 SchemaGrammar fNoNSGrammar = null; 40 41 47 public SchemaGrammar getGrammar(String namespace) { 48 if (namespace == null) 49 return fNoNSGrammar; 50 return (SchemaGrammar)fGrammarRegistry.get(namespace); 51 } 52 53 60 public void putGrammar(SchemaGrammar grammar) { 61 if (grammar.getTargetNamespace() == null) 62 fNoNSGrammar = grammar; 63 else 64 fGrammarRegistry.put(grammar.getTargetNamespace(), grammar); 65 } 66 67 77 public boolean putGrammar(SchemaGrammar grammar, boolean deep) { 78 SchemaGrammar sg = getGrammar(grammar.fTargetNamespace); 80 if (sg != null) { 81 return sg == grammar; 83 } 84 if (!deep) { 86 putGrammar(grammar); 87 return true; 88 } 89 90 Vector currGrammars = (Vector )grammar.getImportedGrammars(); 94 if (currGrammars == null) { 95 putGrammar(grammar); 96 return true; 97 } 98 99 Vector grammars = ((Vector )currGrammars.clone()); 100 SchemaGrammar sg1, sg2; 101 Vector gs; 102 for (int i = 0; i < grammars.size(); i++) { 104 sg1 = (SchemaGrammar)grammars.elementAt(i); 106 sg2 = getGrammar(sg1.fTargetNamespace); 108 if (sg2 == null) { 109 gs = sg1.getImportedGrammars(); 111 if(gs == null) continue; 114 for (int j = gs.size() - 1; j >= 0; j--) { 115 sg2 = (SchemaGrammar)gs.elementAt(j); 116 if (!grammars.contains(sg2)) 117 grammars.addElement(sg2); 118 } 119 } 120 else if (sg2 != sg1) { 123 return false; 124 } 125 } 126 127 putGrammar(grammar); 129 for (int i = grammars.size() - 1; i >= 0; i--) 130 putGrammar((SchemaGrammar)grammars.elementAt(i)); 131 132 return true; 133 } 134 135 140 public SchemaGrammar[] getGrammars() { 141 int count = fGrammarRegistry.size() + (fNoNSGrammar==null ? 0 : 1); 143 SchemaGrammar[] grammars = new SchemaGrammar[count]; 144 Enumeration schemas = fGrammarRegistry.elements(); 146 int i = 0; 147 while (schemas.hasMoreElements()) 148 grammars[i++] = (SchemaGrammar)schemas.nextElement(); 149 if (fNoNSGrammar != null) 151 grammars[count-1] = fNoNSGrammar; 152 return grammars; 153 } 154 155 159 public void reset() { 160 fNoNSGrammar = null; 161 fGrammarRegistry.clear(); 162 } 163 164 } | Popular Tags |