1 57 58 package com.sun.org.apache.xerces.internal.impl.xs; 59 60 import java.io.IOException ; 61 import java.util.Enumeration ; 62 import java.util.Hashtable ; 63 import java.util.HashMap ; 64 import java.util.Stack ; 65 import java.util.Vector ; 66 67 import com.sun.org.apache.xerces.internal.impl.Constants; 68 import com.sun.org.apache.xerces.internal.impl.RevalidationHandler; 69 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 70 import com.sun.org.apache.xerces.internal.impl.dv.DatatypeException; 71 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 72 import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo; 73 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 74 import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl; 75 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; 76 import com.sun.org.apache.xerces.internal.impl.validation.ValidationState; 77 import com.sun.org.apache.xerces.internal.impl.xs.identity.Field; 78 import com.sun.org.apache.xerces.internal.impl.xs.identity.FieldActivator; 79 import com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint; 80 import com.sun.org.apache.xerces.internal.impl.xs.identity.KeyRef; 81 import com.sun.org.apache.xerces.internal.impl.xs.identity.Selector; 82 import com.sun.org.apache.xerces.internal.impl.xs.identity.UniqueOrKey; 83 import com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore; 84 import com.sun.org.apache.xerces.internal.impl.xs.identity.XPathMatcher; 85 import com.sun.org.apache.xerces.internal.impl.xs.models.CMBuilder; 86 import com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory; 87 import com.sun.org.apache.xerces.internal.impl.xs.models.XSCMValidator; 88 import com.sun.org.apache.xerces.internal.xs.XSConstants; 89 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 90 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 91 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl; 92 import com.sun.org.apache.xerces.internal.util.IntStack; 93 import com.sun.org.apache.xerces.internal.util.SymbolTable; 94 import com.sun.org.apache.xerces.internal.util.XMLChar; 95 import com.sun.org.apache.xerces.internal.util.XMLResourceIdentifierImpl; 96 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 97 import com.sun.org.apache.xerces.internal.xni.Augmentations; 98 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 99 import com.sun.org.apache.xerces.internal.xni.QName; 100 import com.sun.org.apache.xerces.internal.xni.XMLAttributes; 101 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 102 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 103 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 104 import com.sun.org.apache.xerces.internal.xni.XMLString; 105 import com.sun.org.apache.xerces.internal.xni.XNIException; 106 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 107 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 108 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 109 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 110 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 111 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentFilter; 112 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 113 import com.sun.org.apache.xerces.internal.xni.parser.XMLEntityResolver; 114 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 115 import com.sun.org.apache.xerces.internal.xs.AttributePSVI; 116 import com.sun.org.apache.xerces.internal.xs.ElementPSVI; 117 import com.sun.org.apache.xerces.internal.xs.XSComplexTypeDefinition; 118 119 141 public class XMLSchemaValidator 142 implements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler { 143 144 private static final boolean DEBUG = false; 148 149 151 152 protected static final String VALIDATION = 153 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 154 155 156 protected static final String SCHEMA_VALIDATION = 157 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; 158 159 160 protected static final String SCHEMA_FULL_CHECKING = 161 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; 162 163 164 protected static final String DYNAMIC_VALIDATION = 165 Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; 166 167 168 protected static final String NORMALIZE_DATA = 169 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; 170 171 172 protected static final String SCHEMA_ELEMENT_DEFAULT = 173 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT; 174 175 176 protected static final String SCHEMA_AUGMENT_PSVI = 177 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; 178 179 180 protected static final String ALLOW_JAVA_ENCODINGS = 181 Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE; 182 183 184 protected static final String STANDARD_URI_CONFORMANT_FEATURE = 185 Constants.XERCES_FEATURE_PREFIX + Constants.STANDARD_URI_CONFORMANT_FEATURE; 186 187 188 protected static final String CONTINUE_AFTER_FATAL_ERROR = 189 Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE; 190 191 192 protected static final String IGNORE_SCHEMA_LOCATION_HINTS = 193 Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_SCHEMA_LOCATION_HINTS; 194 195 protected static final String CHANGE_IGNORABLE_CHARACTERS_INTO_IGNORABLE_WHITESPACES = 196 Constants.XERCES_FEATURE_PREFIX + Constants.CHANGE_IGNORABLE_CHARACTERS_INTO_IGNORABLE_WHITESPACES; 197 198 protected static final String PARSER_SETTINGS = 199 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; 200 201 203 204 public static final String SYMBOL_TABLE = 205 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 206 207 208 public static final String ERROR_REPORTER = 209 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 210 211 212 public static final String ENTITY_RESOLVER = 213 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; 214 215 216 public static final String XMLGRAMMAR_POOL = 217 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 218 219 protected static final String VALIDATION_MANAGER = 220 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 221 222 protected static final String ENTITY_MANAGER = 223 Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; 224 225 226 protected static final String SCHEMA_LOCATION = 227 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION; 228 229 230 protected static final String SCHEMA_NONS_LOCATION = 231 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION; 232 233 234 protected static final String JAXP_SCHEMA_SOURCE = 235 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE; 236 237 238 protected static final String JAXP_SCHEMA_LANGUAGE = 239 Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE; 240 241 243 244 private static final String [] RECOGNIZED_FEATURES = { 245 VALIDATION, 246 SCHEMA_VALIDATION, 247 DYNAMIC_VALIDATION, 248 SCHEMA_FULL_CHECKING, 249 ALLOW_JAVA_ENCODINGS, 250 CONTINUE_AFTER_FATAL_ERROR, 251 STANDARD_URI_CONFORMANT_FEATURE, 252 IGNORE_SCHEMA_LOCATION_HINTS, 253 CHANGE_IGNORABLE_CHARACTERS_INTO_IGNORABLE_WHITESPACES }; 254 255 256 private static final Boolean [] FEATURE_DEFAULTS = { null, 257 null, null, null, null, null, null, null, null }; 271 272 273 private static final String [] RECOGNIZED_PROPERTIES = { 274 SYMBOL_TABLE, 275 ERROR_REPORTER, 276 ENTITY_RESOLVER, 277 VALIDATION_MANAGER, 278 SCHEMA_LOCATION, 279 SCHEMA_NONS_LOCATION, 280 JAXP_SCHEMA_SOURCE, 281 JAXP_SCHEMA_LANGUAGE, 282 }; 283 284 285 private static final Object [] PROPERTY_DEFAULTS = 286 { null, null, null, null, null, null, null, null, }; 287 288 protected static final int ID_CONSTRAINT_NUM = 1; 292 293 297 298 protected ElementPSVImpl fCurrentPSVI = new ElementPSVImpl(); 299 300 protected final AugmentationsImpl fAugmentations = new AugmentationsImpl(); 306 307 311 protected final HashMap fMayMatchFieldMap = new HashMap (); 312 313 protected XMLString fDefaultValue; 315 316 protected boolean fDynamicValidation = false; 318 protected boolean fSchemaDynamicValidation = false; 319 protected boolean fDoValidation = false; 320 protected boolean fFullChecking = false; 321 protected boolean fNormalizeData = true; 322 protected boolean fSchemaElementDefault = true; 323 protected boolean fAugPSVI = true; 324 protected boolean fIdConstraint = false; 325 protected boolean fIgnoreXsiSchemaLocationHints = false; 326 protected boolean fTurnIgnorableCharactersIntoIgnorableWhitespaces = false; 327 328 private String fSchemaType = null; 329 330 protected boolean fEntityRef = false; 332 protected boolean fInCDATA = false; 333 334 336 337 protected SymbolTable fSymbolTable; 338 339 342 private XMLLocator fLocator; 343 344 349 protected final class XSIErrorReporter { 350 351 XMLErrorReporter fErrorReporter; 353 354 Vector fErrors = new Vector (INITIAL_STACK_SIZE, INC_STACK_SIZE); 357 int[] fContext = new int[INITIAL_STACK_SIZE]; 358 int fContextCount; 359 360 public void reset(XMLErrorReporter errorReporter) { 362 fErrorReporter = errorReporter; 363 fErrors.removeAllElements(); 364 fContextCount = 0; 365 } 366 367 public void pushContext() { 370 if (!fAugPSVI) 371 return; 372 if (fContextCount == fContext.length) { 374 int newSize = fContextCount + INC_STACK_SIZE; 375 int[] newArray = new int[newSize]; 376 System.arraycopy(fContext, 0, newArray, 0, fContextCount); 377 fContext = newArray; 378 } 379 380 fContext[fContextCount++] = fErrors.size(); 381 } 382 383 public String [] popContext() { 385 if (!fAugPSVI) 386 return null; 387 int contextPos = fContext[--fContextCount]; 389 int size = fErrors.size() - contextPos; 391 if (size == 0) 393 return null; 394 String [] errors = new String [size]; 396 for (int i = 0; i < size; i++) { 397 errors[i] = (String ) fErrors.elementAt(contextPos + i); 398 } 399 fErrors.setSize(contextPos); 401 return errors; 402 } 403 404 public String [] mergeContext() { 408 if (!fAugPSVI) 409 return null; 410 int contextPos = fContext[--fContextCount]; 412 int size = fErrors.size() - contextPos; 414 if (size == 0) 416 return null; 417 String [] errors = new String [size]; 419 for (int i = 0; i < size; i++) { 420 errors[i] = (String ) fErrors.elementAt(contextPos + i); 421 } 422 return errors; 425 } 426 427 public void reportError(String domain, String key, Object [] arguments, short severity) 428 throws XNIException { 429 fErrorReporter.reportError(domain, key, arguments, severity); 430 fErrors.addElement(key); 431 } 433 public void reportError( 434 XMLLocator location, 435 String domain, 436 String key, 437 Object [] arguments, 438 short severity) 439 throws XNIException { 440 fErrorReporter.reportError(location, domain, key, arguments, severity); 441 fErrors.addElement(key); 442 } } 444 445 446 protected final XSIErrorReporter fXSIErrorReporter = new XSIErrorReporter(); 447 448 449 protected XMLEntityResolver fEntityResolver; 450 451 protected ValidationManager fValidationManager = null; 453 protected ValidationState fValidationState = new ValidationState(); 454 protected XMLGrammarPool fGrammarPool; 455 456 protected String fExternalSchemas = null; 458 protected String fExternalNoNamespaceSchema = null; 459 460 protected Object fJaxpSchemaSource = null; 462 463 final XMLResourceIdentifierImpl fResourceIdentifier = new XMLResourceIdentifierImpl(); 465 466 467 protected final XSDDescription fXSDDescription = new XSDDescription(); 468 protected final Hashtable fLocationPairs = new Hashtable (); 469 470 471 472 473 475 476 protected XMLDocumentHandler fDocumentHandler; 477 478 protected XMLDocumentSource fDocumentSource; 479 480 484 489 public String [] getRecognizedFeatures() { 490 return (String []) (RECOGNIZED_FEATURES.clone()); 491 } 493 508 public void setFeature(String featureId, boolean state) throws XMLConfigurationException { 509 } 511 516 public String [] getRecognizedProperties() { 517 return (String [])(RECOGNIZED_PROPERTIES.clone()); 518 } 520 535 public void setProperty(String propertyId, Object value) throws XMLConfigurationException { 536 } 538 547 public Boolean getFeatureDefault(String featureId) { 548 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { 549 if (RECOGNIZED_FEATURES[i].equals(featureId)) { 550 return FEATURE_DEFAULTS[i]; 551 } 552 } 553 return null; 554 } 556 565 public Object getPropertyDefault(String propertyId) { 566 for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { 567 if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { 568 return PROPERTY_DEFAULTS[i]; 569 } 570 } 571 return null; 572 } 574 578 579 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 580 fDocumentHandler = documentHandler; 581 } 583 584 public XMLDocumentHandler getDocumentHandler() { 585 return fDocumentHandler; 586 } 588 592 593 public void setDocumentSource(XMLDocumentSource source){ 594 fDocumentSource = source; 595 } 597 598 public XMLDocumentSource getDocumentSource(){ 599 return fDocumentSource; 600 } 602 624 public void startDocument( 625 XMLLocator locator, 626 String encoding, 627 NamespaceContext namespaceContext, 628 Augmentations augs) 629 throws XNIException { 630 631 fValidationState.setNamespaceSupport(namespaceContext); 632 fState4XsiType.setNamespaceSupport(namespaceContext); 633 fState4ApplyDefault.setNamespaceSupport(namespaceContext); 634 fLocator = locator; 635 636 handleStartDocument(locator, encoding); 637 if (fDocumentHandler != null) { 639 fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs); 640 } 641 642 } 644 657 public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) 658 throws XNIException { 659 660 if (fDocumentHandler != null) { 662 fDocumentHandler.xmlDecl(version, encoding, standalone, augs); 663 } 664 665 } 667 679 public void doctypeDecl( 680 String rootElement, 681 String publicId, 682 String systemId, 683 Augmentations augs) 684 throws XNIException { 685 686 if (fDocumentHandler != null) { 688 fDocumentHandler.doctypeDecl(rootElement, publicId, systemId, augs); 689 } 690 691 } 693 702 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) 703 throws XNIException { 704 705 Augmentations modifiedAugs = handleStartElement(element, attributes, augs); 706 if (fDocumentHandler != null) { 708 fDocumentHandler.startElement(element, attributes, modifiedAugs ); 709 } 710 711 } 713 722 public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) 723 throws XNIException { 724 725 Augmentations modifiedAugs = handleStartElement(element, attributes, augs); 726 727 fDefaultValue = null; 731 if (fElementDepth != -2) 734 modifiedAugs = handleEndElement(element, modifiedAugs); 735 736 if (fDocumentHandler != null) { 738 if (!fSchemaElementDefault || fDefaultValue == null) { 739 fDocumentHandler.emptyElement(element, attributes, modifiedAugs); 740 } else { 741 fDocumentHandler.startElement(element, attributes, modifiedAugs); 742 fDocumentHandler.characters(fDefaultValue, null); 743 fDocumentHandler.endElement(element, modifiedAugs); 744 } 745 } 746 } 748 756 public void characters(XMLString text, Augmentations augs) throws XNIException { 757 758 text = handleCharacters(text); 759 if (fDocumentHandler != null) { 761 if (fNormalizeData && fUnionType) { 762 if (augs != null) 767 fDocumentHandler.characters(fEmptyXMLStr, augs); 768 } else { 769 if( fTurnIgnorableCharactersIntoIgnorableWhitespaces && isElementOnlyContent() ) 770 fDocumentHandler.ignorableWhitespace(text, augs); 771 else 772 fDocumentHandler.characters(text, augs); 773 } 774 } 775 776 } 778 791 public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { 792 793 handleIgnorableWhitespace(text); 794 if (fDocumentHandler != null) { 796 fDocumentHandler.ignorableWhitespace(text, augs); 797 } 798 799 } 801 809 public void endElement(QName element, Augmentations augs) throws XNIException { 810 811 fDefaultValue = null; 814 Augmentations modifiedAugs = handleEndElement(element, augs); 815 if (fDocumentHandler != null) { 817 if (!fSchemaElementDefault || fDefaultValue == null) { 818 fDocumentHandler.endElement(element, modifiedAugs); 819 } else { 820 fDocumentHandler.characters(fDefaultValue, null); 821 fDocumentHandler.endElement(element, modifiedAugs); 822 } 823 } 824 } 826 833 public void startCDATA(Augmentations augs) throws XNIException { 834 835 fInCDATA = true; 837 if (fDocumentHandler != null) { 839 fDocumentHandler.startCDATA(augs); 840 } 841 842 } 844 851 public void endCDATA(Augmentations augs) throws XNIException { 852 853 fInCDATA = false; 855 if (fDocumentHandler != null) { 856 fDocumentHandler.endCDATA(augs); 857 } 858 859 } 861 868 public void endDocument(Augmentations augs) throws XNIException { 869 870 handleEndDocument(); 871 872 if (fDocumentHandler != null) { 874 fDocumentHandler.endDocument(augs); 875 } 876 fLocator = null; 877 878 } 880 884 885 886 887 888 public boolean characterData(String data, Augmentations augs) { 889 890 fSawText = fSawText || data.length() > 0; 891 892 895 if (fNormalizeData && fWhiteSpace != -1 && fWhiteSpace != XSSimpleType.WS_PRESERVE) { 898 normalizeWhitespace(data, fWhiteSpace == XSSimpleType.WS_COLLAPSE); 900 fBuffer.append(fNormalizedStr.ch, fNormalizedStr.offset, fNormalizedStr.length); 901 } else { 902 if (fAppendBuffer) 903 fBuffer.append(data); 904 } 905 906 boolean allWhiteSpace = true; 909 if (fCurrentType != null 910 && fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { 911 XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType; 912 if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) { 913 for (int i=0; i< data.length(); i++) { 915 if (!XMLChar.isSpace(data.charAt(i))) { 916 allWhiteSpace = false; 917 fSawCharacters = true; 918 break; 919 } 920 } 921 } 922 } 923 924 return allWhiteSpace; 925 } 926 927 public void elementDefault(String data){ 928 } 930 931 935 952 public void startGeneralEntity( 953 String name, 954 XMLResourceIdentifier identifier, 955 String encoding, 956 Augmentations augs) 957 throws XNIException { 958 959 fEntityRef = true; 961 if (fDocumentHandler != null) { 963 fDocumentHandler.startGeneralEntity(name, identifier, encoding, augs); 964 } 965 966 } 968 985 public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { 986 987 if (fDocumentHandler != null) { 989 fDocumentHandler.textDecl(version, encoding, augs); 990 } 991 992 } 994 1002 public void comment(XMLString text, Augmentations augs) throws XNIException { 1003 1004 fSawChildren = true; 1006 1007 if (fDocumentHandler != null) { 1009 fDocumentHandler.comment(text, augs); 1010 } 1011 1012 } 1014 1031 public void processingInstruction(String target, XMLString data, Augmentations augs) 1032 throws XNIException { 1033 1034 fSawChildren = true; 1036 1037 if (fDocumentHandler != null) { 1039 fDocumentHandler.processingInstruction(target, data, augs); 1040 } 1041 1042 } 1044 1056 public void endGeneralEntity(String name, Augmentations augs) throws XNIException { 1057 1058 fEntityRef = false; 1060 if (fDocumentHandler != null) { 1061 fDocumentHandler.endGeneralEntity(name, augs); 1062 } 1063 1064 } 1066 1068 static final int INITIAL_STACK_SIZE = 8; 1069 static final int INC_STACK_SIZE = 8; 1070 1071 1075 1077 private static final boolean DEBUG_NORMALIZATION = false; 1078 private final XMLString fEmptyXMLStr = new XMLString(null, 0, -1); 1080 private static final int BUFFER_SIZE = 20; 1082 private final XMLString fNormalizedStr = new XMLString(); 1083 private boolean fFirstChunk = true; 1084 private boolean fTrailing = false; private short fWhiteSpace = -1; private boolean fUnionType = false; 1088 1089 1090 final XSGrammarBucket fGrammarBucket; 1091 final SubstitutionGroupHandler fSubGroupHandler; 1092 1093 final XMLSchemaLoader fSchemaLoader; 1095 1096 1097 final XSSimpleType fQNameDV = 1100 (XSSimpleType) SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME); 1101 1102 final CMNodeFactory nodeFactory = new CMNodeFactory(); 1103 1104 final CMBuilder fCMBuilder = new CMBuilder(nodeFactory); 1106 1107 1109 1110 String fValidationRoot; 1112 1113 1114 int fSkipValidationDepth; 1115 1116 1117 int fNFullValidationDepth; 1118 1119 1120 int fNNoneValidationDepth; 1121 1122 1123 int fElementDepth; 1124 1125 1126 boolean fSubElement; 1127 1128 1129 boolean[] fSubElementStack = new boolean[INITIAL_STACK_SIZE]; 1130 1131 1132 XSElementDecl fCurrentElemDecl; 1133 1134 1135 XSElementDecl[] fElemDeclStack = new XSElementDecl[INITIAL_STACK_SIZE]; 1136 1137 1138 boolean fNil; 1139 1140 1141 boolean[] fNilStack = new boolean[INITIAL_STACK_SIZE]; 1142 1143 1144 XSNotationDecl fNotation; 1145 1146 1147 XSNotationDecl[] fNotationStack = new XSNotationDecl[INITIAL_STACK_SIZE]; 1148 1149 1150 XSTypeDefinition fCurrentType; 1151 1152 1153 XSTypeDefinition[] fTypeStack = new XSTypeDefinition[INITIAL_STACK_SIZE]; 1154 1155 1156 XSCMValidator fCurrentCM; 1157 1158 1159 XSCMValidator[] fCMStack = new XSCMValidator[INITIAL_STACK_SIZE]; 1160 1161 1162 int[] fCurrCMState; 1163 1164 1165 int[][] fCMStateStack = new int[INITIAL_STACK_SIZE][]; 1166 1167 1168 boolean fStrictAssess = true; 1169 1170 1171 boolean[] fStrictAssessStack = new boolean[INITIAL_STACK_SIZE]; 1172 1173 1174 final StringBuffer fBuffer = new StringBuffer (); 1175 1176 1177 boolean fAppendBuffer = true; 1178 1179 1180 boolean fSawText = false; 1181 1182 1183 boolean[] fSawTextStack = new boolean[INITIAL_STACK_SIZE]; 1184 1185 1186 boolean fSawCharacters = false; 1187 1188 1189 boolean[] fStringContent = new boolean[INITIAL_STACK_SIZE]; 1190 1191 1192 boolean fSawChildren = false; 1193 1194 1195 boolean[] fSawChildrenStack = new boolean[INITIAL_STACK_SIZE]; 1196 1197 1198 final QName fTempQName = new QName(); 1199 1200 1201 ValidatedInfo fValidatedInfo = new ValidatedInfo(); 1202 1203 private ValidationState fState4XsiType = new ValidationState(); 1206 1207 private ValidationState fState4ApplyDefault = new ValidationState(); 1210 1211 1213 1227 protected XPathMatcherStack fMatcherStack = new XPathMatcherStack(); 1228 1229 1230 protected ValueStoreCache fValueStoreCache = new ValueStoreCache(); 1231 1232 1236 1237 public XMLSchemaValidator() { 1238 fGrammarBucket = new XSGrammarBucket(); 1239 fSubGroupHandler = new SubstitutionGroupHandler(fGrammarBucket); 1240 fSchemaLoader = 1242 new XMLSchemaLoader( 1243 fXSIErrorReporter.fErrorReporter, 1244 fGrammarBucket, 1245 fSubGroupHandler, 1246 fCMBuilder); 1247 1248 fState4XsiType.setExtraChecking(false); 1249 fState4ApplyDefault.setFacetChecking(false); 1250 1251 } 1253 1267 public void reset(XMLComponentManager componentManager) throws XMLConfigurationException { 1268 1269 1270 fIdConstraint = false; 1271 fLocationPairs.clear(); 1273 1274 fValidationState.resetIDTables(); 1276 1277 nodeFactory.reset(componentManager); 1279 1280 fSchemaLoader.reset(componentManager); 1282 1283 fCurrentElemDecl = null; 1285 fCurrentCM = null; 1286 fCurrCMState = null; 1287 fSkipValidationDepth = -1; 1288 fNFullValidationDepth = -1; 1289 fNNoneValidationDepth = -1; 1290 fElementDepth = -1; 1291 fSubElement = false; 1292 fSchemaDynamicValidation = false; 1293 1294 fEntityRef = false; 1296 fInCDATA = false; 1297 1298 fMatcherStack.clear(); 1299 1300 1301 if (!fMayMatchFieldMap.isEmpty()) { 1302 fMayMatchFieldMap.clear(); 1304 } 1305 1306 fXSIErrorReporter.reset((XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER)); 1308 1309 boolean parser_settings; 1310 try { 1311 parser_settings = componentManager.getFeature(PARSER_SETTINGS); 1312 } 1313 catch (XMLConfigurationException e){ 1314 parser_settings = true; 1315 } 1316 1317 if (!parser_settings){ 1318 fValidationManager.addValidationState(fValidationState); 1320 return; 1321 } 1322 1323 1324 1325 SymbolTable symbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE); 1327 if (symbolTable != fSymbolTable) { 1328 fSymbolTable = symbolTable; 1329 } 1330 1331 try { 1332 fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION); 1333 } catch (XMLConfigurationException e) { 1334 fDynamicValidation = false; 1335 } 1336 1337 if (fDynamicValidation) { 1338 fDoValidation = true; 1339 } else { 1340 try { 1341 fDoValidation = componentManager.getFeature(VALIDATION); 1342 } catch (XMLConfigurationException e) { 1343 fDoValidation = false; 1344 } 1345 } 1346 1347 if (fDoValidation) { 1348 try { 1349 fDoValidation = componentManager.getFeature(XMLSchemaValidator.SCHEMA_VALIDATION); 1350 } catch (XMLConfigurationException e) { 1351 } 1352 } 1353 1354 try { 1355 fFullChecking = componentManager.getFeature(SCHEMA_FULL_CHECKING); 1356 } catch (XMLConfigurationException e) { 1357 fFullChecking = false; 1358 } 1359 1360 try { 1361 fNormalizeData = componentManager.getFeature(NORMALIZE_DATA); 1362 } catch (XMLConfigurationException e) { 1363 fNormalizeData = false; 1364 } 1365 1366 try { 1367 fSchemaElementDefault = componentManager.getFeature(SCHEMA_ELEMENT_DEFAULT); 1368 } catch (XMLConfigurationException e) { 1369 fSchemaElementDefault = false; 1370 } 1371 1372 try { 1373 fAugPSVI = componentManager.getFeature(SCHEMA_AUGMENT_PSVI); 1374 } catch (XMLConfigurationException e) { 1375 fAugPSVI = true; 1376 } 1377 try { 1378 fSchemaType = 1379 (String )componentManager.getProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE); 1380 } catch (XMLConfigurationException e) { 1381 fSchemaType = null; 1382 } 1383 1384 try { 1385 fIgnoreXsiSchemaLocationHints = componentManager.getFeature(IGNORE_SCHEMA_LOCATION_HINTS); 1386 } catch( XMLConfigurationException e) { 1387 fIgnoreXsiSchemaLocationHints = false; 1388 } 1389 1390 try { 1391 fTurnIgnorableCharactersIntoIgnorableWhitespaces = componentManager.getFeature(CHANGE_IGNORABLE_CHARACTERS_INTO_IGNORABLE_WHITESPACES); 1392 } catch( XMLConfigurationException e) { 1393 fTurnIgnorableCharactersIntoIgnorableWhitespaces = false; 1394 } 1395 1396 fEntityResolver = (XMLEntityResolver)componentManager.getProperty(ENTITY_MANAGER); 1397 1398 fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER); 1399 fValidationManager.addValidationState(fValidationState); 1400 fValidationState.setSymbolTable(fSymbolTable); 1401 1402 try { 1404 fExternalSchemas = (String )componentManager.getProperty(SCHEMA_LOCATION); 1405 fExternalNoNamespaceSchema = (String )componentManager.getProperty(SCHEMA_NONS_LOCATION); 1406 } catch (XMLConfigurationException e) { 1407 fExternalSchemas = null; 1408 fExternalNoNamespaceSchema = null; 1409 } 1410 1411 XMLSchemaLoader.processExternalHints(fExternalSchemas, fExternalNoNamespaceSchema, 1416 fLocationPairs, fXSIErrorReporter.fErrorReporter); 1417 1418 try { 1419 fJaxpSchemaSource = componentManager.getProperty(JAXP_SCHEMA_SOURCE); 1420 } catch (XMLConfigurationException e){ 1421 fJaxpSchemaSource = null; 1422 } 1423 fResourceIdentifier.clear(); 1424 1425 try { 1427 fGrammarPool = (XMLGrammarPool)componentManager.getProperty(XMLGRAMMAR_POOL); 1428 } catch (XMLConfigurationException e){ 1429 fGrammarPool = null; 1430 } 1431 fSchemaLoader.setProperty(XMLGRAMMAR_POOL, fGrammarPool); 1432 1433 fState4XsiType.setSymbolTable(symbolTable); 1434 fState4ApplyDefault.setSymbolTable(symbolTable); 1435 1436 } 1438 1442 1449 public void startValueScopeFor(IdentityConstraint identityConstraint, int initialDepth) { 1450 1451 ValueStoreBase valueStore = 1452 fValueStoreCache.getValueStoreFor(identityConstraint, initialDepth); 1453 valueStore.startValueScope(); 1454 1455 } 1457 1463 public XPathMatcher activateField(Field field, int initialDepth) { 1464 ValueStore valueStore = 1465 fValueStoreCache.getValueStoreFor(field.getIdentityConstraint(), initialDepth); 1466 setMayMatch(field, Boolean.TRUE); 1467 XPathMatcher matcher = field.createMatcher(this, valueStore); 1468 fMatcherStack.addMatcher(matcher); 1469 matcher.startDocumentFragment(); 1470 return matcher; 1471 } 1473 1478 public void endValueScopeFor(IdentityConstraint identityConstraint, int initialDepth) { 1479 1480 ValueStoreBase valueStore = 1481 fValueStoreCache.getValueStoreFor(identityConstraint, initialDepth); 1482 valueStore.endValueScope(); 1483 1484 } 1486 1494 public void setMayMatch(Field field, Boolean state) { 1495 fMayMatchFieldMap.put(field, state); 1496 } 1498 1504 public Boolean mayMatch(Field field) { 1505 return (Boolean ) fMayMatchFieldMap.get(field); 1506 } 1508 private void activateSelectorFor(IdentityConstraint ic) { 1510 Selector selector = ic.getSelector(); 1511 FieldActivator activator = this; 1512 if (selector == null) 1513 return; 1514 XPathMatcher matcher = selector.createMatcher(activator, fElementDepth); 1515 fMatcherStack.addMatcher(matcher); 1516 matcher.startDocumentFragment(); 1517 } 1518 1519 1520 1524 1525 void ensureStackCapacity() { 1526 1527 if (fElementDepth == fElemDeclStack.length) { 1528 int newSize = fElementDepth + INC_STACK_SIZE; 1529 boolean[] newArrayB = new boolean[newSize]; 1530 System.arraycopy(fSubElementStack, 0, newArrayB, 0, fElementDepth); 1531 fSubElementStack = newArrayB; 1532 1533 XSElementDecl[] newArrayE = new XSElementDecl[newSize]; 1534 System.arraycopy(fElemDeclStack, 0, newArrayE, 0, fElementDepth); 1535 fElemDeclStack = newArrayE; 1536 1537 newArrayB = new boolean[newSize]; 1538 System.arraycopy(fNilStack, 0, newArrayB, 0, fElementDepth); 1539 fNilStack = newArrayB; 1540 1541 XSNotationDecl[] newArrayN = new XSNotationDecl[newSize]; 1542 System.arraycopy(fNotationStack, 0, newArrayN, 0, fElementDepth); 1543 fNotationStack = newArrayN; 1544 1545 XSTypeDefinition[] newArrayT = new XSTypeDefinition[newSize]; 1546 System.arraycopy(fTypeStack, 0, newArrayT, 0, fElementDepth); 1547 fTypeStack = newArrayT; 1548 1549 XSCMValidator[] newArrayC = new XSCMValidator[newSize]; 1550 System.arraycopy(fCMStack, 0, newArrayC, 0, fElementDepth); 1551 fCMStack = newArrayC; 1552 1553 newArrayB = new boolean[newSize]; 1554 System.arraycopy(fSawTextStack, 0, newArrayB, 0, fElementDepth); 1555 fSawTextStack = newArrayB; 1556 1557 newArrayB = new boolean[newSize]; 1558 System.arraycopy(fStringContent, 0, newArrayB, 0, fElementDepth); 1559 fStringContent = newArrayB; 1560 1561 newArrayB = new boolean[newSize]; 1562 System.arraycopy(fSawChildrenStack, 0, newArrayB, 0, fElementDepth); 1563 fSawChildrenStack = newArrayB; 1564 1565 newArrayB = new boolean[newSize]; 1566 System.arraycopy(fStrictAssessStack, 0, newArrayB, 0, fElementDepth); 1567 fStrictAssessStack = newArrayB; 1568 1569 int[][] newArrayIA = new int[newSize][]; 1570 System.arraycopy(fCMStateStack, 0, newArrayIA, 0, fElementDepth); 1571 fCMStateStack = newArrayIA; 1572 } 1573 1574 } 1576 void handleStartDocument(XMLLocator locator, String encoding) { 1578 fValueStoreCache.startDocument(); 1579 } 1581 void handleEndDocument() { 1582 fValueStoreCache.endDocument(); 1583 } 1585 XMLString handleCharacters(XMLString text) { 1588 1589 if (fSkipValidationDepth >= 0) 1590 return text; 1591 1592 fSawText = fSawText || text.length > 0; 1593 1594 if (fNormalizeData && fWhiteSpace != -1 && fWhiteSpace != XSSimpleType.WS_PRESERVE) { 1598 normalizeWhitespace(text, fWhiteSpace == XSSimpleType.WS_COLLAPSE); 1600 text = fNormalizedStr; 1601 } 1602 if (fAppendBuffer) 1603 fBuffer.append(text.ch, text.offset, text.length); 1604 1605 if (fCurrentType != null 1608 && fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { 1609 XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType; 1610 if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) { 1611 for (int i=text.offset; i< text.offset+text.length; i++) { 1613 if (!XMLChar.isSpace(text.ch[i])) { 1614 fSawCharacters = true; 1615 break; 1616 } 1617 } 1618 } 1619 } 1620 1621 return text; 1622 } 1624 1628 public final boolean isElementOnlyContent() { 1629 if (fCurrentType == null 1630 || fCurrentType.getTypeCategory() != XSTypeDefinition.COMPLEX_TYPE) 1631 return false; 1632 1633 XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType; 1634 if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT 1635 || ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_EMPTY ) 1636 return !fSawCharacters; 1637 1638 return false; 1639 } 1640 1641 1647 private void normalizeWhitespace( XMLString value, boolean collapse) { 1648 boolean skipSpace = collapse; 1649 boolean sawNonWS = false; 1650 boolean leading = false; 1651 boolean trailing = false; 1652 char c; 1653 int size = value.offset+value.length; 1654 1655 if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < value.length+1) { 1657 fNormalizedStr.ch = new char[value.length+1]; 1658 } 1659 fNormalizedStr.offset = 1; 1661 fNormalizedStr.length = 1; 1662 1663 for (int i = value.offset; i < size; i++) { 1664 c = value.ch[i]; 1665 if (XMLChar.isSpace(c)) { 1666 if (!skipSpace) { 1667 fNormalizedStr.ch[fNormalizedStr.length++] = ' '; 1669 skipSpace = collapse; 1670 } 1671 if (!sawNonWS) { 1672 leading = true; 1674 } 1675 } else { 1676 fNormalizedStr.ch[fNormalizedStr.length++] = c; 1677 skipSpace = false; 1678 sawNonWS = true; 1679 } 1680 } 1681 if (skipSpace) { 1682 if ( fNormalizedStr.length > 1) { 1683 fNormalizedStr.length--; 1685 trailing = true; 1686 } else if (leading && !fFirstChunk) { 1687 trailing = true; 1690 } 1691 } 1692 1693 if (fNormalizedStr.length > 1) { 1694 if (!fFirstChunk && (fWhiteSpace==XSSimpleType.WS_COLLAPSE) ) { 1695 if (fTrailing) { 1696 fNormalizedStr.offset = 0; 1699 fNormalizedStr.ch[0] = ' '; 1700 } else if (leading) { 1701 fNormalizedStr.offset = 0; 1704 fNormalizedStr.ch[0] = ' '; 1705 } 1706 } 1707 } 1708 1709 fNormalizedStr.length -= fNormalizedStr.offset; 1711 1712 fTrailing = trailing; 1713 1714 if (trailing || sawNonWS) 1715 fFirstChunk = false; 1716 } 1717 1718 private void normalizeWhitespace( String value, boolean collapse) { 1719 boolean skipSpace = collapse; 1720 char c; 1721 int size = value.length(); 1722 1723 if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < size) { 1725 fNormalizedStr.ch = new char[size]; 1726 } 1727 fNormalizedStr.offset = 0; 1728 fNormalizedStr.length = 0; 1729 1730 for (int i = 0; i < size; i++) { 1731 c = value.charAt(i); 1732 if (XMLChar.isSpace(c)) { 1733 if (!skipSpace) { 1734 fNormalizedStr.ch[fNormalizedStr.length++] = ' '; 1736 skipSpace = collapse; 1737 } 1738 } else { 1739 fNormalizedStr.ch[fNormalizedStr.length++] = c; 1740 skipSpace = false; 1741 } 1742 } 1743 if (skipSpace) { 1744 if (fNormalizedStr.length != 0) 1745 fNormalizedStr.length--; 1747 } 1748 } 1749 1750 void handleIgnorableWhitespace(XMLString text) { 1752 1753 if (fSkipValidationDepth >= 0) 1754 return; 1755 1756 1759 } 1761 1762 Augmentations handleStartElement(QName element, XMLAttributes attributes, Augmentations augs) { 1763 1764 if (DEBUG) { 1765 System.out.println("==>handleStartElement: " +element); 1766 } 1767 1768 if (fElementDepth == -1 && fValidationManager.isGrammarFound()) { 1770 if (fSchemaType == null) { 1771 fSchemaDynamicValidation = true; 1776 } else { 1777 } 1782 1783 } 1784 1785 1788 String sLocation = 1789 attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_SCHEMALOCATION); 1790 String nsLocation = 1791 attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION); 1792 storeLocations(sLocation, nsLocation) ; 1796 1797 if (fSkipValidationDepth >= 0) { 1800 fElementDepth++; 1801 if (fAugPSVI) 1802 augs = getEmptyAugs(augs); 1803 return augs; 1804 } 1805 1806 SchemaGrammar sGrammar = 1808 findSchemaGrammar( 1809 XSDDescription.CONTEXT_ELEMENT, 1810 element.uri, 1811 null, 1812 element, 1813 attributes); 1814 1815 Object decl = null; 1821 if (fCurrentCM != null) { 1822 decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler); 1823 if (fCurrCMState[0] == XSCMValidator.FIRST_ERROR) { 1825 XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType; 1826 Vector next; 1828 if (ctype.fParticle != null 1829 && (next = fCurrentCM.whatCanGoHere(fCurrCMState)).size() > 0) { 1830 String expected = expectedStr(next); 1831 reportSchemaError( 1832 "cvc-complex-type.2.4.a", 1833 new Object [] { element.rawname, expected }); 1834 } else { 1835 reportSchemaError("cvc-complex-type.2.4.d", new Object []{element.rawname}); 1836 } 1837 } 1838 } 1839 1840 1841 if (fElementDepth != -1) { 1843 ensureStackCapacity(); 1844 fSubElementStack[fElementDepth] = true; 1845 fSubElement = false; 1846 fElemDeclStack[fElementDepth] = fCurrentElemDecl; 1847 fNilStack[fElementDepth] = fNil; 1848 fNotationStack[fElementDepth] = fNotation; 1849 fTypeStack[fElementDepth] = fCurrentType; 1850 fStrictAssessStack[fElementDepth] = fStrictAssess; 1851 fCMStack[fElementDepth] = fCurrentCM; 1852 fCMStateStack[fElementDepth] = fCurrCMState; 1853 fSawTextStack[fElementDepth] = fSawText; 1854 fStringContent[fElementDepth] = fSawCharacters; 1855 fSawChildrenStack[fElementDepth] = fSawChildren; 1856 } 1857 1858 fElementDepth++; 1861 fCurrentElemDecl = null; 1862 XSWildcardDecl wildcard = null; 1863 fCurrentType = null; 1864 fStrictAssess = true; 1865 fNil = false; 1866 fNotation = null; 1867 1868 fBuffer.setLength(0); 1870 fSawText = false; 1871 fSawCharacters = false; 1872 fSawChildren = false; 1873 1874 if (decl != null) { 1877 if (decl instanceof XSElementDecl) { 1878 fCurrentElemDecl = (XSElementDecl)decl; 1879 } else { 1880 wildcard = (XSWildcardDecl)decl; 1881 } 1882 } 1883 1884 if (wildcard != null && wildcard.fProcessContents == XSWildcardDecl.PC_SKIP) { 1886 fSkipValidationDepth = fElementDepth; 1887 if (fAugPSVI) 1888 augs = getEmptyAugs(augs); 1889 return augs; 1890 } 1891 1892 if (fCurrentElemDecl == null) { 1896 if (sGrammar != null){ 1897 fCurrentElemDecl = sGrammar.getGlobalElementDecl(element.localpart); 1898 } 1899 } 1900 1901 if (fCurrentElemDecl != null) { 1902 fCurrentType = fCurrentElemDecl.fType; 1904 } 1905 1906 String xsiType = attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_TYPE); 1908 1909 if (fCurrentType == null && xsiType == null) { 1911 if (fElementDepth == 0) { 1915 if (fDynamicValidation || fSchemaDynamicValidation) { 1918 if (fDocumentSource != null) { 1925 fDocumentSource.setDocumentHandler(fDocumentHandler); 1926 if (fDocumentHandler != null) 1927 fDocumentHandler.setDocumentSource(fDocumentSource); 1928 fElementDepth = -2; 1930 return augs; 1931 } 1932 1933 fSkipValidationDepth = fElementDepth; 1934 if (fAugPSVI) 1935 augs = getEmptyAugs(augs); 1936 return augs; 1937 } 1938 fXSIErrorReporter.fErrorReporter.reportError( 1945 XSMessageFormatter.SCHEMA_DOMAIN, 1946 "cvc-elt.1", 1947 new Object [] { element.rawname }, 1948 XMLErrorReporter.SEVERITY_ERROR); 1949 } 1950 else if (wildcard != null && wildcard.fProcessContents == XSWildcardDecl.PC_STRICT) { 1954 reportSchemaError("cvc-complex-type.2.4.c", new Object [] { element.rawname }); 1956 } 1957 fCurrentType = SchemaGrammar.fAnyType; 1961 fStrictAssess = false; 1962 fNFullValidationDepth = fElementDepth; 1963 fAppendBuffer = false; 1965 1966 fXSIErrorReporter.pushContext(); 1970 } else { 1971 fXSIErrorReporter.pushContext(); 1975 1976 if (xsiType != null) { 1978 XSTypeDefinition oldType = fCurrentType; 1979 fCurrentType = getAndCheckXsiType(element, xsiType, attributes); 1980 if (fCurrentType == null) { 1982 if (oldType == null) 1983 fCurrentType = SchemaGrammar.fAnyType; 1984 else 1985 fCurrentType = oldType; 1986 } 1987 } 1988 1989 fNNoneValidationDepth = fElementDepth; 1990 if (fCurrentElemDecl != null 1992 && fCurrentElemDecl.getConstraintType() == XSConstants.VC_FIXED) { 1993 fAppendBuffer = true; 1994 } 1995 else if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { 1997 fAppendBuffer = true; 1998 } else { 1999 XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType; 2001 fAppendBuffer = (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE); 2002 } 2003 } 2004 2005 if (fCurrentElemDecl != null && fCurrentElemDecl.getAbstract()) 2008 reportSchemaError("cvc-elt.2", new Object [] { element.rawname }); 2009 2010 if (fElementDepth == 0) { 2012 fValidationRoot = element.rawname; 2013 } 2014 2015 if (fNormalizeData) { 2017 fFirstChunk = true; 2019 fTrailing = false; 2020 fUnionType = false; 2021 fWhiteSpace = -1; 2022 } 2023 2024 if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { 2027 XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; 2028 if (ctype.getAbstract()) { 2029 reportSchemaError("cvc-type.2", new Object [] { element.rawname }); 2030 } 2031 if (fNormalizeData) { 2032 if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { 2035 if (ctype.fXSSimpleType.getVariety() == XSSimpleType.VARIETY_UNION) { 2036 fUnionType = true; 2037 } else { 2038 try { 2039 fWhiteSpace = ctype.fXSSimpleType.getWhitespace(); 2040 } catch (DatatypeException e) { 2041 } 2043 } 2044 } 2045 } 2046 } 2047 else if (fNormalizeData) { 2049 XSSimpleType dv = (XSSimpleType) fCurrentType; 2051 if (dv.getVariety() == XSSimpleType.VARIETY_UNION) { 2052 fUnionType = true; 2053 } else { 2054 try { 2055 fWhiteSpace = dv.getWhitespace(); 2056 } catch (DatatypeException e) { 2057 } 2059 } 2060 } 2061 2062 fCurrentCM = null; 2064 if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { 2065 fCurrentCM = ((XSComplexTypeDecl) fCurrentType).getContentModel(fCMBuilder); 2066 } 2067 2068 fCurrCMState = null; 2070 if (fCurrentCM != null) 2071 fCurrCMState = fCurrentCM.startContentModel(); 2072 2073 String xsiNil = attributes.getValue(SchemaSymbols.URI_XSI, SchemaSymbols.XSI_NIL); 2075 if (xsiNil != null && fCurrentElemDecl != null) 2077 fNil = getXsiNil(element, xsiNil); 2078 2079 XSAttributeGroupDecl attrGrp = null; 2082 if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { 2083 XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType; 2084 attrGrp = ctype.getAttrGrp(); 2085 } 2086 fValueStoreCache.startElement(); 2088 fMatcherStack.pushContext(); 2089 if (fCurrentElemDecl != null && fCurrentElemDecl.fIDCPos > 0) { 2090 fIdConstraint = true; 2091 fValueStoreCache.initValueStoresFor(fCurrentElemDecl, this); 2093 } 2094 processAttributes(element, attributes, attrGrp); 2095 2096 if (attrGrp != null) { 2098 addDefaultAttributes(element, attributes, attrGrp); 2099 } 2100 2101 int count = fMatcherStack.getMatcherCount(); 2103 for (int i = 0; i < count; i++) { 2104 XPathMatcher matcher = fMatcherStack.getMatcherAt(i); 2105 matcher.startElement( element, attributes); 2106 } 2107 2108 if (fAugPSVI) { 2109 augs = getEmptyAugs(augs); 2110 2111 fCurrentPSVI.fValidationContext = fValidationRoot; 2113 fCurrentPSVI.fDeclaration = fCurrentElemDecl; 2115 fCurrentPSVI.fTypeDecl = fCurrentType; 2117 fCurrentPSVI.fNotation = fNotation; 2119 } 2120 2121 return augs; 2122 2123 } 2125 2130 Augmentations handleEndElement(QName element, Augmentations augs) { 2131 2132 if (DEBUG) { 2133 System.out.println("==>handleEndElement:" +element); 2134 } 2135 if (fSkipValidationDepth >= 0) { 2137 if (fSkipValidationDepth == fElementDepth && fSkipValidationDepth > 0) { 2140 fNFullValidationDepth = fSkipValidationDepth-1; 2142 fSkipValidationDepth = -1; 2143 fElementDepth--; 2144 fSubElement = fSubElementStack[fElementDepth]; 2145 fCurrentElemDecl = fElemDeclStack[fElementDepth]; 2146 fNil = fNilStack[fElementDepth]; 2147 fNotation = fNotationStack[fElementDepth]; 2148 fCurrentType = fTypeStack[fElementDepth]; 2149 fCurrentCM = fCMStack[fElementDepth]; 2150 fStrictAssess = fStrictAssessStack[fElementDepth]; 2151 fCurrCMState = fCMStateStack[fElementDepth]; 2152 fSawText = fSawTextStack[fElementDepth]; 2153 fSawCharacters = fStringContent[fElementDepth]; 2154 fSawChildren = fSawChildrenStack[fElementDepth]; 2155 } else { 2156 fElementDepth--; 2157 } 2158 2159 2163 if (fElementDepth == -1 && fFullChecking) { 2165 XSConstraints.fullSchemaChecking( 2166 fGrammarBucket, 2167 fSubGroupHandler, 2168 fCMBuilder, 2169 fXSIErrorReporter.fErrorReporter); 2170 } 2171 2172 if (fAugPSVI) 2173 augs = getEmptyAugs(augs); 2174 return augs; 2175 } 2176 2177 processElementContent(element); 2179 2180 2183 int oldCount = fMatcherStack.getMatcherCount(); 2185 for (int i = oldCount - 1; i >= 0; i--) { 2186 XPathMatcher matcher = fMatcherStack.getMatcherAt(i); 2187 if (fCurrentElemDecl == null) 2188 matcher.endElement(element, null, false, fValidatedInfo.actualValue); 2189 2190 else 2191 matcher.endElement( 2192 element, 2193 fCurrentType, 2194 fCurrentElemDecl.getNillable(), 2195 fDefaultValue == null 2196 ? fValidatedInfo.actualValue 2197 : fCurrentElemDecl.fDefault.actualValue); 2198 } 2199 2200 if (fMatcherStack.size() > 0) { 2201 fMatcherStack.popContext(); 2202 } 2203 2204 int newCount = fMatcherStack.getMatcherCount(); 2205 for (int i = oldCount - 1; i >= newCount; i--) { 2207 XPathMatcher matcher = fMatcherStack.getMatcherAt(i); 2208 if(matcher instanceof Selector.Matcher) { 2209 Selector.Matcher selMatcher = (Selector.Matcher)matcher; 2210 IdentityConstraint id; 2211 if ((id = selMatcher.getIdentityConstraint()) != null 2212 && id.getCategory() != IdentityConstraint.IC_KEYREF) { 2213 fValueStoreCache.transplant(id, selMatcher.getInitialDepth()); 2214 } 2215 } 2216 } 2217 2218 for (int i = oldCount - 1; i >= newCount; i--) { 2220 XPathMatcher matcher = fMatcherStack.getMatcherAt(i); 2221 if(matcher instanceof Selector.Matcher) { 2222 Selector.Matcher selMatcher = (Selector.Matcher)matcher; 2223 IdentityConstraint id; 2224 if ((id = selMatcher.getIdentityConstraint()) != null 2225 && id.getCategory() == IdentityConstraint.IC_KEYREF) { 2226 ValueStoreBase values = 2227 fValueStoreCache.getValueStoreFor(id, selMatcher.getInitialDepth()); 2228 if (values != null) values.endDocumentFragment(); 2230 } 2231 } 2232 } 2233 fValueStoreCache.endElement(); 2234 2235 SchemaGrammar[] grammars = null; 2236 if (fElementDepth == 0) { 2238 String invIdRef = fValidationState.checkIDRefID(); 2240 fValidationState.resetIDTables(); 2241 if (invIdRef != null) { 2242 reportSchemaError("cvc-id.1", new Object [] { invIdRef }); 2243 } 2244 if (fFullChecking) { 2246 XSConstraints.fullSchemaChecking( 2247 fGrammarBucket, 2248 fSubGroupHandler, 2249 fCMBuilder, 2250 fXSIErrorReporter.fErrorReporter); 2251 } 2252 2253 grammars = fGrammarBucket.getGrammars(); 2254 if (fGrammarPool != null) { 2256 fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, grammars); 2257 } 2258 augs = endElementPSVI(true, grammars, augs); 2259 } else { 2260 augs = endElementPSVI(false, grammars, augs); 2261 2262 fElementDepth--; 2264 2265 fSubElement = fSubElementStack[fElementDepth]; 2267 fCurrentElemDecl = fElemDeclStack[fElementDepth]; 2268 fNil = fNilStack[fElementDepth]; 2269 fNotation = fNotationStack[fElementDepth]; 2270 fCurrentType = fTypeStack[fElementDepth]; 2271 fCurrentCM = fCMStack[fElementDepth]; 2272 fStrictAssess = fStrictAssessStack[fElementDepth]; 2273 fCurrCMState = fCMStateStack[fElementDepth]; 2274 fSawText = fSawTextStack[fElementDepth]; 2275 fSawCharacters = fStringContent[fElementDepth]; 2276 fSawChildren = fSawChildrenStack[fElementDepth]; 2277 2278 fWhiteSpace = -1; 2284 fAppendBuffer = false; 2287 fUnionType = false; 2289 } 2290 2291 return augs; 2292 } 2294 final Augmentations endElementPSVI( 2295 boolean root, 2296 SchemaGrammar[] grammars, 2297 Augmentations augs){ 2298 2299 if (fAugPSVI) { 2300 augs = getEmptyAugs(augs); 2301 2302 fCurrentPSVI.fDeclaration = this.fCurrentElemDecl; 2304 fCurrentPSVI.fTypeDecl = this.fCurrentType; 2305 fCurrentPSVI.fNotation = this.fNotation; 2306 fCurrentPSVI.fValidationContext = this.fValidationRoot; 2307 if (fElementDepth > fNFullValidationDepth) { 2312 fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_FULL; 2313 } 2314 else if (fElementDepth > fNNoneValidationDepth) { 2318 fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_NONE; 2319 } 2320 else { 2322 fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_PARTIAL; 2323 fNFullValidationDepth = fNNoneValidationDepth = fElementDepth - 1; 2324 } 2325 2326 if (fDefaultValue != null) 2327 fCurrentPSVI.fSpecified = true; 2328 fCurrentPSVI.fNil = fNil; 2329 fCurrentPSVI.fMemberType = fValidatedInfo.memberType; 2330 fCurrentPSVI.fNormalizedValue = fValidatedInfo.normalizedValue; 2331 fCurrentPSVI.fActualValue = fValidatedInfo.actualValue; 2332 fCurrentPSVI.fActualValueType = fValidatedInfo.actualValueType; 2333 fCurrentPSVI.fItemValueTypes = fValidatedInfo.itemValueTypes; 2334 2335 if (fStrictAssess) { 2336 String [] errors = fXSIErrorReporter.mergeContext(); 2341 2342 fCurrentPSVI.fErrorCodes = errors; 2344 fCurrentPSVI.fValidity = 2346 (errors == null) ? ElementPSVI.VALIDITY_VALID : ElementPSVI.VALIDITY_INVALID; 2347 } else { 2348 fCurrentPSVI.fValidity = ElementPSVI.VALIDITY_NOTKNOWN; 2350 fXSIErrorReporter.popContext(); 2354 } 2355 2356 if (root) { 2357 fCurrentPSVI.fSchemaInformation = new XSModelImpl(grammars); 2359 } 2360 } 2361 2362 return augs; 2363 2364 } 2365 2366 Augmentations getEmptyAugs(Augmentations augs) { 2367 if (augs == null) { 2368 augs = fAugmentations; 2369 augs.removeAllItems(); 2370 } 2371 augs.putItem(Constants.ELEMENT_PSVI, fCurrentPSVI); 2372 fCurrentPSVI.reset(); 2373 2374 return augs; 2375 } 2376 2377 void storeLocations(String sLocation, String nsLocation){ 2378 if (sLocation != null) { 2379 if (!XMLSchemaLoader.tokenizeSchemaLocationStr(sLocation, fLocationPairs)) { 2380 fXSIErrorReporter.reportError( 2382 XSMessageFormatter.SCHEMA_DOMAIN, 2383 "SchemaLocation", 2384 new Object []{sLocation}, 2385 XMLErrorReporter.SEVERITY_WARNING); 2386 } 2387 } 2388 if (nsLocation != null) { 2389 XMLSchemaLoader.LocationArray la = 2390 ((XMLSchemaLoader.LocationArray) fLocationPairs.get(XMLSymbols.EMPTY_STRING)); 2391 if(la == null) { 2392 la = new XMLSchemaLoader.LocationArray(); 2393 fLocationPairs.put(XMLSymbols.EMPTY_STRING, la); 2394 } 2395 la.addLocation(nsLocation); 2396 } 2397 2398 } 2400 SchemaGrammar findSchemaGrammar( 2404 short contextType, 2405 String namespace, 2406 QName enclosingElement, 2407 QName triggeringComponet, 2408 XMLAttributes attributes) { 2409 SchemaGrammar grammar = null; 2410 grammar = fGrammarBucket.getGrammar(namespace); 2412 if (grammar == null) { 2413 fXSDDescription.reset(); 2414 fXSDDescription.fContextType = contextType; 2415 fXSDDescription.setNamespace(namespace); 2416 fXSDDescription.fEnclosedElementName = enclosingElement; 2417 fXSDDescription.fTriggeringComponent = triggeringComponet; 2418 fXSDDescription.fAttributes = attributes; 2419 if (fLocator != null) { 2420 fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId()); 2421 } 2422 2423 String [] temp = null ; 2424 Object locationArray = 2425 fLocationPairs.get(namespace == null ? XMLSymbols.EMPTY_STRING : namespace); 2426 if(locationArray != null) 2427 temp = ((XMLSchemaLoader.LocationArray)locationArray).getLocationArray() ; 2428 if (temp != null && temp.length != 0) { 2429 fXSDDescription.fLocationHints = new String [temp.length] ; 2430 System.arraycopy(temp, 0 , fXSDDescription.fLocationHints, 0, temp.length ); 2431 } 2432 2433 if (fGrammarPool != null){ 2435 grammar = (SchemaGrammar)fGrammarPool.retrieveGrammar(fXSDDescription); 2436 if (grammar != null) { 2437 if (!fGrammarBucket.putGrammar(grammar, true)) { 2440 fXSIErrorReporter.fErrorReporter.reportError( 2443 XSMessageFormatter.SCHEMA_DOMAIN, 2444 "GrammarConflict", 2445 null, 2446 XMLErrorReporter.SEVERITY_WARNING); 2447 grammar = null; 2448 } 2449 } 2450 } 2451 if (grammar == null && !fIgnoreXsiSchemaLocationHints) { 2452 try { 2454 XMLInputSource xis = 2455 XMLSchemaLoader.resolveDocument( 2456 fXSDDescription, 2457 fLocationPairs, 2458 fEntityResolver); 2459 grammar = fSchemaLoader.loadSchema(fXSDDescription, xis.toSource(), fLocationPairs); 2460 } catch (IOException ex) { 2461 fXSIErrorReporter.fErrorReporter.reportError( 2462 XSMessageFormatter.SCHEMA_DOMAIN, 2463 "schema_reference.4", 2464 new Object []{fXSDDescription.getLocationHints()[0]}, 2465 XMLErrorReporter.SEVERITY_WARNING); 2466 } 2467 } 2468 } 2469 2470 return grammar ; 2471 2472 } 2474 XSTypeDefinition getAndCheckXsiType(QName element, String xsiType, XMLAttributes attributes) { 2475 2478 QName typeName = null; 2482 try { 2483 typeName = (QName)fQNameDV.validate(xsiType, fValidationState, null); 2484 } catch (InvalidDatatypeValueException e) { 2485 reportSchemaError(e.getKey(), e.getArgs()); 2486 reportSchemaError( 2487 "cvc-elt.4.1", 2488 new Object [] { 2489 element.rawname, 2490 SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_TYPE, 2491 xsiType }); 2492 return null; 2493 } 2494 2495 XSTypeDefinition type = null; 2497 if (typeName.uri == SchemaSymbols.URI_SCHEMAFORSCHEMA) { 2499 type = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(typeName.localpart); 2500 } 2501 if (type == null) { 2503 SchemaGrammar grammar = 2505 findSchemaGrammar( 2506 XSDDescription.CONTEXT_XSITYPE, 2507 typeName.uri, 2508 element, 2509 typeName, 2510 attributes); 2511 2512 if (grammar != null) 2513 type = grammar.getGlobalTypeDecl(typeName.localpart); 2514 } 2515 if (type == null) { 2517 reportSchemaError("cvc-elt.4.2", new Object []{element.rawname, xsiType}); 2518 return null; 2519 } 2520 2521 if (fCurrentType != null) { 2524 short block = fCurrentElemDecl.fBlock; 2526 if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) 2527 block |= ((XSComplexTypeDecl)fCurrentType).fBlock; 2528 if (!XSConstraints.checkTypeDerivationOk(type, fCurrentType, block)) 2529 reportSchemaError( 2530 "cvc-elt.4.3", 2531 new Object [] { element.rawname, xsiType, fCurrentType.getName()}); 2532 } 2533 2534 return type; 2535 } 2537 boolean getXsiNil(QName element, String xsiNil) { 2538 if (fCurrentElemDecl != null && !fCurrentElemDecl.getNillable()) { 2542 reportSchemaError( 2543 "cvc-elt.3.1", 2544 new Object [] { 2545 element.rawname, 2546 SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_NIL }); 2547 } 2548 else { 2551 String value = xsiNil.trim(); 2552 if (value.equals(SchemaSymbols.ATTVAL_TRUE) 2553 || value.equals(SchemaSymbols.ATTVAL_TRUE_1)) { 2554 if (fCurrentElemDecl != null 2555 && fCurrentElemDecl.getConstraintType() == XSConstants.VC_FIXED) { 2556 reportSchemaError( 2557 "cvc-elt.3.2.2", 2558 new Object [] { 2559 element.rawname, 2560 SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_NIL }); 2561 } 2562 return true; 2563 } 2564 } 2565 return false; 2566 } 2567 2568 void processAttributes(QName element, XMLAttributes attributes, XSAttributeGroupDecl attrGrp) { 2569 2570 if (DEBUG) { 2571 System.out.println("==>processAttributes: " +attributes.getLength()); 2572 } 2573 2574 String wildcardIDName = null; 2576 2577 int attCount = attributes.getLength(); 2579 2580 Augmentations augs = null; 2581 AttributePSVImpl attrPSVI = null; 2582 2583 boolean isSimple = 2584 fCurrentType == null || fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE; 2585 2586 XSObjectList attrUses = null; 2587 int useCount = 0; 2588 XSWildcardDecl attrWildcard = null; 2589 if (!isSimple) { 2590 attrUses = attrGrp.getAttributeUses(); 2591 useCount = attrUses.getLength(); 2592 attrWildcard = attrGrp.fAttributeWC; 2593 } 2594 2595 for (int index = 0; index < attCount; index++) { 2599 2600 attributes.getName(index, fTempQName); 2601 2602 if (DEBUG) { 2603 System.out.println("==>process attribute: "+fTempQName); 2604 } 2605 2606 if (fAugPSVI || fIdConstraint) { 2607 augs = attributes.getAugmentations(index); 2608 attrPSVI = (AttributePSVImpl) augs.getItem(Constants.ATTRIBUTE_PSVI); 2609 if (attrPSVI != null) { 2610 attrPSVI.reset(); 2611 } else { 2612 attrPSVI= new AttributePSVImpl(); 2613 augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI); 2614 } 2615 attrPSVI.fValidationContext = fValidationRoot; 2617 } 2618 2619 2624 if (fTempQName.uri == SchemaSymbols.URI_XSI) { 2626 XSAttributeDecl attrDecl = null; 2627 if (fTempQName.localpart == SchemaSymbols.XSI_SCHEMALOCATION) 2628 attrDecl = 2629 SchemaGrammar.SG_XSI.getGlobalAttributeDecl( 2630 SchemaSymbols.XSI_SCHEMALOCATION); 2631 else if (fTempQName.localpart == SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION) 2632 attrDecl = 2633 SchemaGrammar.SG_XSI.getGlobalAttributeDecl( 2634 SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION); 2635 else if (fTempQName.localpart == SchemaSymbols.XSI_NIL) 2636 attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NIL); 2637 else if (fTempQName.localpart == SchemaSymbols.XSI_TYPE) 2638 attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_TYPE); 2639 if (attrDecl != null) { 2640 processOneAttribute(element, attributes, index, attrDecl, null, attrPSVI); 2641 continue; 2642 } 2643 } 2644 2645 if (fTempQName.rawname == XMLSymbols.PREFIX_XMLNS 2647 || fTempQName.rawname.startsWith("xmlns:")) { 2648 continue; 2649 } 2650 2651 if (isSimple) { 2653 reportSchemaError( 2654 "cvc-type.3.1.1", 2655 new Object [] { element.rawname, fTempQName.rawname }); 2656 continue; 2657 } 2658 2659 XSAttributeUseImpl currUse = null, oneUse; 2661 for (int i = 0; i < useCount; i++) { 2662 oneUse = (XSAttributeUseImpl)attrUses.item(i); 2663 if (oneUse.fAttrDecl.fName == fTempQName.localpart 2664 && oneUse.fAttrDecl.fTargetNamespace == fTempQName.uri) { 2665 currUse = oneUse; 2666 break; 2667 } 2668 } 2669 2670 2674 if (currUse == null) { 2676 if (attrWildcard == null || !attrWildcard.allowNamespace(fTempQName.uri)) { 2679 reportSchemaError( 2681 "cvc-complex-type.3.2.2", 2682 new Object [] { element.rawname, fTempQName.rawname }); 2683 continue; 2684 } 2685 } 2686 2687 XSAttributeDecl currDecl = null; 2688 if (currUse != null) { 2689 currDecl = currUse.fAttrDecl; 2690 } else { 2691 if (attrWildcard.fProcessContents == XSWildcardDecl.PC_SKIP) 2694 continue; 2695 2696 SchemaGrammar grammar = 2698 findSchemaGrammar( 2699 XSDDescription.CONTEXT_ATTRIBUTE, 2700 fTempQName.uri, 2701 element, 2702 fTempQName, 2703 attributes); 2704 2705 if (grammar != null){ 2706 currDecl = grammar.getGlobalAttributeDecl(fTempQName.localpart); 2707 } 2708 2709 if (currDecl == null) { 2711 if (attrWildcard.fProcessContents == XSWildcardDecl.PC_STRICT){ 2713 reportSchemaError( 2714 "cvc-complex-type.3.2.2", 2715 new Object [] { element.rawname, fTempQName.rawname }); 2716 } 2717 2718 continue; 2720 } else { 2721 if (currDecl.fType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE 2724 && ((XSSimpleType) currDecl.fType).isIDType()) { 2725 if (wildcardIDName != null){ 2726 reportSchemaError( 2727 "cvc-complex-type.5.1", 2728 new Object [] { element.rawname, currDecl.fName, wildcardIDName }); 2729 } else 2730 wildcardIDName = currDecl.fName; 2731 } 2732 } 2733 } 2734 2735 processOneAttribute(element, attributes, index, currDecl, currUse, attrPSVI); 2736 } 2738 if (!isSimple && attrGrp.fIDAttrName != null && wildcardIDName != null){ 2740 reportSchemaError( 2741 "cvc-complex-type.5.2", 2742 new Object [] { element.rawname, wildcardIDName, attrGrp.fIDAttrName }); 2743 } 2744 2745 } 2747 void processOneAttribute( 2748 QName element, 2749 XMLAttributes attributes, 2750 int index, 2751 XSAttributeDecl currDecl, 2752 XSAttributeUseImpl currUse, 2753 AttributePSVImpl attrPSVI) { 2754 2755 String attrValue = attributes.getValue(index); 2756 fXSIErrorReporter.pushContext(); 2757 2758 XSSimpleType attDV = currDecl.fType; 2765 2766 Object actualValue = null; 2767 try { 2768 actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo); 2769 if (fNormalizeData) 2771 attributes.setValue(index, fValidatedInfo.normalizedValue); 2772 2773 Augmentations augs = attributes.getAugmentations(index); 2774 2775 XSSimpleType effectiveType = fValidatedInfo.memberType != null 2776 ? fValidatedInfo.memberType : attDV; 2777 2778 augs.putItem(Constants.ID_ATTRIBUTE, 2779 effectiveType.isIDType()?Boolean.TRUE:Boolean.FALSE ); 2780 augs.putItem(Constants.TYPEINFO, effectiveType ); 2781 2782 if (attDV.getVariety() == XSSimpleType.VARIETY_ATOMIC && 2784 attDV.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION){ 2785 QName qName = (QName)actualValue; 2786 SchemaGrammar grammar = fGrammarBucket.getGrammar(qName.uri); 2787 2788 2794 if (grammar != null) { 2795 fNotation = grammar.getGlobalNotationDecl(qName.localpart); 2796 } 2797 } 2798 } catch (InvalidDatatypeValueException idve) { 2799 reportSchemaError(idve.getKey(), idve.getArgs()); 2800 reportSchemaError( 2801 "cvc-attribute.3", 2802 new Object [] { element.rawname, fTempQName.rawname, attrValue, attDV.getName()}); 2803 } 2804 2805 if (actualValue != null && currDecl.getConstraintType() == XSConstants.VC_FIXED) { 2808 if (!actualValue.equals(currDecl.fDefault.actualValue)){ 2809 reportSchemaError( 2810 "cvc-attribute.4", 2811 new Object [] { 2812 element.rawname, 2813 fTempQName.rawname, 2814 attrValue, 2815 currDecl.fDefault.stringValue()}); 2816 } 2817 } 2818 2819 if (actualValue != null 2821 && currUse != null 2822 && currUse.fConstraintType == XSConstants.VC_FIXED) { 2823 if (!actualValue.equals(currUse.fDefault.actualValue)){ 2824 reportSchemaError( 2825 "cvc-complex-type.3.1", 2826 new Object [] { 2827 element.rawname, 2828 fTempQName.rawname, 2829 attrValue, 2830 currUse.fDefault.stringValue()}); 2831 } 2832 } 2833 if (fIdConstraint) { 2834 attrPSVI.fActualValue = actualValue; 2835 } 2836 2837 if (fAugPSVI) { 2838 attrPSVI.fDeclaration = currDecl; 2840 attrPSVI.fTypeDecl = attDV; 2842 2843 attrPSVI.fMemberType = fValidatedInfo.memberType; 2845 attrPSVI.fNormalizedValue = fValidatedInfo.normalizedValue; 2850 attrPSVI.fActualValue = fValidatedInfo.actualValue; 2851 attrPSVI.fActualValueType = fValidatedInfo.actualValueType; 2852 attrPSVI.fItemValueTypes = fValidatedInfo.itemValueTypes; 2853 2854 2855 2856 attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL; 2858 2859 String [] errors = fXSIErrorReporter.mergeContext(); 2860 attrPSVI.fErrorCodes = errors; 2862 attrPSVI.fValidity = 2864 (errors == null) ? AttributePSVI.VALIDITY_VALID : AttributePSVI.VALIDITY_INVALID; 2865 } 2866 } 2867 2868 void addDefaultAttributes( 2869 QName element, 2870 XMLAttributes attributes, 2871 XSAttributeGroupDecl attrGrp) { 2872 if (DEBUG) { 2879 System.out.println("==>addDefaultAttributes: " + element); 2880 } 2881 XSObjectList attrUses = attrGrp.getAttributeUses(); 2882 int useCount = attrUses.getLength(); 2883 XSAttributeUseImpl currUse; 2884 XSAttributeDecl currDecl; 2885 short constType; 2886 ValidatedInfo defaultValue; 2887 boolean isSpecified; 2888 QName attName; 2889 for (int i = 0; i < useCount; i++) { 2891 2892 currUse = (XSAttributeUseImpl)attrUses.item(i); 2893 currDecl = currUse.fAttrDecl; 2894 constType = currUse.fConstraintType; 2896 defaultValue = currUse.fDefault; 2897 if (constType == XSConstants.VC_NONE) { 2898 constType = currDecl.getConstraintType(); 2899 defaultValue = currDecl.fDefault; 2900 } 2901 isSpecified = attributes.getValue(currDecl.fTargetNamespace, currDecl.fName) != null; 2903 2904 if (currUse.fUse == SchemaSymbols.USE_REQUIRED) { 2909 if (!isSpecified) 2910 reportSchemaError("cvc-complex-type.4", new Object []{element.rawname, currDecl.fName}); 2911 } 2912 if (!isSpecified && constType != XSConstants.VC_NONE) { 2914 attName = new QName(null, currDecl.fName, currDecl.fName, currDecl.fTargetNamespace); 2915 String normalized = (defaultValue!=null)?defaultValue.stringValue():""; 2916 int attrIndex = attributes.addAttribute(attName, "CDATA", normalized); 2917 2918 Augmentations augs = attributes.getAugmentations(attrIndex); 2919 2920 XSSimpleType effectiveType = defaultValue.memberType!=null 2921 ? defaultValue.memberType : currDecl.fType; 2922 2923 augs.putItem(Constants.ID_ATTRIBUTE, 2924 effectiveType.isIDType()?Boolean.TRUE:Boolean.FALSE ); 2925 augs.putItem(Constants.TYPEINFO,effectiveType); 2926 2927 if (fAugPSVI) { 2928 2929 AttributePSVImpl attrPSVI = new AttributePSVImpl(); 2931 augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI); 2932 2933 attrPSVI.fDeclaration = currDecl; 2934 attrPSVI.fTypeDecl = currDecl.fType; 2935 attrPSVI.fMemberType = defaultValue.memberType; 2936 attrPSVI.fNormalizedValue = normalized; 2937 attrPSVI.fActualValue = defaultValue.actualValue; 2938 attrPSVI.fActualValueType = defaultValue.actualValueType; 2939 attrPSVI.fItemValueTypes = defaultValue.itemValueTypes; 2940 attrPSVI.fValidationContext = fValidationRoot; 2941 attrPSVI.fValidity = AttributePSVI.VALIDITY_VALID; 2942 attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL; 2943 attrPSVI.fSpecified = true; 2944 } 2945 } 2946 2947 } } 2950 2955 void processElementContent(QName element) { 2956 if (fCurrentElemDecl != null 2958 && fCurrentElemDecl.fDefault != null 2959 && !fSawText 2960 && !fSubElement 2961 && !fNil) { 2962 2963 String strv = fCurrentElemDecl.fDefault.stringValue(); 2964 int bufLen = strv.length(); 2965 if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < bufLen) { 2966 fNormalizedStr.ch = new char[bufLen]; 2967 } 2968 strv.getChars(0, bufLen, fNormalizedStr.ch, 0); 2969 fNormalizedStr.offset = 0; 2970 fNormalizedStr.length = bufLen; 2971 fDefaultValue = fNormalizedStr; 2972 } 2973 2975 fValidatedInfo.normalizedValue = null; 2976 2977 if (fNil) { 2980 if (fSubElement || fSawText){ 2981 reportSchemaError( 2982 "cvc-elt.3.2.1", 2983 new Object [] { 2984 element.rawname, 2985 SchemaSymbols.URI_XSI + "," + SchemaSymbols.XSI_NIL }); 2986 } 2987 } 2988 2989 this.fValidatedInfo.reset(); 2990 2991 if (fCurrentElemDecl != null 2994 && fCurrentElemDecl.getConstraintType() != XSConstants.VC_NONE 2995 && !fSubElement 2996 && !fSawText 2997 && !fNil) { 2998 if (fCurrentType != fCurrentElemDecl.fType) { 3000 if (XSConstraints 3002 .ElementDefaultValidImmediate( 3003 fCurrentType, 3004 fCurrentElemDecl.fDefault.stringValue(), 3005 fState4XsiType, 3006 null) 3007 == null) 3008 reportSchemaError( 3009 "cvc-elt.5.1.1", 3010 new Object [] { 3011 element.rawname, 3012 fCurrentType.getName(), 3013 fCurrentElemDecl.fDefault.stringValue()}); 3014 } 3015 elementLocallyValidType(element, fCurrentElemDecl.fDefault.stringValue()); 3019 } else { 3020 3023 Object actualValue = elementLocallyValidType(element, fBuffer); 3026 if (fCurrentElemDecl != null 3028 && fCurrentElemDecl.getConstraintType() == XSConstants.VC_FIXED 3029 && !fNil) { 3030 String content = fBuffer.toString(); 3031 if (fSubElement) 3033 reportSchemaError("cvc-elt.5.2.2.1", new Object []{element.rawname}); 3034 if (fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { 3036 XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType; 3037 if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED) { 3039 if (!fCurrentElemDecl.fDefault.normalizedValue.equals(content)) 3041 reportSchemaError( 3042 "cvc-elt.5.2.2.2.1", 3043 new Object [] { 3044 element.rawname, 3045 content, 3046 fCurrentElemDecl.fDefault.normalizedValue }); 3047 } 3048 else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { 3050 if (actualValue != null 3051 && !actualValue.equals(fCurrentElemDecl.fDefault.actualValue)) 3052 reportSchemaError( 3053 "cvc-elt.5.2.2.2.2", 3054 new Object [] { 3055 element.rawname, 3056 content, 3057 fCurrentElemDecl.fDefault.stringValue()}); 3058 } 3059 } else if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { 3060 if (actualValue != null 3061 && !actualValue.equals(fCurrentElemDecl.fDefault.actualValue)) 3062 reportSchemaError( 3065 "cvc-elt.5.2.2.2.2", 3066 new Object [] { 3067 element.rawname, 3068 content, 3069 fCurrentElemDecl.fDefault.stringValue()}); 3070 } 3071 } 3072 } 3073 3074 if (fDefaultValue == null && fNormalizeData && fDocumentHandler != null && fUnionType) { 3075 String content = fValidatedInfo.normalizedValue; 3078 if (content == null) 3079 content = fBuffer.toString(); 3080 3081 int bufLen = content.length(); 3082 if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < bufLen) { 3083 fNormalizedStr.ch = new char[bufLen]; 3084 } 3085 content.getChars(0, bufLen, fNormalizedStr.ch, 0); 3086 fNormalizedStr.offset = 0; 3087 fNormalizedStr.length = bufLen; 3088 fDocumentHandler.characters(fNormalizedStr, null); 3089 } 3090 } 3092 Object elementLocallyValidType(QName element, Object textContent) { 3093 if (fCurrentType == null) 3094 return null; 3095 3096 Object retValue = null; 3097 if (fCurrentType.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { 3101 if (fSubElement) 3103 reportSchemaError("cvc-type.3.1.2", new Object []{element.rawname}); 3104 if (!fNil) { 3106 XSSimpleType dv = (XSSimpleType)fCurrentType; 3107 try { 3108 if (!fNormalizeData || fUnionType) { 3109 fValidationState.setNormalizationRequired(true); 3110 } 3111 retValue = dv.validate(textContent, fValidationState, fValidatedInfo); 3112 } catch (InvalidDatatypeValueException e) { 3113 reportSchemaError(e.getKey(), e.getArgs()); 3114 reportSchemaError( 3115 "cvc-type.3.1.3", 3116 new Object [] { element.rawname, textContent }); 3117 } 3118 } 3119 } else { 3120 retValue = elementLocallyValidComplexType(element, textContent); 3122 } 3123 3124 return retValue; 3125 } 3127 Object elementLocallyValidComplexType(QName element, Object textContent) { 3128 Object actualValue = null; 3129 XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType; 3130 3131 if (!fNil) { 3136 if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_EMPTY 3138 && (fSubElement || fSawText || fSawChildren)) { 3139 reportSchemaError("cvc-complex-type.2.1", new Object []{element.rawname}); 3140 } 3141 else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) { 3143 if (fSubElement) 3144 reportSchemaError("cvc-complex-type.2.2", new Object []{element.rawname}); 3145 XSSimpleType dv = ctype.fXSSimpleType; 3146 try { 3147 if (!fNormalizeData || fUnionType) { 3148 fValidationState.setNormalizationRequired(true); 3149 } 3150 actualValue = dv.validate(textContent, fValidationState, fValidatedInfo); 3151 } catch (InvalidDatatypeValueException e) { 3152 reportSchemaError(e.getKey(), e.getArgs()); 3153 reportSchemaError("cvc-complex-type.2.2", new Object []{element.rawname}); 3154 } 3155 } 3158 else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) { 3160 if (fSawCharacters) { 3161 reportSchemaError("cvc-complex-type.2.3", new Object []{element.rawname}); 3162 } 3163 } 3164 if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT 3166 || ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED) { 3167 if (DEBUG) { 3170 System.out.println(fCurrCMState); 3171 } 3172 if (fCurrCMState[0] >= 0 && !fCurrentCM.endContentModel(fCurrCMState)) { 3173 String expected = expectedStr(fCurrentCM.whatCanGoHere(fCurrCMState)); 3174 reportSchemaError( 3175 "cvc-complex-type.2.4.b", 3176 new Object [] { element.rawname, expected }); 3177 } 3178 } 3179 } 3180 return actualValue; 3181 } 3183 public void reportSchemaError(String key, Object [] arguments) { 3184 if (fDoValidation) 3185 fXSIErrorReporter.reportError( 3186 XSMessageFormatter.SCHEMA_DOMAIN, 3187 key, 3188 arguments, 3189 XMLErrorReporter.SEVERITY_ERROR); 3190 } 3191 3192 private String expectedStr(Vector expected) { 3193 StringBuffer ret = new StringBuffer ("{"); 3194 int size = expected.size(); 3195 for (int i = 0; i < size; i++) { 3196 if (i > 0) 3197 ret.append(", "); 3198 ret.append(expected.elementAt(i).toString()); 3199 } 3200 ret.append('}'); 3201 return ret.toString(); 3202 } 3203 3204 3205 3206 3208 3213 protected static class XPathMatcherStack { 3214 3215 3219 3220 protected XPathMatcher[] fMatchers = new XPathMatcher[4]; 3221 3222 3223 protected int fMatchersCount; 3224 3225 3226 protected IntStack fContextStack = new IntStack(); 3227 3228 3232 public XPathMatcherStack() { 3233 } 3235 3239 3240 public void clear() { 3241 for (int i = 0; i < fMatchersCount; i++) { 3242 fMatchers[i] = null; 3243 } 3244 fMatchersCount = 0; 3245 fContextStack.clear(); 3246 } 3248 3249 public int size() { 3250 return fContextStack.size(); 3251 } 3253 3254 public int getMatcherCount() { 3255 return fMatchersCount; 3256 } 3258 3259 public void addMatcher(XPathMatcher matcher) { 3260 ensureMatcherCapacity(); 3261 fMatchers[fMatchersCount++] = matcher; 3262 } 3264 3265 public XPathMatcher getMatcherAt(int index) { 3266 return fMatchers[index]; 3267 } 3269 3270 public void pushContext() { 3271 fContextStack.push(fMatchersCount); 3272 } 3274 3275 public void popContext() { 3276 fMatchersCount = fContextStack.pop(); 3277 } 3279 3283 3284 private void ensureMatcherCapacity() { 3285 if (fMatchersCount == fMatchers.length) { 3286 XPathMatcher[] array = new XPathMatcher[fMatchers.length * 2]; 3287 System.arraycopy(fMatchers, 0, array, 0, fMatchers.length); 3288 fMatchers = array; 3289 } 3290 } 3292 } 3294 3296 3302 protected abstract class ValueStoreBase implements ValueStore { 3303 3304 3308 3309 protected IdentityConstraint fIdentityConstraint; 3310 protected int fFieldCount = 0; 3311 protected Field[] fFields = null; 3312 3313 protected Object [] fLocalValues = null; 3314 protected Object [] fLocalValueTypes = null; 3315 3316 3317 protected int fValuesCount; 3318 3319 3320 public final Vector fValues = new Vector (); 3321 public final Vector fValueTypes = new Vector (); 3322 3323 3324 final StringBuffer fTempBuffer = new StringBuffer (); 3325 3326 3330 3331 protected ValueStoreBase(IdentityConstraint identityConstraint) { 3332 fIdentityConstraint = identityConstraint; 3333 fFieldCount = fIdentityConstraint.getFieldCount(); 3334 fFields = new Field[fFieldCount]; 3335 fLocalValues = new Object [fFieldCount]; 3336 fLocalValueTypes = new Object [fFieldCount]; 3337 for (int i = 0; i < fFieldCount; i++) { 3338 fFields[i] = fIdentityConstraint.getFieldAt(i); 3339 } 3340 } 3342 3346 public void clear() { 3349 fValuesCount = 0; 3350 fValues.setSize(0); 3351 fValueTypes.setSize(0); 3352 } 3354 public void append(ValueStoreBase newVal) { 3356 for (int i = 0; i < newVal.fValues.size(); i++) { 3357 fValues.addElement(newVal.fValues.elementAt(i)); 3358 fValueTypes.addElement(newVal.fValueTypes.elementAt(i)); 3359 } 3360 } 3362 3363 public void startValueScope() { 3364 fValuesCount = 0; 3365 for (int i = 0; i < fFieldCount; i++) { 3366 fLocalValues[i] = null; 3367 fLocalValueTypes[i] = null; 3368 } 3369 } 3371 3372 public void endValueScope() { 3373 3374 if (fValuesCount == 0) { 3375 if (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY) { 3376 String code = "AbsentKeyValue"; 3377 String eName = fIdentityConstraint.getElementName(); 3378 reportSchemaError(code, new Object [] { eName }); 3379 } 3380 return; 3381 } 3382 3383 if (fValuesCount != fFieldCount) { 3385 switch (fIdentityConstraint.getCategory()) { 3386 case IdentityConstraint.IC_UNIQUE : { 3387 String code = "UniqueNotEnoughValues"; 3388 String ename = fIdentityConstraint.getElementName(); 3389 reportSchemaError(code, new Object [] { ename }); 3390 break; 3391 } 3392 case IdentityConstraint.IC_KEY : { 3393 String code = "KeyNotEnoughValues"; 3394 UniqueOrKey key = (UniqueOrKey) fIdentityConstraint; 3395 String ename = fIdentityConstraint.getElementName(); 3396 String kname = key.getIdentityConstraintName(); 3397 reportSchemaError(code, new Object [] { ename, kname }); 3398 break; 3399 } 3400 case IdentityConstraint.IC_KEYREF : { 3401 String code = "KeyRefNotEnoughValues"; 3402 KeyRef keyref = (KeyRef) fIdentityConstraint; 3403 String ename = fIdentityConstraint.getElementName(); 3404 String kname = (keyref.getKey()).getIdentityConstraintName(); 3405 reportSchemaError(code, new Object [] { ename, kname }); 3406 break; 3407 } 3408 } 3409 return; 3410 } 3411 3412 } 3414 public void endDocumentFragment() { 3420 } 3422 3427 public void endDocument() { 3428 } 3430 3434 3437 3438 public void reportError(String key, Object [] args) { 3439 reportSchemaError(key, args); 3440 } 3442 3450 public void addValue(Field field, Object actualValue) { 3451 addValue(field,actualValue,null); 3452 } 3453 3454 public void addValue(Field field, Object actualValue,Object type) { 3455 int i; 3456 for (i = fFieldCount - 1; i > -1; i--) { 3457 if (fFields[i] == field) { 3458 break; 3459 } 3460 } 3461 if (i == -1) { 3463 String code = "UnknownField"; 3464 reportSchemaError(code, new Object [] { field.toString()}); 3465 return; 3466 } 3467 if (Boolean.TRUE != mayMatch(field)) { 3468 String code = "FieldMultipleMatch"; 3469 reportSchemaError(code, new Object [] { field.toString()}); 3470 } else { 3471 fValuesCount++; 3472 } 3473 fLocalValues[i] = actualValue; 3474 fLocalValueTypes[i] = type; 3475 if (fValuesCount == fFieldCount) { 3476 checkDuplicateValues(); 3477 for (i = 0; i < fFieldCount; i++) { 3479 fValues.addElement(fLocalValues[i]); 3480 if(fLocalValueTypes[i] != null) 3481 fValueTypes.addElement(fLocalValueTypes[i]); 3482 } 3483 } 3484 } 3486 3489 public boolean contains() { 3490 int next = 0; 3493 LOOP : for (int i = 0; i < fValues.size(); i = next) { 3494 next = i + fFieldCount; 3495 for (int j = 0; j < fFieldCount; j++) { 3496 Object value1 = fLocalValues[j]; 3497 Object value2 = fValues.elementAt(i++); 3498 if (value1 == null || value2 == null || !(value1.equals(value2))) { 3499 continue LOOP; 3500 } 3501 } 3502 return true; 3504 } 3505 return false; 3507 } 3509 3513 public Object contains(Vector values) { 3514 for (int i = 0; i < values.size(); i++) { 3515 if (!fValues.contains(values.elementAt(i))) 3516 return values.elementAt(i); 3517 3518 } 3519 return null; 3520 } 3522 protected boolean isDerivedFromSamePrimitiveType(XSTypeDefinition typeOne , XSTypeDefinition typeTwo){ 3523 if(typeOne == null || typeTwo == null) 3524 return false; 3525 3526 if(typeOne.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE && 3527 ((XSComplexTypeDefinition) typeOne).getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE) { 3528 typeOne = ((XSComplexTypeDefinition)typeOne).getSimpleType(); 3529 3530 } 3531 if(typeTwo.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE && ((XSComplexTypeDefinition) typeTwo).getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE) { 3532 typeTwo = ((XSComplexTypeDefinition)typeTwo).getSimpleType(); 3533 } 3534 3535 if(typeOne == null || typeTwo == null) 3536 return false; 3537 3538 if((typeOne.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) && (typeTwo.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE)){ 3539 try{ 3540 short s1 = ((XSSimpleTypeDecl)typeOne).getPrimitiveKind(); 3541 short s2 = ((XSSimpleTypeDecl)typeTwo).getPrimitiveKind(); 3542 if(s1 == s2) 3543 return true; 3544 }catch(Exception ex){ 3545 if(DEBUG)ex.printStackTrace(); 3546 } 3547 3548 } 3549 return false; 3550 } 3551 3552 public Object contains(Vector values,Vector types) { 3553 for (int i = 0; i < values.size(); i++) { 3554 if (fValues.contains(values.elementAt(i))){ 3555 int j = fValues.indexOf(values.elementAt(i)); 3556 try{ 3557 if(!isDerivedFromSamePrimitiveType((XSTypeDefinition)fValueTypes.elementAt(j),(XSTypeDefinition)types.elementAt(i))) 3558 return values.elementAt(i); 3559 }catch(Exception ex){ 3560 return values.elementAt(i); 3561 } 3562 }else 3563 return values.elementAt(i); 3564 } 3565 return null; 3566 } 3571 protected void checkDuplicateValues() { 3572 } 3575 3576 protected String toString(Object [] values) { 3577 3578 int size = values.length; 3580 if (size == 0) { 3581 return ""; 3582 } 3583 3584 fTempBuffer.setLength(0); 3585 3586 for (int i = 0; i < size; i++) { 3588 if (i > 0) { 3589 fTempBuffer.append(','); 3590 } 3591 fTempBuffer.append(values[i]); 3592 } 3593 return fTempBuffer.toString(); 3594 3595 } 3597 3601 3602 public String toString() { 3603 String s = super.toString(); 3604 int index1 = s.lastIndexOf('$'); 3605 if (index1 != -1) { 3606 s = s.substring(index1 + 1); 3607 } 3608 int index2 = s.lastIndexOf('.'); 3609 if (index2 != -1) { 3610 s = s.substring(index2 + 1); 3611 } 3612 return s + '[' + fIdentityConstraint + ']'; 3613 } 3615 } 3617 3618 3623 protected class UniqueValueStore extends ValueStoreBase { 3624 3625 3629 3630 public UniqueValueStore(UniqueOrKey unique) { 3631 super(unique); 3632 } 3634 3638 3641 protected void checkDuplicateValues() { 3642 if (contains()) { 3644 String code = "DuplicateUnique"; 3645 String value = toString(fLocalValues); 3646 String ename = fIdentityConstraint.getElementName(); 3647 reportSchemaError(code, new Object []{value,ename}); 3648 } 3649 } 3651 } 3653 3658 protected class KeyValueStore extends ValueStoreBase { 3659 3660 3662 3666 3667 public KeyValueStore(UniqueOrKey key) { 3668 super(key); 3669 } 3671 3675 3678 protected void checkDuplicateValues() { 3679 if (contains()) { 3680 String code = "DuplicateKey"; 3681 String value = toString(fLocalValues); 3682 String ename = fIdentityConstraint.getElementName(); 3683 reportSchemaError(code, new Object []{value,ename}); 3684 } 3685 } 3687 } 3689 3694 protected class KeyRefValueStore extends ValueStoreBase { 3695 3696 3700 3701 protected ValueStoreBase fKeyValueStore; 3702 3703 3707 3708 public KeyRefValueStore(KeyRef keyRef, KeyValueStore keyValueStore) { 3709 super(keyRef); 3710 fKeyValueStore = keyValueStore; 3711 } 3713 3717 public void endDocumentFragment() { 3720 3721 super.endDocumentFragment(); 3723 3724 fKeyValueStore = 3727 (ValueStoreBase) fValueStoreCache.fGlobalIDConstraintMap.get( 3728 ((KeyRef) fIdentityConstraint).getKey()); 3729 3730 if (fKeyValueStore == null) { 3731 String code = "KeyRefOutOfScope"; 3733 String value = fIdentityConstraint.toString(); 3734 reportSchemaError(code, new Object []{value}); 3735 return; 3736 } 3737 Object value = fKeyValueStore.contains(fValues,fValueTypes); 3738 if (value != null) { 3739 String code = "KeyNotFound"; 3740 String element = fIdentityConstraint.getElementName(); 3741 String name = fIdentityConstraint.getName(); 3742 reportSchemaError(code, new Object [] { name, value.toString(), element }); 3743 } 3744 3745 } 3747 3748 public void endDocument() { 3749 super.endDocument(); 3750 3751 } 3753 } 3755 3757 3763 protected class ValueStoreCache { 3764 3765 final LocalIDKey fLocalId = new LocalIDKey(); 3769 3771 3772 protected final Vector fValueStores = new Vector (); 3773 3774 3783 protected final Hashtable fIdentityConstraint2ValueStoreMap = new Hashtable (); 3784 3785 protected final Stack fGlobalMapStack = new Stack (); 3805 protected final Hashtable fGlobalIDConstraintMap = new Hashtable (); 3806 3807 3811 3812 public ValueStoreCache() { 3813 } 3815 3819 3820 public void startDocument() { 3821 fValueStores.removeAllElements(); 3822 fIdentityConstraint2ValueStoreMap.clear(); 3823 fGlobalIDConstraintMap.clear(); 3824 fGlobalMapStack.removeAllElements(); 3825 } 3827 public void startElement() { 3830 if (fGlobalIDConstraintMap.size() > 0) 3832 fGlobalMapStack.push(fGlobalIDConstraintMap.clone()); 3833 else 3834 fGlobalMapStack.push(null); 3835 fGlobalIDConstraintMap.clear(); 3836 } 3838 3841 public void endElement() { 3842 if (fGlobalMapStack.isEmpty()) 3843 return; Hashtable oldMap = (Hashtable )fGlobalMapStack.pop(); 3845 if (oldMap == null) 3847 return; 3848 3849 Enumeration keys = oldMap.keys(); 3850 while (keys.hasMoreElements()) { 3851 IdentityConstraint id = (IdentityConstraint)keys.nextElement(); 3852 ValueStoreBase oldVal = (ValueStoreBase)oldMap.get(id); 3853 if (oldVal != null) { 3854 ValueStoreBase currVal = (ValueStoreBase)fGlobalIDConstraintMap.get(id); 3855 if (currVal == null) 3856 fGlobalIDConstraintMap.put(id, oldVal); 3857 else if (currVal != oldVal) { 3858 currVal.append(oldVal); 3859 } 3860 } 3861 } 3862 } 3864 3868 public void initValueStoresFor(XSElementDecl eDecl, FieldActivator activator) { 3869 IdentityConstraint [] icArray = eDecl.fIDConstraints; 3871 int icCount = eDecl.fIDCPos; 3872 for (int i = 0; i < icCount; i++) { 3873 switch (icArray[i].getCategory()) { 3874 case (IdentityConstraint.IC_UNIQUE): 3875 UniqueOrKey unique = (UniqueOrKey)icArray[i]; 3877 LocalIDKey toHash = new LocalIDKey(unique, fElementDepth); 3878 UniqueValueStore uniqueValueStore = 3879 (UniqueValueStore) fIdentityConstraint2ValueStoreMap.get(toHash); 3880 if (uniqueValueStore == null) { 3881 uniqueValueStore = new UniqueValueStore(unique); 3882 fIdentityConstraint2ValueStoreMap.put(toHash, uniqueValueStore); 3883 } else { 3884 uniqueValueStore.clear(); 3885 } 3886 fValueStores.addElement(uniqueValueStore); 3887 activateSelectorFor(icArray[i]); 3888 break; 3889 case (IdentityConstraint.IC_KEY): 3890 UniqueOrKey key = (UniqueOrKey)icArray[i]; 3892 toHash = new LocalIDKey(key, fElementDepth); 3893 KeyValueStore keyValueStore = 3894 (KeyValueStore) fIdentityConstraint2ValueStoreMap.get(toHash); 3895 if (keyValueStore == null) { 3896 keyValueStore = new KeyValueStore(key); 3897 fIdentityConstraint2ValueStoreMap.put(toHash, keyValueStore); 3898 } else { 3899 keyValueStore.clear(); 3900 } 3901 fValueStores.addElement(keyValueStore); 3902 activateSelectorFor(icArray[i]); 3903 break; 3904 case (IdentityConstraint.IC_KEYREF): 3905 KeyRef keyRef = (KeyRef)icArray[i]; 3907 toHash = new LocalIDKey(keyRef, fElementDepth); 3908 KeyRefValueStore keyRefValueStore = 3909 (KeyRefValueStore) fIdentityConstraint2ValueStoreMap.get(toHash); 3910 if (keyRefValueStore == null) { 3911 keyRefValueStore = new KeyRefValueStore(keyRef, null); 3912 fIdentityConstraint2ValueStoreMap.put(toHash, keyRefValueStore); 3913 } else { 3914 keyRefValueStore.clear(); 3915 } 3916 fValueStores.addElement(keyRefValueStore); 3917 activateSelectorFor(icArray[i]); 3918 break; 3919 } 3920 } 3921 } 3923 3924 public ValueStoreBase getValueStoreFor(IdentityConstraint id, int initialDepth) { 3925 fLocalId.fDepth = initialDepth; 3926 fLocalId.fId = id; 3927 return (ValueStoreBase) fIdentityConstraint2ValueStoreMap.get(fLocalId); 3928 } 3930 3931 public ValueStoreBase getGlobalValueStoreFor(IdentityConstraint id) { 3932 return(ValueStoreBase)fGlobalIDConstraintMap.get(id); 3933 } 3935 public void transplant(IdentityConstraint id, int initialDepth) { 3940 fLocalId.fDepth = initialDepth; 3941 fLocalId.fId = id; 3942 ValueStoreBase newVals = 3943 (ValueStoreBase) fIdentityConstraint2ValueStoreMap.get(fLocalId); 3944 if (id.getCategory() == IdentityConstraint.IC_KEYREF) 3945 return; 3946 ValueStoreBase currVals = (ValueStoreBase)fGlobalIDConstraintMap.get(id); 3947 if (currVals != null) { 3948 currVals.append(newVals); 3949 fGlobalIDConstraintMap.put(id, currVals); 3950 } else 3951 fGlobalIDConstraintMap.put(id, newVals); 3952 3953 } 3955 3956 public void endDocument() { 3957 3958 int count = fValueStores.size(); 3959 for (int i = 0; i < count; i++) { 3960 ValueStoreBase valueStore = (ValueStoreBase)fValueStores.elementAt(i); 3961 valueStore.endDocument(); 3962 } 3963 3964 } 3966 3970 3971 public String toString() { 3972 String s = super.toString(); 3973 int index1 = s.lastIndexOf('$'); 3974 if (index1 != -1) { 3975 return s.substring(index1 + 1); 3976 } 3977 int index2 = s.lastIndexOf('.'); 3978 if (index2 != -1) { 3979 return s.substring(index2 + 1); 3980 } 3981 return s; 3982 } 3984 } 3986 protected class LocalIDKey { 3989 3990 public IdentityConstraint fId; 3991 public int fDepth; 3992 3993 public LocalIDKey() { 3994 } 3995 3996 public LocalIDKey(IdentityConstraint id, int depth) { 3997 fId = id; 3998 fDepth = depth; 3999 } 4001 public int hashCode() { 4003 return fId.hashCode()+fDepth; 4004 } 4005 4006 public boolean equals(Object localIDKey) { 4007 if(localIDKey instanceof LocalIDKey) { 4008 LocalIDKey lIDKey = (LocalIDKey)localIDKey; 4009 return (lIDKey.fId == fId && lIDKey.fDepth == fDepth); 4010 } 4011 return false; 4012 } 4013 } 4015} | Popular Tags |