1 16 17 package org.apache.xerces.impl.xs.traversers; 18 19 import java.util.Stack ; 20 import java.util.Vector ; 21 22 import org.apache.xerces.impl.validation.ValidationState; 23 import org.apache.xerces.impl.xs.SchemaNamespaceSupport; 24 import org.apache.xerces.impl.xs.SchemaSymbols; 25 import org.apache.xerces.impl.xs.XMLSchemaException; 26 import org.apache.xerces.impl.xs.util.XInt; 27 import org.apache.xerces.util.SymbolTable; 28 import org.w3c.dom.Element ; 29 30 41 class XSDocumentInfo { 42 43 protected SchemaNamespaceSupport fNamespaceSupport; 45 protected SchemaNamespaceSupport fNamespaceSupportRoot; 46 protected Stack SchemaNamespaceSupportStack = new Stack (); 47 48 protected boolean fAreLocalAttributesQualified; 50 51 protected boolean fAreLocalElementsQualified; 53 54 protected short fBlockDefault; 56 protected short fFinalDefault; 57 58 String fTargetNamespace; 60 61 protected boolean fIsChameleonSchema; 63 64 protected Element fSchemaElement; 66 67 Vector fImportedNS = new Vector (); 69 70 protected ValidationState fValidationContext = new ValidationState(); 71 72 SymbolTable fSymbolTable = null; 73 74 protected XSAttributeChecker fAttrChecker; 77 78 protected Object [] fSchemaAttrs; 81 82 protected XSAnnotationInfo fAnnotations = null; 85 86 XSDocumentInfo (Element schemaRoot, XSAttributeChecker attrChecker, SymbolTable symbolTable) 89 throws XMLSchemaException { 90 fSchemaElement = schemaRoot; 91 fNamespaceSupport = new SchemaNamespaceSupport(); 92 fNamespaceSupport.reset(); 93 fIsChameleonSchema = false; 94 95 fSymbolTable = symbolTable; 96 fAttrChecker = attrChecker; 97 98 if (schemaRoot != null) { 99 Element root = schemaRoot; 100 fSchemaAttrs = attrChecker.checkAttributes(root, true, this); 101 if (fSchemaAttrs == null) { 105 throw new XMLSchemaException(null, null); 106 } 107 fAreLocalAttributesQualified = 108 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_AFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; 109 fAreLocalElementsQualified = 110 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_EFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED; 111 fBlockDefault = 112 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_BLOCKDEFAULT]).shortValue(); 113 fFinalDefault = 114 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_FINALDEFAULT]).shortValue(); 115 fTargetNamespace = 116 (String )fSchemaAttrs[XSAttributeChecker.ATTIDX_TARGETNAMESPACE]; 117 if (fTargetNamespace != null) 118 fTargetNamespace = symbolTable.addSymbol(fTargetNamespace); 119 120 fNamespaceSupportRoot = new SchemaNamespaceSupport(fNamespaceSupport); 121 122 fValidationContext.setNamespaceSupport(fNamespaceSupport); 124 fValidationContext.setSymbolTable(symbolTable); 125 128 } 131 } 132 133 void backupNSSupport(SchemaNamespaceSupport nsSupport) { 136 SchemaNamespaceSupportStack.push(fNamespaceSupport); 137 if (nsSupport == null) 138 nsSupport = fNamespaceSupportRoot; 139 fNamespaceSupport = new SchemaNamespaceSupport(nsSupport); 140 141 fValidationContext.setNamespaceSupport(fNamespaceSupport); 142 } 143 144 void restoreNSSupport() { 145 fNamespaceSupport = (SchemaNamespaceSupport)SchemaNamespaceSupportStack.pop(); 146 fValidationContext.setNamespaceSupport(fNamespaceSupport); 147 } 148 149 public String toString() { 151 return fTargetNamespace == null?"no targetNamspace":"targetNamespace is " + fTargetNamespace; 152 } 153 154 public void addAllowedNS(String namespace) { 155 fImportedNS.addElement(namespace == null ? "" : namespace); 156 } 157 158 public boolean isAllowedNS(String namespace) { 159 return fImportedNS.contains(namespace == null ? "" : namespace); 160 } 161 162 private Vector fReportedTNS = null; 165 final boolean needReportTNSError(String uri) { 169 if (fReportedTNS == null) 170 fReportedTNS = new Vector (); 171 else if (fReportedTNS.contains(uri)) 172 return false; 173 fReportedTNS.addElement(uri); 174 return true; 175 } 176 177 Object [] getSchemaAttrs () { 179 return fSchemaAttrs; 180 } 181 182 void returnSchemaAttrs () { 185 fAttrChecker.returnAttrArray (fSchemaAttrs, null); 186 fSchemaAttrs = null; 187 } 188 189 void addAnnotation(XSAnnotationInfo info) { 191 info.next = fAnnotations; 192 fAnnotations = info; 193 } 194 195 XSAnnotationInfo getAnnotations() { 198 return fAnnotations; 199 } 200 201 void removeAnnotations() { 203 fAnnotations = null; 204 } 205 206 } | Popular Tags |