Top Description Inners Fields Constructors Methods
com.sun.org.apache.xerces.internal.jaxp.validation

pack-priv final Class SoftReferenceGrammarPool

extends Object
implements XMLGrammarPool
Class Inheritance
All Implemented Interfaces
com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool
Imports
java.lang.ref.Reference, .ReferenceQueue, .SoftReference, com.sun.org.apache.xerces.internal.xni.grammars.Grammar, .XMLGrammarDescription, .XMLSchemaDescription, .XMLGrammarPool

This grammar pool is a memory sensitive cache. The grammars stored in the pool are softly reachable and may be cleared by the garbage collector in response to memory demand. Equality of XMLSchemaDescriptions is determined using both the target namespace for the schema and schema location.

Author
Michael Glavassevich, IBM

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
SoftReferenceGrammarPool.Entry

This class is a grammar pool entry.

pack-priv static class
SoftReferenceGrammarPool.SoftGrammarReference

This class stores a soft reference to a grammar object.

Field Summary

Modifier and TypeField and Description
protected int
fGrammarCount

The number of grammars in the pool

protected SoftReferenceGrammarPool.Entry[]
fGrammars

Grammars.

protected boolean
fPoolIsLocked

Flag indicating whether this pool is locked

protected final ReferenceQueue<Grammar>
fReferenceQueue

Reference queue for cleared grammar references

protected static final int
TABLE_SIZE

Default size.

protected static final Grammar[]
ZERO_LENGTH_GRAMMAR_ARRAY

Zero length grammar array.

Constructor Summary

AccessConstructor and Description
public
SoftReferenceGrammarPool()

Constructs a grammar pool with a default number of buckets.

public
SoftReferenceGrammarPool(int initialCapacity)

Constructs a grammar pool with a specified number of buckets.

Method Summary

Modifier and TypeMethod and Description
public void
cacheGrammars(String
the type of the grammars being returned;
grammarType
,
Grammar[]
an array containing the set of grammars being returned; order is not significant.
grammars
)

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.cacheGrammars.

return the final set of grammars that the validator ended up with.

private void
clean()

Removes stale entries from the pool.

public void
clear()

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.clear.

Removes all grammars from the pool.

public boolean
containsGrammar(XMLGrammarDescription
The Grammar Description.
desc
)

Returns true if the grammar pool contains a grammar associated to the specified grammar description.

public boolean

Returns:

True if the grammars are equal, otherwise false
equals
(XMLGrammarDescription
The grammar description
desc1
,
XMLGrammarDescription
The grammar description of the grammar to be compared to
desc2
)

This method checks whether two grammars are the same.

public Grammar
getGrammar(XMLGrammarDescription
The Grammar Description.
desc
)

Returns the grammar associated to the specified grammar description.

public int

Returns:

The hash code value
hashCode
(XMLGrammarDescription
The grammar description
desc
)

Returns the hash code value for the given grammar description.

public void
lockPool()

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.lockPool.

Causes the XMLGrammarPool not to store any grammars when the cacheGrammars(String, Grammar[[]) method is called.

public void
putGrammar(Grammar
The Grammar.
grammar
)

Puts the specified grammar into the grammar pool and associates it to its root element name or its target namespace.

private Grammar

Returns:

The grammar attached to this entry
removeEntry
(SoftReferenceGrammarPool.Entry
the entry to remove
entry
)

Removes the given entry from the pool

public Grammar

Returns:

The removed grammar.
removeGrammar
(XMLGrammarDescription
The Grammar Description.
desc
)

Removes the grammar associated to the specified grammar description from the grammar pool and returns the removed grammar.

public Grammar
retrieveGrammar(XMLGrammarDescription
The description of the Grammar being requested.
desc
)

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.retrieveGrammar.

This method requests that the application retrieve a grammar corresponding to the given GrammarIdentifier from its cache.

public Grammar[]
retrieveInitialGrammarSet(String
the type of the grammar, from the com.sun.org.apache.xerces.internal.xni.grammars.Grammar interface.
grammarType
)

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.retrieveInitialGrammarSet.

retrieve the initial known set of grammars.

public void
unlockPool()

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.unlockPool.

Allows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[]) method is called.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fGrammarCountback to summary
protected int fGrammarCount

The number of grammars in the pool

fGrammarsback to summary
protected SoftReferenceGrammarPool.Entry[] fGrammars

Grammars.

fPoolIsLockedback to summary
protected boolean fPoolIsLocked

Flag indicating whether this pool is locked

fReferenceQueueback to summary
protected final ReferenceQueue<Grammar> fReferenceQueue

Reference queue for cleared grammar references

TABLE_SIZEback to summary
protected static final int TABLE_SIZE

Default size.

ZERO_LENGTH_GRAMMAR_ARRAYback to summary
protected static final Grammar[] ZERO_LENGTH_GRAMMAR_ARRAY

Zero length grammar array.

Constructor Detail

SoftReferenceGrammarPoolback to summary
public SoftReferenceGrammarPool()

Constructs a grammar pool with a default number of buckets.

SoftReferenceGrammarPoolback to summary
public SoftReferenceGrammarPool(int initialCapacity)

Constructs a grammar pool with a specified number of buckets.

Method Detail

cacheGrammarsback to summary
public void cacheGrammars(String grammarType, Grammar[] grammars)

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.cacheGrammars.

Doc from com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.cacheGrammars.

return the final set of grammars that the validator ended up with. This method is called after the validation finishes. The application may then choose to cache some of the returned grammars.

Parameters
grammarType:String

