1 16 17 18 package org.apache.xerces.impl.xs.models; 19 20 import org.apache.xerces.impl.XMLErrorReporter; 21 import org.apache.xerces.xni.parser.XMLComponentManager; 22 import org.apache.xerces.util.SecurityManager ; 23 import org.apache.xerces.impl.dtd.models.CMNode; 24 import org.apache.xerces.xni.parser.XMLConfigurationException; 25 import org.apache.xerces.impl.xs.XSMessageFormatter; 26 import org.apache.xerces.impl.Constants; 27 28 35 public class CMNodeFactory { 36 37 38 39 private static final String ERROR_REPORTER = 40 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 41 42 43 private static final String SECURITY_MANAGER = 44 Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY; 45 46 private static final boolean DEBUG = false ; 47 48 private static final int MULTIPLICITY = 1 ; 50 51 private int nodeCount = 0; 53 54 private int maxNodeLimit ; 56 57 58 62 private XMLErrorReporter fErrorReporter; 63 64 private SecurityManager fSecurityManager = null; 67 68 69 public CMNodeFactory() { 70 } 71 72 public void reset(XMLComponentManager componentManager){ 73 fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER); 74 try { 75 fSecurityManager = (SecurityManager )componentManager.getProperty(SECURITY_MANAGER); 76 if(fSecurityManager != null){ 78 maxNodeLimit = fSecurityManager.getMaxOccurNodeLimit() * MULTIPLICITY ; 79 } 80 } 81 catch (XMLConfigurationException e) { 82 fSecurityManager = null; 83 } 84 85 } 87 public CMNode getCMLeafNode(int type, Object leaf, int id, int position) { 88 nodeCountCheck() ; 89 return new XSCMLeaf(type, leaf, id, position) ; 90 } 91 92 public CMNode getCMUniOpNode(int type, CMNode childNode) { 93 nodeCountCheck(); 94 return new XSCMUniOp(type, childNode) ; 95 } 96 97 public CMNode getCMBinOpNode(int type, CMNode leftNode, CMNode rightNode) { 98 nodeCountCheck() ; 99 return new XSCMBinOp(type, leftNode, rightNode) ; 100 } 101 102 public void nodeCountCheck(){ 103 if( fSecurityManager != null && nodeCount++ > maxNodeLimit){ 104 if(DEBUG){ 105 System.out.println("nodeCount = " + nodeCount ) ; 106 System.out.println("nodeLimit = " + maxNodeLimit ) ; 107 } 108 fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, "maxOccurLimit", new Object []{ new Integer (maxNodeLimit) }, XMLErrorReporter.SEVERITY_FATAL_ERROR); 109 nodeCount = 0; 112 } 113 114 } 116 public void resetNodeCount(){ 118 nodeCount = 0 ; 119 } 120 135 public void setProperty(String propertyId, Object value) 136 throws XMLConfigurationException { 137 138 if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { 140 final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); 141 142 if (suffixLength == Constants.SECURITY_MANAGER_PROPERTY.length() && 143 propertyId.endsWith(Constants.SECURITY_MANAGER_PROPERTY)) { 144 fSecurityManager = (SecurityManager )value; 145 maxNodeLimit = (fSecurityManager != null) ? fSecurityManager.getMaxOccurNodeLimit() * MULTIPLICITY : 0 ; 146 return; 147 } 148 if (suffixLength == Constants.ERROR_REPORTER_PROPERTY.length() && 149 propertyId.endsWith(Constants.ERROR_REPORTER_PROPERTY)) { 150 fErrorReporter = (XMLErrorReporter)value; 151 return; 152 } 153 } 154 155 } 157 } | Popular Tags |