/**
* Formats the given object.
*/
@Override
public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) {
final ReferenceIdentifier identifier = ((IdentifiedObject) obj).getName();
if (identifier == null) {
return toAppendTo.append(Vocabulary.getResources(locale).getString(Vocabulary.Keys.Unnamed));
}
if (identifier instanceof GenericName) {
// The toString() behavior is specified by the GenericName javadoc.
return toAppendTo.append(((GenericName) identifier).toInternationalString().toString(locale));
}
final String code = identifier.getCode();
String cs = identifier.getCodeSpace();
if (cs == null || cs.isEmpty()) {
cs = Citations.getIdentifier(identifier.getAuthority());
}
if (cs != null) {
toAppendTo.append(cs).append(DefaultNameSpace.DEFAULT_SEPARATOR);
}
return toAppendTo.append(code);