Example #1
0
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            BL retVal = base.Parse <BL>(s, result);

            // Now parse our data out... Attributes
            if (s.GetAttribute("value") != null)
            {
                retVal.Value = XmlConvert.ToBoolean(s.GetAttribute("value"));
            }

            base.Validate(retVal, s.ToString(), result);
            return(retVal);
        }
Example #2
0
        /// <summary>
        /// Parse an object instance from <paramref name="s"/>
        /// </summary>
        public virtual object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            var retVal = ParseAttributes <ST>(s, result);

            // Elements
            if (!s.IsEmptyElement)
            {
                // Exit markers
                int    sDepth = s.Depth;
                string sName  = s.Name;

                Encoding textEncoding = System.Text.Encoding.UTF8;
                s.Read();
                // Read until exit condition is fulfilled
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        ParseElementsInline(s, retVal, result);
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);
            return(retVal);
        }
Example #3
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type ivlType        = typeof(IVL <>);
            Type ivlGenericType = ivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "IVL", s.ToString()));
                }
                if (s.GetAttribute("value") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "IVL", s.ToString()));
                }

                // Get property information
                PropertyInfo lowProperty          = ivlGenericType.GetProperty("Low"),
                             highProperty         = ivlGenericType.GetProperty("High"),
                             widthProperty        = ivlGenericType.GetProperty("Width"),
                             valueProperty        = ivlGenericType.GetProperty("Value"),
                             originalTextProperty = ivlGenericType.GetProperty("OriginalText"),
                             lowClosedProperty    = ivlGenericType.GetProperty("LowClosed"),
                             highClosedProperty   = ivlGenericType.GetProperty("HighClosed");

                // Attributes
                if (s.GetAttribute("lowClosed") != null)
                {
                    lowClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("lowClosed")), null);
                }
                if (s.GetAttribute("highClosed") != null)
                {
                    highClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("highClosed")), null);
                }

                // Now process the elements
                #region Elements
                if (!s.IsEmptyElement)
                {
                    int    sDepth = s.Depth;
                    string sName  = s.Name;

                    s.Read();
                    // string Name
                    while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                    {
                        string oldName = s.Name; // Name
                        try
                        {
                            if (s.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                case "originalText":
                                    setProperty = originalTextProperty;
                                    break;

                                case "low":
                                    setProperty = lowProperty;
                                    break;

                                case "high":
                                    setProperty = highProperty;
                                    break;

                                case "any":
                                    setProperty = valueProperty;
                                    break;

                                case "width":
                                    setProperty = widthProperty;
                                    break;

                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, String.Format("Element '{0}' is not supported in IVL", s.LocalName), s.ToString(), null));
                                    break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion

                // Validate combination
                if (!((lowProperty.GetValue(instance, null) != null || highProperty.GetValue(instance, null) != null) ^ (valueProperty.GetValue(instance, null) != null || widthProperty.GetValue(instance, null) != null)))
                {
                    result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "IVL instance is not comformant to ISO21090 data types specification. 'Value' and/or 'Width', or 'Low' and/or 'High' are compliant representations.", s.ToString(), null));
                }
            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
