org.opensaml.xml.parse
Class BasicParserPool

java.lang.Object
  extended by org.opensaml.xml.parse.BasicParserPool
All Implemented Interfaces:
ParserPool

public class BasicParserPool
extends java.lang.Object
implements ParserPool

A pool of JAXP 1.3 DocumentBuilders. Builder retrieved from this pool should be returned to the pool with the method returnBuilder(DocumentBuilder). Builders checked out prior to a change in the pool's properties will not be effected by the change and will be appropriately dealt with when they are returned. If a the pool reaches its max size and another request for a builder is made behavior is dependent upon getCreateBuildersAtPoolLimit(). If this returns the true then a new builder will be created and returned but will be discarded when it is returned. If it returns false a builder will not be created and null will be returned. References to builders are kept by way of SoftReference so that the garbage collector may reap the builders if the system is running out of memory.


Nested Class Summary
protected  class BasicParserPool.DocumentBuilderProxy
          A proxy that prevents the manages document builders retrieved from the parser pool.
 
Constructor Summary
BasicParserPool()
          Constructor.
 
Method Summary
protected  javax.xml.parsers.DocumentBuilder createBuilder()
          Creates a new document builder.
 javax.xml.parsers.DocumentBuilder getBuilder()
          Gets a builder from the pool.
 java.util.Map<java.lang.String,java.lang.Object> getBuilderAttributes()
          Gets the builder attributes used when creating builders.
 java.util.Map<java.lang.String,java.lang.Boolean> getBuilderFeatures()
          Gets the builders' features.
 boolean getCreateBuildersAtPoolLimit()
          Gets whether new builders will be created when the max pool size is reached.
 boolean getIgnoreComments()
          Gets whether the builders ignore comments.
 int getMaxPoolSize()
          Gets the max number of builders the pool will hold.
protected  long getPoolVersion()
          Gets the current pool version.
 javax.xml.validation.Schema getSchema()
          Gets the schema builders use to validate.
protected  void initializePool()
          Initializes the pool with a new set of configuration options.
 boolean isCoalescing()
          Gets whether the builders are coalescing.
 boolean isDTDValidating()
          Gets whether the builders are validating.
 boolean isExpandEntityReferences()
          Gets whether builders expand entity references.
 boolean isIgnoreElementContentWhitespace()
          Get whether the builders ignore element content whitespace.
 boolean isNamespaceAware()
          Gets whether the builders are namespace aware.
 boolean isXincludeAware()
          Gets whether the builders are XInclude aware.
 org.w3c.dom.Document newDocument()
          Convience method for creating a new document with a pooled builder.
 org.w3c.dom.Document parse(java.io.InputStream input)
          Convience method for parsing an XML file using a pooled builder.
 org.w3c.dom.Document parse(java.io.Reader input)
          Convience method for parsing an XML file using a pooled builder.
 void returnBuilder(javax.xml.parsers.DocumentBuilder builder)
          Returns a builder to the pool.
 void setBuilderAttributes(java.util.Map<java.lang.String,java.lang.Object> newAttributes)
          Sets the builder attributes used when creating builders.
 void setBuilderFeatures(java.util.Map<java.lang.String,java.lang.Boolean> newFeatures)
          Sets the the builders' features.
 void setCoalescing(boolean isCoalescing)
          Sets whether the builders are coalescing.
 void setCreateBuildersAtPoolLimit(boolean createBuilders)
          Sets whether new builders will be created when the max pool size is reached.
 void setDTDValidating(boolean isValidating)
          Sets whether the builders are validating.
 void setExpandEntityReferences(boolean expand)
          Sets whether builders expand entity references.
 void setIgnoreComments(boolean ignore)
          Sets whether the builders ignore comments.
 void setIgnoreElementContentWhitespace(boolean ignore)
          Sets whether the builders ignore element content whitespace.
 void setMaxPoolSize(int newSize)
          Sets the max number of builders the pool will hold.
 void setNamespaceAware(boolean isNamespaceAware)
          Sets whether the builders are namespace aware.
 void setSchema(javax.xml.validation.Schema newSchema)
          Sets the schema builders use to validate.
 void setXincludeAware(boolean isXIncludeAware)
          Sets whether the builders are XInclude aware.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicParserPool

public BasicParserPool()
Constructor.

Method Detail

getBuilder

public javax.xml.parsers.DocumentBuilder getBuilder()
                                             throws XMLParserException
Gets a builder from the pool.

Specified by:
getBuilder in interface ParserPool
Returns:
a builder from the pool
Throws:
XMLParserException - thrown if the document builder factory is misconfigured

returnBuilder

public void returnBuilder(javax.xml.parsers.DocumentBuilder builder)
Returns a builder to the pool.

Specified by:
returnBuilder in interface ParserPool
Parameters:
builder - the builder to return

newDocument

public org.w3c.dom.Document newDocument()
                                 throws XMLParserException
Convience method for creating a new document with a pooled builder.

Specified by:
newDocument in interface ParserPool
Returns:
created document
Throws:
XMLParserException - thrown if there is a problem retrieving a builder

parse

public org.w3c.dom.Document parse(java.io.InputStream input)
                           throws XMLParserException
Convience method for parsing an XML file using a pooled builder.

