1 57 58 package com.sun.org.apache.xerces.internal.impl.xs; 59 60 import java.util.Hashtable ; 61 import java.util.Enumeration ; 62 import java.util.Vector ; 63 64 69 public class XSGrammarBucket { 70 71 73 76 Hashtable fGrammarRegistry = new Hashtable (); 77 SchemaGrammar fNoNSGrammar = null; 78 79 85 public SchemaGrammar getGrammar(String namespace) { 86 if (namespace == null) 87 return fNoNSGrammar; 88 return (SchemaGrammar)fGrammarRegistry.get(namespace); 89 } 90 91 98 public void putGrammar(SchemaGrammar grammar) { 99 if (grammar.getTargetNamespace() == null) 100 fNoNSGrammar = grammar; 101 else 102 fGrammarRegistry.put(grammar.getTargetNamespace(), grammar); 103 } 104 105 115 public boolean putGrammar(SchemaGrammar grammar, boolean deep) { 116 SchemaGrammar sg = getGrammar(grammar.fTargetNamespace); 118 if (sg != null) { 119 return sg == grammar; 121 } 122 if (!deep) { 124 putGrammar(grammar); 125 return true; 126 } 127 128 Vector currGrammars = (Vector )grammar.getImportedGrammars(); 132 if (currGrammars == null) { 133 putGrammar(grammar); 134 return true; 135 } 136 137 Vector grammars = ((Vector )currGrammars.clone()); 138 SchemaGrammar sg1, sg2; 139 Vector gs; 140 for (int i = 0; i < grammars.size(); i++) { 142 sg1 = (SchemaGrammar)grammars.elementAt(i); 144 sg2 = getGrammar(sg1.fTargetNamespace); 146 if (sg2 == null) { 147 gs = sg1.getImportedGrammars(); 149 if(gs == null) continue; 152 for (int j = gs.size() - 1; j >= 0; j--) { 153 sg2 = (SchemaGrammar)gs.elementAt(j); 154 if (!grammars.contains(sg2)) 155 grammars.addElement(sg2); 156 } 157 } 158 else if (sg2 != sg1) { 161 return false; 162 } 163 } 164 165 putGrammar(grammar); 167 for (int i = grammars.size() - 1; i >= 0; i--) 168 putGrammar((SchemaGrammar)grammars.elementAt(i)); 169 170 return true; 171 } 172 173 178 public SchemaGrammar[] getGrammars() { 179 int count = fGrammarRegistry.size() + (fNoNSGrammar==null ? 0 : 1); 181 SchemaGrammar[] grammars = new SchemaGrammar[count]; 182 Enumeration schemas = fGrammarRegistry.elements(); 184 int i = 0; 185 while (schemas.hasMoreElements()) 186 grammars[i++] = (SchemaGrammar)schemas.nextElement(); 187 if (fNoNSGrammar != null) 189 grammars[count-1] = fNoNSGrammar; 190 return grammars; 191 } 192 193 197 public void reset() { 198 fNoNSGrammar = null; 199 fGrammarRegistry.clear(); 200 } 201 202 } | Popular Tags |