use of org.apache.sis.xml.IdentifiedObject in project sis by apache.
the class ObjectReference method resolve.
/**
* If the given metadata object is null, tries to get an instance from the identifiers
* declared in this {@code ObjectReference}. If the given metadata object is non-null,
* assigns to that object the identifiers declared in this {@code ObjectReference}.
*
* <p>This method is invoked at unmarshalling time by {@link PropertyType#resolve(Context)}.</p>
*
* @param <T> the compile-time type of the {@code type} argument.
* @param context the marshalling context, or {@code null} if none.
* @param type the expected type of the metadata object.
* @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<>(IdentifierSpace.UUID, uuid);
if (xlink != null)
identifiers[count++] = new SpecializedIdentifier<>(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) {
final IdentifierMap map = ((IdentifiedObject) metadata).getIdentifierMap();
putInto(context, map, IdentifierSpace.UUID, uuid);
putInto(context, map, IdentifierSpace.XLINK, xlink);
}
}
return metadata;
}
Aggregations