internal static bool HasParticleRef(XmlSchemaParticle particle, XmlSchema parentSchema) { XmlSchemaGroupBase base2 = particle as XmlSchemaGroupBase; if (base2 == null) { return (particle is XmlSchemaGroupRef); } bool flag = false; int num = 0; while ((num < base2.Items.Count) && !flag) { XmlSchemaParticle particle2 = (XmlSchemaParticle) base2.Items[num++]; if (particle2 is XmlSchemaGroupRef) { flag = true; } else { XmlSchemaElement element = particle2 as XmlSchemaElement; if ((element != null) && ((!element.RefName.IsEmpty || !element.SchemaTypeName.IsEmpty) || (GetResolvedElementForm(parentSchema, element) == XmlSchemaForm.Qualified))) { flag = true; continue; } flag = HasParticleRef(particle2, parentSchema); } } return flag; }
internal override bool ParticleEquals(XmlSchemaParticle other) { XmlSchemaGroupBase xmlSchemaGroupBase = other as XmlSchemaGroupBase; if (xmlSchemaGroupBase == null) { return(false); } if (base.GetType() != xmlSchemaGroupBase.GetType()) { return(false); } if (base.ValidatedMaxOccurs != xmlSchemaGroupBase.ValidatedMaxOccurs || base.ValidatedMinOccurs != xmlSchemaGroupBase.ValidatedMinOccurs) { return(false); } if (this.CompiledItems.Count != xmlSchemaGroupBase.CompiledItems.Count) { return(false); } for (int i = 0; i < this.CompiledItems.Count; i++) { XmlSchemaParticle xmlSchemaParticle = this.CompiledItems[i] as XmlSchemaParticle; XmlSchemaParticle other2 = xmlSchemaGroupBase.CompiledItems[i] as XmlSchemaParticle; if (!xmlSchemaParticle.ParticleEquals(other2)) { return(false); } } return(true); }
internal override bool ParticleEquals(XmlSchemaParticle other) { XmlSchemaGroupBase gb = other as XmlSchemaGroupBase; if (gb == null) { return(false); } if (this.GetType() != gb.GetType()) { return(false); } if (this.ValidatedMaxOccurs != gb.ValidatedMaxOccurs || this.ValidatedMinOccurs != gb.ValidatedMinOccurs) { return(false); } if (this.CompiledItems.Count != gb.CompiledItems.Count) { return(false); } for (int i = 0; i < CompiledItems.Count; i++) { XmlSchemaParticle p1 = this.CompiledItems [i] as XmlSchemaParticle; XmlSchemaParticle p2 = gb.CompiledItems [i] as XmlSchemaParticle; if (!p1.ParticleEquals(p2)) { return(false); } } return(true); }
internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle) { XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase; if (groupBase != null && !(groupBase is XmlSchemaAll)) //Choice or sequence { XmlSchemaGroupBase newGroupBase = groupBase; XmlSchemaObjectCollection newGroupbaseParticles = CloneGroupBaseParticles(groupBase.Items); newGroupBase = (XmlSchemaGroupBase)groupBase.Clone(); newGroupBase.SetItems(newGroupbaseParticles); return(newGroupBase); } else if (particle is XmlSchemaGroupRef) // group ref { XmlSchemaGroupRef newGroupRef = (XmlSchemaGroupRef)particle.Clone(); newGroupRef.RefName = newGroupRef.RefName.Clone(); return(newGroupRef); } else { XmlSchemaElement oldElem = particle as XmlSchemaElement; if (oldElem != null && (!oldElem.RefName.IsEmpty || !oldElem.SchemaTypeName.IsEmpty)) //Its element ref or type name is present { XmlSchemaElement newElem = (XmlSchemaElement)oldElem.Clone(); return(newElem); } } return(particle); }
internal void CopyOptimizedItems (XmlSchemaGroupBase gb) { for (int i = 0; i < Items.Count; i++) { XmlSchemaParticle p = Items [i] as XmlSchemaParticle; p = p.GetOptimizedParticle (false); if (p == XmlSchemaParticle.Empty) continue; gb.Items.Add (p); gb.CompiledItems.Add (p); } }
internal void CopyOptimizedItems(XmlSchemaGroupBase gb) { for (int i = 0; i < this.Items.Count; i++) { XmlSchemaParticle xmlSchemaParticle = this.Items[i] as XmlSchemaParticle; xmlSchemaParticle = xmlSchemaParticle.GetOptimizedParticle(false); if (xmlSchemaParticle != XmlSchemaParticle.Empty) { gb.Items.Add(xmlSchemaParticle); gb.CompiledItems.Add(xmlSchemaParticle); } } }
internal void CopyOptimizedItems(XmlSchemaGroupBase gb) { for (int i = 0; i < Items.Count; i++) { XmlSchemaParticle p = Items [i] as XmlSchemaParticle; p = p.GetOptimizedParticle(false); if (p == XmlSchemaParticle.Empty) { continue; } gb.Items.Add(p); gb.CompiledItems.Add(p); } }
internal static bool HasParticleRef(XmlSchemaParticle particle, XmlSchema parentSchema) { XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase; if (groupBase != null) { bool foundRef = false; int i = 0; while (i < groupBase.Items.Count && !foundRef) { XmlSchemaParticle p = (XmlSchemaParticle)groupBase.Items[i++]; if (p is XmlSchemaGroupRef) { foundRef = true; } else { XmlSchemaElement elem = p as XmlSchemaElement; // This is the same condition as in the CloneParticle method // that's on purpose. This method is used to determine if we need to clone the whole particle. // If we do, then the CloneParticle is called and it will try to clone only // those elements which need cloning - and those are the ones matching this condition. if (elem != null && (!elem.RefName.IsEmpty || !elem.SchemaTypeName.IsEmpty || GetResolvedElementForm(parentSchema, elem) == XmlSchemaForm.Qualified)) { foundRef = true; } else { foundRef = HasParticleRef(p, parentSchema); } } } return(foundRef); } else if (particle is XmlSchemaGroupRef) { return(true); } return(false); }
internal static bool HasParticleRef(XmlSchemaParticle particle) { XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase; if (groupBase != null && !(groupBase is XmlSchemaAll)) { bool foundRef = false; int i = 0; while (i < groupBase.Items.Count && !foundRef) { XmlSchemaParticle p = (XmlSchemaParticle)groupBase.Items[i++]; if (p is XmlSchemaGroupRef) { foundRef = true; } else { XmlSchemaElement elem = p as XmlSchemaElement; if (elem != null && (!elem.RefName.IsEmpty || !elem.SchemaTypeName.IsEmpty)) { foundRef = true; } else { foundRef = HasParticleRef(p); } } } return(foundRef); } else if (particle is XmlSchemaGroupRef) { return(true); } return(false); }
internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle, XmlSchema parentSchema) { XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase; if (groupBase != null) //Choice or sequence { XmlSchemaGroupBase newGroupBase = groupBase; XmlSchemaObjectCollection newGroupbaseParticles = CloneGroupBaseParticles(groupBase.Items, parentSchema); newGroupBase = (XmlSchemaGroupBase)groupBase.Clone(); newGroupBase.SetItems(newGroupbaseParticles); return(newGroupBase); } else if (particle is XmlSchemaGroupRef) // group ref { XmlSchemaGroupRef newGroupRef = (XmlSchemaGroupRef)particle.Clone(); newGroupRef.RefName = newGroupRef.RefName.Clone(); return(newGroupRef); } else { XmlSchemaElement oldElem = particle as XmlSchemaElement; // If the particle is an element and one of the following is true: // - it references another element by name // - it references its type by name // - it's form (effective) is qualified (meaning it will inherint namespace from chameleon includes if that happens) // then the element itself needs to be cloned. if (oldElem != null && (!oldElem.RefName.IsEmpty || !oldElem.SchemaTypeName.IsEmpty || GetResolvedElementForm(parentSchema, oldElem) == XmlSchemaForm.Qualified)) { XmlSchemaElement newElem = (XmlSchemaElement)oldElem.Clone(parentSchema); return(newElem); } } return(particle); }
internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle, XmlSchema parentSchema) { XmlSchemaGroupBase base2 = particle as XmlSchemaGroupBase; if (base2 != null) { XmlSchemaGroupBase base3 = base2; XmlSchemaObjectCollection newItems = CloneGroupBaseParticles(base2.Items, parentSchema); base3 = (XmlSchemaGroupBase) base2.Clone(); base3.SetItems(newItems); return base3; } if (particle is XmlSchemaGroupRef) { XmlSchemaGroupRef ref2 = (XmlSchemaGroupRef) particle.Clone(); ref2.RefName = ref2.RefName.Clone(); return ref2; } XmlSchemaElement element = particle as XmlSchemaElement; if ((element == null) || ((element.RefName.IsEmpty && element.SchemaTypeName.IsEmpty) && (GetResolvedElementForm(parentSchema, element) != XmlSchemaForm.Qualified))) { return particle; } return (XmlSchemaElement) element.Clone(parentSchema); }
public RecursiveChildren(XmlSchemaGroupBase group) { this.group = group; }
internal bool ValidateSeqRecurseMapSumCommon(XmlSchemaGroupBase baseGroup, ValidationEventHandler h, XmlSchema schema, bool isLax, bool isMapAndSum, bool raiseError) { int index = 0; int baseIndex = 0; decimal baseOccured = 0; if (baseGroup.CompiledItems.Count == 0 && this.CompiledItems.Count > 0) { if (raiseError) { error(h, "Invalid particle derivation by restriction was found. base particle does not contain particles."); } return(false); } for (int i = 0; i < CompiledItems.Count; i++) { // get non-empty derived particle XmlSchemaParticle pd = null; while (this.CompiledItems.Count > index) { pd = ((XmlSchemaParticle)this.CompiledItems [index]); //.GetOptimizedParticle (false); if (pd != XmlSchemaParticle.Empty) // && pd.ValidatedMaxOccurs > 0) { break; } else { index++; } } if (index >= CompiledItems.Count) { if (raiseError) { error(h, "Invalid particle derivation by restriction was found. Cannot be mapped to base particle."); } return(false); } // get non-empty base particle XmlSchemaParticle pb = null; while (baseGroup.CompiledItems.Count > baseIndex) { pb = ((XmlSchemaParticle)baseGroup.CompiledItems [baseIndex]); //.GetOptimizedParticle (false); if (pb == XmlSchemaParticle.Empty && pb.ValidatedMaxOccurs > 0) { continue; } if (!pd.ValidateDerivationByRestriction(pb, h, schema, false)) { if (!isLax && !isMapAndSum && pb.MinOccurs > baseOccured && !pb.ValidateIsEmptiable()) { if (raiseError) { error(h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found."); } return(false); } else { baseOccured = 0; baseIndex++; } } else { baseOccured += pb.ValidatedMinOccurs; if (baseOccured >= baseGroup.ValidatedMaxOccurs) { baseOccured = 0; baseIndex++; } index++; break; } } } if (this.CompiledItems.Count > 0 && index != this.CompiledItems.Count) { if (raiseError) { error(h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found."); } return(false); } if (!isLax && !isMapAndSum) { if (baseOccured > 0) { baseIndex++; } for (int i = baseIndex; i < baseGroup.CompiledItems.Count; i++) { XmlSchemaParticle p = baseGroup.CompiledItems [i] as XmlSchemaParticle; if (!p.ValidateIsEmptiable()) { if (raiseError) { error(h, "Invalid particle derivation by restriction was found. There is a base particle which does not have mapped derived particle and is not emptiable."); } return(false); } } } return(true); }
private bool IsGroupBaseFromGroupBase(XmlSchemaGroupBase derivedGroupBase, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) { if (!IsValidOccurrenceRangeRestriction(derivedGroupBase, baseGroupBase)) { restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseRestRangeInvalid); return false; } if (derivedGroupBase.Items.Count > baseGroupBase.Items.Count) { restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseRestNoMap); return false; } int count = 0; for (int i = 0; i < baseGroupBase.Items.Count; ++i) { XmlSchemaParticle baseParticle = (XmlSchemaParticle)baseGroupBase.Items[i]; if ((count < derivedGroupBase.Items.Count) && IsValidRestriction((XmlSchemaParticle)derivedGroupBase.Items[count], baseParticle)) { count ++; } else if (skipEmptableOnly && !IsParticleEmptiable(baseParticle)) { if (restrictionErrorMsg == null) { //If restriction failed on previous check, do not overwrite error restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseRestNotEmptiable); } return false; } } if (count < derivedGroupBase.Items.Count) { return false; } return true; }
private bool IsElementFromGroupBaseHack(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) { bool isMatched = false; foreach(XmlSchemaParticle baseParticle in baseGroupBase.Items) { if (!isMatched && IsRangeSimple(baseParticle.MinOccurs, baseParticle.MaxOccurs)) { string minOccursElement = baseParticle.MinOccursString; string maxOccursElement = baseParticle.MaxOccursString; baseParticle.MinOccurs *= baseGroupBase.MinOccurs; if ( baseParticle.MaxOccurs != decimal.MaxValue) { if (baseGroupBase.MaxOccurs == decimal.MaxValue) baseParticle.MaxOccurs = decimal.MaxValue; else baseParticle.MaxOccurs *= baseGroupBase.MaxOccurs; } isMatched = IsValidRestriction(derivedElement, baseParticle); baseParticle.MinOccursString = minOccursElement; baseParticle.MaxOccursString = maxOccursElement; } if (!isMatched && skipEmptableOnly && !IsParticleEmptiable(baseParticle)) { return false; } } return isMatched; }
private bool IsGroupBaseFromAny(XmlSchemaGroupBase derivedGroupBase, XmlSchemaAny baseAny) { decimal minOccurs, maxOccurs; CalculateEffectiveTotalRange(derivedGroupBase, out minOccurs, out maxOccurs); if (!IsValidOccurrenceRangeRestriction(minOccurs, maxOccurs, baseAny.MinOccurs, baseAny.MaxOccurs)) { restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseFromAny2, derivedGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseAny.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseAny.LinePosition.ToString(NumberFormatInfo.InvariantInfo)); return false; } // eliminate occurrance range check string minOccursAny = baseAny.MinOccursString; baseAny.MinOccurs = decimal.Zero; for (int i = 0; i < derivedGroupBase.Items.Count; ++i) { if (!IsValidRestriction((XmlSchemaParticle)derivedGroupBase.Items[i], baseAny)) { restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseFromAny1); baseAny.MinOccursString = minOccursAny; return false; } } baseAny.MinOccursString = minOccursAny; return true; }
private void ExportElementAccessor(XmlSchemaGroupBase group, ElementAccessor accessor, bool repeats, bool valueTypeOptional, string ns) { if (accessor.Any && (accessor.Name.Length == 0)) { XmlSchemaAny item = new XmlSchemaAny { MinOccurs = 0M, MaxOccurs = repeats ? 79228162514264337593543950335M : 1M }; if (((accessor.Namespace != null) && (accessor.Namespace.Length > 0)) && (accessor.Namespace != ns)) { item.Namespace = accessor.Namespace; } group.Items.Add(item); } else { XmlSchemaElement element = (XmlSchemaElement) this.elements[accessor]; int num = (((repeats || accessor.HasDefault) || (!accessor.IsNullable && !accessor.Mapping.TypeDesc.IsValueType)) || valueTypeOptional) ? 0 : 1; decimal num2 = (repeats || accessor.IsUnbounded) ? 79228162514264337593543950335M : 1M; if (element == null) { element = new XmlSchemaElement { IsNillable = accessor.IsNullable, Name = accessor.Name }; if (accessor.HasDefault) { element.DefaultValue = ExportDefaultValue(accessor.Mapping, accessor.Default); } if (accessor.IsTopLevelInSchema) { this.elements.Add(accessor, element); element.Form = accessor.Form; this.AddSchemaItem(element, accessor.Namespace, ns); } else { element.MinOccurs = num; element.MaxOccurs = num2; XmlSchema schema = this.schemas[ns]; if (schema == null) { element.Form = (accessor.Form == XmlSchemaForm.Qualified) ? XmlSchemaForm.None : accessor.Form; } else { element.Form = (accessor.Form == schema.ElementFormDefault) ? XmlSchemaForm.None : accessor.Form; } } this.ExportElementMapping(element, accessor.Mapping, accessor.Namespace, accessor.Any); } if (accessor.IsTopLevelInSchema) { XmlSchemaElement element2 = new XmlSchemaElement { RefName = new XmlQualifiedName(accessor.Name, accessor.Namespace), MinOccurs = num, MaxOccurs = num2 }; group.Items.Add(element2); this.AddSchemaImport(accessor.Namespace, ns); } else { group.Items.Add(element); } } }
private void GenerateGroupBase(XmlSchemaGroupBase gBase, InstanceGroup grp) { foreach(XmlSchemaParticle particle1 in gBase.Items) { GenerateParticle(particle1, false, grp); } }
private bool IsGroupBaseFromGroupBase(XmlSchemaGroupBase derivedGroupBase, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) { if (!this.IsValidOccurrenceRangeRestriction(derivedGroupBase, baseGroupBase)) { this.restrictionErrorMsg = Res.GetString("Sch_GroupBaseRestRangeInvalid"); return false; } if (derivedGroupBase.Items.Count > baseGroupBase.Items.Count) { this.restrictionErrorMsg = Res.GetString("Sch_GroupBaseRestNoMap"); return false; } int num = 0; for (int i = 0; i < baseGroupBase.Items.Count; i++) { XmlSchemaParticle baseParticle = (XmlSchemaParticle) baseGroupBase.Items[i]; if ((num < derivedGroupBase.Items.Count) && this.IsValidRestriction((XmlSchemaParticle) derivedGroupBase.Items[num], baseParticle)) { num++; } else if (skipEmptableOnly && !this.IsParticleEmptiable(baseParticle)) { if (this.restrictionErrorMsg == null) { this.restrictionErrorMsg = Res.GetString("Sch_GroupBaseRestNotEmptiable"); } return false; } } if (num < derivedGroupBase.Items.Count) { return false; } return true; }
private bool IsGroupBaseFromAny(XmlSchemaGroupBase derivedGroupBase, XmlSchemaAny baseAny) { decimal num; decimal num2; this.CalculateEffectiveTotalRange(derivedGroupBase, out num, out num2); if (!this.IsValidOccurrenceRangeRestriction(num, num2, baseAny.MinOccurs, baseAny.MaxOccurs)) { this.restrictionErrorMsg = Res.GetString("Sch_GroupBaseFromAny2", new object[] { derivedGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseAny.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseAny.LinePosition.ToString(NumberFormatInfo.InvariantInfo) }); return false; } string minOccursString = baseAny.MinOccursString; baseAny.MinOccurs = 0M; for (int i = 0; i < derivedGroupBase.Items.Count; i++) { if (!this.IsValidRestriction((XmlSchemaParticle) derivedGroupBase.Items[i], baseAny)) { this.restrictionErrorMsg = Res.GetString("Sch_GroupBaseFromAny1"); baseAny.MinOccursString = minOccursString; return false; } } baseAny.MinOccursString = minOccursString; return true; }
private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase) { if (baseGroupBase is XmlSchemaSequence) { XmlSchemaSequence derivedGroupBase = new XmlSchemaSequence { MinOccurs = 1M, MaxOccurs = 1M }; derivedGroupBase.Items.Add(derivedElement); if (this.IsGroupBaseFromGroupBase(derivedGroupBase, baseGroupBase, true)) { return true; } this.restrictionErrorMsg = Res.GetString("Sch_ElementFromGroupBase1", new object[] { derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo) }); } else if (baseGroupBase is XmlSchemaChoice) { XmlSchemaChoice choice = new XmlSchemaChoice { MinOccurs = 1M, MaxOccurs = 1M }; choice.Items.Add(derivedElement); if (this.IsGroupBaseFromGroupBase(choice, baseGroupBase, false)) { return true; } this.restrictionErrorMsg = Res.GetString("Sch_ElementFromGroupBase2", new object[] { derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo) }); } else if (baseGroupBase is XmlSchemaAll) { XmlSchemaAll all = new XmlSchemaAll { MinOccurs = 1M, MaxOccurs = 1M }; all.Items.Add(derivedElement); if (this.IsGroupBaseFromGroupBase(all, baseGroupBase, true)) { return true; } this.restrictionErrorMsg = Res.GetString("Sch_ElementFromGroupBase3", new object[] { derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo) }); } return false; }
private MemberMapping ImportChoiceGroup(XmlSchemaGroupBase group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, bool groupRepeats, ref bool needExplicitOrder, bool allowDuplicates) { NameTable choiceElements = new NameTable(); if (GatherGroupChoices(group, choiceElements, identifier, ns, ref needExplicitOrder, allowDuplicates)) groupRepeats = true; MemberMapping member = new MemberMapping(); member.Elements = (ElementAccessor[])choiceElements.ToArray(typeof(ElementAccessor)); Array.Sort(member.Elements, new ElementComparer()); AddScopeElements(elementsScope, member.Elements, ref needExplicitOrder, allowDuplicates); bool duplicateTypes = false; bool nullableMismatch = false; Hashtable uniqueTypeDescs = new Hashtable(member.Elements.Length); for (int i = 0; i < member.Elements.Length; i++) { ElementAccessor element = member.Elements[i]; string tdFullName = element.Mapping.TypeDesc.FullName; object val = uniqueTypeDescs[tdFullName]; if (val != null) { duplicateTypes = true; ElementAccessor existingElement = (ElementAccessor)val; if (!nullableMismatch && existingElement.IsNullable != element.IsNullable) nullableMismatch = true; } else { uniqueTypeDescs.Add(tdFullName, element); } ArrayMapping arrayMapping = element.Mapping as ArrayMapping; if (arrayMapping != null) { if (IsNeedXmlSerializationAttributes(arrayMapping)) { // we cannot use ArrayMapping in choice if additional custom // serialization attributes are needed to serialize it element.Mapping = arrayMapping.TopLevelMapping; element.Mapping.ReferencedByTopLevelElement = false; element.Mapping.ReferencedByElement = true; } } } if (nullableMismatch) member.TypeDesc = Scope.GetTypeDesc(typeof(object)); else { TypeDesc[] typeDescs = new TypeDesc[uniqueTypeDescs.Count]; IEnumerator enumerator = uniqueTypeDescs.Values.GetEnumerator(); for (int i = 0; i < typeDescs.Length; i++) { if (!enumerator.MoveNext()) break; typeDescs[i] = ((ElementAccessor)enumerator.Current).Mapping.TypeDesc; } member.TypeDesc = TypeDesc.FindCommonBaseTypeDesc(typeDescs); if (member.TypeDesc == null) member.TypeDesc = Scope.GetTypeDesc(typeof(object)); } if (groupRepeats) member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc(); if (membersScope != null) { member.Name = membersScope.AddUnique(groupRepeats ? "Items" : "Item", member); if (members != null) { members.Add(member.Name, member); } } if (duplicateTypes) { member.ChoiceIdentifier = new ChoiceIdentifierAccessor(); member.ChoiceIdentifier.MemberName = member.Name + "ElementName"; // we need to create the EnumMapping to store all of the element names member.ChoiceIdentifier.Mapping = ImportEnumeratedChoice(member.Elements, ns, member.Name + "ChoiceType"); member.ChoiceIdentifier.MemberIds = new string[member.Elements.Length]; ConstantMapping[] constants = ((EnumMapping)member.ChoiceIdentifier.Mapping).Constants; for (int i = 0; i < member.Elements.Length; i++) { member.ChoiceIdentifier.MemberIds[i] = constants[i].Name; } MemberMapping choiceIdentifier = new MemberMapping(); choiceIdentifier.Ignore = true; choiceIdentifier.Name = member.ChoiceIdentifier.MemberName; if (groupRepeats) { choiceIdentifier.TypeDesc = member.ChoiceIdentifier.Mapping.TypeDesc.CreateArrayTypeDesc(); } else { choiceIdentifier.TypeDesc = member.ChoiceIdentifier.Mapping.TypeDesc; } // create element accessor for the choiceIdentifier ElementAccessor choiceAccessor = new ElementAccessor(); choiceAccessor.Name = choiceIdentifier.Name; choiceAccessor.Namespace = ns; choiceAccessor.Mapping = member.ChoiceIdentifier.Mapping; choiceIdentifier.Elements = new ElementAccessor[] { choiceAccessor }; if (membersScope != null) { choiceAccessor.Name = choiceIdentifier.Name = member.ChoiceIdentifier.MemberName = membersScope.AddUnique(member.ChoiceIdentifier.MemberName, choiceIdentifier); if (members != null) { members.Add(choiceAccessor.Name, choiceIdentifier); } } } return member; }
private void ImportGroup(XmlSchemaGroupBase group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, bool mixed, ref bool needExplicitOrder, bool allowDuplicates, bool groupRepeats, bool allowUnboundedElements) { if (group is XmlSchemaChoice) ImportChoiceGroup((XmlSchemaChoice)group, identifier, members, membersScope, elementsScope, ns, groupRepeats, ref needExplicitOrder, allowDuplicates); else ImportGroupMembers(group, identifier, members, membersScope, elementsScope, ns, groupRepeats, ref mixed, ref needExplicitOrder, allowDuplicates, allowUnboundedElements); if (mixed) { ImportTextMember(members, membersScope, null); } }
internal bool ValidateSeqRecurseMapSumCommon(XmlSchemaGroupBase baseGroup, ValidationEventHandler h, XmlSchema schema, bool isLax, bool isMapAndSum, bool raiseError) { int num = 0; int num2 = 0; decimal num3 = 0m; if (baseGroup.CompiledItems.Count == 0 && this.CompiledItems.Count > 0) { if (raiseError) { base.error(h, "Invalid particle derivation by restriction was found. base particle does not contain particles."); } return(false); } for (int i = 0; i < this.CompiledItems.Count; i++) { XmlSchemaParticle xmlSchemaParticle = null; while (this.CompiledItems.Count > num) { xmlSchemaParticle = (XmlSchemaParticle)this.CompiledItems[num]; if (xmlSchemaParticle != XmlSchemaParticle.Empty) { break; } num++; } if (num >= this.CompiledItems.Count) { if (raiseError) { base.error(h, "Invalid particle derivation by restriction was found. Cannot be mapped to base particle."); } return(false); } while (baseGroup.CompiledItems.Count > num2) { XmlSchemaParticle xmlSchemaParticle2 = (XmlSchemaParticle)baseGroup.CompiledItems[num2]; if (xmlSchemaParticle2 != XmlSchemaParticle.Empty || !(xmlSchemaParticle2.ValidatedMaxOccurs > 0m)) { if (xmlSchemaParticle.ValidateDerivationByRestriction(xmlSchemaParticle2, h, schema, false)) { num3 += xmlSchemaParticle2.ValidatedMinOccurs; if (num3 >= baseGroup.ValidatedMaxOccurs) { num3 = 0m; num2++; } num++; break; } if (!isLax && !isMapAndSum && xmlSchemaParticle2.MinOccurs > num3 && !xmlSchemaParticle2.ValidateIsEmptiable()) { if (raiseError) { base.error(h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found."); } return(false); } num3 = 0m; num2++; } } } if (this.CompiledItems.Count > 0 && num != this.CompiledItems.Count) { if (raiseError) { base.error(h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found."); } return(false); } if (!isLax && !isMapAndSum) { if (num3 > 0m) { num2++; } for (int j = num2; j < baseGroup.CompiledItems.Count; j++) { XmlSchemaParticle xmlSchemaParticle3 = baseGroup.CompiledItems[j] as XmlSchemaParticle; if (!xmlSchemaParticle3.ValidateIsEmptiable()) { if (raiseError) { base.error(h, "Invalid particle derivation by restriction was found. There is a base particle which does not have mapped derived particle and is not emptiable."); } return(false); } } } return(true); }
private bool IsGroupBaseFromGroupBase(XmlSchemaGroupBase derivedGroupBase, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) { if (!IsValidOccurrenceRangeRestriction(derivedGroupBase, baseGroupBase) || derivedGroupBase.Items.Count > baseGroupBase.Items.Count) { return false; } int count = 0; for (int i = 0; i < baseGroupBase.Items.Count; ++i) { XmlSchemaParticle baseParticle = (XmlSchemaParticle)baseGroupBase.Items[i]; if ((count < derivedGroupBase.Items.Count) && IsValidRestriction((XmlSchemaParticle)derivedGroupBase.Items[count], baseParticle)) { count ++; } else if (skipEmptableOnly && !IsParticleEmptiable(baseParticle)) { return false; } } if (count < derivedGroupBase.Items.Count) { return false; } return true; }
public XmlSchemaObjectContainer (XmlSchemaGroupBase group) { _xmlSchemaObject = group; }
public ParticleData(XmlSchemaGroupBase groupBase, GroupingInfo gInfo, int index) { currentGroupBase = groupBase; currentGroupingInfo = gInfo; currentIndex = index; }
/* * Pass1. Collect info on classes, collections (List<> types), and any local enumerations. */ private void ParseGroupBasePass1(XmlSchemaGroupBase groupBase, String dotnetClassName, ArrayList childClasses, ArrayList parentClassStack, string parentNamespace, string currentNamespace) { for (int i = 0; i < groupBase.Items.Count; i++) { if (groupBase.Items[i] is XmlSchemaElement) { XmlSchemaElement elementRef = (XmlSchemaElement)groupBase.Items[i]; XmlSchemaElement element = (XmlSchemaElement)schema.Elements[elementRef.QualifiedName]; if (element == null) element = elementRef; string ns = element.QualifiedName.Namespace != "" ? element.QualifiedName.Namespace : parentNamespace; if (element.ElementType is XmlSchemaComplexType && element.SchemaTypeName.Namespace != Globals.XSD_NAMESPACE) { XmlSchemaComplexType elementComplex = (XmlSchemaComplexType)element.ElementType; string childComplexTypeName = ""; // a nested complexType, who's name may not be unique in the schema // The complex type is locally defined so a child class needs to be created. if ((element == elementRef) && (schema.SchemaTypes[elementComplex.QualifiedName] == null)) { childComplexTypeName = CalculateNestedChildTypeName(element.Name, globalComplexTypeClasses, parentClassStack); childClasses.Add(new ChildComplexType(elementComplex, element.Name, childComplexTypeName, ns, element.QualifiedName)); globalComplexTypeClasses.Add(childComplexTypeName, childComplexTypeName); // local complexType elements can repeat within a namespace string parentList = ""; foreach (string s in parentClassStack) { parentList += s; } globalQualifiedComplexTypeClasses.Add(element.QualifiedName + parentList, childComplexTypeName); } // For "unbounded" types -- check to see if this fits the IEnumerator pattern. Collect support for IEnumerator here. if (elementRef.MaxOccurs > 1 || groupBase.MaxOccurs > 1) { // If this is the only element in a contained ComplexType, and this element // is unbounded, then we can support IEnumerator on the contained class // so we can easilly enumerate through the contained child collection. string enumerableClass = dotnetClassName; if (childComplexTypeName != "") enumerableClass = childComplexTypeName; if (groupBase.Items.Count == 1 && !enumerableClasses.ContainsKey(enumerableClass)) { // enumerable class ArrayList values = new ArrayList(); values.Add(element.Name); //name // type if (childComplexTypeName != "") { values.Add(childComplexTypeName); // nested local complextype } else if ((schema.Elements[elementRef.QualifiedName] != null) && (elementComplex.Name != null && elementComplex.Name != "")) { string q = AddQualifiedNamespaceReference(element.Name, element.QualifiedName.Namespace, currentNamespace, GlobalXsdType.Element); values.Add(q); //global element who's name and type are set } else if (elementComplex.Name != null && elementComplex.Name != "") { string q = AddQualifiedNamespaceReference(elementComplex.Name, elementComplex.QualifiedName.Namespace, currentNamespace, GlobalXsdType.ComplexType); values.Add(q); // global named schema type } else { string q = AddQualifiedNamespaceReference(element.Name, element.QualifiedName.Namespace, currentNamespace, GlobalXsdType.Element); values.Add(q); // global element complextype } enumerableClasses.Add(dotnetClassName, values); } } // collect support for abstract classes if (elementComplex.IsAbstract) { ArrayList abstractClasses = null; if (classesReferencingAbstractTypes[dotnetClassName] == null) { abstractClasses = new ArrayList(); abstractClasses.Add(elementComplex.QualifiedName); classesReferencingAbstractTypes.Add(dotnetClassName, abstractClasses); } else { abstractClasses = (ArrayList)classesReferencingAbstractTypes[dotnetClassName]; abstractClasses.Add(elementComplex.QualifiedName); } } } else { // not a ComplexType string xsdTypeName = element.SchemaTypeName.Name; string clrTypeName = code.FrameworkTypeMapping(xsdTypeName); // build SimpleType enumeration if needed if (element.ElementType is XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)element.ElementType; if (Globals.globalSeparateImportedNamespaces) { // if this is an external imported simpleType element, then it get's added into its appropriate .net source file if (simpleType.QualifiedName.Namespace == "" || (element.QualifiedName.Namespace == currentNamespace && simpleType.QualifiedName.Namespace == currentNamespace)) ParseEnumeration1(simpleType, element.Name); } else ParseEnumeration1(simpleType, element.Name); } // For "unbounded" types, add them to collectionClasses container. We will build // special ArrayList subclasses for each of these later. if (elementRef.MaxOccurs > 1 || groupBase.MaxOccurs > 1) { if (element.ElementType is XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)element.ElementType; // if this is the only element in a contained ComplexType, and this element // is unbounded, then we can implement IEnumerator on the contained class // so we can easilly enumerate through the child collection. if (groupBase.Items.Count == 1 && !enumerableClasses.ContainsKey(dotnetClassName)) { ArrayList values = new ArrayList(); values.Add(element.Name); //name if (IsEnumeration(simpleType)) { if (simpleType.Name != null) { // colinco: 2005-07-05: Enums referenced from external .net namespace aren't prefixed with the .net namespace in ArrayLists or enumerable classes. string n = AddQualifiedNamespaceReference(simpleType.QualifiedName.Name, simpleType.QualifiedName.Namespace, currentNamespace, GlobalXsdType.Enum); values.Add(n); } else // simpleType locally defined inline within an element values.Add(element.Name); //type } else values.Add(simpleType.Datatype.ValueType.FullName); //type enumerableClasses.Add(dotnetClassName, values); } } else { // if this is the only element in a contained ComplexType, and this element // is unbounded, then we can implement IEnumerator on the contained class // so we can easilly enumerate through the child collection. if (groupBase.Items.Count == 1 && !enumerableClasses.ContainsKey(dotnetClassName)) { ArrayList values = new ArrayList(); values.Add(element.Name); //name values.Add(clrTypeName); //type enumerableClasses.Add(dotnetClassName, values); } } } } } else if (groupBase.Items[i] is XmlSchemaAny) { //XmlSchemaAny any = (XmlSchemaAny) groupBase.Items[i]; // do nothing for xsd:any. Add a special array instead of a collection. } else if (groupBase.Items[i] is XmlSchemaGroupRef) { XmlSchemaGroup group = (XmlSchemaGroup)schema.Groups[((XmlSchemaGroupRef)groupBase.Items[i]).RefName]; ParseGroupBasePass1(group.Particle, dotnetClassName, childClasses, parentClassStack, parentNamespace, currentNamespace); } else if (groupBase.Items[i] is XmlSchemaGroupBase) { // Particle inside a particle : ie. <xsd:sequence> <xsd:choice/> </xsd:sequence> ParseGroupBasePass1((XmlSchemaGroupBase)groupBase.Items[i], dotnetClassName, childClasses, parentClassStack, parentNamespace, currentNamespace); } } }
private void ExportElementAccessors(XmlSchemaGroupBase group, ElementAccessor[] accessors, bool repeats, bool valueTypeOptional, string ns) { if (accessors.Length != 0) { if (accessors.Length == 1) { this.ExportElementAccessor(group, accessors[0], repeats, valueTypeOptional, ns); } else { XmlSchemaChoice choice = new XmlSchemaChoice { MaxOccurs = repeats ? 79228162514264337593543950335M : 1M, MinOccurs = repeats ? 0 : 1 }; for (int i = 0; i < accessors.Length; i++) { this.ExportElementAccessor(choice, accessors[i], false, valueTypeOptional, ns); } if (choice.Items.Count > 0) { group.Items.Add(choice); } } } }
private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) { bool flag = false; for (int i = 0; i < baseGroupBase.Items.Count; i++) { XmlSchemaParticle baseParticle = (XmlSchemaParticle) baseGroupBase.Items[i]; if (!flag) { string minOccursString = baseParticle.MinOccursString; string maxOccursString = baseParticle.MaxOccursString; baseParticle.MinOccurs *= baseGroupBase.MinOccurs; if (baseParticle.MaxOccurs != 79228162514264337593543950335M) { if (baseGroupBase.MaxOccurs == 79228162514264337593543950335M) { baseParticle.MaxOccurs = 79228162514264337593543950335M; } else { baseParticle.MaxOccurs *= baseGroupBase.MaxOccurs; } } flag = this.IsValidRestriction(derivedElement, baseParticle); baseParticle.MinOccursString = minOccursString; baseParticle.MaxOccursString = maxOccursString; } else if (skipEmptableOnly && !this.IsParticleEmptiable(baseParticle)) { return false; } } return flag; }
private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) { if (!IsRangeSimple(baseGroupBase.MinOccurs, baseGroupBase.MaxOccurs) || !IsRangeSimple(derivedElement.MinOccurs, derivedElement.MaxOccurs)) { return IsElementFromGroupBase(derivedElement, baseGroupBase); //SPEC COMPLIANT } else { //Base partilce's and Derived Element's range is simple //If all particles in baseParticle also have simple ranges, then can use our algorithm //So that we dont break common cases that we used to accept earlier //Example Choice -> Element if (IsElementFromGroupBaseHack(derivedElement, baseGroupBase, skipEmptableOnly)) { return true; } else { //Fall back to regular checking return IsElementFromGroupBase(derivedElement, baseGroupBase); } } }
private bool IsGroupBaseFromGroupBase(XmlSchemaGroupBase derivedGroupBase, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) { if (!this.IsValidOccurrenceRangeRestriction(derivedGroupBase, baseGroupBase) || (derivedGroupBase.Items.Count > baseGroupBase.Items.Count)) { return false; } int num = 0; for (int i = 0; i < baseGroupBase.Items.Count; i++) { XmlSchemaParticle baseParticle = (XmlSchemaParticle) baseGroupBase.Items[i]; if ((num < derivedGroupBase.Items.Count) && this.IsValidRestriction((XmlSchemaParticle) derivedGroupBase.Items[num], baseParticle)) { num++; } else if (skipEmptableOnly && !this.IsParticleEmptiable(baseParticle)) { return false; } } if (num < derivedGroupBase.Items.Count) { return false; } return true; }
private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase) { if (baseGroupBase is XmlSchemaSequence) { XmlSchemaSequence virtualSeq = new XmlSchemaSequence(); virtualSeq.MinOccurs = 1; virtualSeq.MaxOccurs = 1; virtualSeq.Items.Add(derivedElement); if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualSeq, baseGroupBase, true)) { return true; } restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase1, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo)); } else if (baseGroupBase is XmlSchemaChoice) { XmlSchemaChoice virtualChoice = new XmlSchemaChoice(); virtualChoice.MinOccurs = 1; virtualChoice.MaxOccurs = 1; virtualChoice.Items.Add(derivedElement); if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualChoice, baseGroupBase, false)) { return true; } restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase2, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo)); } else if (baseGroupBase is XmlSchemaAll) { XmlSchemaAll virtualAll = new XmlSchemaAll(); virtualAll.MinOccurs = 1; virtualAll.MaxOccurs = 1; virtualAll.Items.Add(derivedElement); if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualAll, baseGroupBase, true)) { return true; } restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase3, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo)); } return false; }
/* * Pass0. Collect references to globally defined complextypes and simpletypes. */ private void ParseGroupBasePass0(XmlSchemaGroupBase groupBase, String dotnetClassName, ArrayList childClasses, string parentNamespace, string currentNamespace, ElementsSubset es) { for (int i = 0; i < groupBase.Items.Count; i++) { if (groupBase.Items[i] is XmlSchemaElement) { XmlSchemaElement elementRef = (XmlSchemaElement)groupBase.Items[i]; XmlSchemaElement element = (XmlSchemaElement)schema.Elements[elementRef.QualifiedName]; if (element == null) element = elementRef; string ns = element.QualifiedName.Namespace != "" ? element.QualifiedName.Namespace : parentNamespace; if (element.ElementType is XmlSchemaComplexType && element.SchemaTypeName.Namespace != Globals.XSD_NAMESPACE) { XmlSchemaComplexType elementComplex = (XmlSchemaComplexType)element.ElementType; // The complex type is locally defined so a child class needs to be created. if ((element == elementRef) && (schema.SchemaTypes[elementComplex.QualifiedName] == null)) { // recure these later childClasses.Add(new ChildComplexType(elementComplex, element.Name, "", ns, element.QualifiedName)); } if ((schema.Elements[elementRef.QualifiedName] != null) && (elementComplex.Name != null && elementComplex.Name != "")) { // global element who's name and type are set. Both element and complextype are named. if (!es.Elements.ContainsKey(elementRef.QualifiedName.Name)) { // add element and recure it's complextype es.Elements.Add(elementRef.QualifiedName.Name, elementRef.QualifiedName.Name); if (!es.ComplexTypes.ContainsKey(elementComplex.QualifiedName.Name) && !string.IsNullOrEmpty(elementComplex.QualifiedName.Name)) { es.ComplexTypes.Add(elementComplex.QualifiedName.Name, elementComplex.QualifiedName.Name); ParseComplexTypePass0(elementComplex, elementComplex.QualifiedName.Name, elementComplex.QualifiedName, elementComplex.QualifiedName.Namespace, es); } } } else if (elementComplex.Name != null && elementComplex.Name != "") { // globally defined named schema type if (!es.ComplexTypes.ContainsKey(elementComplex.QualifiedName.Name)) { es.ComplexTypes.Add(elementComplex.QualifiedName.Name, elementComplex.QualifiedName.Name); ParseComplexTypePass0(elementComplex, elementComplex.QualifiedName.Name, elementComplex.QualifiedName, elementComplex.QualifiedName.Namespace, es); } } else { // global element complexType -- element is named, but complex type is not if (!es.Elements.ContainsKey(elementRef.QualifiedName.Name)) { // add element and recure it's complextype es.Elements.Add(elementRef.QualifiedName.Name, elementRef.QualifiedName.Name); ParseComplexTypePass0(elementComplex, elementRef.QualifiedName.Name, elementRef.QualifiedName, elementRef.QualifiedName.Namespace, es); } } } else { // not a ComplexType string xsdTypeName = element.SchemaTypeName.Name; string clrTypeName = code.FrameworkTypeMapping(xsdTypeName); // build SimpleType enumeration if needed if (element.ElementType is XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)element.ElementType; ParseEnumeration0(simpleType, element.Name, es); } } } else if (groupBase.Items[i] is XmlSchemaGroupRef) { XmlSchemaGroup group = (XmlSchemaGroup)schema.Groups[((XmlSchemaGroupRef)groupBase.Items[i]).RefName]; ParseGroupBasePass0(group.Particle, dotnetClassName, childClasses, parentNamespace, currentNamespace, es); } else if (groupBase.Items[i] is XmlSchemaGroupBase) { // Particle inside a particle : ie. <xsd:sequence> <xsd:choice/> </xsd:sequence> ParseGroupBasePass0((XmlSchemaGroupBase)groupBase.Items[i], dotnetClassName, childClasses, parentNamespace, currentNamespace, es); } } }
internal bool ValidateRecurse(XmlSchemaGroupBase baseGroup, ValidationEventHandler h, XmlSchema schema, bool raiseError) { return(ValidateSeqRecurseMapSumCommon(baseGroup, h, schema, false, false, raiseError)); }
private void ImportColumnGroupBase (XmlSchemaElement parent, XmlSchemaGroupBase gb) { foreach (XmlSchemaParticle p in gb.Items) { XmlSchemaElement el = p as XmlSchemaElement; if (el != null) ImportColumnElement (parent, el); else if (p is XmlSchemaGroupBase) ImportColumnGroupBase (parent, (XmlSchemaGroupBase) p); // otherwise p is xs:any } }
/* * Add class fields for xsd:all, xsd:choice and xsd:sequence xml elements. * These will either be native CLR typed fields or other schema classes. */ private void ParseGroupBasePass2(XmlSchemaGroupBase groupBase, String className, ArrayList ctorList, ArrayList childClasses, ArrayList parentClassStack, Hashtable dotnetFieldList, string parentNamespace, Hashtable classReferencesAdded) { if (classReferencesAdded == null) classReferencesAdded = new Hashtable(); // avoid duplicate complexType field references within a .net class for (int i = 0; i < groupBase.Items.Count; i++) { decimal maxOccurs = groupBase.MaxOccurs; if (groupBase.Items[i] is XmlSchemaElement) { XmlSchemaElement elementRef = (XmlSchemaElement)groupBase.Items[i]; XmlSchemaElement element = (XmlSchemaElement)schema.Elements[elementRef.QualifiedName]; if (element == null) element = elementRef; maxOccurs = elementRef.MaxOccurs > maxOccurs ? elementRef.MaxOccurs : maxOccurs; // for unqualified elements or attributes, element/attribute.QualifiedName.Namespace will be empty -- so use parentNamespace string ns = element.QualifiedName.Namespace != "" ? element.QualifiedName.Namespace : parentNamespace; if (element.ElementType is XmlSchemaComplexType && element.SchemaTypeName.Namespace != Globals.XSD_NAMESPACE) { // this will generate to a class in code string dotnetTypeName = ""; XmlSchemaComplexType elementComplex = (XmlSchemaComplexType)element.ElementType; // avoid duplicate references for the same type (allowed in xsd -- not in .net) string fname = element.Name; if (classReferencesAdded.ContainsKey(fname)) { continue; //fname = element.Name + "2"; //while (classReferencesAdded.ContainsKey(fname)) // fname = fname + "2"; } else classReferencesAdded.Add(element.Name, element.Name); // The complex type is locally defined so a child class needs to be created. if ((element == elementRef) && (schema.SchemaTypes[elementComplex.QualifiedName] == null)) { // The complex type is locally defined. Locally scoped complexTypes may not be unique string parentList = ""; foreach (string s in parentClassStack) { parentList += s; } dotnetTypeName = (string)globalQualifiedComplexTypeClasses[element.QualifiedName + parentList]; childClasses.Add(new ChildComplexType(elementComplex, element.Name, dotnetTypeName, ns, element.QualifiedName)); dotnetTypeName = LanguageBase.ReplaceInvalidChars(dotnetTypeName); code.ClassComplexTypeFieldCode(outStream, element.Name, fname, dotnetTypeName, dotnetTypeName, className, maxOccurs, 1, elementFormDefault, ns, element.IsNillable, false); } else // not a locally defined complexType { // The complexType is either globally defined at the <xsd:schema> level, // or it's tied to a globally defined element. In the case of the // globally defined complexType at the <xsd:schema> level, elementComplex.Name // will not be null because the complexType will have name. In that case // we use the complexType name for the class name. string qualifiedTypeName = ""; if ((elementComplex.QualifiedName.Name == null || elementComplex.QualifiedName.Name == "") && (elementRef.QualifiedName.Name != null && elementRef.QualifiedName.Name != "")) { // global element ns = elementRef.QualifiedName.Namespace; // element's referenced namespace is used //qualifiedTypeName = (string) globalQualifiedComplexTypeClasses[elementRef.QualifiedName]; qualifiedTypeName = GlobalElementToClrMap(elementRef.QualifiedName); dotnetTypeName = AddQualifiedNamespaceReference(element.Name, ns, parentNamespace, GlobalXsdType.Element); } else if ((schema.Elements[elementRef.QualifiedName] != null) && (elementComplex.QualifiedName.Name != null && elementComplex.QualifiedName.Name != "")) { // An element who's "ref" attribute points to a global typed element (name and type are set and has no schema children) // use the ref in this case -- and not the type ns = elementRef.QualifiedName.Namespace; // element's referenced namespace is used //qualifiedTypeName = (string) globalQualifiedComplexTypeClasses[elementRef.QualifiedName]; qualifiedTypeName = GlobalElementToClrMap(elementRef.QualifiedName); dotnetTypeName = AddQualifiedNamespaceReference(element.Name, ns, parentNamespace, GlobalXsdType.Element); } else if (elementRef.QualifiedName.Name != null && elementRef.QualifiedName.Name != "") { // named complexType ns = parentNamespace; //elements of a "type" take their parent namespace. The children go into the "types" namespace. qualifiedTypeName = (string)globalQualifiedComplexTypeClasses[elementComplex.QualifiedName]; dotnetTypeName = elementComplex.Name; if (elementComplex.QualifiedName.Namespace != ns && elementComplex.QualifiedName.Namespace != null) dotnetTypeName = AddQualifiedNamespaceReference(dotnetTypeName, elementComplex.QualifiedName.Namespace, parentNamespace, GlobalXsdType.ComplexType); else dotnetTypeName = AddQualifiedNamespaceReference(dotnetTypeName, ns, parentNamespace, GlobalXsdType.ComplexType); } else { // shouldn't happen throw new ArgumentException("An element points to a global type or global element that isn't properly qualified"); } string collectionContainedType = ""; if (maxOccurs > 1) { // collections are always local to the namespace collectionContainedType = dotnetTypeName; // fully namespace referenced with namesapce dotnetTypeName = qualifiedTypeName; // reference removed for collection class } dotnetTypeName = LanguageBase.ReplaceInvalidChars(dotnetTypeName); code.ClassComplexTypeFieldCode(outStream, element.Name, fname, dotnetTypeName, collectionContainedType, className, maxOccurs, 1, elementFormDefault, ns, element.IsNillable, elementComplex.IsAbstract); } // If the subelement is required, then force it's creation through constructor and // a special MakeSchemaCompliant method. ClassConstructor ctor = new ClassConstructor(); if (elementRef.MinOccurs > 0 && element.MinOccurs > 0) ctor.required = true; // required child complex types else ctor.required = false; // non required child complex tyes if (maxOccurs > 1) { ctor.defaultValue = element.Name; ctor.fieldName = dotnetTypeName; if (elementComplex.IsAbstract) ctor.datatype = CtorDatatypeContext.PropertyCollectionAbstractComplexType; else ctor.datatype = CtorDatatypeContext.PropertyCollectionComplexType; } else { ctor.defaultValue = element.Name; ctor.fieldName = dotnetTypeName; ctor.datatype = CtorDatatypeContext.Property; } ctorList.Add(ctor); } else // not a ComplexType -- so this will be a leaf-node class field in code { string dotnetElementName = CalculateUniqueTypeOrFieldName(element.Name, "", dotnetFieldList); dotnetFieldList.Add(dotnetElementName, element.QualifiedName); if (element.ElementType is XmlSchemaSimpleType) { ParseElementSimpleType(element, elementRef, maxOccurs, dotnetElementName, ctorList, parentNamespace); } else { string xsdTypeName = element.SchemaTypeName.Name; string clrTypeName = code.FrameworkTypeMapping(xsdTypeName); clrTypeName = LanguageBase.ReplaceInvalidChars(clrTypeName); code.ClassElementFieldCode(outStream, clrTypeName, xsdTypeName, element.Name, dotnetElementName, maxOccurs, 1, elementFormDefault, false, ns, element.IsNillable); BuildConstructorList(element.DefaultValue, element.FixedValue, (elementRef.MinOccurs > 0 && element.MinOccurs > 0), maxOccurs, dotnetElementName, clrTypeName, element.Name, ctorList, false); } } } else if (groupBase.Items[i] is XmlSchemaAny) { XmlSchemaAny any = (XmlSchemaAny)groupBase.Items[i]; string dotnetElementName = CalculateUniqueTypeOrFieldName("Any", "", dotnetFieldList); dotnetFieldList.Add(dotnetElementName, "Any"); string ns = CalculateAnyNamespace(any.Namespace, parentNamespace); code.ClassElementFieldCode(outStream, "System.Xml.XmlElement", "", "Any", dotnetElementName, any.MaxOccurs, 1, elementFormDefault, false, ns, false); } else if (groupBase.Items[i] is XmlSchemaGroupRef) { XmlSchemaGroup group = (XmlSchemaGroup)schema.Groups[((XmlSchemaGroupRef)groupBase.Items[i]).RefName]; ParseGroupBasePass2(group.Particle, className, ctorList, childClasses, parentClassStack, dotnetFieldList, parentNamespace, classReferencesAdded); } else if (groupBase.Items[i] is XmlSchemaGroupBase) { // Particle inside a particle : ie. <xsd:sequence> <xsd:choice/> </xsd:sequence> ParseGroupBasePass2((XmlSchemaGroupBase)groupBase.Items[i], className, ctorList, childClasses, parentClassStack, dotnetFieldList, parentNamespace, classReferencesAdded); } } }
/// <summary> /// Parses xs:sequence and xs:choice elements in the schema /// </summary> /// <param name="group"></param> /// <returns>A list of direct children elements references</returns> private RecursiveChildren ParseGroupBase(XmlSchemaGroupBase group) { RecursiveChildren result; if (groupCache.TryGetValue(group, out result)) { log.WriteLine("Used cache: {0}", GetParticleDesc(group)); return result; } log.WriteLine("Parsing group {0}", GetParticleDesc(group)); result = new RecursiveChildren(group); groupCache.Add(group, result); foreach (XmlSchemaParticle particle in group.Items) { using (log.Indent()) { if (particle is XmlSchemaGroupBase) { XmlSchemaGroupBase subGroup = (XmlSchemaGroupBase)particle; result.dependencies.Add(subGroup, ParseGroupBase(subGroup)); } else if (particle is XmlSchemaElement) { result.children.Add(ParseElement((XmlSchemaElement)particle)); } else if (particle is XmlSchemaAny) { } else { throw new NotImplementedException(particle.GetType().Name); } } } return result; }
internal void SetParticle(XmlSchemaGroupBase value) { particle = value; }
private bool IsGroupBaseFromAny(XmlSchemaGroupBase derivedGroupBase, XmlSchemaAny baseAny) { decimal num; decimal num2; this.CalculateEffectiveTotalRange(derivedGroupBase, out num, out num2); if (!this.IsValidOccurrenceRangeRestriction(num, num2, baseAny.MinOccurs, baseAny.MaxOccurs)) { return false; } string minOccursString = baseAny.MinOccursString; baseAny.MinOccurs = 0M; for (int i = 0; i < derivedGroupBase.Items.Count; i++) { if (!this.IsValidRestriction((XmlSchemaParticle) derivedGroupBase.Items[i], baseAny)) { baseAny.MinOccursString = minOccursString; return false; } } baseAny.MinOccursString = minOccursString; return true; }
void ExportElementAccessors(XmlSchemaGroupBase group, ElementAccessor[] accessors, bool repeats, bool valueTypeOptional, string ns) { if (accessors.Length == 0) return; if (accessors.Length == 1) { ExportElementAccessor(group, accessors[0], repeats, valueTypeOptional, ns); } else { XmlSchemaChoice choice = new XmlSchemaChoice(); choice.MaxOccurs = repeats ? decimal.MaxValue : 1; choice.MinOccurs = repeats ? 0 : 1; for (int i = 0; i < accessors.Length; i++) ExportElementAccessor(choice, accessors[i], false, valueTypeOptional, ns); if (choice.Items.Count > 0) group.Items.Add(choice); } }
private void roopItem(XmlSchemaGroupBase xgb, bool tf, string choiceStr) { bool choice = tf; bool isVector = false; string includePathStr; string cStr = choiceStr; if (xgb is XmlSchemaChoice) { choice = true; if (xgb.Id == null) { choiceStr = "choiceStr_" + m_ClassGen.ChoiceStr.Count; } else { choiceStr = "choiceStr_" + xgb.Id; } m_ClassGen.ChoiceStr.Add(choiceStr); m_ClassGen.ChoiceStrMember.Add(choiceStr, new List<string>()); } foreach (XmlSchemaObject item in xgb.Items) { isVector = false; if (item is XmlSchemaElement) { XmlSchemaElement itemCast = item as XmlSchemaElement; if (itemCast.RefName.IsEmpty) { #region directDef if (choice) { m_ClassGen.ChoiceStrMember[choiceStr].Add(itemCast.Name); } if (itemCast.SchemaTypeName.IsEmpty) { includePathStr = includePath["boolean"]; m_MemberVariable.Add(new Variable("boolean", itemCast.Name, includePathStr, isVector, choice)); } else { decimal aa = itemCast.MaxOccurs; if (itemCast.MaxOccurs > 1) { isVector = true; } includePathStr = includePath[itemCast.SchemaTypeName.Name]; m_MemberVariable.Add(new Variable(itemCast.SchemaTypeName.Name, itemCast.Name, includePathStr, isVector, choice)); } #endregion } else { #region refDef string type = elementRef[itemCast.RefName.Name]; if (choice) { m_ClassGen.ChoiceStrMember[choiceStr].Add(itemCast.RefName.Name); } includePathStr = includePath[type]; m_MemberVariable.Add(new Variable(type, itemCast.RefName.Name, includePathStr, isVector, choice)); foreach (KeyValuePair<string, string> substiItem in elementSubstitutionRef) { if(substiItem.Key == itemCast.RefName.Name) { choice = false; bool substi = true; // 주석을 위한 것 string substiStr = elementRef[substiItem.Value]; includePathStr = includePath[substiStr]; Variable substiVariable = new Variable(substiStr, substiItem.Value, includePathStr, isVector, choice, substi); //substiVariable.SubstitudeStr = itemCast.RefName.Name; 주석에 들어갈건데 먼저 생성자에서 코드가 생성되서리 적용이 안댐 그냥 우선은 패스 m_MemberVariable.Add(substiVariable); } } #endregion } } else if (item is XmlSchemaGroupRef) { #region groupRefDef XmlSchemaGroupRef xsgr = item as XmlSchemaGroupRef; XmlSchemaGroup xsg = elementGroupRef[xsgr.RefName.Name]; roopItem(xsg.Particle, choice, choiceStr); #endregion } else if (item is XmlSchemaGroupBase) { XmlSchemaGroupBase xgbSub = item as XmlSchemaGroupBase; roopItem(xgbSub, choice, choiceStr); } } }
void ExportElementAccessor(XmlSchemaGroupBase group, ElementAccessor accessor, bool repeats, bool valueTypeOptional, string ns) { if (accessor.Any && accessor.Name.Length == 0) { XmlSchemaAny any = new XmlSchemaAny(); any.MinOccurs = 0; any.MaxOccurs = repeats ? decimal.MaxValue : 1; if (accessor.Namespace != null && accessor.Namespace.Length > 0 && accessor.Namespace != ns) any.Namespace = accessor.Namespace; group.Items.Add(any); } else { XmlSchemaElement element = (XmlSchemaElement)elements[accessor]; int minOccurs = repeats || accessor.HasDefault || (!accessor.IsNullable && !accessor.Mapping.TypeDesc.IsValueType) || valueTypeOptional ? 0 : 1; decimal maxOccurs = repeats || accessor.IsUnbounded ? decimal.MaxValue : 1; if (element == null) { element = new XmlSchemaElement(); element.IsNillable = accessor.IsNullable; element.Name = accessor.Name; if (accessor.HasDefault) element.DefaultValue = ExportDefaultValue(accessor.Mapping, accessor.Default); if (accessor.IsTopLevelInSchema) { elements.Add(accessor, element); element.Form = accessor.Form; AddSchemaItem(element, accessor.Namespace, ns); } else { element.MinOccurs = minOccurs; element.MaxOccurs = maxOccurs; // determine the form attribute value XmlSchema schema = schemas[ns]; if (schema == null) element.Form = accessor.Form == elementFormDefault ? XmlSchemaForm.None : accessor.Form; else { element.Form = accessor.Form == schema.ElementFormDefault ? XmlSchemaForm.None : accessor.Form; } } ExportElementMapping(element, (TypeMapping)accessor.Mapping, accessor.Namespace, accessor.Any); } if (accessor.IsTopLevelInSchema) { XmlSchemaElement refElement = new XmlSchemaElement(); refElement.RefName = new XmlQualifiedName(accessor.Name, accessor.Namespace); refElement.MinOccurs = minOccurs; refElement.MaxOccurs = maxOccurs; group.Items.Add(refElement); AddSchemaImport(accessor.Namespace, ns); } else { group.Items.Add(element); } } }