org.apache.cocoon.components.validation.impl
Class CachingValidator

java.lang.Object
  extended by org.apache.cocoon.components.validation.impl.AbstractValidator
      extended by org.apache.cocoon.components.validation.impl.DefaultValidator
          extended by org.apache.cocoon.components.validation.impl.CachingValidator
All Implemented Interfaces:
Disposable, Initializable, Configurable, Contextualizable, LogEnabled, Serviceable, ServiceSelector, ThreadSafe, Validator

public class CachingValidator
extends DefaultValidator

An extension of the DefaultValidator class allowing Schema instances to be cached.

The getSchema(SchemaParser, Source, String) method will manage whether to return a cached or a freshly parsed Schema instance.


Field Summary
 
Fields inherited from class org.apache.cocoon.components.validation.impl.AbstractValidator
logger, manager, resolver
 
Fields inherited from interface org.apache.cocoon.components.validation.Validator
GRAMMAR_ISO_SCHEMATRON, GRAMMAR_RELAX_CORE, GRAMMAR_RELAX_NG, GRAMMAR_RELAX_NS, GRAMMAR_SCHEMATRON, GRAMMAR_TREX, GRAMMAR_XML_DTD, GRAMMAR_XML_SCHEMA, ROLE
 
Constructor Summary
CachingValidator()
          Create a new CachingValidator instance.
 
Method Summary
protected  String detectGrammar(Source source)
          Attempt to detect the grammar language used by the schema identified by the specified Source.
 void dispose()
          Dispose this component instance.
 Schema getSchema(SchemaParser parser, Source source, String grammar)
          Return a Schema instance from the specified SchemaParser associated with the given Source and grammar language.
 void initialize()
          Initialize this component instance.
 
Methods inherited from class org.apache.cocoon.components.validation.impl.DefaultValidator
configure, contextualize, isSelectable, lookupParserByGrammar, lookupParserByName, release, releaseParser, select
 
Methods inherited from class org.apache.cocoon.components.validation.impl.AbstractValidator
enableLogging, getValidationHandler, getValidationHandler, getValidationHandler, getValidationHandler, getValidationHandler, getValidationHandler, getValidationHandler, getValidationHandler, service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingValidator

public CachingValidator()

Create a new CachingValidator instance.

Method Detail

initialize

public void initialize()
                throws Exception

Initialize this component instance.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class DefaultValidator
Throws:
Exception

dispose

public void dispose()

Dispose this component instance.

Specified by:
dispose in interface Disposable
Overrides:
dispose in class DefaultValidator

getSchema

public Schema getSchema(SchemaParser parser,
                        Source source,
                        String grammar)
                 throws IOException,
                        SAXException

Return a Schema instance from the specified SchemaParser associated with the given Source and grammar language.

This method will overriding the default behaviour specified by the AbstractValidator.getSchema(SchemaParser, Source, String) method, and supports cacheability of Schema instances through the use of a Store looked up using the Store.TRANSIENT_STORE Avalon role.

Cached Schema instances will be retained in the configured Store until the checks on the validity obtained calling the Schema.getValidity() method will declare that the schema is still valid.

Overrides:
getSchema in class AbstractValidator
Parameters:
parser - the SchemaParser producing the Schema.
source - the Source associated with the Schema to return.
grammar - the grammar language of the schema to produce.
Throws:
SAXException - if a grammar error occurred parsing the schema.
IOException - if an I/O error occurred parsing the schema.

detectGrammar

protected String detectGrammar(Source source)
                        throws IOException,
                               SAXException,
                               ValidatorException

Attempt to detect the grammar language used by the schema identified by the specified Source.

The grammar languages detected will be cached until the Source's SourceValidity declares that the schema is valid.

Overrides:
detectGrammar in class AbstractValidator
Parameters:
source - a Source instance pointing to the schema to be analyzed.
Throws:
IOException - if an I/O error occurred accessing the schema.
SAXException - if an error occurred parsing the schema.
ValidatorException - if the language of the schema could not be guessed.


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.