Interface PolymorphicDomainObjectContainer<T>

Type Parameters:
T - the (base) type of domain objects in the container
All Superinterfaces:
Collection<T>, org.gradle.util.Configurable<NamedDomainObjectContainer<T>>, DomainObjectCollection<T>, Iterable<T>, NamedDomainObjectCollection<T>, NamedDomainObjectContainer<T>, NamedDomainObjectSet<T>, Set<T>
All Known Subinterfaces:
AuthenticationContainer, ExtensiblePolymorphicDomainObjectContainer<T>, NativeToolChainRegistry, PlatformContainer, PlayDistributionContainer, PublicationContainer, Repositories, TaskContainer

@Incubating public interface PolymorphicDomainObjectContainer<T> extends NamedDomainObjectContainer<T>
A NamedDomainObjectContainer that allows to create domain objects with different types.
  • Method Details

    • create

      <U extends T> U create(String name, Class<U> type) throws InvalidUserDataException
      Creates a domain object with the specified name and type, and adds it to the container.
      Type Parameters:
      U - the type of the domain object to be created
      Parameters:
      name - the name of the domain object to be created
      type - the type of the domain object to be created
      Returns:
      the created domain object
      Throws:
      InvalidUserDataException - if a domain object with the specified name already exists or the container does not support creating a domain object with the specified type
    • maybeCreate

      <U extends T> U maybeCreate(String name, Class<U> type) throws InvalidUserDataException
      Looks for an item with the given name and type, creating and adding it to this container if it does not exist.
      Type Parameters:
      U - the type of the domain object to be created
      Parameters:
      name - the name of the domain object to be created
      type - the type of the domain object to be created
      Returns:
      the found or created domain object, never null.
      Throws:
      InvalidUserDataException - if the container does not support creating a domain object with the specified type
      ClassCastException - if a domain object with the specified name exists with a different type
    • create

      <U extends T> U create(String name, Class<U> type, Action<? super U> configuration) throws InvalidUserDataException
      Creates a domain object with the specified name and type, adds it to the container, and configures it with the specified action.
      Type Parameters:
      U - the type of the domain object to be created
      Parameters:
      name - the name of the domain object to be created
      type - the type of the domain object to be created
      configuration - an action for configuring the domain object
      Returns:
      the created domain object
      Throws:
      InvalidUserDataException - if a domain object with the specified name already exists or the container does not support creating a domain object with the specified type
    • containerWithType

      <U extends T> NamedDomainObjectContainer<U> containerWithType(Class<U> type)
      Creates a regular container that wraps the polymorphic container presenting all elements of a specified type.
      Type Parameters:
      U - the type of the container elements
      Parameters:
      type - the type of the container elements
      Returns:
      a NamedDomainObjectContainer providing access to elements of type U.