1 57 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 58 59 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 60 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 61 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 62 import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl; 63 import com.sun.org.apache.xerces.internal.util.DOMUtil; 64 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 65 import com.sun.org.apache.xerces.internal.xni.QName; 66 import org.w3c.dom.Element ; 67 68 84 class XSDAttributeGroupTraverser extends XSDAbstractTraverser { 85 86 XSDAttributeGroupTraverser (XSDHandler handler, 87 XSAttributeChecker gAttrCheck) { 88 89 super(handler, gAttrCheck); 90 } 91 92 93 XSAttributeGroupDecl traverseLocal(Element elmNode, 94 XSDocumentInfo schemaDoc, 95 SchemaGrammar grammar) { 96 97 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, false, schemaDoc); 99 100 QName refAttr = (QName) attrValues[XSAttributeChecker.ATTIDX_REF]; 102 103 XSAttributeGroupDecl attrGrp = null; 104 105 if (refAttr == null) { 107 reportSchemaError("s4s-att-must-appear", new Object []{"attributeGroup (local)", "ref"}, elmNode); 108 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 109 return null; 110 } 111 112 attrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTEGROUP_TYPE, refAttr, elmNode); 114 115 116 Element child = DOMUtil.getFirstChildElement(elmNode); 118 if (child != null) { 119 String childName = DOMUtil.getLocalName(child); 120 if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) { 121 traverseAnnotationDecl(child, attrValues, false, schemaDoc); 122 child = DOMUtil.getNextSiblingElement(child); 123 } 124 125 if (child != null) { 126 Object [] args = new Object [] {refAttr.rawname, "(annotation?)", DOMUtil.getLocalName(child)}; 127 reportSchemaError("s4s-elt-must-match.1", args, child); 128 } 129 } 131 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 132 return attrGrp; 133 134 } 136 XSAttributeGroupDecl traverseGlobal(Element elmNode, 137 XSDocumentInfo schemaDoc, 138 SchemaGrammar grammar) { 139 140 XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl(); 141 142 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc); 144 145 String nameAttr = (String ) attrValues[XSAttributeChecker.ATTIDX_NAME]; 146 147 if (nameAttr == null) { 149 reportSchemaError("s4s-att-must-appear", new Object []{"attributeGroup (global)", "name"}, elmNode); 150 nameAttr = "no name"; 151 } 152 153 attrGrp.fName = nameAttr; 154 attrGrp.fTargetNamespace = schemaDoc.fTargetNamespace; 155 156 Element child = DOMUtil.getFirstChildElement(elmNode); 158 XSAnnotationImpl annotation = null; 159 160 if (child!=null) { 161 String childName = DOMUtil.getLocalName(child); 162 if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) { 163 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc); 164 child = DOMUtil.getNextSiblingElement(child); 165 } 166 } 167 168 171 Element nextNode = traverseAttrsAndAttrGrps(child, attrGrp, schemaDoc, grammar, null); 172 if (nextNode!=null) { 173 Object [] args = new Object [] {nameAttr, "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))", DOMUtil.getLocalName(nextNode)}; 175 reportSchemaError("s4s-elt-must-match.1", args, nextNode); 176 } 177 178 attrGrp.removeProhibitedAttrs(); 180 181 XSAttributeGroupDecl redefinedAttrGrp = (XSAttributeGroupDecl)fSchemaHandler.getGrpOrAttrGrpRedefinedByRestriction( 183 XSDHandler.ATTRIBUTEGROUP_TYPE, 184 new QName(XMLSymbols.EMPTY_STRING, nameAttr, nameAttr, schemaDoc.fTargetNamespace), 185 schemaDoc, elmNode); 186 if(redefinedAttrGrp != null) { 187 Object [] errArgs = attrGrp.validRestrictionOf(nameAttr, redefinedAttrGrp); 188 if (errArgs != null) { 189 reportSchemaError((String )errArgs[errArgs.length-1], errArgs, child); 190 reportSchemaError("src-redefine.7.2.2", new Object [] {nameAttr, errArgs[errArgs.length-1]}, child); 191 } 192 } 193 194 attrGrp.fAnnotation = annotation; 195 196 grammar.addGlobalAttributeGroupDecl(attrGrp); 198 199 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 200 return attrGrp; 201 202 } 204 } | Popular Tags |