Example #1
0
        private void ImportGroupMembers(XmlSchemaParticle particle, CodeIdentifiers members, string ns)
        {
            XmlQualifiedName parentType = XmlSchemas.GetParentName(particle);

            if (particle is XmlSchemaGroupRef)
            {
                throw new InvalidOperationException(string.Format(ResXml.XmlSoapUnsupportedGroupRef, parentType.Name, parentType.Namespace));
            }
            else if (particle is XmlSchemaGroupBase)
            {
                XmlSchemaGroupBase group = (XmlSchemaGroupBase)particle;
                if (group.IsMultipleOccurrence)
                {
                    throw new InvalidOperationException(string.Format(ResXml.XmlSoapUnsupportedGroupRepeat, parentType.Name, parentType.Namespace));
                }
                for (int i = 0; i < group.Items.Count; i++)
                {
                    object item = group.Items[i];
                    if (item is XmlSchemaGroupBase || item is XmlSchemaGroupRef)
                    {
                        throw new InvalidOperationException(string.Format(ResXml.XmlSoapUnsupportedGroupNested, parentType.Name, parentType.Namespace));
                    }
                    else if (item is XmlSchemaElement)
                    {
                        ImportElementMember((XmlSchemaElement)item, members, ns);
                    }
                    else if (item is XmlSchemaAny)
                    {
                        throw new InvalidOperationException(string.Format(ResXml.XmlSoapUnsupportedGroupAny, parentType.Name, parentType.Namespace));
                    }
                }
            }
        }
Example #2
0
 private void ImportGroup(XmlSchemaParticle group, CodeIdentifiers members, string ns)
 {
     if (group is XmlSchemaChoice)
     {
         XmlQualifiedName parentType = XmlSchemas.GetParentName(group);
         throw new InvalidOperationException(string.Format(ResXml.XmlSoapInvalidChoice, parentType.Name, parentType.Namespace));
     }
     else
     {
         ImportGroupMembers(group, members, ns);
     }
 }
Example #3
0
        private TypeMapping ImportElementType(XmlSchemaElement element, string ns)
        {
            TypeMapping mapping;

            if (!element.SchemaTypeName.IsEmpty)
            {
                mapping = ImportType(element.SchemaTypeName, false);
            }
            else if (element.SchemaType != null)
            {
                XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
                if (element.SchemaType is XmlSchemaComplexType)
                {
                    mapping = ImportType((XmlSchemaComplexType)element.SchemaType, ns, false);
                    if (!(mapping is ArrayMapping))
                    {
                        throw new InvalidOperationException(string.Format(ResXml.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name));
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format(ResXml.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name));
                }
            }
            else if (!element.SubstitutionGroup.IsEmpty)
            {
                XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
                throw new InvalidOperationException(string.Format(ResXml.XmlInvalidSubstitutionGroupUse, parentType.Name, parentType.Namespace));
            }
            else
            {
                XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
                throw new InvalidOperationException(string.Format(ResXml.XmlElementMissingType, parentType.Name, parentType.Namespace, element.Name));
            }

            mapping.ReferencedByElement = true;

            return(mapping);
        }
Example #4
0
        private ElementAccessor ImportElement(XmlSchemaElement element, string ns)
        {
            if (!element.RefName.IsEmpty)
            {
                throw new InvalidOperationException(string.Format(ResXml.RefSyntaxNotSupportedForElements0, element.RefName.Name, element.RefName.Namespace));
            }

            if (element.Name.Length == 0)
            {
                XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
                throw new InvalidOperationException(string.Format(ResXml.XmlElementHasNoName, parentType.Name, parentType.Namespace));
            }
            TypeMapping     mapping  = ImportElementType(element, ns);
            ElementAccessor accessor = new ElementAccessor();

            accessor.IsSoap     = true;
            accessor.Name       = element.Name;
            accessor.Namespace  = ns;
            accessor.Mapping    = mapping;
            accessor.IsNullable = element.IsNillable;
            accessor.Form       = XmlSchemaForm.None;

            return(accessor);
        }
