org.apache.cocoon.components.validation.jing
Class JingResolver

java.lang.Object
  extended by org.apache.cocoon.components.validation.impl.ValidationResolver
      extended by org.apache.cocoon.components.validation.jing.JingResolver
All Implemented Interfaces:
com.thaiopensource.xml.sax.XMLReaderCreator, EntityResolver

public class JingResolver
extends ValidationResolver
implements com.thaiopensource.xml.sax.XMLReaderCreator

A simple resolver used when parsing RELAX NG schemas through the use of JING.

This is not thread safe and not recyclable. Once used, it must be garbage collected.


Constructor Summary
JingResolver(SourceResolver sourceResolver, EntityResolver entityResolver)
          Create a new JingResolver instance.
 
Method Summary
 XMLReader createXMLReader()
          Create an XMLReader instance that can be used by JING for parsing schemas.
 InputSource popInputSource()
          Pop the last InputSource from the stack used for relative URIs resolution.
 void pushInputSource(InputSource inputSource)
          Push a new InputSource in the stack used for relative URIs resolution.
 InputSource resolveEntity(String publicId, String systemId)
          Resolve an InputSource from a public ID and/or a system ID.
 
Methods inherited from class org.apache.cocoon.components.validation.impl.ValidationResolver
close, finalize, resolveEntity, resolveEntity, resolveSource, resolveSource, resolveSource
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JingResolver

public JingResolver(SourceResolver sourceResolver,
                    EntityResolver entityResolver)

Create a new JingResolver instance.

Method Detail

pushInputSource

public void pushInputSource(InputSource inputSource)

Push a new InputSource in the stack used for relative URIs resolution.


popInputSource

public InputSource popInputSource()

Pop the last InputSource from the stack used for relative URIs resolution.


resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws SAXException,
                                 IOException

Resolve an InputSource from a public ID and/or a system ID.

This method can be called only while a schema is being parsed and will resolve URIs against a dynamic Stack of InputSources.

Since JING doesn't offer a complete URI resolution contract, a Stack is kept for all the sources parsed while reading a schema. Keeping in mind that the last InputSource pushed in the Stack can be considered to be the "base URI" for the current resolution, full relative resolution of system IDs can be achieved this way.

Note that this method of resolving URIs by keeping a Stack of processed URIs is a sort of a hack, but it mimics the internal state of JING itself: if URI resolution fails, the Stack analysis is the first part to look at.

Resolution will use the EntityResolver specified at construction to resolve public IDs, and then the SourceResolver again specified at construction to resolve the system IDs and to access the underlying byte streams of the entities to be parsed.

Specified by:
resolveEntity in interface EntityResolver
Overrides:
resolveEntity in class ValidationResolver
Parameters:
publicId - the public ID of the entity to resolve.
systemId - the system ID of the entity to resolve.
Returns:
a non-null InputSource instance.
Throws:
IOException - if an I/O error occurred resolving the entity.
SAXException - if an XML error occurred resolving the entity.

createXMLReader

public XMLReader createXMLReader()
                          throws SAXException

Create an XMLReader instance that can be used by JING for parsing schemas.

The returned XMLReader will keep track of populating/clearing the Stack of InputSources kept for URI resolution as explained in the description of the resolveEntity(String, String) method.

Specified by:
createXMLReader in interface com.thaiopensource.xml.sax.XMLReaderCreator
Returns:
a non-null XMLReader instance.
Throws:
SAXException - if an error occurrent creating the XMLReader.
See Also:
JingReader


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