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.XSGroupDecl; 22 import org.apache.xerces.impl.xs.XSModelGroupImpl; 23 import org.apache.xerces.impl.xs.XSParticleDecl; 24 import org.apache.xerces.impl.xs.util.XInt; 25 import org.apache.xerces.util.DOMUtil; 26 import org.apache.xerces.util.XMLSymbols; 27 import org.apache.xerces.xni.QName; 28 import org.w3c.dom.Element ; 29 30 45 class XSDGroupTraverser extends XSDAbstractParticleTraverser { 46 47 XSDGroupTraverser (XSDHandler handler, 48 XSAttributeChecker gAttrCheck) { 49 50 super(handler, gAttrCheck); 51 } 52 53 XSParticleDecl traverseLocal(Element elmNode, 54 XSDocumentInfo schemaDoc, 55 SchemaGrammar grammar) { 56 57 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, false, 59 schemaDoc); 60 QName refAttr = (QName) attrValues[XSAttributeChecker.ATTIDX_REF]; 61 XInt minAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]; 62 XInt maxAttr = (XInt) attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]; 63 64 XSGroupDecl group = null; 65 66 if (refAttr == null) { 68 reportSchemaError("s4s-att-must-appear", new Object []{"group (local)", "ref"}, elmNode); 69 } else { 70 group = (XSGroupDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.GROUP_TYPE, refAttr, elmNode); 73 } 74 75 Element child = DOMUtil.getFirstChildElement(elmNode); 77 if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 78 traverseAnnotationDecl(child, attrValues, false, schemaDoc); 80 child = DOMUtil.getNextSiblingElement(child); 81 } 82 83 if (child != null) { 84 reportSchemaError("s4s-elt-must-match.1", new Object []{"group (local)", "(annotation?)", DOMUtil.getLocalName(elmNode)}, elmNode); 85 } 86 87 int minOccurs = minAttr.intValue(); 88 int maxOccurs = maxAttr.intValue(); 89 90 XSParticleDecl particle = null; 91 92 if (group != null && group.fModelGroup != null && 94 !(minOccurs == 0 && maxOccurs == 0)) { 95 if (fSchemaHandler.fDeclPool != null) { 97 particle = fSchemaHandler.fDeclPool.getParticleDecl(); 98 } else { 99 particle = new XSParticleDecl(); 100 } 101 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 102 particle.fValue = group.fModelGroup; 103 particle.fMinOccurs = minOccurs; 104 particle.fMaxOccurs = maxOccurs; 105 } 106 107 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 108 109 return particle; 110 111 } 113 XSGroupDecl traverseGlobal(Element elmNode, 114 XSDocumentInfo schemaDoc, 115 SchemaGrammar grammar) { 116 117 Object [] attrValues = fAttrChecker.checkAttributes(elmNode, true, 119 schemaDoc); 120 String strNameAttr = (String ) attrValues[XSAttributeChecker.ATTIDX_NAME]; 121 122 if (strNameAttr == null) { 124 reportSchemaError("s4s-att-must-appear", new Object []{"group (global)", "name"}, elmNode); 125 } 126 127 XSGroupDecl group = null; 128 XSParticleDecl particle = null; 129 130 Element l_elmChild = DOMUtil.getFirstChildElement(elmNode); 132 XSAnnotationImpl annotation = null; 133 if (l_elmChild == null) { 134 reportSchemaError("s4s-elt-must-match.2", 135 new Object []{"group (global)", "(annotation?, (all | choice | sequence))"}, 136 elmNode); 137 } else { 138 group = new XSGroupDecl(); 141 142 String childName = l_elmChild.getLocalName(); 143 if (childName.equals(SchemaSymbols.ELT_ANNOTATION)) { 144 annotation = traverseAnnotationDecl(l_elmChild, attrValues, true, schemaDoc); 145 l_elmChild = DOMUtil.getNextSiblingElement(l_elmChild); 146 if (l_elmChild != null) 147 childName = l_elmChild.getLocalName(); 148 } 149 else { 150 String text = DOMUtil.getSyntheticAnnotation(elmNode); 151 if (text != null) { 152 annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc); 153 } 154 } 155 156 if (l_elmChild == null) { 157 reportSchemaError("s4s-elt-must-match.2", 158 new Object []{"group (global)", "(annotation?, (all | choice | sequence))"}, 159 elmNode); 160 } else if (childName.equals(SchemaSymbols.ELT_ALL)) { 161 particle = traverseAll(l_elmChild, schemaDoc, grammar, CHILD_OF_GROUP, group); 162 } else if (childName.equals(SchemaSymbols.ELT_CHOICE)) { 163 particle = traverseChoice(l_elmChild, schemaDoc, grammar, CHILD_OF_GROUP, group); 164 } else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) { 165 particle = traverseSequence(l_elmChild, schemaDoc, grammar, CHILD_OF_GROUP, group); 166 } else { 167 reportSchemaError("s4s-elt-must-match.1", 168 new Object []{"group (global)", "(annotation?, (all | choice | sequence))", DOMUtil.getLocalName(l_elmChild)}, 169 l_elmChild); 170 } 171 172 if (l_elmChild != null && 173 DOMUtil.getNextSiblingElement(l_elmChild) != null) { 174 reportSchemaError("s4s-elt-must-match.1", 175 new Object []{"group (global)", "(annotation?, (all | choice | sequence))", 176 DOMUtil.getLocalName(DOMUtil.getNextSiblingElement(l_elmChild))}, 177 DOMUtil.getNextSiblingElement(l_elmChild)); 178 } 179 180 if (strNameAttr != null) { 182 group.fName = strNameAttr; 183 group.fTargetNamespace = schemaDoc.fTargetNamespace; 184 if (particle != null) 185 group.fModelGroup = (XSModelGroupImpl)particle.fValue; 186 group.fAnnotation = annotation; 187 grammar.addGlobalGroupDecl(group); 188 } 189 else { 190 group = null; 192 } 193 } 194 if(group != null) { 195 Object redefinedGrp = fSchemaHandler.getGrpOrAttrGrpRedefinedByRestriction(XSDHandler.GROUP_TYPE, 198 new QName(XMLSymbols.EMPTY_STRING, strNameAttr, strNameAttr, schemaDoc.fTargetNamespace), 199 schemaDoc, elmNode); 200 if(redefinedGrp != null) { 201 grammar.addRedefinedGroupDecl(group, (XSGroupDecl)redefinedGrp, 203 fSchemaHandler.element2Locator(elmNode)); 204 } 205 } 206 207 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 208 209 return group; 210 211 } } 213 | Popular Tags |