{
Element rules = _document.createElement("rules");
for (Iterator i = em.getRules().iterator(); i.hasNext();)
{
Rule r = (Rule) i.next();
Element rule = null;
if (r instanceof CreateObjectRule)
{
CreateObjectRule cor = (CreateObjectRule) r;
rule = _document.createElement("create-object");
rule.setAttribute("class", cor.getClassName());
}
else if (r instanceof InvokeParentRule)
{
InvokeParentRule ipr = (InvokeParentRule) r;
rule = _document.createElement("invoke-parent");
rule.setAttribute("method", ipr.getMethodName());
if (ipr.getDepth() != 1)
rule.setAttribute("depth", Integer.toString(ipr.getDepth()));
}
else if (r instanceof PushAttributeRule)
{
PushAttributeRule par = (PushAttributeRule) r;
rule = _document.createElement("push-attribute");
rule.setAttribute("attribute", par.getAttributeName());
}
else if (r instanceof PushContentRule)
{
rule = _document.createElement("push-content");
}
else if (r instanceof ReadAttributeRule)
{
ReadAttributeRule rar = (ReadAttributeRule) r;
rule = _document.createElement("read-attribute");
rule.setAttribute("property", rar.getPropertyName());
rule.setAttribute("attribute", rar.getAttributeName());
if (!rar.getSkipIfNull())
rule.setAttribute("skip-if-null", "false");
if (rar.getTranslator() != null)
rule.setAttribute("translator", rar.getTranslator());
}
else if (r instanceof ReadContentRule)
{
ReadContentRule rcr = (ReadContentRule) r;
rule = _document.createElement("read-content");
rule.setAttribute("property", rcr.getPropertyName());
}
else if (r instanceof SetModuleRule)
{
SetModuleRule smr = (SetModuleRule) r;
rule = _document.createElement("set-module");
rule.setAttribute("property", smr.getPropertyName());
}
else if (r instanceof SetParentRule)
{
SetParentRule spr = (SetParentRule) r;
rule = _document.createElement("set-parent");
rule.setAttribute("property", spr.getPropertyName());
}
else if (r instanceof SetPropertyRule)
{
SetPropertyRule spr = (SetPropertyRule) r;
rule = _document.createElement("set-property");
rule.setAttribute("property", spr.getPropertyName());
rule.setAttribute("value", spr.getValue());
}
else if (r instanceof ConversionDescriptor)
{
ConversionDescriptor cd = (ConversionDescriptor) r;
rule = _document.createElement("conversion");
rule.setAttribute("class", cd.getClassName());
if (!cd.getParentMethodName().equals("addElement"))
rule.setAttribute("parent-method", cd.getParentMethodName());
for (Iterator j = cd.getAttributeMappings().iterator(); j.hasNext();)
{
AttributeMappingDescriptor amd = (AttributeMappingDescriptor) j.next();
Element map = _document.createElement("map");
map.setAttribute("attribute", amd.getAttributeName());
map.setAttribute("property", amd.getPropertyName());
rule.appendChild(map);
}
}
else
{
rule = _document.createElement("custom");
rule.setAttribute("class", r.getClass().getName());
}
if (rule != null)
rules.appendChild(rule);
}