1 16 package org.apache.xerces.impl.xs.traversers; 17 18 import org.apache.xerces.impl.xs.SchemaGrammar; 19 import org.apache.xerces.impl.xs.SchemaSymbols; 20 import org.apache.xerces.impl.xs.XSAnnotationImpl; 21 import org.apache.xerces.impl.xs.XSAttributeGroupDecl; 22 import org.apache.xerces.util.DOMUtil; 23 import org.apache.xerces.util.XMLSymbols; 24 import org.apache.xerces.xni.QName; 25 import org.w3c.dom.Element ; 26 27 45 class XSDAttributeGroupTraverser extends XSDAbstractTraverser { 46 47 XSDAttributeGroupTraverser (XSDHandler handler, 48 XSAttributeChecker gAttrCheck) { 49 50 super(handler, gAttrCheck); 51 } 52 53 54 XSAttributeGroupDecl traverseLocal(Element elmNode, 55 XSDocumentInfo schemaDoc, 56 SchemaGrammar grammar) { 57 58 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc); 60 61 QName refAttr = (QName) attrValues[XSAttributeChecker.ATTIDX_REF]; 63 64 XSAttributeGroupDecl attrGrp = null; 65 66 if (refAttr == null) { 68 reportSchemaError("s4s-att-must-appear", new Object []{"attributeGroup (local)", "ref"}, elmNode); 69 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 70 return null; 71 } 72 73 attrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTEGROUP_TYPE, refAttr, elmNode); 75 76 77 Element child = DOMUtil.getFirstChildElement(elmNode); 79 if (child != null) { 80 String childName = DOMUtil.getLocalName(child); 81 if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) { 82 traverseAnnotationDecl(child, attrValues, false, schemaDoc); 83 child = DOMUtil.getNextSiblingElement(child); 84 } 85 86 if (child != null) { 87 Object [] args = new Object [] {refAttr.rawname, "(annotation?)", DOMUtil.getLocalName(child)}; 88 reportSchemaError("s4s-elt-must-match.1", args, child); 89 } 90 } 92 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 93 return attrGrp; 94 95 } 97 XSAttributeGroupDecl traverseGlobal(Element elmNode, 98 XSDocumentInfo schemaDoc, 99 SchemaGrammar grammar) { 100 101 XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl(); 102 103 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc); 105 106 String nameAttr = (String ) attrValues[XSAttributeChecker.ATTIDX_NAME]; 107 108 if (nameAttr == null) { 110 reportSchemaError("s4s-att-must-appear", new Object []{"attributeGroup (global)", "name"}, elmNode); 111 nameAttr = "no name"; 112 } 113 114 attrGrp.fName = nameAttr; 115 attrGrp.fTargetNamespace = schemaDoc.fTargetNamespace; 116 117 Element child = DOMUtil.getFirstChildElement(elmNode); 119 XSAnnotationImpl annotation = null; 120 121 if (child!=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 122 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc); 123 child = DOMUtil.getNextSiblingElement(child); 124 } 125 else { 126 String text = DOMUtil.getSyntheticAnnotation(elmNode); 127 if (text != null) { 128 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc); 129 } 130 } 131 132 135 Element nextNode = traverseAttrsAndAttrGrps(child, attrGrp, schemaDoc, grammar, null); 136 if (nextNode!=null) { 137 Object [] args = new Object [] {nameAttr, "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))", DOMUtil.getLocalName(nextNode)}; 139 reportSchemaError("s4s-elt-must-match.1", args, nextNode); 140 } 141 142 attrGrp.removeProhibitedAttrs(); 144 145 XSAttributeGroupDecl redefinedAttrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGrpOrAttrGrpRedefinedByRestriction( 147 XSDHandler.ATTRIBUTEGROUP_TYPE, 148 new QName(XMLSymbols.EMPTY_STRING, nameAttr, nameAttr, schemaDoc.fTargetNamespace), 149 schemaDoc, elmNode); 150 if(redefinedAttrGrp != null) { 151 Object [] errArgs = attrGrp.validRestrictionOf(nameAttr, redefinedAttrGrp); 152 if (errArgs != null) { 153 reportSchemaError((String )errArgs[errArgs.length-1], errArgs, child); 154 reportSchemaError("src-redefine.7.2.2", new Object [] {nameAttr, errArgs[errArgs.length-1]}, child); 155 } 156 } 157 158 attrGrp.fAnnotation = annotation; 159 160 grammar.addGlobalAttributeGroupDecl(attrGrp); 162 163 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 164 return attrGrp; 165 166 } 168 } | Popular Tags |