about us      downloads      documentation      contact      home 
 products
 antHR
 workflow studio
 technical toolkits
 content entry
 workflow
 security
 hierarchy
 concepts
 how tos
 reference
 FAQs
previous: Add validation  next: Test config

How to: Create new converter - Add config

  Step 1 : Summary
  Step 2 : Define converter
  Step 3 : Test class
  Step 4 : Test application
  Step 5 : Add validation
  Step 6 : Add config
  Step 7 : Test config

Add configuration to the converter - (page 6 of 7)

Level: developer
Required reading: Defining content, Class markup

In order to make the converter configurable we mark the class for content entry. First add the following usings to the top of the converter class file, using Ant.ContentEntry.Converters, Ant.ContentEntry.ClassInformation and Ant.ContentEntry.FieldDisplayers; Then add a [ClassOverview] attribute top of the class. Add the following code to the class.
// adding configuration
int divisor=3;

[PropertyInformation(typeof(Int32Converter), typeof(InputEntry), true, 0)]
[PropertyLanguage("ENGLISH", "Divisor", "Specify the divisor", "*")]
public int Divisor {get {return divisor;} set {divisor = value;}}
// finishing configuration
        
Add the code to handle unpacking of the configuration information. This code is added to the Init method.
String xml = def.XmlFragment;
if (xml != null && xml.Length != 0)
{
    XmlDocument instance = new XmlDocument();
    try
    {    
        instance.LoadXml(xml);
    }
    catch (XmlException e)
    {
        throw new ContentEntryException("Failed to parse xml "+xml, e);
    }
    instance = XmlHelper.GetExtensionBlock(instance, GetType().FullName);                
    if (instance != null)
    {
        ContentDefinition myDef = new ContentDefinitionFactory(def.ContentDefinition.User, 
            def.ContentDefinition.Language, def.ContentDefinition.State).ForClass(this.GetType());
    
        XmlHelper.PutValuesIntoObjectFromInstance(myDef, instance, this);
    }
}
        
Finally remove the reference to 3 in the code and replace by divisor.
We now have the code need to handle configuration.


 

Did you find this article helpful? Comments on this page are welcome and can only help us improve the quality of our documentation.
© Ant Organisation Ltd, 2003