/** * Clears the table */ public void Clear() { fTable.Clear(); fReverseTable.Clear(); fDefaultAppEntry = null; fDefaultSifEntry = null; fRenderAppDefaultIfNull = false; fRenderSifDefaultIfNull = false; }
/// <summary> Performs a reverse translation. /// /// </summary> /// <param name="sifValue">An SIF-defined value /// </param> /// <returns> The corresponding application-defined value /// </returns> public virtual string TranslateReverse(string sifValue) { ValueSetEntry e = GetReverseEntry(sifValue); if (e != null) { return(e.Name); } else { return(EvaluateDefault( fDefaultAppEntry == null ? null : fDefaultAppEntry.Name, fRenderAppDefaultIfNull, sifValue)); } }
/// <summary> Translates a value. /// /// This method differs from <code>get</code> in that it returns <i>appValue</i> /// if no mapping is defined in the ValueSet. The <code>get</code> method /// returns null if no mapping is defined. /// /// /// </summary> /// <param name="appValue">An application-defined value /// </param> /// <returns> The corresponding SIF-defined value /// </returns> public virtual string Translate(string appValue) { ValueSetEntry e = GetEntry(appValue); if (e != null) { return(e.Value); } else { return(EvaluateDefault( fDefaultSifEntry == null ? null : fDefaultSifEntry.Value, fRenderSifDefaultIfNull, appValue)); } }
/** * Sets the default SIF value that will be returned if no match * is found during a valueset translation * @param sifValue The value to return if there is no match. Pass in <code>Null</code> if the * previously-set default is to be removed * @param renderIfNull True if the default value should be returned even if the app value * being translated is null. If false, NULL will be returned. * @throws ADKMappingException Thrown if the value has not yet been defined in this valueset * by calling <code>define</code> * * @see #define(String, String, String) * @see #define(String, String, String, Node) */ public void SetSifDefault(String sifValue, bool renderIfNull) { fRenderSifDefaultIfNull = renderIfNull; if (fDefaultSifEntry != null) { ValueSetEntry oldEntry = fDefaultSifEntry; fDefaultSifEntry = null; ToXml(oldEntry, oldEntry.Node); } if (sifValue != null) { ValueSetEntry entry = GetReverseEntry(sifValue); if (entry == null) { throw new AdkMappingException("Value: '" + sifValue + "' is not defined.", null); } fDefaultSifEntry = entry; ToXml(fDefaultSifEntry, fDefaultSifEntry.Node); } }
/// <summary> Sets a value</summary> public virtual void Define(string appValue, string sifValue, string title, XmlElement node) { if (appValue != null) { ValueSetEntry entry = new ValueSetEntry(appValue, sifValue, title); entry.DisplayOrder = fTable.Count; entry.Node = node; if (node != null) { entry.ToXml(node); } fTable[appValue] = entry; fReverseTable[sifValue] = entry; } }
private void ToXml(ValueSetEntry entry, XmlElement element) { // If the element passed in is null, this ValueSet doesn't currently have an // XML Element that it is associated with. This is OK. Exit Gracefully. if (element == null) { return; } entry.ToXml(element); // Since this class controls the notion of defaults, write the // attributes controlling defaults here bool isDefaultAppValue = fDefaultAppEntry == entry; bool isDefaultSifValue = fDefaultSifEntry == entry; if (isDefaultAppValue) { if (isDefaultSifValue) { element.SetAttribute("default", "both"); element.SetAttribute("ifnull", GetIfNull(fRenderSifDefaultIfNull)); } else { element.SetAttribute("default", "inbound"); element.SetAttribute("ifnull", GetIfNull(fRenderAppDefaultIfNull)); } } else if (isDefaultSifValue) { element.SetAttribute("default", "outbound"); element.SetAttribute("ifnull", GetIfNull(fRenderSifDefaultIfNull)); } else { element.RemoveAttribute("default"); element.RemoveAttribute("ifnull"); } }
/** * Removes a value */ public void Remove(String appValue) { if (appValue != null) { ValueSetEntry entry = (ValueSetEntry)fTable[appValue]; if (entry != null) { fTable.Remove(appValue); fReverseTable.Remove(entry.Value); fNode.RemoveChild(entry.Node); if (fDefaultAppEntry == entry) { fDefaultAppEntry = null; } if (fDefaultSifEntry == entry) { fDefaultSifEntry = null; } } } }
/** * Sets the default application value that will be returned if no match * is found during a valueset translation * @param appValue The value to return if there is no match. Pass in <code>Null</code> if the * previously-set default is to be removed * @param renderIfNull True if the default value should be returned even if the SIF Value being * translated is NULL. If false, NULL will be returned. * @throws ADKMappingException Thrown if the value has not yet been defined in this valueset * by calling <code>define</code> */ public void SetAppDefault(String appValue, bool renderIfNull) { fRenderAppDefaultIfNull = renderIfNull; if (fDefaultAppEntry != null) { ValueSetEntry oldEntry = fDefaultAppEntry; fDefaultAppEntry = null; ToXml(oldEntry, oldEntry.Node); } if (appValue != null) { ValueSetEntry entry = GetEntry(appValue); if (entry == null) { throw new AdkMappingException("Value: '" + appValue + "' is not defined.", null); } fDefaultAppEntry = entry; ToXml(fDefaultAppEntry, fDefaultAppEntry.Node); } }
public ValueSetEntry[] GetEntries() { ValueSetEntry[] entries = new ValueSetEntry[fTable.Count]; fTable.Values.CopyTo( entries, 0 ); return entries; }
/** * Removes a value */ public void Remove( String appValue ) { if ( appValue != null ) { ValueSetEntry entry = (ValueSetEntry) fTable[appValue]; if ( entry != null ) { fTable.Remove( appValue ); fReverseTable.Remove( entry.Value ); fNode.RemoveChild( entry.Node ); if ( fDefaultAppEntry == entry ) { fDefaultAppEntry = null; } if ( fDefaultSifEntry == entry ) { fDefaultSifEntry = null; } } } }
/** * Looks up a ValueSetEntry by a SIF value * @param sifValue * @return The ValueSetEntry that matches, if found, or null */ private ValueSetEntry GetReverseEntry(String sifValue) { ValueSetEntry e = sifValue != null ? (ValueSetEntry)fReverseTable[sifValue] : null; return(e); }
/** * Gets a ValueSet entry for the specified application value * @param appValue * @return The ValueSetEntry that matches, if found, or null */ private ValueSetEntry GetEntry(String appValue) { ValueSetEntry e = appValue != null ? (ValueSetEntry)fTable[appValue] : null; return(e); }
public ValueSetEntry[] GetEntries() { ValueSetEntry[] entries = new ValueSetEntry[fTable.Count]; fTable.Values.CopyTo(entries, 0); return(entries); }
/** * Sets the default application value that will be returned if no match * is found during a valueset translation * @param appValue The value to return if there is no match. Pass in <code>Null</code> if the * previously-set default is to be removed * @param renderIfNull True if the default value should be returned even if the SIF Value being * translated is NULL. If false, NULL will be returned. * @throws ADKMappingException Thrown if the value has not yet been defined in this valueset * by calling <code>define</code> */ public void SetAppDefault( String appValue, bool renderIfNull ) { fRenderAppDefaultIfNull = renderIfNull; if ( fDefaultAppEntry != null ) { ValueSetEntry oldEntry = fDefaultAppEntry; fDefaultAppEntry = null; ToXml( oldEntry, oldEntry.Node ); } if ( appValue != null ) { ValueSetEntry entry = GetEntry( appValue ); if ( entry == null ) { throw new AdkMappingException( "Value: '" + appValue + "' is not defined.", null ); } fDefaultAppEntry = entry; ToXml( fDefaultAppEntry, fDefaultAppEntry.Node ); } }
/// <summary> Sets a value</summary> public virtual void Define( string appValue, string sifValue, string title, XmlElement node ) { if ( appValue != null ) { ValueSetEntry entry = new ValueSetEntry( appValue, sifValue, title ); entry.DisplayOrder = fTable.Count; entry.Node = node; if ( node != null ) { entry.ToXml( node ); } fTable[appValue] = entry; fReverseTable[sifValue] = entry; } }
/// <summary> Gets a value</summary> public virtual string Lookup(string appValue) { ValueSetEntry e = appValue == null ? null : (ValueSetEntry)fTable[appValue]; return(e == null ? null : e.Value); }
/** * Sets the default SIF value that will be returned if no match * is found during a valueset translation * @param sifValue The value to return if there is no match. Pass in <code>Null</code> if the * previously-set default is to be removed * @param renderIfNull True if the default value should be returned even if the app value * being translated is null. If false, NULL will be returned. * @throws ADKMappingException Thrown if the value has not yet been defined in this valueset * by calling <code>define</code> * * @see #define(String, String, String) * @see #define(String, String, String, Node) */ public void SetSifDefault( String sifValue, bool renderIfNull ) { fRenderSifDefaultIfNull = renderIfNull; if ( fDefaultSifEntry != null ) { ValueSetEntry oldEntry = fDefaultSifEntry; fDefaultSifEntry = null; ToXml( oldEntry, oldEntry.Node ); } if ( sifValue != null ) { ValueSetEntry entry = GetReverseEntry( sifValue ); if ( entry == null ) { throw new AdkMappingException( "Value: '" + sifValue + "' is not defined.", null ); } fDefaultSifEntry = entry; ToXml( fDefaultSifEntry, fDefaultSifEntry.Node ); } }
private void ToXml( ValueSetEntry entry, XmlElement element ) { // If the element passed in is null, this ValueSet doesn't currently have an // XML Element that it is associated with. This is OK. Exit Gracefully. if ( element == null ) { return; } entry.ToXml( element ); // Since this class controls the notion of defaults, write the // attributes controlling defaults here bool isDefaultAppValue = fDefaultAppEntry == entry; bool isDefaultSifValue = fDefaultSifEntry == entry; if ( isDefaultAppValue ) { if ( isDefaultSifValue ) { element.SetAttribute( "default", "both" ); element.SetAttribute( "ifnull", GetIfNull( fRenderSifDefaultIfNull ) ); } else { element.SetAttribute( "default", "inbound" ); element.SetAttribute( "ifnull", GetIfNull( fRenderAppDefaultIfNull ) ); } } else if ( isDefaultSifValue ) { element.SetAttribute( "default", "outbound" ); element.SetAttribute( "ifnull", GetIfNull( fRenderSifDefaultIfNull ) ); } else { element.RemoveAttribute( "default" ); element.RemoveAttribute( "ifnull" ); } }