1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 59 60 import java.util.Stack ; 61 import java.util.Vector ; 62 63 import com.sun.org.apache.xerces.internal.impl.validation.ValidationState; 64 import com.sun.org.apache.xerces.internal.impl.xs.SchemaNamespaceSupport; 65 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 66 import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaException; 67 import com.sun.org.apache.xerces.internal.impl.xs.util.XInt; 68 import com.sun.org.apache.xerces.internal.util.DOMUtil; 69 import com.sun.org.apache.xerces.internal.util.SymbolTable; 70 import org.w3c.dom.Document ; 71 import org.w3c.dom.Element ; 72 73 82 class XSDocumentInfo { 83 84 protected SchemaNamespaceSupport fNamespaceSupport; 86 protected SchemaNamespaceSupport fNamespaceSupportRoot; 87 protected Stack SchemaNamespaceSupportStack = new Stack (); 88 89 protected boolean fAreLocalAttributesQualified; 91 92 protected boolean fAreLocalElementsQualified; 94 95 protected short fBlockDefault; 97 protected short fFinalDefault; 98 99 String fTargetNamespace; 101 102 protected boolean fIsChameleonSchema; 104 105 protected Document fSchemaDoc; 107 108 Vector fImportedNS = new Vector (); 110 111 protected ValidationState fValidationContext = new ValidationState(); 112 113 SymbolTable fSymbolTable = null; 114 115 protected XSAttributeChecker fAttrChecker; 118 119 protected Object [] fSchemaAttrs; 122 123 XSDocumentInfo (Document schemaDoc, XSAttributeChecker attrChecker, SymbolTable symbolTable) 126 throws XMLSchemaException { 127 fSchemaDoc = schemaDoc; 128 fNamespaceSupport = new SchemaNamespaceSupport(); 129 fNamespaceSupport.reset(); 130 fIsChameleonSchema = false; 131 132 fSymbolTable = symbolTable; 133 fAttrChecker = attrChecker; 134 135 if(schemaDoc != null) { 136 Element root = DOMUtil.getRoot(schemaDoc); 137 fSchemaAttrs = attrChecker.checkAttributes(root, true, this); 138 if (fSchemaAttrs == null) { 142 throw new XMLSchemaException(null, null); 143 } 144 fAreLocalAttributesQualified = 145 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_AFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; 146 fAreLocalElementsQualified = 147 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_EFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; 148 fBlockDefault = 149 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_BLOCKDEFAULT]).shortValue(); 150 fFinalDefault = 151 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_FINALDEFAULT]).shortValue(); 152 fTargetNamespace = 153 (String )fSchemaAttrs[XSAttributeChecker.ATTIDX_TARGETNAMESPACE]; 154 if (fTargetNamespace != null) 155 fTargetNamespace = symbolTable.addSymbol(fTargetNamespace); 156 157 fNamespaceSupportRoot = new SchemaNamespaceSupport(fNamespaceSupport); 158 159 fValidationContext.setNamespaceSupport(fNamespaceSupport); 161 fValidationContext.setSymbolTable(symbolTable); 162 165 } 168 } 169 170 void backupNSSupport(SchemaNamespaceSupport nsSupport) { 173 SchemaNamespaceSupportStack.push(fNamespaceSupport); 174 if (nsSupport == null) 175 nsSupport = fNamespaceSupportRoot; 176 fNamespaceSupport = new SchemaNamespaceSupport(nsSupport); 177 178 fValidationContext.setNamespaceSupport(fNamespaceSupport); 179 } 180 181 void restoreNSSupport() { 182 fNamespaceSupport = (SchemaNamespaceSupport)SchemaNamespaceSupportStack.pop(); 183 fValidationContext.setNamespaceSupport(fNamespaceSupport); 184 } 185 186 public String toString() { 188 return fTargetNamespace == null?"no targetNamspace":"targetNamespace is " + fTargetNamespace; 189 } 190 191 public void addAllowedNS(String namespace) { 192 fImportedNS.addElement(namespace == null ? "" : namespace); 193 } 194 195 public boolean isAllowedNS(String namespace) { 196 return fImportedNS.contains(namespace == null ? "" : namespace); 197 } 198 199 private Vector fReportedTNS = null; 202 final boolean needReportTNSError(String uri) { 206 if (fReportedTNS == null) 207 fReportedTNS = new Vector (); 208 else if (fReportedTNS.contains(uri)) 209 return false; 210 fReportedTNS.addElement(uri); 211 return true; 212 } 213 214 Object [] getSchemaAttrs () { 216 return fSchemaAttrs; 217 } 218 219 void returnSchemaAttrs () { 222 fAttrChecker.returnAttrArray (fSchemaAttrs, null); 223 fSchemaAttrs = null; 224 } 225 226 } | Popular Tags |