clarifyLocator method

dynamic clarifyLocator(
  1. dynamic locator,
  2. IFactory? factory
)

Clarifies a component locator by merging two descriptors into one to replace missing fields. That allows to get a more complete descriptor that includes all possible fields.

  • locator a component locator to clarify.
  • factory a factory that shall create the component. Returns clarified component descriptor (locator)

Implementation

dynamic clarifyLocator(locator, IFactory? factory) {
  if (factory == null) return locator;
  if (!(locator is Descriptor)) return locator;

  var anotherLocator = factory.canCreate(locator);
  if (anotherLocator == null) return locator;
  if (!(anotherLocator is Descriptor)) return locator;

  var descriptor = locator;
  var anotherDescriptor = anotherLocator;

  return Descriptor(
      descriptor.getGroup() ?? anotherDescriptor.getGroup(),
      descriptor.getType() ?? anotherDescriptor.getType(),
      descriptor.getKind() ?? anotherDescriptor.getKind(),
      descriptor.getName() ?? anotherDescriptor.getName(),
      descriptor.getVersion() ?? anotherDescriptor.getVersion());
}