Exemple #1
0
 internal XdtoPackage(string namespaceUri, IEnumerable <IXdtoType> types)
 {
     NamespaceUri = namespaceUri;
     _types.AddRange(types);
     Dependencies   = new XdtoPackageCollection(new XdtoPackage [] { });
     RootProperties = new XdtoPropertyCollection(new XdtoProperty [] { });
     _built         = true;
 }
Exemple #2
0
        // anyType
        internal XdtoObjectType()
        {
            Name         = "anyType";
            NamespaceUri = XmlNs.xs;

            Open       = true;
            Sequenced  = true;
            Mixed      = true;
            Properties = new XdtoPropertyCollection(new List <XdtoProperty> ());
        }
Exemple #3
0
        internal void BuildPackage()
        {
            if (_built)
            {
                return;
            }
            _built = true;

            foreach (var include in _schema.Includes)
            {
                if (include is XmlSchemaImport)
                {
                    var import          = include as XmlSchemaImport;
                    var packagetoImport = _factory.Packages.Get(import.Namespace);
                    // TODO: what if null ?
                    packagetoImport?.BuildPackage();
                }
            }

            foreach (var oType in _schema.SchemaTypes)
            {
                var dElement = (DictionaryEntry)oType;
                var type     = dElement.Value;
                if (type is XmlSchemaSimpleType)
                {
                    _types.Add(new XdtoValueType(type as XmlSchemaSimpleType, _factory));
                }
                else
                if (type is XmlSchemaComplexType)
                {
                    _types.Add(new XdtoObjectType(type as XmlSchemaComplexType, _factory));
                }
            }

            var rootProperties = new List <XdtoProperty> ();

            foreach (var oElement in _schema.Elements)
            {
                var elPair  = (DictionaryEntry)oElement;
                var element = elPair.Value as XmlSchemaElement;

                // в XDTO под элемент создаётся свой тип с таким же именем
                IXdtoType elementType;
                if (element.SchemaType is XmlSchemaSimpleType)
                {
                    elementType = new XdtoValueType(element.SchemaType as XmlSchemaSimpleType, _factory);
                }
                else if (element.SchemaType is XmlSchemaComplexType)
                {
                    elementType = new XdtoObjectType(element, _factory);
                }
                else
                {
                    // TODO: Присвоить anyType
                    throw new NotImplementedException();
                }

                _types.Add(elementType);

                var property = new XdtoProperty(XmlFormEnum.Element,
                                                element.QualifiedName.Namespace,
                                                element.QualifiedName.Name,
                                                elementType);
                rootProperties.Add(property);
            }

            RootProperties = new XdtoPropertyCollection(rootProperties);
        }
Exemple #4
0
        public XdtoObjectType(XmlSchemaComplexType xmlType, XdtoFactory factory)
        {
            Name         = xmlType.QualifiedName.Name;
            NamespaceUri = xmlType.QualifiedName.Namespace;

            Abstract = xmlType.IsAbstract;
            Mixed    = xmlType.IsMixed;

            var properties = new List <XdtoProperty> ();

            var particle = xmlType.Particle;

            if (xmlType.ContentModel is XmlSchemaComplexContent)
            {
                var complexContent = xmlType.ContentModel as XmlSchemaComplexContent;
                if (complexContent.Content is XmlSchemaComplexContentExtension)
                {
                    var extension = complexContent.Content as XmlSchemaComplexContentExtension;
                    BaseType = factory.Type(Normalize(extension.BaseTypeName, NamespaceUri)) as XdtoObjectType;
                    particle = extension.Particle;
                }
                else
                {
                    throw new NotImplementedException("Недоработочка в XDTO-объекте");
                }
            }

            if (particle is XmlSchemaSequence)
            {
                var sequence = particle as XmlSchemaSequence;

                foreach (var item in sequence.Items)
                {
                    var       element = item as XmlSchemaElement;
                    IXdtoType propertyType;
                    if (!element.SchemaTypeName.IsEmpty)
                    {
                        propertyType = new TypeResolver(factory, element.SchemaTypeName);
                    }
                    else
                    {
                        var type = element.SchemaType;
                        if (type is XmlSchemaSimpleType)
                        {
                            propertyType = new XdtoValueType(type as XmlSchemaSimpleType, factory);
                        }
                        else if (type is XmlSchemaComplexType)
                        {
                            propertyType = new XdtoObjectType(type as XmlSchemaComplexType, factory);
                        }
                        else
                        {
                            propertyType = new XdtoObjectType();
                        }
                    }

                    var minOccurs = element.MinOccurs;
                    var maxOccurs = string.Equals(element.MaxOccursString, "unbounded", StringComparison.Ordinal)
                                                        ? -1
                                                        : element.MaxOccurs
                    ;

                    properties.Add(new XdtoProperty(this, null,
                                                    XmlFormEnum.Element,
                                                    element.QualifiedName.Namespace,
                                                    element.QualifiedName.Name,
                                                    (int)minOccurs, (int)maxOccurs,
                                                    propertyType));
                }
            }
            else if (particle is XmlSchemaChoice)
            {
                var choice = particle as XmlSchemaChoice;
                foreach (var item in choice.Items)
                {
                    var element = item as XmlSchemaElement;
                    // TODO: копипаста
                    IXdtoType propertyType;
                    if (!element.SchemaTypeName.IsEmpty)
                    {
                        propertyType = new TypeResolver(factory, element.SchemaTypeName);
                    }
                    else
                    {
                        var type = element.SchemaType;
                        if (type is XmlSchemaSimpleType)
                        {
                            propertyType = new XdtoValueType(type as XmlSchemaSimpleType, factory);
                        }
                        else if (type is XmlSchemaComplexType)
                        {
                            propertyType = new XdtoObjectType(type as XmlSchemaComplexType, factory);
                        }
                        else
                        {
                            throw new NotImplementedException("Anonymous type...");
                        }
                    }

                    properties.Add(new XdtoProperty(this, null,
                                                    XmlFormEnum.Element,
                                                    element.QualifiedName.Namespace,
                                                    element.QualifiedName.Name,
                                                    0, 1,
                                                    propertyType));
                }
            }
            else
            {
                throw new NotImplementedException("Недоработочка в XDTO-объекте");
            }

            Properties = new XdtoPropertyCollection(properties);
        }