boolean omitId = PropertyHelper.parseBoolean(propertyMap,
PropertyKeys.OMIT_ID);
boolean isIdRef = false;
AttrImpl attrs = new AttrImpl();
if (obj != null) {
if (omitId) {
// need to call always writeReplace
// if object ids and references can't be written
obj = writeReplaceObject(obj);
} else {
// check if this object was already serialized
Integer id = (Integer) objectIdMap.get(obj);
if (id != null) {
// yes, provide only the reference of the object
// that was already serialized
isIdRef = true;
} else {
// this is the first time this objects is going to be serialized
// provide an id for this object
id = new Integer(objectIdMap.size());
objectIdMap.put(obj, id);
obj = writeReplaceObject(obj);
}
attrs.addAttribute(isIdRef ? "reference" : "id", new StringBuffer("i")
.append(id).toString());
}
}
if (!omitXsi) {
attrs.addAttribute(NSConstants.SCHEMA_INSTANCE_NS_NAME,
NSConstants.SCHEMA_INSTANCE_NS_PREFIX, "type", _xmlTypeName);
}
if (obj == null && !omitNil) {
attrs.addAttribute(NSConstants.SCHEMA_INSTANCE_NS_NAME,
NSConstants.SCHEMA_INSTANCE_NS_PREFIX, "nil", "true");
}
output.startElement(name, attrs);