Groovy Documentation

org.gradle.api
[Java] Interface PolymorphicDomainObjectContainer

org.gradle.api.DomainObjectCollection
  org.gradle.api.NamedDomainObjectCollection
      java.lang.Iterable
          org.gradle.api.PolymorphicDomainObjectContainer
              org.gradle.util.Configurable
                  org.gradle.api.NamedDomainObjectSet
                      org.gradle.api.NamedDomainObjectContainer
                          java.util.Collection
All Superinterfaces:
DomainObjectCollection, NamedDomainObjectCollection, Iterable, Configurable, NamedDomainObjectSet, NamedDomainObjectContainer, Collection

@Incubating
public interface PolymorphicDomainObjectContainer
extends NamedDomainObjectContainer

A NamedDomainObjectContainer that allows to create domain objects with different types.

Parameters:
- the (base) type of domain objects in the container


Method Summary
Object create(String name, Class type)

Creates a domain object with the specified name and type, and adds it to the container.

Object create(String name, Class type, Action configuration)

Creates a domain object with the specified name and type, adds it to the container, and configures it with the specified action.

Object maybeCreate(String name, Class type)

Looks for an item with the given name and type, creating and adding it to this container if it does not exist.

 
Methods inherited from interface NamedDomainObjectContainer
configure, create, create, create, maybeCreate
 
Methods inherited from interface NamedDomainObjectSet
findAll, matching, matching, withType
 
Methods inherited from interface NamedDomainObjectCollection
add, addAll, addRule, addRule, findByName, getAsMap, getAt, getByName, getByName, getNamer, getNames, getRules, matching, matching, withType
 
Methods inherited from interface Set
add, equals, hashCode, clear, contains, isEmpty, size, toArray, toArray, addAll, iterator, remove, containsAll, removeAll, retainAll
 

Method Detail

create

public Object create(String name, Class type)
Creates a domain object with the specified name and type, and adds it to the container.
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
Parameters:
name - the name of the domain object to be created
type - the type of the domain object to be created
- the type of the domain object to be created
Returns:
the created domain object


create

public Object create(String name, Class type, Action configuration)
Creates a domain object with the specified name and type, adds it to the container, and configures it with the specified action.
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
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
- the type of the domain object to be created
Returns:
the created domain object


maybeCreate

@Incubating
public Object maybeCreate(String name, Class type)
Looks for an item with the given name and type, creating and adding it to this container if it does not exist.
throws:
InvalidUserDataException if the container does not support creating a domain object with the specified type
throws:
ClassCastException if a domain object with the specified name exists with a different type
Parameters:
name - the name of the domain object to be created
type - the type of the domain object to be created
- the type of the domain object to be created
Returns:
the found or created domain object, never null.


 

Gradle API 1.11