1 16 17 package org.apache.xerces.impl.xs.traversers; 18 19 import org.apache.xerces.impl.xs.SchemaGrammar; 20 import org.apache.xerces.impl.xs.SchemaSymbols; 21 import org.apache.xerces.impl.xs.XSElementDecl; 22 import org.apache.xerces.impl.xs.identity.IdentityConstraint; 23 import org.apache.xerces.impl.xs.identity.KeyRef; 24 import org.apache.xerces.impl.xs.identity.UniqueOrKey; 25 import org.apache.xerces.xni.QName; 26 import org.w3c.dom.Element ; 27 28 36 class XSDKeyrefTraverser extends XSDAbstractIDConstraintTraverser { 37 38 public XSDKeyrefTraverser (XSDHandler handler, 39 XSAttributeChecker gAttrCheck) { 40 super(handler, gAttrCheck); 41 } 42 43 void traverse(Element krElem, XSElementDecl element, 44 XSDocumentInfo schemaDoc, SchemaGrammar grammar) { 45 46 Object [] attrValues = fAttrChecker.checkAttributes(krElem, false, schemaDoc); 48 49 String krName = (String )attrValues[XSAttributeChecker.ATTIDX_NAME]; 51 if(krName == null){ 52 reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_KEYREF , SchemaSymbols.ATT_NAME }, krElem); 53 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 55 return; 56 } 57 QName kName = (QName)attrValues[XSAttributeChecker.ATTIDX_REFER]; 58 if(kName == null){ 59 reportSchemaError("s4s-att-must-appear", new Object [] {SchemaSymbols.ELT_KEYREF , SchemaSymbols.ATT_REFER }, krElem); 60 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 62 return; 63 } 64 65 UniqueOrKey key = null; 66 IdentityConstraint ret = (IdentityConstraint)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.IDENTITYCONSTRAINT_TYPE, kName, krElem); 67 if (ret != null) { 70 if (ret.getCategory() == IdentityConstraint.IC_KEY || 71 ret.getCategory() == IdentityConstraint.IC_UNIQUE) { 72 key = (UniqueOrKey)ret; 73 } else { 74 reportSchemaError("src-resolve", new Object []{kName.rawname, "identity constraint key/unique"}, krElem); 75 } 76 } 77 78 if(key == null) { 79 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 80 return; 81 } 82 83 KeyRef keyRef = new KeyRef(schemaDoc.fTargetNamespace, krName, element.fName, key); 84 85 traverseIdentityConstraint(keyRef, krElem, schemaDoc, attrValues); 87 88 if(key.getFieldCount() != keyRef.getFieldCount()) { 91 reportSchemaError("c-props-correct.2" , new Object [] {krName,key.getIdentityConstraintName()}, krElem); 92 } else { 93 grammar.addIDConstraintDecl(element, keyRef); 96 } 97 98 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 100 } } 103 | Popular Tags |