Specified by:
parse in interface ParserPool
Parameters:
input - XML to parse
Returns:
parsed document
Throws:
XMLParserException - thrown if there is a problem retrieving a builder, the input stream can not be read, or the XML was invalid

parse

public org.w3c.dom.Document parse(java.io.Reader input)
                           throws XMLParserException
Convience method for parsing an XML file using a pooled builder.

Specified by:
parse in interface ParserPool
Parameters:
input - XML to parse
Returns:
parsed document
Throws:
XMLParserException - thrown if there is a problem retrieving a builder, the input stream can not be read, or the XML was invalid

getMaxPoolSize

public int getMaxPoolSize()
Gets the max number of builders the pool will hold.

Returns:
max number of builders the pool will hold

setMaxPoolSize

public void setMaxPoolSize(int newSize)
Sets the max number of builders the pool will hold.

Parameters:
newSize - max number of builders the pool will hold

getCreateBuildersAtPoolLimit

public boolean getCreateBuildersAtPoolLimit()
Gets whether new builders will be created when the max pool size is reached.

Returns:
whether new builders will be created when the max pool size is reached

setCreateBuildersAtPoolLimit

public void setCreateBuildersAtPoolLimit(boolean createBuilders)
Sets whether new builders will be created when the max pool size is reached.

Parameters:
createBuilders - whether new builders will be created when the max pool size is reached

getBuilderAttributes

public java.util.Map<java.lang.String,java.lang.Object> getBuilderAttributes()
Gets the builder attributes used when creating builders. This collection is unmodifiable.

Returns:
builder attributes used when creating builders

setBuilderAttributes

public void setBuilderAttributes(java.util.Map<java.lang.String,java.lang.Object> newAttributes)
Sets the builder attributes used when creating builders.

Parameters:
newAttributes - builder attributes used when creating builders

isCoalescing

public boolean isCoalescing()
Gets whether the builders are coalescing.

Returns:
whether the builders are coalescing

setCoalescing

public void setCoalescing(boolean isCoalescing)
Sets whether the builders are coalescing.

Parameters:
isCoalescing - whether the builders are coalescing

isExpandEntityReferences

public boolean isExpandEntityReferences()
Gets whether builders expand entity references.

Returns:
whether builders expand entity references

setExpandEntityReferences

public void setExpandEntityReferences(boolean expand)
Sets whether builders expand entity references.

Parameters:
expand - whether builders expand entity references

getBuilderFeatures

public java.util.Map<java.lang.String,java.lang.Boolean> getBuilderFeatures()
Gets the builders' features. This collection is unmodifiable.

Returns:
the builders' features

setBuilderFeatures

public void setBuilderFeatures(java.util.Map<java.lang.String,java.lang.Boolean> newFeatures)
Sets the the builders' features.

Parameters:
newFeatures - the builders' features

getIgnoreComments

public boolean getIgnoreComments()
Gets whether the builders ignore comments.

Returns:
whether the builders ignore comments

setIgnoreComments

public void setIgnoreComments(boolean ignore)
Sets whether the builders ignore comments.

Parameters:
ignore - The ignoreComments to set.

isIgnoreElementContentWhitespace

public boolean isIgnoreElementContentWhitespace()
Get whether the builders ignore element content whitespace.

Returns:
whether the builders ignore element content whitespace

setIgnoreElementContentWhitespace

public void setIgnoreElementContentWhitespace(boolean ignore)
Sets whether the builders ignore element content whitespace.

Parameters:
ignore - whether the builders ignore element content whitespace

isNamespaceAware

public boolean isNamespaceAware()
Gets whether the builders are namespace aware.

Returns:
whether the builders are namespace aware

setNamespaceAware

public void setNamespaceAware(boolean isNamespaceAware)
Sets whether the builders are namespace aware.

Parameters:
isNamespaceAware - whether the builders are namespace aware

getSchema

public javax.xml.validation.Schema getSchema()
Gets the schema builders use to validate.

Specified by:
getSchema in interface ParserPool
Returns:
the schema builders use to validate

setSchema

public void setSchema(javax.xml.validation.Schema newSchema)
Sets the schema builders use to validate.

Specified by:
setSchema in interface ParserPool
Parameters:
newSchema - the schema builders use to validate

isDTDValidating

public boolean isDTDValidating()
Gets whether the builders are validating.

Returns:
whether the builders are validating

setDTDValidating

public void setDTDValidating(boolean isValidating)
Sets whether the builders are validating.

Parameters:
isValidating - whether the builders are validating

isXincludeAware

public boolean isXincludeAware()
Gets whether the builders are XInclude aware.

Returns:
whether the builders are XInclude aware

setXincludeAware

public void setXincludeAware(boolean isXIncludeAware)
Sets whether the builders are XInclude aware.

Parameters:
isXIncludeAware - whether the builders are XInclude aware

getPoolVersion

protected long getPoolVersion()
Gets the current pool version.

Returns:
current pool version

initializePool

protected void initializePool()
                       throws XMLParserException
Initializes the pool with a new set of configuration options.

Throws:
XMLParserException - thrown if there is a problem initialzing the pool

createBuilder

protected javax.xml.parsers.DocumentBuilder createBuilder()
                                                   throws XMLParserException
Creates a new document builder.

Returns:
newly created document builder
Throws:
XMLParserException - thrown if their is a configuration error with the builder factory


Copyright © 2006-2011 Internet2. All Rights Reserved.