Exemplo n.º 1
0
        public static bool?ValidateFlavor(string flavor, ANY instance, out IResultDetail[] details)
        {
            // Does this flavor exist?
            string kFormat = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", instance.GetType().FullName, flavor.ToUpper());

            // JF - Makes this much faster
            MethodInfo validatorMi = null;

            if (s_flavorValidation.TryGetValue(kFormat, out validatorMi))
            {
                details = new IResultDetail[0];
                return((bool)validatorMi.Invoke(null, new object[] { instance }));
            }

            details = new IResultDetail[0];

            // Add warning
            if (flavor != instance.GetType().Name)
            {
                details = new IResultDetail[] { new ResultDetail(ResultDetailType.Warning, string.Format(EverestFrameworkContext.CurrentCulture, "Can't find flavor '{0}'", flavor), null, null) }
            }
            ;

            return(null);
        }
Exemplo n.º 2
0
 /// MDHT operation: asks whether the content has actual content (except for the nullFlavor attribute)
 public bool hasContent(ANY o)
 {
     foreach (PropertyInfo field in o.GetType().GetProperties())
     {
         Object value = field.GetValue(o, null);
         if (value != null && field.Name != "nullFlavor")
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 /// MDHT operation: asks whether the string-valued feature of the given object matches the given regular expression
 public bool matches(ANY o, String featureName, String regularExpression)
 {
     try
     {
         PropertyInfo field = o.GetType().GetProperty(featureName);
         if (field == null)
         {
             return(false);
         }
         object x = field.GetValue(o, null);
         if (x is String)
         {
             String s      = (String)x;
             bool   result = System.Text.RegularExpressions.Regex.IsMatch(s, "^" + regularExpression + "$");
             return(result);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            ANY instance = o as ANY;

            IResultDetail[] enumer = new IResultDetail[0], flavor = new IResultDetail[0],
            invalidAttributes = new IResultDetail[0];

            // Now render
            if (instance == null)
            {
                throw new InvalidOperationException("Could not cast object to the ANY data type");
            }

            if (instance.Flavor != null &&
                (instance.NullFlavor == null ||
                 (instance is ICodedSimple && ((NullFlavor)instance.NullFlavor).IsChildConcept(NullFlavor.Other)) ||
                 (instance is IQuantity && ((NullFlavor)instance.NullFlavor).IsChildConcept(NullFlavor.Derived))
                )
                )
            {
                s.WriteAttributeString("flavorId", instance.Flavor);
            }

            if (instance.NullFlavor != null)
            {
                s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor));
            }
            else
            {
                // Warn if items can't be represented in R2
                if (instance.ControlActExt != null)
                {
                    s.WriteAttributeString("controlInformationExtension", instance.ControlActExt);
                }
                if (instance.ControlActRoot != null)
                {
                    s.WriteAttributeString("controlInformationRoot", instance.ControlActRoot);
                }
                if (instance.ValidTimeHigh != null && !instance.ValidTimeHigh.IsNull)
                {
                    s.WriteAttributeString("validTimeHigh", instance.ValidTimeHigh.Value);
                }
                if (instance.ValidTimeLow != null && !instance.ValidTimeLow.IsNull)
                {
                    s.WriteAttributeString("validTimeLow", instance.ValidTimeLow.Value);
                }
                if (instance.UpdateMode != null && !instance.UpdateMode.IsNull)
                {
                    s.WriteAttributeString("updateMode", Util.ToWireFormat(instance.UpdateMode));
                }
            }

            string currentElementName = "";

            if (s is MARC.Everest.Xml.XmlStateWriter)
            {
                currentElementName = (s as MARC.Everest.Xml.XmlStateWriter).CurrentPath;
            }

            // Validate
            if (result.ValidateConformance && !instance.Validate())
            {
                foreach (var r in instance.ValidateEx())
                {
                    r.Location = currentElementName;
                    result.AddResultDetail(r);
                }
            }
            //{
            //    result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, o.GetType().Name, currentElementName));
            //}

            // Disabled for test
            // Validate flavor...
            if (result.ValidateConformance && instance.Flavor != null && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, currentElementName));
                result.AddResultDetail(flavor);
            }
        }
Exemplo n.º 5
0
        internal void Validate(ANY instance, string path, DatatypeR2FormatterParseResult resultDetails)
        {
            IResultDetail[] flavor;
            // Validate
            if (resultDetails.ValidateConformance && !instance.Validate())
            {
                foreach (var r in instance.ValidateEx())
                {
                    r.Location = path;
                    resultDetails.AddResultDetail(r);
                }
            }
            //resultDetails.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, instance.GetType().Name, path));

            // Validate flavor...
            if (resultDetails.ValidateConformance && instance.Flavor != null && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                resultDetails.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, path));
            }
        }