Example #4
0
        /// <summary>
        /// Parse an instance of PIVL from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type pivlType       = typeof(PIVL <>);
            Type ivlGenericType = pivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "PIVL", s.ToString()));
                }
                if (s.GetAttribute("value") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "PIVL", s.ToString()));
                }

                // Get property information
                PropertyInfo alignmentProperty            = ivlGenericType.GetProperty("Alignment"),
                             phaseProperty                = ivlGenericType.GetProperty("Phase"),
                             periodProperty               = ivlGenericType.GetProperty("Period"),
                             institutionSpecifiedProperty = ivlGenericType.GetProperty("InstitutionSpecified"),
                             countProperty                = ivlGenericType.GetProperty("Count"),
                             frequencyProperty            = ivlGenericType.GetProperty("Frequency"),
                             originalTextProperty         = ivlGenericType.GetProperty("OriginalText");

                // Attributes
                if (s.GetAttribute("isFlexible") != null)
                {
                    institutionSpecifiedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("isFlexible")), null);
                }
                if (s.GetAttribute("alignment") != null)
                {
                    alignmentProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("alignment"), alignmentProperty.PropertyType), null);
                }
                if (s.GetAttribute("count") != null)
                {
                    countProperty.SetValue(instance, Util.Convert <INT>(s.GetAttribute("count")), null);
                }

                // Now process the elements
                #region Elements
                if (!s.IsEmptyElement)
                {
                    int    sDepth = s.Depth;
                    string sName  = s.Name;

                    s.Read();
                    // string Name
                    while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                    {
                        string oldName = s.Name; // Name
                        try
                        {
                            if (s.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                case "originalText":
                                    setProperty = originalTextProperty;
                                    break;

                                case "phase":
                                    setProperty = phaseProperty;
                                    break;

                                case "frequency":
                                    setProperty = frequencyProperty;
                                    break;

                                case "period":
                                    setProperty = periodProperty;
                                    break;

                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                    break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion
            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
Example #5
0
        /// <summary>
        /// Parse an object from <paramref name="r"/> using the type hint <paramref name="t"/>
        /// </summary>
        /// <param name="r">The reader to read from</param>
        /// <param name="t">The type hint for the formatter</param>
        /// <returns>A structured result</returns>
        public IFormatterParseResult Parse(XmlReader r, Type t)
        {
            // Get the struct attribute
            IDatatypeFormatter formatter = null;
            Type cType = t;

            // Don't check for XSI type if the type is a GTS or iterable
            // This is because the XSI type on these classes will mislead the formatter selector
            if (t == typeof(GTS) || t.GetInterface(typeof(IEnumerable).FullName, false) != null && !t.IsAbstract)
                formatter = GetFormatter(t);
            else
            {
                // Force processing as an XSI:Type
                if (r.GetAttribute("type", NS_XSI) != null)
                    cType = Util.ParseXSITypeName(r.GetAttribute("type", NS_XSI));

                formatter = GetFormatter(cType);
            }

            if (formatter == null)
                return null;

            // Set host and parse
            DatatypeFormatterParseResult result = new DatatypeFormatterParseResult(this.CompatibilityMode, ResultCode.Accepted, null, this.ValidateConformance);
            formatter.Host = (IXmlStructureFormatter)(this.Host ?? this);

            
#if WINDOWS_PHONE
            bool hasErrors = s_unsupportedNames.Exists(o => (t.IsGenericType ? t.GetGenericTypeDefinition() : t).Equals(o));
#else
            bool hasErrors = Array.Exists(s_unsupportedNames, o => (t.IsGenericType ? t.GetGenericTypeDefinition() : t).Equals(o));
#endif
            // Errors
            if (hasErrors)
            {
                var structAtt = t.GetCustomAttributes(typeof(StructureAttribute), false);
                if (structAtt.Length > 0)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(
                        ResultDetailType.Warning,
                        "All",
                        (structAtt[0] as StructureAttribute).Name,
                        r.ToString()
                    ));
            }
            // Structure graph
            result.Structure = formatter.Parse(r, result) as IGraphable;
            
            return result;
        }
Example #6
0
        public void XML2ON(XmlReader xmlReader, double dtdVersion, bool checkMissingArguments)
        {
            string XMLTAG = "";
            // Check the elements arguments of the request
            try
            {
                if ((!xmlReader.IsStartElement(ONXml.XMLTAG_ARGUMENTS)) && (!xmlReader.IsStartElement(ONXml.XMLTAG_FILTERVARIABLES)))
                    throw new ONXMLNavFilterException(null, xmlReader.ToString(), ONXml.XMLTAG_ARGUMENTS, ONXml.XMLTAG_FILTERVARIABLES);
            }
            catch
            {
                throw new ONXMLNavFilterException(null, xmlReader.ToString(), ONXml.XMLTAG_ARGUMENTS, ONXml.XMLTAG_FILTERVARIABLES);
            }

            if (xmlReader.IsEmptyElement) // Service dont have arguments
            {
                xmlReader.ReadElementString();
                return;
            }

            if (xmlReader.IsStartElement(ONXml.XMLTAG_ARGUMENTS))
            {
                xmlReader.ReadStartElement(ONXml.XMLTAG_ARGUMENTS);
                XMLTAG = ONXml.XMLTAG_ARGUMENT;
            }
            else if (xmlReader.IsStartElement(ONXml.XMLTAG_FILTERVARIABLES))
            {
                xmlReader.ReadStartElement(ONXml.XMLTAG_FILTERVARIABLES);
                XMLTAG = ONXml.XMLTAG_FILTERVARIABLE;
            }

            // While there are arguments to solve ...
            string lName;
            while(xmlReader.IsStartElement(XMLTAG))
            {
                string lXmlType;
                try
                {
                    if (dtdVersion <= 2.0)
                        lName = xmlReader.GetAttribute(ONXml.XMLATT_NAME_DTD20);
                    else
                        lName = xmlReader.GetAttribute(ONXml.XMLATT_NAME);

                    lXmlType = xmlReader.GetAttribute(ONXml.XMLATT_TYPE);

                    if ((mIdClass == "") && (mIdService == ""))
                    {
                        string lClass = "";
                        DataTypeEnumerator lType = new DataTypeEnumerator();
                        if (string.Compare(lXmlType, "autonumeric", true) == 0)
                            lType = DataTypeEnumerator.Autonumeric;
                        else if (string.Compare(lXmlType, "int", true) == 0)
                            lType = DataTypeEnumerator.Int;
                        else if (string.Compare(lXmlType, "bool", true) == 0)
                            lType = DataTypeEnumerator.Bool;
                        else if (string.Compare(lXmlType, "blob", true) == 0)
                            lType = DataTypeEnumerator.Blob;
                        else if (string.Compare(lXmlType, "date", true) == 0)
                            lType = DataTypeEnumerator.Date;
                        else if (string.Compare(lXmlType, "datetime", true) == 0)
                            lType = DataTypeEnumerator.DateTime;
                        else if (string.Compare(lXmlType, "nat", true) == 0)
                            lType = DataTypeEnumerator.Nat;
                        else if (string.Compare(lXmlType, "real", true) == 0)
                            lType = DataTypeEnumerator.Real;
                        else if (string.Compare(lXmlType, "password", true) == 0)
                            lType = DataTypeEnumerator.Password;
                        else if (string.Compare(lXmlType, "string", true) == 0)
                            lType = DataTypeEnumerator.String;
                        else if (string.Compare(lXmlType, "text", true) == 0)
                            lType = DataTypeEnumerator.Text;
                        else if (string.Compare(lXmlType, "time", true) == 0)
                            lType = DataTypeEnumerator.Time;
                        else
                            lType = DataTypeEnumerator.OID;

                        xmlReader.ReadStartElement(XMLTAG);
                        if (lType == DataTypeEnumerator.OID)
                            lClass = xmlReader.GetAttribute("Class");

                        mArgumentList.Add(lName, new ONArgumentInfo(lName, true, lType, 1000, lClass, "", ""));
                    }
                    else
                        xmlReader.ReadStartElement(XMLTAG);
                }
                catch(Exception e)
                {
                    throw new ONXMLStructureException(e, ONXml.XMLATT_NAME);
                }

                try
                {
                    ReadArgument(xmlReader, dtdVersion, lName, lXmlType);
                }
                catch(Exception e)
                {
                    if (e.GetType() == typeof(ONInstanceNotExistException))
                        throw;
                    else
                        throw new ONArgumentException(e, lName);

                }
                xmlReader.ReadEndElement(); // Argument
            }

            xmlReader.ReadEndElement(); // Arguments

            // Check the change detection items of the request
            if (xmlReader.IsStartElement(ONXml.XMLTAG_CHANGEDETECTIONITEMS))
            {
                if (xmlReader.IsEmptyElement) // Service dont have change detection items
                {
                    xmlReader.ReadElementString();
                    return;
                }

                if (xmlReader.IsStartElement(ONXml.XMLTAG_CHANGEDETECTIONITEMS))
                {
                    xmlReader.ReadStartElement(ONXml.XMLTAG_CHANGEDETECTIONITEMS);
                    XMLTAG = ONXml.XMLTAG_CHANGEDETECTIONITEM;
                }

                // While there are change detection items to solve ...
                while (xmlReader.IsStartElement(XMLTAG))
                {
                    try
                    {
                        lName = xmlReader.GetAttribute(ONXml.XMLATT_NAME);
                        xmlReader.ReadStartElement(XMLTAG);
                    }
                    catch (Exception e)
                    {
                        throw new ONXMLStructureException(e, ONXml.XMLATT_NAME);
                    }

                    try
                    {
                        ReadChangeDetectionItem(xmlReader, dtdVersion, lName);
                    }
                    catch (Exception e)
                    {
                        throw new ONArgumentException(e, lName);

                    }
                    xmlReader.ReadEndElement(); // ChangeDetectionItem
                }

                xmlReader.ReadEndElement(); // ChangeDetectionItems
            }

            // Comprobations over the arguments
            foreach(DictionaryEntry lElem in mArgumentList)
            {

                ONArgumentInfo lArg = (ONArgumentInfo) lElem.Value;

                // Check if it is all the arguments
                        if (lArg.Value == null)
                        {
                            if (checkMissingArguments)
                            {
                                throw new ONMissingArgumentException(null, lArg.IdArgument, lArg.Alias);
                            }
                            else
                            {
                                continue;
                            }
                        }

                if (lArg.Value.Value == null && lArg.Null == false)
                    throw new ONNotNullArgumentException(null, mIdService, mIdClass, lArg.IdArgument, mAlias, mClassAlias, lArg.Alias);

                if (lArg.MaxLength > 0 )
                {
                    ONString lString = lArg.Value as ONString;
                    //MARTA DEFECT 3766
                    //ONText lText = lArg.Value as ONText;
                    if (((object) lString != null) && (lString.TypedValue != null) && (lString.TypedValue.Length > lArg.MaxLength))
                        throw new ONMaxLenghtArgumentException(null, lArg.IdArgument, lArg.Alias, lArg.MaxLength.ToString());
                    //MARTA DEFECT 3766
                    //if (((object) lText != null) && (lText.TypedValue != null) && (lText.TypedValue.Length > lArg.MaxLength))
                    //	throw new ONMaxLenghtArgumentException(null, lArg.IdArgument, lArg.Alias, lArg.MaxLength.ToString());
                }
            }
        }
        /// <summary>
        /// Parse an object from <paramref name="r"/> using the type hint <paramref name="t"/>
        /// </summary>
        /// <param name="r">The reader to read from</param>
        /// <param name="t">The type hint for the formatter</param>
        /// <returns>A structured result</returns>
        public IFormatterParseResult Parse(XmlReader r, Type t)
        {
            // Get the struct attribute
            IDatatypeFormatter formatter = null;
            Type cType = t;

            //if (formatter != null && t != typeof(GTS) && formatter.GenericArguments == null )
            //    formatter.GenericArguments = t.GetGenericArguments();
            if (t == typeof(GTS) || t.GetInterface(typeof(IEnumerable).FullName) != null && !t.IsAbstract)
                formatter = GetFormatter(t);
            else
            {
                // Force processing as an XSI:Type
                if (r.GetAttribute("type", NS_XSI) != null)
                    cType = Util.ParseXSITypeName(r.GetAttribute("type", NS_XSI));

                formatter = GetFormatter(cType);
            }

            if (formatter == null)
                return null;

            // Set host and parse
            DatatypeFormatterParseResult result = new DatatypeFormatterParseResult(this.CompatibilityMode, ResultCode.Accepted, null, this.ValidateConformance);
            formatter.Host = (IXmlStructureFormatter)(this.Host ?? this);

            // Errors
            if (Array.Exists(s_unsupportedNames, o => (t.IsGenericType ? t.GetGenericTypeDefinition() : t).Equals(o)))
            {
                var structAtt = t.GetCustomAttributes(typeof(StructureAttribute), false);
                if (structAtt.Length > 0)
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(
                        ResultDetailType.Warning,
                        "All",
                        (structAtt[0] as StructureAttribute).Name,
                        r.ToString()
                    ));
            }

            // Structure graph
            result.Structure = formatter.Parse(r, result) as IGraphable;

            return result;
        }