FileDocCategorySizeDatePackage
AbstractConfiguration.javaAPI DocApache Xerces 3.0.115245Fri Sep 14 20:33:58 BST 2007xni.parser

AbstractConfiguration

public abstract class AbstractConfiguration extends Object implements org.apache.xerces.xni.parser.XMLParserConfiguration
This abstract parser configuration simply helps manage components, features and properties, and other tasks common to all parser configurations. In order to subclass this configuration and use it effectively, the subclass is required to do the following:
  • Add all configurable components using the addComponent method,
  • Implement the parse method, and
  • Call the resetComponents before parsing.
author
Andy Clark, IBM
version
$Id: AbstractConfiguration.java 447690 2006-09-19 02:41:53Z mrglavas $

Fields Summary
protected final Vector
fRecognizedFeatures
Recognized features.
protected final Vector
fRecognizedProperties
Recognized properties.
protected final Hashtable
fFeatures
Features.
protected final Hashtable
fProperties
Properties.
protected org.apache.xerces.xni.parser.XMLEntityResolver
fEntityResolver
The registered entity resolver.
protected org.apache.xerces.xni.parser.XMLErrorHandler
fErrorHandler
The registered error handler.
protected org.apache.xerces.xni.XMLDocumentHandler
fDocumentHandler
The registered document handler.
protected org.apache.xerces.xni.XMLDTDHandler
fDTDHandler
The registered DTD handler.
protected org.apache.xerces.xni.XMLDTDContentModelHandler
fDTDContentModelHandler
The registered DTD content model handler.
protected Locale
fLocale
Locale for error messages.
protected final Vector
fComponents
List of configurable components.
Constructors Summary
Methods Summary
protected voidaddComponent(org.apache.xerces.xni.parser.XMLComponent component)
Adds a component to list of configurable components. If the same component is added multiple times, the component is added only the first time.

This method helps manage the components in the configuration. Therefore, all subclasses should call this method to add the components specific to the configuration.

param
component The component to add.
see
#resetComponents

        if (!fComponents.contains(component)) {
            fComponents.addElement(component);
            addRecognizedFeatures(component.getRecognizedFeatures());
            addRecognizedProperties(component.getRecognizedProperties());
        }
    
public voidaddRecognizedFeatures(java.lang.String[] featureIds)
Allows a parser to add parser specific features to be recognized and managed by the parser configuration.

param
featureIds An array of the additional feature identifiers to be recognized.


    //
    // XMLParserConfiguration methods
    //

                                                         
        
        int length = featureIds != null ? featureIds.length : 0;
        for (int i = 0; i < length; i++) {
            String featureId = featureIds[i];
            if (!fRecognizedFeatures.contains(featureId)) {
                fRecognizedFeatures.addElement(featureId);
            }
        }
    
public voidaddRecognizedProperties(java.lang.String[] propertyIds)
Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.

param
propertyIds An array of the additional property identifiers to be recognized.

        int length = propertyIds != null ? propertyIds.length : 0;
        for (int i = 0; i < length; i++) {
            String propertyId = propertyIds[i];
            if (!fRecognizedProperties.contains(propertyId)) {
                fRecognizedProperties.addElement(propertyId);
            }
        }
    
public org.apache.xerces.xni.XMLDTDContentModelHandlergetDTDContentModelHandler()
Returns the registered DTD content model handler.

        return fDTDContentModelHandler;
    
public org.apache.xerces.xni.XMLDTDHandlergetDTDHandler()
Returns the registered DTD handler.

        return fDTDHandler;
    
public org.apache.xerces.xni.XMLDocumentHandlergetDocumentHandler()
Returns the registered document handler.

        return fDocumentHandler;
    
public org.apache.xerces.xni.parser.XMLEntityResolvergetEntityResolver()
Returns the registered entity resolver.

        return fEntityResolver;
    
public org.apache.xerces.xni.parser.XMLErrorHandlergetErrorHandler()
Returns the registered error handler.

        return fErrorHandler;
    
public booleangetFeature(java.lang.String featureId)
Returns the state of a feature.

param
featureId The feature identifier.
throws
XMLConfigurationException Thrown if there is a configuration error.

        if (!fRecognizedFeatures.contains(featureId)) {
            short type = XMLConfigurationException.NOT_RECOGNIZED;
            throw new XMLConfigurationException(type, featureId);
        }
        Boolean state = (Boolean)fFeatures.get(featureId);
        return state != null ? state.booleanValue() : false;
    
public java.util.LocalegetLocale()
Returns the locale.

        return fLocale;
    
public java.lang.ObjectgetProperty(java.lang.String propertyId)
Returns the value of a property.