the type of the grammars being returned;

grammars:Grammar[]

an array containing the set of grammars being returned; order is not significant.

cleanback to summary
private void clean()

Removes stale entries from the pool.

clearback to summary
public void clear()

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.clear.

Doc from com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.clear.

Removes all grammars from the pool.

containsGrammarback to summary
public boolean containsGrammar(XMLGrammarDescription desc)

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.

Parameters
desc:XMLGrammarDescription

The Grammar Description.

equalsback to summary
public boolean equals(XMLGrammarDescription desc1, XMLGrammarDescription 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.

Parameters
desc1:XMLGrammarDescription

The grammar description

desc2:XMLGrammarDescription

The grammar description of the grammar to be compared to

Returns:boolean

True if the grammars are equal, otherwise false

getGrammarback to summary
public Grammar getGrammar(XMLGrammarDescription desc)

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.

Parameters
desc:XMLGrammarDescription

The Grammar Description.

hashCodeback to summary
public int hashCode(XMLGrammarDescription desc)

Returns the hash code value for the given grammar description.

Parameters
desc:XMLGrammarDescription

The grammar description

Returns:int

The hash code value

lockPoolback to summary
public void lockPool()

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.lockPool.

Doc from com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.lockPool.

Causes the XMLGrammarPool not to store any grammars when the cacheGrammars(String, Grammar[[]) method is called.

putGrammarback to summary
public void putGrammar(Grammar grammar)

Puts the specified grammar into the grammar pool and associates it to its root element name or its target namespace.

Parameters
grammar:Grammar

The Grammar.

removeEntryback to summary
private Grammar removeEntry(SoftReferenceGrammarPool.Entry entry)

Removes the given entry from the pool

Parameters
entry:SoftReferenceGrammarPool.Entry

the entry to remove

Returns:Grammar

The grammar attached to this entry

removeGrammarback to summary
public Grammar removeGrammar(XMLGrammarDescription desc)

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.

Parameters
desc:XMLGrammarDescription

The Grammar Description.

Returns:Grammar

The removed grammar.

retrieveGrammarback to summary
public Grammar retrieveGrammar(XMLGrammarDescription desc)

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.retrieveGrammar.

Doc from com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.retrieveGrammar.

This method requests that the application retrieve a grammar corresponding to the given GrammarIdentifier from its cache. If it cannot do so it must return null; the parser will then call the EntityResolver. An application must not call its EntityResolver itself from this method; this may result in infinite recursions.

Parameters
desc:XMLGrammarDescription

The description of the Grammar being requested.

Returns:Grammar

the Grammar corresponding to this description or null if no such Grammar is known.

retrieveInitialGrammarSetback to summary
public Grammar[] retrieveInitialGrammarSet(String grammarType)

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.retrieveInitialGrammarSet.

Doc from com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.retrieveInitialGrammarSet.

retrieve the initial known set of grammars. this method is called by a validator before the validation starts. the application can provide an initial set of grammars available to the current validation attempt.

Parameters
grammarType:String

the type of the grammar, from the com.sun.org.apache.xerces.internal.xni.grammars.Grammar interface.

Returns:Grammar[]

the set of grammars the validator may put in its "bucket"

unlockPoolback to summary
public void unlockPool()

Implements com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.unlockPool.

Doc from com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool.unlockPool.

Allows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[]) method is called. This is the default state of the object.

com.sun.org.apache.xerces.internal.jaxp.validation back to summary

pack-priv final Class SoftReferenceGrammarPool.Entry

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.org.apache.xerces.internal.jaxp.validation.SoftReferenceGrammarPool.Entry

This class is a grammar pool entry. Each entry acts as a node in a doubly linked list.

Field Summary

Modifier and TypeField and Description
public int
public XMLGrammarDescription
public SoftReferenceGrammarPool.SoftGrammarReference
public int
public SoftReferenceGrammarPool.Entry
public SoftReferenceGrammarPool.Entry

Constructor Summary

AccessConstructor and Description
protected
Entry(int hash, int bucket, XMLGrammarDescription desc, Grammar grammar, SoftReferenceGrammarPool.Entry next, ReferenceQueue<Grammar> queue)

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bucketback to summary
public int bucket
descback to summary
public XMLGrammarDescription desc
grammarback to summary
public SoftReferenceGrammarPool.SoftGrammarReference grammar
hashback to summary
public int hash
nextback to summary
public SoftReferenceGrammarPool.Entry next
prevback to summary
public SoftReferenceGrammarPool.Entry prev

Constructor Detail

Entryback to summary
protected Entry(int hash, int bucket, XMLGrammarDescription desc, Grammar grammar, SoftReferenceGrammarPool.Entry next, ReferenceQueue<Grammar> queue)

Method Detail

clearback to summary
protected void clear()
com.sun.org.apache.xerces.internal.jaxp.validation back to summary

pack-priv final Class SoftReferenceGrammarPool.SoftGrammarReference

extends SoftReference<Grammar>
Class Inheritance

This class stores a soft reference to a grammar object. It keeps a reference to its associated entry, so that it can be easily removed from the pool.

Field Summary

Modifier and TypeField and Description
public SoftReferenceGrammarPool.Entry

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Inherited from java.lang.ref.SoftReference:
get

Field Detail

entryback to summary
public SoftReferenceGrammarPool.Entry entry

Constructor Detail

SoftGrammarReferenceback to summary
protected SoftGrammarReference(SoftReferenceGrammarPool.Entry entry, Grammar grammar, ReferenceQueue<Grammar> queue)