FileDocCategorySizeDatePackage
CMNodeFactory.javaAPI DocApache Xerces 3.0.16422Fri Sep 14 20:33:54 BST 2007org.apache.xerces.impl.xs.models

CMNodeFactory

public class CMNodeFactory extends Object
xerces.internal
author
Neeraj Bajaj
version
$Id: CMNodeFactory.java 511014 2007-02-23 16:53:57Z mrglavas $

Fields Summary
private static final String
ERROR_REPORTER
Property identifier: error reporter.
private static final String
SECURITY_MANAGER
property identifier: security manager.
private static final boolean
DEBUG
private static final int
MULTIPLICITY
private int
nodeCount
private int
maxNodeLimit
private org.apache.xerces.impl.XMLErrorReporter
fErrorReporter
Error reporter. This property identifier is: http://apache.org/xml/properties/internal/error-reporter
private org.apache.xerces.util.SecurityManager
fSecurityManager
Constructors Summary
public CMNodeFactory()
default constructor

    
       
      
    
Methods Summary
public org.apache.xerces.impl.dtd.models.CMNodegetCMBinOpNode(int type, org.apache.xerces.impl.dtd.models.CMNode leftNode, org.apache.xerces.impl.dtd.models.CMNode rightNode)

        nodeCountCheck() ;
        return new XSCMBinOp(type, leftNode, rightNode) ;
    
public org.apache.xerces.impl.dtd.models.CMNodegetCMLeafNode(int type, java.lang.Object leaf, int id, int position)

        nodeCountCheck();
        return new XSCMLeaf(type, leaf, id, position) ;
    
public org.apache.xerces.impl.dtd.models.CMNodegetCMRepeatingLeafNode(int type, java.lang.Object leaf, int minOccurs, int maxOccurs, int id, int position)

        nodeCountCheck();
        return new XSCMRepeatingLeaf(type, leaf, minOccurs, maxOccurs, id, position);
    
public org.apache.xerces.impl.dtd.models.CMNodegetCMUniOpNode(int type, org.apache.xerces.impl.dtd.models.CMNode childNode)

        nodeCountCheck();
        return new XSCMUniOp(type, childNode) ;
    
public voidnodeCountCheck()

        if( fSecurityManager != null && nodeCount++ > maxNodeLimit){
            if(DEBUG){
                System.out.println("nodeCount = " + nodeCount ) ;
                System.out.println("nodeLimit = " + maxNodeLimit ) ;
            }
            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "maxOccurLimit", new Object[]{ new Integer(maxNodeLimit) }, XMLErrorReporter.SEVERITY_FATAL_ERROR);
            // similarly to entity manager behaviour, take into accont
            // behaviour if continue-after-fatal-error is set.
            nodeCount = 0;
        }
        
    
public voidreset(org.apache.xerces.xni.parser.XMLComponentManager componentManager)

        fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
        try {
            fSecurityManager = (SecurityManager)componentManager.getProperty(SECURITY_MANAGER);
            //we are setting the limit of number of nodes to 3times the maxOccur value..
            if(fSecurityManager != null){
                maxNodeLimit = fSecurityManager.getMaxOccurNodeLimit() * MULTIPLICITY ;
            }
        }
        catch (XMLConfigurationException e) {
            fSecurityManager = null;
        }
        
    
public voidresetNodeCount()

        nodeCount = 0 ;
    
public voidsetProperty(java.lang.String propertyId, java.lang.Object value)
Sets the value of a property. This method is called by the component manager any time after reset when a property changes value.

Note: Components should silently ignore properties that do not affect the operation of the component.

param
propertyId The property identifier.
param
value The value of the property.
throws
SAXNotRecognizedException The component should not throw this exception.
throws
SAXNotSupportedException The component should not throw this exception.


        // Xerces properties
        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
        	final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
        	
            if (suffixLength == Constants.SECURITY_MANAGER_PROPERTY.length() && 
                propertyId.endsWith(Constants.SECURITY_MANAGER_PROPERTY)) {
                fSecurityManager = (SecurityManager)value;                
                maxNodeLimit = (fSecurityManager != null) ? fSecurityManager.getMaxOccurNodeLimit() * MULTIPLICITY : 0 ;
                return;
            }
            if (suffixLength == Constants.ERROR_REPORTER_PROPERTY.length() && 
                propertyId.endsWith(Constants.ERROR_REPORTER_PROPERTY)) {
                fErrorReporter = (XMLErrorReporter)value;
                return;
            }
        }