📄 xsdcomplextypetraverser.java
字号:
if (existingAttrUse == null) { String idName = toAttrGrp.addAttributeUse(oneAttrUse); if (idName != null) { throw new ComplexTypeRecoverableError("ct-props-correct.5", new Object[]{typeName, idName, oneAttrUse.fAttrDecl.getName()}, elem); } } else { if (extension) { throw new ComplexTypeRecoverableError("ct-props-correct.4", new Object[]{typeName, oneAttrUse.fAttrDecl.getName()}, elem); } } } // For extension, the wildcard must be formed by doing a union of the wildcards if (extension) { if (toAttrGrp.fAttributeWC==null) { toAttrGrp.fAttributeWC = fromAttrGrp.fAttributeWC; } else if (fromAttrGrp.fAttributeWC != null) { toAttrGrp.fAttributeWC = toAttrGrp.fAttributeWC.performUnionWith(fromAttrGrp.fAttributeWC, toAttrGrp.fAttributeWC.fProcessContents); } } } private void processComplexContent(Element complexContentChild, boolean isMixed, boolean isDerivation, XSDocumentInfo schemaDoc, SchemaGrammar grammar) throws ComplexTypeRecoverableError { Element attrNode = null; XSParticleDecl particle = null; // whether there is a particle with empty model group boolean emptyParticle = false; if (complexContentChild != null) { // ------------------------------------------------------------- // GROUP, ALL, SEQUENCE or CHOICE, followed by attributes, if specified. // Note that it's possible that only attributes are specified. // ------------------------------------------------------------- String childName = DOMUtil.getLocalName(complexContentChild); if (childName.equals(SchemaSymbols.ELT_GROUP)) { particle = fSchemaHandler.fGroupTraverser.traverseLocal(complexContentChild, schemaDoc, grammar); attrNode = DOMUtil.getNextSiblingElement(complexContentChild); } else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) { particle = traverseSequence(complexContentChild,schemaDoc,grammar, NOT_ALL_CONTEXT,fComplexTypeDecl); if (particle != null) { XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; if (group.fParticleCount == 0) emptyParticle = true; } attrNode = DOMUtil.getNextSiblingElement(complexContentChild); } else if (childName.equals(SchemaSymbols.ELT_CHOICE)) { particle = traverseChoice(complexContentChild,schemaDoc,grammar, NOT_ALL_CONTEXT,fComplexTypeDecl); if (particle != null && particle.fMinOccurs == 0) { XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; if (group.fParticleCount == 0) emptyParticle = true; } attrNode = DOMUtil.getNextSiblingElement(complexContentChild); } else if (childName.equals(SchemaSymbols.ELT_ALL)) { particle = traverseAll(complexContentChild,schemaDoc,grammar, PROCESSING_ALL_GP,fComplexTypeDecl); if (particle != null) { XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; if (group.fParticleCount == 0) emptyParticle = true; } attrNode = DOMUtil.getNextSiblingElement(complexContentChild); } else { // Should be attributes here - will check below... attrNode = complexContentChild; } } // if the particle is empty because there is no non-annotation chidren, // we need to make the particle itself null (so that the effective // content is empty). if (emptyParticle) { // get the first child Element child = DOMUtil.getFirstChildElement(complexContentChild); // if it's annotation, get the next one if (child != null) { if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { child = DOMUtil.getNextSiblingElement(child); } } // if there is no (non-annotation) children, mark particle empty if (child == null) particle = null; // child != null means we might have seen an element with // minOccurs == maxOccurs == 0 } if (particle == null && isMixed) { if (fEmptyParticle == null) { XSModelGroupImpl group = new XSModelGroupImpl(); group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; group.fParticleCount = 0; group.fParticles = null; fEmptyParticle = new XSParticleDecl(); fEmptyParticle.fType = XSParticleDecl.PARTICLE_MODELGROUP; fEmptyParticle.fValue = group; } particle = fEmptyParticle; } fParticle = particle; // ----------------------------------------------------------------------- // Set the content type // ----------------------------------------------------------------------- if (fParticle == null) fContentType = XSComplexTypeDecl.CONTENTTYPE_EMPTY; else if (isMixed) fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED; else fContentType = XSComplexTypeDecl.CONTENTTYPE_ELEMENT; // ------------------------------------------------------------- // Now, process attributes // ------------------------------------------------------------- if (attrNode != null) { if (!isAttrOrAttrGroup(attrNode)) { throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", new Object[]{fName,DOMUtil.getLocalName(attrNode)}, attrNode); } Element node = traverseAttrsAndAttrGrps(attrNode,fAttrGrp,schemaDoc,grammar,fComplexTypeDecl); if (node!=null) { throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1", new Object[]{fName,DOMUtil.getLocalName(node)}, node); } // Only remove prohibited attribute uses if this isn't a derived type // Derivation-specific code worries about this elsewhere if (!isDerivation) { fAttrGrp.removeProhibitedAttrs(); } } } // end processComplexContent private boolean isAttrOrAttrGroup(Element e) { String elementName = DOMUtil.getLocalName(e); if (elementName.equals(SchemaSymbols.ELT_ATTRIBUTE) || elementName.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP) || elementName.equals(SchemaSymbols.ELT_ANYATTRIBUTE)) return true; else return false; } private void traverseSimpleContentDecl(Element simpleContentDecl) { } private void traverseComplexContentDecl(Element complexContentDecl, boolean mixedOnComplexTypeDecl) { } /* * Generate a name for an anonymous type */ private String genAnonTypeName(Element complexTypeDecl) { // Generate a unique name for the anonymous type by concatenating together the // names of parent nodes // The name is quite good for debugging/error purposes, but we may want to // revisit how this is done for performance reasons (LM). StringBuffer typeName = new StringBuffer("#AnonType_"); Element node = DOMUtil.getParent(complexTypeDecl); while (node != null && (node != DOMUtil.getRoot(DOMUtil.getDocument(node)))) { typeName.append(node.getAttribute(SchemaSymbols.ATT_NAME)); node = DOMUtil.getParent(node); } return typeName.toString(); } private void handleComplexTypeError(String messageId,Object[] args, Element e) { if (messageId!=null) { reportSchemaError(messageId, args, e); } // // Mock up the typeInfo structure so that there won't be problems during // validation // fBaseType = SchemaGrammar.fAnyType; fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED; fParticle = getErrorContent(); // REVISIT: do we need to remove all attribute uses already added into // the attribute group? maybe it's ok to leave them there. -SG fAttrGrp.fAttributeWC = getErrorWildcard(); return; } private XSParticleDecl getErrorContent() { XSParticleDecl particle = new XSParticleDecl(); particle.fType = XSParticleDecl.PARTICLE_WILDCARD; particle.fValue = getErrorWildcard(); particle.fMinOccurs = 0; particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED; XSModelGroupImpl group = new XSModelGroupImpl(); group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE; group.fParticleCount = 1; group.fParticles = new XSParticleDecl[1]; group.fParticles[0] = particle; XSParticleDecl errorContent = new XSParticleDecl(); errorContent.fType = XSParticleDecl.PARTICLE_MODELGROUP; errorContent.fValue = group; return errorContent; } private XSWildcardDecl getErrorWildcard() { XSWildcardDecl errorWildcard = new XSWildcardDecl(); errorWildcard.fProcessContents = XSWildcardDecl.PC_SKIP; return errorWildcard; } private void contentBackup() { if(fGlobalStore == null) { fGlobalStore = new Object [GLOBAL_NUM]; fGlobalStorePos = 0; } if(fGlobalStorePos == fGlobalStore.length) { Object [] newArray = new Object[fGlobalStorePos+GLOBAL_NUM]; System.arraycopy(fGlobalStore, 0, newArray, 0, fGlobalStorePos); fGlobalStore = newArray; } fGlobalStore[fGlobalStorePos++] = fComplexTypeDecl; fGlobalStore[fGlobalStorePos++] = fIsAbstract?Boolean.TRUE:Boolean.FALSE; fGlobalStore[fGlobalStorePos++] = fName ; fGlobalStore[fGlobalStorePos++] = fTargetNamespace; // let's save ourselves a couple of objects... fGlobalStore[fGlobalStorePos++] = new Integer((fDerivedBy << 16) + fFinal); fGlobalStore[fGlobalStorePos++] = new Integer((fBlock << 16) + fContentType); fGlobalStore[fGlobalStorePos++] = fBaseType; fGlobalStore[fGlobalStorePos++] = fAttrGrp; fGlobalStore[fGlobalStorePos++] = fParticle; fGlobalStore[fGlobalStorePos++] = fXSSimpleType; fGlobalStore[fGlobalStorePos++] = fAnnotations; } private void contentRestore() { fAnnotations = (XSAnnotationImpl [])fGlobalStore[--fGlobalStorePos]; fXSSimpleType = (XSSimpleType)fGlobalStore[--fGlobalStorePos]; fParticle = (XSParticleDecl)fGlobalStore[--fGlobalStorePos]; fAttrGrp = (XSAttributeGroupDecl)fGlobalStore[--fGlobalStorePos]; fBaseType = (XSTypeDefinition)fGlobalStore[--fGlobalStorePos]; int i = ((Integer)(fGlobalStore[--fGlobalStorePos])).intValue(); fBlock = (short)(i >> 16); fContentType = (short)i; i = ((Integer)(fGlobalStore[--fGlobalStorePos])).intValue(); fDerivedBy = (short)(i >> 16); fFinal = (short)i; fTargetNamespace = (String)fGlobalStore[--fGlobalStorePos]; fName = (String)fGlobalStore[--fGlobalStorePos]; fIsAbstract = ((Boolean)fGlobalStore[--fGlobalStorePos]).booleanValue(); fComplexTypeDecl = (XSComplexTypeDecl)fGlobalStore[--fGlobalStorePos]; } private void addAnnotation(XSAnnotationImpl annotation) { if(annotation == null) return; // it isn't very likely that there will be more than one annotation // in a complexType decl. This saves us fromhaving to push/pop // one more object from the fGlobalStore, and that's bound // to be a savings for most applications if(fAnnotations == null) { fAnnotations = new XSAnnotationImpl[1]; } else { XSAnnotationImpl [] tempArray = new XSAnnotationImpl[fAnnotations.length + 1]; System.arraycopy(fAnnotations, 0, tempArray, 0, fAnnotations.length); fAnnotations = tempArray; } fAnnotations[fAnnotations.length-1] = annotation; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -