FileDocCategorySizeDatePackage
ParserConfigurationSettings.javaAPI DocJava SE 5 API11431Fri Aug 26 14:55:56 BST 2005com.sun.org.apache.xerces.internal.util

ParserConfigurationSettings

public class ParserConfigurationSettings extends Object implements XMLComponentManager
This class implements the basic operations for managing parser configuration features and properties. This utility class can be used as a base class for parser configurations or separately to encapsulate a number of parser settings as a component manager.

This class can be constructed with a "parent" settings object (in the form of an XMLComponentManager) that allows parser configuration settings to be "chained" together.

author
Andy Clark, IBM
version
$Id: ParserConfigurationSettings.java,v 1.11 2004/04/25 05:05:50 mrglavas Exp $

Fields Summary
protected static final String
PARSER_SETTINGS
protected ArrayList
fRecognizedProperties
Recognized properties.
protected HashMap
fProperties
Properties.
protected ArrayList
fRecognizedFeatures
Recognized features.
protected HashMap
fFeatures
Features.
protected XMLComponentManager
fParentSettings
Parent parser configuration settings.
Constructors Summary
public ParserConfigurationSettings()
Default Constructor.


    //
    // Constructors
    //

       
      
        this(null);
    
public ParserConfigurationSettings(XMLComponentManager parent)
Constructs a parser configuration settings object with a parent settings object.


        // create storage for recognized features and properties
        fRecognizedFeatures = new ArrayList();
        fRecognizedProperties = new ArrayList();

        // create table for features and properties
        fFeatures = new HashMap();
        fProperties = new HashMap();

        // save parent
        fParentSettings = parent;

    
Methods Summary
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.


        // add recognized features
        int featureIdsCount = featureIds != null ? featureIds.length : 0;
        for (int i = 0; i < featureIdsCount; i++) {
            String featureId = featureIds[i];
            if (!fRecognizedFeatures.contains(featureId)) {
                fRecognizedFeatures.add(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.


        // add recognizedProperties
        int propertyIdsCount = propertyIds != null ? propertyIds.length : 0;
        for (int i = 0; i < propertyIdsCount; i++) {
            String propertyId = propertyIds[i];
            if (!fRecognizedProperties.contains(propertyId)) {
                fRecognizedProperties.add(propertyId);
            }
        }

    
protected voidcheckFeature(java.lang.String featureId)
Check a feature. If feature is known and supported, this method simply returns. Otherwise, the appropriate exception is thrown.

param
featureId The unique identifier (URI) of the feature.
exception
com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the requested feature is not known.


        // check feature
        if (!fRecognizedFeatures.contains(featureId)) {
            if (fParentSettings != null) {
                fParentSettings.getFeature(featureId);
            }
            else {
                short type = XMLConfigurationException.NOT_RECOGNIZED;
                throw new XMLConfigurationException(type, featureId);
            }
        }

    
protected voidcheckProperty(java.lang.String propertyId)
Check a property. If the property is known and supported, this method simply returns. Otherwise, the appropriate exception is thrown.

param
propertyId The unique identifier (URI) of the property being set.
exception
com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the requested feature is not known.


        // check property
        if (!fRecognizedProperties.contains(propertyId)) {
            if (fParentSettings != null) {
                fParentSettings.getProperty(propertyId);
            }
            else {
                short type = XMLConfigurationException.NOT_RECOGNIZED;
                throw new XMLConfigurationException(type, propertyId);
            }
        }

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

param
featureId The feature identifier.
return
true if the feature is supported
throws
XMLConfigurationException Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.


        Boolean state = (Boolean) fFeatures.get(featureId);

        if (state == null) {
            checkFeature(featureId);
            return false;
        }
        return state.booleanValue();

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

param
propertyId The property identifier.
return
the value of the property
throws
XMLConfigurationException Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.


        Object propertyValue = fProperties.get(propertyId);

        if (propertyValue == null) {
            checkProperty(propertyId);
        }

        return propertyValue;

    
public voidsetFeature(java.lang.String featureId, boolean state)
Set the state of a feature. Set the state of any feature in a SAX2 parser. The parser might not recognize the feature, and if it does recognize it, it might not be able to fulfill the request.

param
featureId The unique identifier (URI) of the feature.
param
state The requested state of the feature (true or false).
exception
com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the requested feature is not known.


        // check and store
        checkFeature(featureId);

        fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE);
    
public voidsetProperty(java.lang.String propertyId, java.lang.Object value)
setProperty

param
propertyId
param
value
exception
com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the requested feature is not known.


        // check and store
        checkProperty(propertyId);
		if(value == null){
			fProperties.remove(propertyId);
		}else
        	fProperties.put(propertyId, value);