/** * Creates a new FieldMapping instance and populates its properties from * the given XML Element * @param parent * @param element * @return a new FieldMapping instance * @throws ADKConfigException If the FieldMapping cannot read expected * values from the DOM Node */ public static FieldMapping FromXml( ObjectMapping parent, XmlElement element) { if (element == null) { throw new ArgumentException("Argument: 'element' cannot be null"); } String name = element.GetAttribute(ATTR_NAME); FieldMapping fm = new FieldMapping(); fm.SetNode(element); fm.FieldName = name; fm.DefaultValue = XmlUtils.GetAttributeValue(element, ATTR_DEFAULT); fm.Alias = XmlUtils.GetAttributeValue(element, ATTR_ALIAS); fm.ValueSetID = XmlUtils.GetAttributeValue(element, ATTR_VALUESET); String ifNullBehavior = element.GetAttribute(ATTR_IFNULL); if (ifNullBehavior.Length > 0) { if (String.Compare(ifNullBehavior, "default", true) == 0) { fm.NullBehavior = MappingBehavior.IfNullDefault; } else if (String.Compare(ifNullBehavior, "suppress", true) == 0) { fm.NullBehavior = MappingBehavior.IfNullSuppress; } } String dataType = element.GetAttribute(ATTR_DATATYPE); if (dataType != null && dataType.Length > 0) { try { fm.DataType = (SifDataType)Enum.Parse(typeof(SifDataType), dataType, true); } catch (FormatException iae) { Adk.Log.Warn("Unable to parse datatype '" + dataType + "' for field " + name, iae); } } String filtVer = element.GetAttribute(ATTR_SIFVERSION); String filtDir = element.GetAttribute(ATTR_DIRECTION); if (!(String.IsNullOrEmpty(filtVer)) || !(String.IsNullOrEmpty(filtDir))) { MappingsFilter filt = new MappingsFilter(); if (!String.IsNullOrEmpty(filtVer)) { filt.SifVersion = filtVer; } if (!String.IsNullOrEmpty(filtDir)) { if (String.Compare(filtDir, "inbound", true) == 0) { filt.Direction = MappingDirection.Inbound; } else if (String.Compare(filtDir, "outbound", true) == 0) { filt.Direction = MappingDirection.Outbound; } else { throw new AdkConfigException( "Field mapping rule for " + parent.ObjectType + "." + fm.FieldName + " specifies an unknown Direction flag: '" + filtDir + "'"); } } fm.Filter = filt; } // FieldMapping must either have node text or an <otherid> child XmlElement otherIdNode = XmlUtils.GetFirstElementIgnoreCase(element, "otherid"); if (otherIdNode == null) { String def = element.InnerText; if (def != null) { fm.SetRule(def); } else { fm.SetRule(""); } } else { fm.SetRule(OtherIdMapping.FromXml(parent, fm, otherIdNode), otherIdNode); } return(fm); }