Advanced Customization > Services and Infrastructure Customization > Import Export Framework > How to Write Exp/Imp Handlers > How to Write a Class (Element) Import Handler > How to Write an Attribute Import Handler
  
How to Write an Attribute Import Handler
If there is an attribute that is required to be imported the same way for different classes or if you simply decide to handle it is a separate handler, you can create an attribute handler. The steps to follow are:
1. Create a Java class that extends AttrExporterImporterTemplate.
2. Override the following methods if needed:
prepareForCheckConflicts(Importer importer): prepares for conflict checking. It is likely never be implemented by a particular handler.
checkConflictForAttribute( Object existingOb, IxbElement fileXML, Importer importer) : This method does the conflict checking for particular attribute, so if the imported attribute can potentially have conflicts with an attribute that exists in the database, this method must be overridden.
importAttribute ( Object object,

IxbElement fileXML,

Importer importer):
Retrieves the attribute data from the XML DOM Document and set it to the imported object. This method must be overridden to suit particular attribute.
Here is an example for importAttribute() for the attribute MyAttr to the object MyObject:
public Object importAttribute
( Object object,
IxbElement fileXML,
Importer importer)
throws WTException {
String myAttr;
try{
myAttr = fileXML.getValue(IxbHndHelper.XML_ATTR_MYATTR);
// XML_ATTR_MYATTR tag must be defined in IxbHndHelper
}
catch (Exception exc){
// The paragraph bellows allows the import process continue,
// even when the import of MyAttr fails. If the programmer
// wants the import process to stop when the import of
// MyAttr fails, please assign ob=null and throw exception
System.out.println(
"Exception when getting MyAttr in importAttribute");
System.out.println("MyAttr attribute is not imported");
return object;
}

MyObject ob = (MyObject) object;
try {
MyObjectHelper.service.setMyAttr(ob, myAttr);
}
catch (Exception e) {
if (! importer.
attributeExporterImporterManager.
overrideConflicts) {
ob = null;
throw e;
}
else{
// override the conflict by doing something here…
}
}
finally{
return ob;
}