* @param metadata The metadata object, or {@code null}.
* @return A metadata object for the identifiers, or {@code null}
*/
final <T> T resolve(final Context context, final Class<T> type, T metadata) {
if (metadata == null) {
final ReferenceResolver resolver = Context.resolver(context);
if ((uuid == null || (metadata = resolver.resolve(context, type, uuid )) == null) &&
(xlink == null || (metadata = resolver.resolve(context, type, xlink)) == null))
{
// Failed to find an existing metadata instance.
// Creates an empty instance with the identifiers.
int count = 0;
SpecializedIdentifier<?>[] identifiers = new SpecializedIdentifier<?>[2];
if (uuid != null) identifiers[count++] = new SpecializedIdentifier<UUID> (IdentifierSpace.UUID, uuid);
if (xlink != null) identifiers[count++] = new SpecializedIdentifier<XLink>(IdentifierSpace.XLINK, xlink);
identifiers = ArraysExt.resize(identifiers, count);
metadata = resolver.newIdentifiedObject(context, type, identifiers);
}
} else {
// In principle, the XML should contain a full metadata object OR a uuidref attribute.
// However if both are present, assign the identifiers to that instance.
if (metadata instanceof IdentifiedObject) {