Exemplo n.º 6
0
        public virtual void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANY            instance = o as ANY;
            XmlStateWriter stw      = s as XmlStateWriter;

            // Now render
            if (instance == null)
            {
                throw new InvalidOperationException("Could not cast object to the ANY data type");
            }
            else if (instance.NullFlavor != null)
            {
                s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor));
            }
            else if (instance.Flavor != null)
            {
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                {
                    s.WriteAttributeString("specializationType", instance.Flavor);
                }
                else
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ANY", s.ToString()));
                }
            }

            // Validate
            if (result.ValidateConformance && !instance.Validate())
            {
                foreach (var r in instance.ValidateEx())
                {
                    r.Location = s.ToString();
                    result.AddResultDetail(r);
                }
                result.Code = ResultCode.Rejected;
            }
            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, s.ToString()));
                result.AddResultDetail(flavor);
                if (result.Code < ResultCode.AcceptedNonConformant)
                {
                    result.Code = ResultCode.AcceptedNonConformant;
                }
            }

            // Warn if items can't be represented in R1
            if (instance.ControlActExt != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ANY", s.ToString()));
            }
            if (instance.ControlActRoot != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ANY", s.ToString()));
            }
            if (instance.ValidTimeHigh != null && !(instance is EN))
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ANY", s.ToString()));
            }
            if (instance.ValidTimeLow != null && !(instance is EN))
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ANY", s.ToString()));
            }
            if (instance.UpdateMode != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ANY", s.ToString()));
            }
        }
Exemplo n.º 7
0
        internal void Validate(ANY instance, string path, DatatypeFormatterParseResult resultDetails)
        {
            // Don't validate null
            if (instance == null)
            {
                return;
            }

            IResultDetail[] flavor;

            // Validate
            if (resultDetails.ValidateConformance && !instance.Validate())
            {
                foreach (var dtl in instance.ValidateEx())
                {
                    dtl.Location = path;
                    resultDetails.AddResultDetail(dtl);
                }
            }

            // Validate flavor...
            if (instance.Flavor != null && resultDetails.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                resultDetails.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, path));
            }

            // Append details
        }
Exemplo n.º 8
0
        public virtual object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANY instance = this.Parse <ANY>(s, result);

            if (result.ValidateConformance && !instance.Validate())
            {
                foreach (var r in instance.ValidateEx())
                {
                    r.Location = s.ToString();
                    result.AddResultDetail(r);
                }
            }
            //result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, instance.GetType().Name, s.ToString()));
            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, s.ToString()));
                result.AddResultDetail(flavor);
            }

            return(instance);
        }
Exemplo n.º 9
0
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANY            instance = o as ANY;
            XmlStateWriter stw      = s as XmlStateWriter;

            // Now render
            if (instance == null)
            {
                throw new InvalidOperationException("Could not cast object to the ANY data type");
            }
            else if (instance.NullFlavor != null)
            {
                s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor));
            }
            else if (instance.Flavor != null)
            {
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                {
                    s.WriteAttributeString("specializationType", instance.Flavor);
                }
                else
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ANY", s.ToString()));
                }
            }

            string currentElementName = "";

            if (s is MARC.Everest.Xml.XmlStateWriter)
            {
                currentElementName = (s as MARC.Everest.Xml.XmlStateWriter).CurrentPath;
            }

            // Validate
            if (result.ValidateConformance && !instance.Validate())
            {
                result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, o.GetType().Name, currentElementName));
            }

            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, currentElementName));
                result.AddResultDetail(flavor);
            }

            // Warn if items can't be represented in R1
            if (instance.ControlActExt != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ANY", currentElementName));
            }
            if (instance.ControlActRoot != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ANY", currentElementName));
            }
            if (instance.ValidTimeHigh != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ANY", currentElementName));
            }
            if (instance.ValidTimeLow != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ANY", currentElementName));
            }
            if (instance.UpdateMode != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ANY", currentElementName));
            }
        }
Exemplo n.º 10
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANY instance = new ANY();

            // Read the NullFlavor, and Specialization data from the wire
            if (s.GetAttribute("nullFlavor") != null) // Stop processing if null flavor is present
            {
                instance.NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            }
            else if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
            {
                instance.Flavor = s.GetAttribute("specializationType");
            }

            if (result.ValidateConformance && !instance.Validate())
            {
                result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, instance.GetType().Name, s.ToString()));
            }

            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, s.ToString()));
                result.AddResultDetail(flavor);
            }

            return(instance);
        }