Example #5
0
        private StructMapping ImportStructType(XmlSchemaComplexType type, string typeNs, bool excludeFromImport)
        {
            if (type.Name == null)
            {
                XmlSchemaElement element    = (XmlSchemaElement)type.Parent;
                XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
                throw new InvalidOperationException(string.Format(ResXml.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name));
            }

            TypeDesc baseTypeDesc = null;

            Mapping baseMapping = null;

            if (!type.DerivedFrom.IsEmpty)
            {
                baseMapping = ImportType(type.DerivedFrom, excludeFromImport);

                if (baseMapping is StructMapping)
                {
                    baseTypeDesc = ((StructMapping)baseMapping).TypeDesc;
                }
                else
                {
                    baseMapping = null;
                }
            }
            if (baseMapping == null)
            {
                baseMapping = GetRootMapping();
            }
            Mapping previousMapping = (Mapping)ImportedMappings[type];

            if (previousMapping != null)
            {
                return((StructMapping)previousMapping);
            }
            string        typeName      = GenerateUniqueTypeName(Accessor.UnescapeName(type.Name));
            StructMapping structMapping = new StructMapping();

            structMapping.IsReference = Schemas.IsReference(type);
            TypeFlags flags = TypeFlags.Reference;

            if (type.IsAbstract)
            {
                flags |= TypeFlags.Abstract;
            }
            structMapping.TypeDesc    = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags);
            structMapping.Namespace   = typeNs;
            structMapping.TypeName    = type.Name;
            structMapping.BaseMapping = (StructMapping)baseMapping;
            ImportedMappings.Add(type, structMapping);
            if (excludeFromImport)
            {
                structMapping.IncludeInSchema = false;
            }
            CodeIdentifiers members = new CodeIdentifiers();

            members.AddReserved(typeName);
            AddReservedIdentifiersForDataBinding(members);
            structMapping.Members = ImportTypeMembers(type, typeNs, members);
            Scope.AddTypeMapping(structMapping);
            ImportDerivedTypes(new XmlQualifiedName(type.Name, typeNs));
            return(structMapping);
        }
Example #6
0
        private static string GetSchemaItem(XmlSchemaObject o, string ns, string details)
        {
            if (o == null)
            {
                return(null);
            }
            while (o.Parent != null && !(o.Parent is XmlSchema))
            {
                o = o.Parent;
            }
            if (ns == null || ns.Length == 0)
            {
                XmlSchemaObject tmp = o;
                while (tmp.Parent != null)
                {
                    tmp = tmp.Parent;
                }
                if (tmp is XmlSchema)
                {
                    ns = ((XmlSchema)tmp).TargetNamespace;
                }
            }
            string item = null;

            if (o is XmlSchemaNotation)
            {
                item = string.Format(ResXml.XmlSchemaNamedItem, ns, "notation", ((XmlSchemaNotation)o).Name, details);
            }
            else if (o is XmlSchemaGroup)
            {
                item = string.Format(ResXml.XmlSchemaNamedItem, ns, "group", ((XmlSchemaGroup)o).Name, details);
            }
            else if (o is XmlSchemaElement)
            {
                XmlSchemaElement e = ((XmlSchemaElement)o);
                if (e.Name == null || e.Name.Length == 0)
                {
                    XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
                    // Element reference '{0}' declared in schema type '{1}' from namespace '{2}'
                    item = string.Format(ResXml.XmlSchemaElementReference, e.RefName.ToString(), parentName.Name, parentName.Namespace);
                }
                else
                {
                    item = string.Format(ResXml.XmlSchemaNamedItem, ns, "element", e.Name, details);
                }
            }
            else if (o is XmlSchemaType)
            {
                item = string.Format(ResXml.XmlSchemaNamedItem, ns, o.GetType() == typeof(XmlSchemaSimpleType) ? "simpleType" : "complexType", ((XmlSchemaType)o).Name, null);
            }
            else if (o is XmlSchemaAttributeGroup)
            {
                item = string.Format(ResXml.XmlSchemaNamedItem, ns, "attributeGroup", ((XmlSchemaAttributeGroup)o).Name, details);
            }
            else if (o is XmlSchemaAttribute)
            {
                XmlSchemaAttribute a = ((XmlSchemaAttribute)o);
                if (a.Name == null || a.Name.Length == 0)
                {
                    XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
                    // Attribure reference '{0}' declared in schema type '{1}' from namespace '{2}'
                    return(string.Format(ResXml.XmlSchemaAttributeReference, a.RefName.ToString(), parentName.Name, parentName.Namespace));
                }
                else
                {
                    item = string.Format(ResXml.XmlSchemaNamedItem, ns, "attribute", a.Name, details);
                }
            }
            else if (o is XmlSchemaContent)
            {
                XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
                // Check content definition of schema type '{0}' from namespace '{1}'. {2}
                item = string.Format(ResXml.XmlSchemaContentDef, parentName.Name, parentName.Namespace, null);
            }
            else if (o is XmlSchemaExternal)
            {
                string itemType = o is XmlSchemaImport ? "import" : o is XmlSchemaInclude ? "include" : o is XmlSchemaRedefine ? "redefine" : o.GetType().Name;
                item = string.Format(ResXml.XmlSchemaItem, ns, itemType, details);
            }
            else if (o is XmlSchema)
            {
                item = string.Format(ResXml.XmlSchema, ns, details);
            }
            else
            {
                item = string.Format(ResXml.XmlSchemaNamedItem, ns, o.GetType().Name, null, details);
            }

            return(item);
        }