| Method from org.apache.xerces.util.XMLGrammarPoolImpl Detail: |
public void cacheGrammars(String grammarType,
Grammar[] grammars) {
if(!fPoolIsLocked) {
for (int i = 0; i < grammars.length; i++) {
if(DEBUG) {
System.out.println("CACHED GRAMMAR " + (i+1) ) ;
Grammar temp = grammars[i] ;
//print(temp.getGrammarDescription());
}
putGrammar(grammars[i]);
}
}
}
|
public void clear() {
for (int i=0; i< fGrammars.length; i++) {
if(fGrammars[i] != null) {
fGrammars[i].clear();
fGrammars[i] = null;
}
}
fGrammarCount = 0;
}
|
public boolean containsGrammar(XMLGrammarDescription desc) {
synchronized (fGrammars) {
int hash = hashCode(desc);
int index = (hash & 0x7FFFFFFF) % fGrammars.length;
for (Entry entry = fGrammars[index] ; entry != null ; entry = entry.next) {
if ((entry.hash == hash) && equals(entry.desc, desc)) {
return true;
}
}
return false;
}
}
Returns true if the grammar pool contains a grammar associated
to the specified grammar description. Currently, the root element name
is used as the key for DTD grammars and the target namespace is used
as the key for Schema grammars. |
public boolean equals(XMLGrammarDescription desc1,
XMLGrammarDescription desc2) {
return desc1.equals(desc2);
}
This method checks whether two grammars are the same. Currently, we compare
the root element names for DTD grammars and the target namespaces for Schema grammars.
The application can override this behaviour and add its own logic. |
public Grammar getGrammar(XMLGrammarDescription desc) {
synchronized (fGrammars) {
int hash = hashCode(desc);
int index = (hash & 0x7FFFFFFF) % fGrammars.length;
for (Entry entry = fGrammars[index] ; entry != null ; entry = entry.next) {
if ((entry.hash == hash) && equals(entry.desc, desc)) {
return entry.grammar;
}
}
return null;
}
}
Returns the grammar associated to the specified grammar description.
Currently, the root element name is used as the key for DTD grammars
and the target namespace is used as the key for Schema grammars. |
public int hashCode(XMLGrammarDescription desc) {
return desc.hashCode();
}
Returns the hash code value for the given grammar description. |
public void lockPool() {
fPoolIsLocked = true;
}
|
public void putGrammar(Grammar grammar) {
if(!fPoolIsLocked) {
synchronized (fGrammars) {
XMLGrammarDescription desc = grammar.getGrammarDescription();
int hash = hashCode(desc);
int index = (hash & 0x7FFFFFFF) % fGrammars.length;
for (Entry entry = fGrammars[index]; entry != null; entry = entry.next) {
if (entry.hash == hash && equals(entry.desc, desc)) {
entry.grammar = grammar;
return;
}
}
// create a new entry
Entry entry = new Entry(hash, desc, grammar, fGrammars[index]);
fGrammars[index] = entry;
fGrammarCount++;
}
}
}
Puts the specified grammar into the grammar pool and associates it to
its root element name or its target namespace. |
public Grammar removeGrammar(XMLGrammarDescription desc) {
synchronized (fGrammars) {
int hash = hashCode(desc);
int index = (hash & 0x7FFFFFFF) % fGrammars.length;
for (Entry entry = fGrammars[index], prev = null ; entry != null ; prev = entry, entry = entry.next) {
if ((entry.hash == hash) && equals(entry.desc, desc)) {
if (prev != null) {
prev.next = entry.next;
}
else {
fGrammars[index] = entry.next;
}
Grammar tempGrammar = entry.grammar;
entry.grammar = null;
fGrammarCount--;
return tempGrammar;
}
}
return null;
}
}
Removes the grammar associated to the specified grammar description from the
grammar pool and returns the removed grammar. Currently, the root element name
is used as the key for DTD grammars and the target namespace is used
as the key for Schema grammars. |
public Grammar retrieveGrammar(XMLGrammarDescription desc) {
if(DEBUG){
System.out.println("RETRIEVING GRAMMAR FROM THE APPLICATION WITH FOLLOWING DESCRIPTION :");
//print(desc);
}
return getGrammar(desc);
}
|
public Grammar[] retrieveInitialGrammarSet(String grammarType) {
synchronized (fGrammars) {
int grammarSize = fGrammars.length ;
Grammar [] tempGrammars = new Grammar[fGrammarCount];
int pos = 0;
for (int i = 0; i < grammarSize; i++) {
for (Entry e = fGrammars[i]; e != null; e = e.next) {
if (e.desc.getGrammarType().equals(grammarType)) {
tempGrammars[pos++] = e.grammar;
}
}
}
Grammar[] toReturn = new Grammar[pos];
System.arraycopy(tempGrammars, 0, toReturn, 0, pos);
return toReturn;
}
}
|
public void unlockPool() {
fPoolIsLocked = false;
}
|