예제 #1
0
 internal XdtoDataObject(XdtoObjectType type, XdtoDataObject owner, XdtoProperty property)
 {
     _type           = type;
     _owner          = owner;
     _owningProperty = property;
     _sequence       = new XdtoSequence(this, true);
     FillPropertiesFromType();
 }
예제 #2
0
        public IValue ReadXml(XmlReaderImpl reader, IXdtoType type = null)
        {
            if (reader.MoveToContent() == null)
            {
                // TODO: бросить исключение??
                return(null);
            }
            if (type == null)
            {
                var explicitType = reader.GetAttribute(ValueFactory.Create("type"), XmlNs.xsi);
                if (explicitType.DataType == DataType.Undefined)
                {
                    type = new XdtoObjectType();
                }
                else
                {
                    var defaultNamespace = reader.NamespaceContext.DefaultNamespace;

                    // Задан тип - пытаемся его распознать
                    var sType        = explicitType.AsString();
                    var nameElements = sType.Split(':');

                    var typeUri = nameElements.Count() > 1
                                                                  ? nameElements [0]
                                                                  : defaultNamespace;
                    var typeName = nameElements.Count() > 1
                                                                  ? nameElements [1]
                                                                  : nameElements [0];

                    var nsMapping = reader.NamespaceContext.LookupNamespaceUri(typeUri);
                    if (nsMapping != null && nsMapping.DataType == DataType.String)
                    {
                        typeUri = nsMapping.AsString();
                    }

                    type = this.Type(typeUri, typeName);
                }
            }

            if (type is XdtoObjectType)
            {
                return(ValueFactory.Create(type.Reader.ReadXml(reader, type, this)));
            }

            var xmlNodeTypeEnum = XmlNodeTypeEnum.CreateInstance();
            var xmlElementStart = xmlNodeTypeEnum.FromNativeValue(XmlNodeType.Element);
            var xmlElementEnd   = xmlNodeTypeEnum.FromNativeValue(XmlNodeType.EndElement);

            if (type is XdtoValueType)
            {
                if (reader.NodeType.Equals(xmlElementStart))
                {
                    reader.Read();
                }
                var result = type.Reader.ReadXml(reader, type, this);
                if (!reader.NodeType.Equals(xmlElementEnd))
                {
                    reader.Skip();
                }

                var pd = new PrimitiveValuesSerializer();
                return(pd.DeserializeXdto(result));
            }

            throw new NotSupportedException("Неожиданный тип XDTO!");
        }
예제 #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);
        }