Beispiel #1
0
 internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context)
 {
     if (!schemas.Contains(XmlSchema.Namespace))
     {
         schemas.AddReference(XmlSchemas.XsdSchema);
         schemas.SchemaSet.Add(XmlSchemas.XsdSchema);
     }
     if (!schemas.Contains(XmlReservedNs.NsXml))
     {
         schemas.AddReference(XmlSchemas.XmlSchema);
         schemas.SchemaSet.Add(XmlSchemas.XmlSchema);
     }
     _schemas      = schemas;
     _options      = options;
     _codeProvider = codeProvider;
     _context      = context;
     Schemas.SetCache(Context.Cache, Context.ShareTypes);
     _extensions = new SchemaImporterExtensionCollection();
 }
Beispiel #2
0
        internal void CheckDuplicateElement(XmlSchemaElement element, string elementNs)
        {
            if (element == null)
            {
                return;
            }

            // only check duplicate definitions for top-level element
            if (element.Parent == null || !(element.Parent is XmlSchema))
            {
                return;
            }

            XmlSchemaObjectTable elements = null;

            if (Schema != null && Schema.TargetNamespace == elementNs)
            {
                XmlSchemas.Preprocess(Schema);
                elements = Schema.Elements;
            }
            else if (Schemas != null)
            {
                elements = Schemas.GlobalElements;
            }
            else
            {
                return;
            }
            foreach (XmlSchemaElement e in elements.Values)
            {
                if (e.Name == element.Name && e.QualifiedName.Namespace == elementNs)
                {
                    if (Match(e, element))
                    {
                        return;
                    }
                    // XmlSerializableRootDupName=Cannot reconcile schema for '{0}'. Please use [XmlRoot] attribute to change name or namepace of the top-level element to avoid duplicate element declarations: element name='{1} namespace='{2}'.
                    throw new InvalidOperationException(string.Format(ResXml.XmlSerializableRootDupName, _getSchemaMethod.DeclaringType.FullName, e.Name, elementNs));
                }
            }
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #5
0
 /// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter4"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapSchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, ImportContext context) : base(schemas, options, codeProvider, context)
 {
 }
Beispiel #6
0
 /// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter3"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapSchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, ImportContext context) : base(schemas, options, null, context)
 {
 }
Beispiel #7
0
 /// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter2"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapSchemaImporter(XmlSchemas schemas, CodeIdentifiers typeIdentifiers, CodeGenerationOptions options) : base(schemas, options, null, new ImportContext(typeIdentifiers, false))
 {
 }
Beispiel #8
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);
        }
Beispiel #9
0
 /// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.SoapSchemaImporter"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapSchemaImporter(XmlSchemas schemas) : base(schemas, CodeGenerationOptions.GenerateProperties, null, new ImportContext())
 {
 }
Beispiel #10
0
        internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas)
        {
            if (item == null)
            {
                return(null);
            }
            if (qname == null || qname.IsEmpty)
            {
                return(null);
            }

            string    key  = item.GetType().Name + ":" + qname.ToString();
            ArrayList list = (ArrayList)ObjectCache[key];

            if (list == null)
            {
                list             = new ArrayList();
                ObjectCache[key] = list;
            }

            for (int i = 0; i < list.Count; i++)
            {
                XmlSchemaObject cachedItem = (XmlSchemaObject)list[i];
                if (cachedItem == item)
                {
                    return(cachedItem);
                }

                if (Match(cachedItem, item, true))
                {
                    return(cachedItem);
                }
                else
                {
                    Warnings.Add(string.Format(ResXml.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace));
                    Warnings.Add("DEBUG:Cached item key:\r\n" + (string)looks[cachedItem] + "\r\nnew item key:\r\n" + (string)looks[item]);
                }
            }
            // no match found we need to insert the new type in the cache
            list.Add(item);
            return(item);
        }
Beispiel #11
0
 public XmlSchemaEnumerator(XmlSchemas list)
 {
     _list = list;
     _idx  = -1;
     _end  = list.Count - 1;
 }
Beispiel #12
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);
        }
Beispiel #13
0
 /// <include file='doc\SoapSchemaExporter.uex' path='docs/doc[@for="SoapSchemaExporter.SoapSchemaExporter"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public SoapSchemaExporter(XmlSchemas schemas)
 {
     _schemas = schemas;
 }