param
propertyId The property identifier.
throws
XMLConfigurationException Thrown if there is a configuration error.

        if (!fRecognizedProperties.contains(propertyId)) {
            short type = XMLConfigurationException.NOT_RECOGNIZED;
            throw new XMLConfigurationException(type, propertyId);
        }
        Object value = fProperties.get(propertyId);
        return value;
    
protected voidopenInputSourceStream(org.apache.xerces.xni.parser.XMLInputSource source)
This method tries to open the necessary stream for the given XMLInputSource. If the input source already has a character stream (java.io.Reader) or a byte stream (java.io.InputStream) set, this method returns immediately. However, if no character or byte stream is already open, this method attempts to open an input stream using the source's system identifier.

param
source The input source to open.

        if (source.getCharacterStream() != null) {
            return;
        }
        InputStream stream = source.getByteStream();
        if (stream == null) {
            String systemId = source.getSystemId();
            try {
                URL url = new URL(systemId);
                stream = url.openStream();
            }
            catch (MalformedURLException e) {
                stream = new FileInputStream(systemId);
            }
            source.setByteStream(stream);
        }
    
public abstract voidparse(org.apache.xerces.xni.parser.XMLInputSource inputSource)
Parse an XML document.

The parser can use this method to instruct this configuration to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI).

Parsers may not invoke this method while a parse is in progress. Once a parse is complete, the parser may then parse another XML document.

This method is synchronous: it will not return until parsing has ended. If a client application wants to terminate parsing early, it should throw an exception.

Note: This method needs to be implemented by the subclass.

param
source The input source for the top-level of the XML document.
exception
XNIException Any XNI exception, possibly wrapping another exception.
exception
IOException An IO exception from the parser, possibly from a byte stream or character stream supplied by the parser.

protected voidresetComponents()
Resets all of the registered components. Before the subclassed configuration begins parsing, it should call this method to reset the components.

see
#addComponent

        int length = fComponents.size();
        for (int i = 0; i < length; i++) {
            XMLComponent component = (XMLComponent)fComponents.elementAt(i);
            component.reset(this);
        }
    
public voidsetDTDContentModelHandler(org.apache.xerces.xni.XMLDTDContentModelHandler handler)
Sets the DTD content model handler.

param
handler The DTD content model handler.

        fDTDContentModelHandler = handler;
    
public voidsetDTDHandler(org.apache.xerces.xni.XMLDTDHandler handler)
Sets the DTD handler.

param
handler The DTD handler.

        fDTDHandler = handler;
    
public voidsetDocumentHandler(org.apache.xerces.xni.XMLDocumentHandler handler)
Sets the document handler to receive information about the document.

param
handler The document handler.

        fDocumentHandler = handler;
    
public voidsetEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver resolver)
Sets the entity resolver.

param
resolver The new entity resolver.

        fEntityResolver = resolver;
    
public voidsetErrorHandler(org.apache.xerces.xni.parser.XMLErrorHandler handler)
Sets the error handler.

param
handler The error resolver.

        fErrorHandler = handler;
    
public voidsetFeature(java.lang.String featureId, boolean state)
Sets the state of a feature. This method is called by the parser and gets propagated to components in this parser configuration.

param
featureId The feature identifier.
param
state The state of the feature.
throws
XMLConfigurationException Thrown if there is a configuration error.

        if (!fRecognizedFeatures.contains(featureId)) {
            short type = XMLConfigurationException.NOT_RECOGNIZED;
            throw new XMLConfigurationException(type, featureId);
        }
        fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE);
        int length = fComponents.size();
        for (int i = 0; i < length; i++) {
            XMLComponent component = (XMLComponent)fComponents.elementAt(i);
            component.setFeature(featureId, state);
        }
    
public voidsetLocale(java.util.Locale locale)
Set the locale to use for messages.

param
locale The locale object to use for localization of messages.
exception
XNIException Thrown if the parser does not support the specified locale.

        fLocale = locale;
    
public voidsetProperty(java.lang.String propertyId, java.lang.Object value)
Sets the value of a property. This method is called by the parser and gets propagated to components in this parser configuration.

param
propertyId The property identifier.
param
value The value of the property.
throws
XMLConfigurationException Thrown if there is a configuration error.

        if (!fRecognizedProperties.contains(propertyId)) {
            short type = XMLConfigurationException.NOT_RECOGNIZED;
            throw new XMLConfigurationException(type, propertyId);
        }
        if (value != null) {
            fProperties.put(propertyId, value);
        }
        else {
            fProperties.remove(propertyId);
        }
        int length = fComponents.size();
        for (int i = 0; i < length; i++) {
            XMLComponent component = (XMLComponent)fComponents.elementAt(i);
            component.setProperty(propertyId, value);
        }