/// <summary> /// Sets a value that has been retrieved from a SIF Element in an inbound field /// mapping operation. /// </summary> /// <param name="fieldName">The field name that is mapped to a SIFElement</param> /// <param name="value">The value of the SIF element</param> /// <param name="mapping">The FieldMappings that will be used to set this value or null</param> public override void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping) { int ordinal = SafeGetOrdinal(fieldName); if (ordinal > -1) { fDataRow[ordinal] = value.RawValue; } }
/// <summary> Insert a FieldMapping definition at the specified index. /// /// </summary> /// <param name="mapping">A FieldMapping that defines the rules for mapping a field /// of the application to an element or attribute of a SIF Data Object. /// There can only be one FieldMapping per unique field name (i.e. if /// you have defined a FieldMapping rule with a field name of 'STUDENTNUM', /// there cannot be another FieldMapping rule with that same field name.) /// To map a single application field to more than one SIF element or /// attribute, create a FieldMapping with a unique field name (e.g. 'STUDENTNUM_2') /// and call the <code>setAlias</code> method to define it as an alias /// of an existing field. /// /// </param> /// <param name="index">The index to insert the rule at</param> /// <param name="buildDomTree">true to create a DOM XmlElement element for this /// FieldMapping and append it to the parent XmlElement /// /// </param> /// <exception cref="OpenADK.Library.Tools.Mapping.AdkMappingException"> AdkMappingException thrown if there is already a FieldMapping /// with the specified field name /// </exception> protected internal void InsertRule(FieldMapping mapping, int index, bool buildDomTree) { XmlElement relativeTo = null; if (fFieldRules == null) { fFieldRules = new List <FieldMapping>(); } else { // Check for duplicate foreach (FieldMapping existing in fFieldRules) { if (existing.Key == mapping.Key) { throw new AdkMappingException("Duplicate field mapping: " + mapping.Key, null); } } // If we'll be building a child DOM XmlElement, find the existing XmlElement // that it will be inserted at if (buildDomTree && fNode != null && fFieldRules.Count > index) { relativeTo = fFieldRules[index].XmlElement; } } try { fFieldRules.Insert(index, mapping); } catch (Exception ex) { throw new AdkMappingException(ex.ToString(), null); } if (buildDomTree && fNode != null) { // Create and insert a child DOM XmlElement XmlElement element = fNode.OwnerDocument.CreateElement(Mappings.XML_FIELD); mapping.XmlElement = element; mapping.ToXml(element); if (relativeTo != null) { fNode.InsertBefore(element, relativeTo); } else { fNode.AppendChild(element); } } }
/// <summary> Produces a duplicate of this Rule object /// /// </summary> /// <returns> A "deep copy" of this Rule object /// </returns> public override Rule Copy(FieldMapping newParent) { OtherIdRule m = new OtherIdRule(fMapping == null ? null : fMapping.Copy()); if (fNode != null && newParent.fNode != null) { m.fNode = (XmlElement)fNode.CloneNode(false); } return(m); }
/// <summary> Produces a duplicate of this Rule object /// /// </summary> /// <returns> A "deep copy" of this Rule object /// </returns> public override Rule Copy(FieldMapping newParent) { XPathRule clone = new XPathRule(fDef); if (newParent.fNode != null) { newParent.fNode.InnerText = fDef; } return(clone); }
/// <summary> Remove a FieldMapping definition</summary> public void RemoveRule(FieldMapping mapping) { if (fFieldRules != null) { fFieldRules.Remove(mapping); // Remove the DOM XmlElement if there is one XmlElement n = mapping.XmlElement; if (n != null) { n.ParentNode.RemoveChild(n); } } }
/// <summary> Removes the FieldMapping at the specified index</summary> /// <param name="index">The zero-based index of the FieldMapping /// </param> public void RemoveRule(int index) { if (fFieldRules != null && index >= 0 && index < fFieldRules.Count) { FieldMapping existing = fFieldRules[index]; fFieldRules.RemoveAt(index); // Remove the DOM XmlElement if there is one XmlElement n = existing == null ? null : existing.XmlElement; if (n != null) { n.ParentNode.RemoveChild(n); } } }
/** * Evaluates the filters defined for this FieldMapping. If any of the filters * evaluate to false, the FieldMapping is not added * * @param fieldMapping The FieldMapping to add * @return True if the FieldMapping was added. Otherwise false */ private bool AddRule(FieldMapping fieldMapping) { MappingsFilter filt = fieldMapping.Filter; // Filter out this rule? if (filt != null) { if (!filt.EvalDirection(fDirection) || !filt.EvalVersion(fSIFVersion)) { return(false); } } fFieldMappings.Add(fieldMapping); return(true); }
/// <summary> Creates a copy this ObjectMapping instance. /// /// </summary> /// <returns> A "deep copy" of this object /// </returns> public virtual FieldMapping Copy(ObjectMapping newParent) { FieldMapping m = new FieldMapping(); if (fNode != null && newParent.fNode != null) { m.fNode = (XmlElement)newParent.fNode.OwnerDocument.ImportNode(fNode, false); } m.FieldName = fField; m.DefaultValue = fDefValue; m.Alias = fAlias; m.ValueSetID = fValueSet; m.NullBehavior = fNullBehavior; if (fFilter != null) { MappingsFilter filtCopy = new MappingsFilter(); filtCopy.fVersion = fFilter.fVersion; filtCopy.fDirection = fFilter.fDirection; m.Filter = filtCopy; } m.DataType = fDatatype; if (fRule != null) { m.fRule = fRule.Copy(m); } else { m.fRule = null; } return(m); }
/** * 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); }
/// <summary> /// Gets the specified value from the underlying IDictionary /// </summary> /// <param name="fieldName"></param> /// <param name="typeConverter"></param> /// <param name="mapping"></param> /// <returns></returns> public SifSimpleType GetSifValue(String fieldName, TypeConverter typeConverter, FieldMapping mapping) { if (fMap.Contains(fieldName)) { Object value = fMap[fieldName]; return(FromMapValue(value, typeConverter)); } else { // No value in the Map. Return null return(null); } }
/// <summary> /// Gets a value from the underlying data store to be used in an outbound /// field mapping operation /// </summary> /// <param name="fieldName"> The field name that is mapped to a SIFElement</param> /// <param name="typeConverter">The converter class for the requested SIF data type</param> /// <param name="mapping">The FieldMapping this value was generated from or null</param> /// <returns>The value to set to the SIF element. This value must contain the /// SIFSimpleType subclass represented by the SIFTypeConverter passed in to the /// method.</returns> public abstract SifSimpleType GetSifValue(string fieldName, TypeConverter typeConverter, FieldMapping mapping);
/// <summary> /// Sets a value that has been retrieved from a SIF Element in an inbound field /// mapping operation. /// </summary> /// <param name="fieldName">The field name that is mapped to a SIFElement</param> /// <param name="value">The value of the SIF element</param> /// <param name="mapping">The FieldMappings that will be used to set this value or null</param> public abstract void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping);
/// <summary> /// Sets a value that has been retrieved from a SIF Element in an inbound field /// mapping operation. /// </summary> /// <param name="fieldName">The field name that is mapped to a SIFElement</param> /// <param name="value">The value of the SIF element</param> /// <param name="mapping">The FieldMappings that will be used to set this value or null</param> public void SetSifValue(string fieldName, SifSimpleType value, FieldMapping mapping) { throw new NotSupportedException("Unable to set values to a DataReader"); }
/// <summary> Insert a FieldMapping definition at the specified index. /// /// </summary> /// <param name="mapping">A FieldMapping that defines the rules for mapping a field /// of the application to an element or attribute of a SIF Data Object. /// There can only be one FieldMapping per unique field name (i.e. if /// you have defined a FieldMapping rule with a field name of 'STUDENTNUM', /// there cannot be another FieldMapping rule with that same field name.) /// To map a single application field to more than one SIF element or /// attribute, create a FieldMapping with a unique field name (e.g. 'STUDENTNUM_2') /// and call the <code>setAlias</code> method to define it as an alias /// of an existing field. /// /// </param> /// <exception cref="AdkMappingException"> thrown if there is already a FieldMapping /// with the specified field name /// </exception> /// <param name="index">The index to insert the rule at</param> public void InsertRule(FieldMapping mapping, int index) { InsertRule(mapping, index, true); }
/// <summary> Appends a FieldMapping definition /// /// </summary> /// <param name="mapping">A FieldMapping that defines the rules for mapping a field /// of the application to an element or attribute of a SIF Data Object. /// There can only be one FieldMapping per unique field name (i.e. if /// you have defined a FieldMapping rule with a field name of 'STUDENTNUM', /// there cannot be another FieldMapping rule with that same field name.) /// To map a single application field to more than one SIF element or /// attribute, create a FieldMapping with a unique field name (e.g. 'STUDENTNUM_2') /// and call the <code>setAlias</code> method to define it as an alias /// of an existing field. /// /// </param> /// <param name="buildDomTree">true to create a DOM XmlElement element for this /// FieldMapping and append it to the parent XmlElement /// /// </param> /// <exception cref="AdkMappingException"> thrown if there is already a FieldMapping /// with the specified field name /// </exception> protected internal void AddRule(FieldMapping mapping, bool buildDomTree) { InsertRule(mapping, fFieldRules == null ? 0 : fFieldRules.Count, buildDomTree); }
/// <summary> Appends a FieldMapping definition /// /// </summary> /// <param name="mapping">A FieldMapping that defines the rules for mapping a field /// of the application to an element or attribute of a SIF Data Object. /// There can only be one FieldMapping per unique field name (i.e. if /// you have defined a FieldMapping rule with a field name of 'STUDENTNUM', /// there cannot be another FieldMapping rule with that same field name.) /// To map a single application field to more than one SIF element or /// attribute, create a FieldMapping with a unique field name (e.g. 'STUDENTNUM_2') /// and call the <code>setAlias</code> method to define it as an alias /// of an existing field. /// /// </param> /// <exception cref="AdkMappingException"> thrown if there is already a FieldMapping /// with the specified field name /// </exception> public void AddRule(FieldMapping mapping) { InsertRule(mapping, fFieldRules == null ? 0 : fFieldRules.Count, true); }
/// <summary> /// Gets a value from the underlying data store to be used in an outbound /// field mapping operation /// </summary> /// <param name="fieldName"> The field name that is mapped to a SIFElement</param> /// <param name="typeConverter">The converter class for the requested SIF data type</param> /// <param name="mapping">The FieldMapping this value was generated from or null</param> /// <returns>The value to set to the SIF element. This value must contain the /// SIFSimpleType subclass represented by the SIFTypeConverter passed in to the /// method.</returns> public override SifSimpleType GetSifValue(string fieldName, TypeConverter typeConverter, FieldMapping mapping) { int ordinal = SafeGetOrdinal(fieldName); if (ordinal == -1) { return(null); } object value = fDataRow[ordinal]; return(typeConverter.GetSifSimpleType(value)); }
/// <summary> Produces a duplicate of this Rule object /// /// </summary> /// <returns> A "deep copy" of this Rule object /// </returns> public abstract Rule Copy(FieldMapping newParent);