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.XSGroupDecl; 63 import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl; 64 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl; 65 import com.sun.org.apache.xerces.internal.impl.xs.util.XInt; 66 import com.sun.org.apache.xerces.internal.util.DOMUtil; 67 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 68 import com.sun.org.apache.xerces.internal.xni.QName; 69 import org.w3c.dom.Element ; 70 71 84 class XSDGroupTraverser extends XSDAbstractParticleTraverser { 85 86 XSDGroupTraverser (XSDHandler handler, 87 XSAttributeChecker gAttrCheck) { 88 89 super(handler, gAttrCheck); 90 } 91 92 XSParticleDecl traverseLocal(Element elmNode, 93 XSDocumentInfo schemaDoc, 94 SchemaGrammar grammar) { 95 96 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, false, 98 schemaDoc); 99 QName refAttr = (QName) attrValues[XSAttributeChecker.ATTIDX_REF]; 100 XInt minAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]; 101 XInt maxAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]; 102 103 XSGroupDecl group = null; 104 105 if (refAttr == null) { 107 reportSchemaError("s4s-att-must-appear", new Object []{"group (local)", "ref"}, elmNode); 108 } else { 109 group = (XSGroupDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.GROUP_TYPE, refAttr, elmNode); 112 } 113 114 Element child = DOMUtil.getFirstChildElement(elmNode); 116 if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 117 traverseAnnotationDecl(child, attrValues, false, schemaDoc); 119 child = DOMUtil.getNextSiblingElement(child); 120 } 121 if (child != null) { 122 reportSchemaError("s4s-elt-must-match.1", new Object []{"group (local)", "(annotation?)", DOMUtil.getLocalName(elmNode)}, elmNode); 123 } 124 125 int minOccurs = minAttr.intValue(); 126 int maxOccurs = maxAttr.intValue(); 127 128 XSParticleDecl particle = null; 129 130 if (group != null && group.fModelGroup != null && 132 !(minOccurs == 0 && maxOccurs == 0)) { 133 if (fSchemaHandler.fDeclPool != null) { 135 particle = fSchemaHandler.fDeclPool.getParticleDecl(); 136 } else { 137 particle = new XSParticleDecl(); 138 } 139 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 140 particle.fValue = group.fModelGroup; 141 particle.fMinOccurs = minOccurs; 142 particle.fMaxOccurs = maxOccurs; 143 } 144 145 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 146 147 return particle; 148 149 } 151 XSGroupDecl traverseGlobal(Element elmNode, 152 XSDocumentInfo schemaDoc, 153 SchemaGrammar grammar) { 154 155 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, true, 157 schemaDoc); 158 String strNameAttr = (String ) attrValues[XSAttributeChecker.ATTIDX_NAME]; 159 160 if (strNameAttr == null) { 162 reportSchemaError("s4s-att-must-appear", new Object []{"group (global)", "name"}, elmNode); 163 } 164 165 XSGroupDecl group = null; 166 XSParticleDecl particle = null; 167 168 Element l_elmChild = DOMUtil.getFirstChildElement(elmNode); 170 XSAnnotationImpl annotation = null; 171 if (l_elmChild == null) { 172 reportSchemaError("s4s-elt-must-match.2", 173 new Object []{"group (global)", "(annotation?, (all | choice | sequence))"}, 174 elmNode); 175 } else { 176 group = new XSGroupDecl(); 179 180 String childName = l_elmChild.getLocalName(); 181 if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) { 182 annotation = traverseAnnotationDecl(l_elmChild, attrValues, true, schemaDoc); 183 l_elmChild = DOMUtil.getNextSiblingElement(l_elmChild); 184 if (l_elmChild != null) 185 childName = l_elmChild.getLocalName(); 186 } 187 188 if (l_elmChild == null) { 189 reportSchemaError("s4s-elt-must-match.2", 190 new Object []{"group (global)", "(annotation?, (all | choice | sequence))"}, 191 elmNode); 192 } else if (childName.equals(SchemaSymbols.ELT_ALL)) { 193 particle = traverseAll(l_elmChild, schemaDoc, grammar, CHILD_OF_GROUP, group); 194 } else if (childName.equals(SchemaSymbols.ELT_CHOICE)) { 195 particle = traverseChoice(l_elmChild, schemaDoc, grammar, CHILD_OF_GROUP, group); 196 } else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) { 197 particle = traverseSequence(l_elmChild, schemaDoc, grammar, CHILD_OF_GROUP, group); 198 } else { 199 reportSchemaError("s4s-elt-must-match.1", 200 new Object []{"group (global)", "(annotation?, (all | choice | sequence))", DOMUtil.getLocalName(l_elmChild)}, 201 l_elmChild); 202 } 203 204 if (l_elmChild != null && 205 DOMUtil.getNextSiblingElement(l_elmChild) != null) { 206 reportSchemaError("s4s-elt-must-match.1", 207 new Object []{"group (global)", "(annotation?, (all | choice | sequence))", 208 DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(l_elmChild))}, 209 DOMUtil.getNextSiblingElement(l_elmChild)); 210 } 211 212 if (strNameAttr != null) { 214 group.fName = strNameAttr; 215 group.fTargetNamespace = schemaDoc.fTargetNamespace; 216 if (particle != null) 217 group.fModelGroup = (XSModelGroupImpl)particle.fValue; 218 group.fAnnotation = annotation; 219 grammar.addGlobalGroupDecl(group); 220 } 221 else { 222 group = null; 224 } 225 } 226 if(group != null) { 227 Object redefinedGrp = fSchemaHandler.getGrpOrAttrGrpRedefinedByRestriction(XSDHandler.GROUP_TYPE, 230 new QName(XMLSymbols.EMPTY_STRING, strNameAttr, strNameAttr, schemaDoc.fTargetNamespace), 231 schemaDoc, elmNode); 232 if(redefinedGrp != null) { 233 grammar.addRedefinedGroupDecl(group, (XSGroupDecl)redefinedGrp, 235 fSchemaHandler.element2Locator(elmNode)); 236 } 237 } 238 239 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 240 241 return group; 242 243 } } 245 | Popular Tags |