Interface ExtensionContainer

  • All Known Subinterfaces:
    Convention

    public interface ExtensionContainer
    Allows adding 'namespaced' DSL extensions to a target object.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <T> void add​(java.lang.Class<T> publicType, java.lang.String name, T extension)
      Adds a new extension to this container.
      void add​(java.lang.String name, java.lang.Object extension)
      Adds a new extension to this container.
      <T> void add​(TypeOf<T> publicType, java.lang.String name, T extension)
      Adds a new extension to this container.
      <T> void configure​(java.lang.Class<T> type, Action<? super T> action)
      Looks for the extension of the specified type and configures it with the supplied action.
      <T> void configure​(java.lang.String name, Action<? super T> action)
      Looks for the extension with the specified name and configures it with the supplied action.
      <T> void configure​(TypeOf<T> type, Action<? super T> action)
      Looks for the extension of the specified type and configures it with the supplied action.
      <T> T create​(java.lang.Class<T> publicType, java.lang.String name, java.lang.Class<? extends T> instanceType, java.lang.Object... constructionArguments)
      Creates and adds a new extension to this container.
      <T> T create​(java.lang.String name, java.lang.Class<T> type, java.lang.Object... constructionArguments)
      Creates and adds a new extension to this container.
      <T> T create​(TypeOf<T> publicType, java.lang.String name, java.lang.Class<? extends T> instanceType, java.lang.Object... constructionArguments)
      Creates and adds a new extension to this container.
      java.lang.Object findByName​(java.lang.String name)
      Looks for the extension of a given name.
      <T> T findByType​(java.lang.Class<T> type)
      Looks for the extension of a given type (useful to avoid casting).
      <T> T findByType​(TypeOf<T> type)
      Looks for the extension of a given type (useful to avoid casting).
      java.lang.Object getByName​(java.lang.String name)
      Looks for the extension of a given name.
      <T> T getByType​(java.lang.Class<T> type)
      Looks for the extension of a given type (useful to avoid casting).
      <T> T getByType​(TypeOf<T> type)
      Looks for the extension of a given type (useful to avoid casting).
      ExtensionsSchema getExtensionsSchema()
      Provides access to the schema of all known extensions.
      ExtraPropertiesExtension getExtraProperties()
      The extra properties extension in this extension container.
    • Method Detail

      • add

        <T> void add​(java.lang.Class<T> publicType,
                     java.lang.String name,
                     T extension)
        Adds a new extension to this container. Adding an extension of name 'foo' will:
        • add 'foo' dynamic property
        • add 'foo' dynamic method that accepts a closure that is a configuration script block
        The extension will be exposed as publicType.
        Parameters:
        publicType - The extension public type
        name - The name for the extension
        extension - Any object implementing publicType
        Throws:
        java.lang.IllegalArgumentException - When an extension with the given name already exists.
        Since:
        3.5
      • add

        <T> void add​(TypeOf<T> publicType,
                     java.lang.String name,
                     T extension)
        Adds a new extension to this container. Adding an extension of name 'foo' will:
        • add 'foo' dynamic property
        • add 'foo' dynamic method that accepts a closure that is a configuration script block
        The extension will be exposed as publicType.
        Parameters:
        publicType - The extension public type
        name - The name for the extension
        extension - Any object implementing publicType
        Throws:
        java.lang.IllegalArgumentException - When an extension with the given name already exists.
        Since:
        3.5
      • add

        void add​(java.lang.String name,
                 java.lang.Object extension)
        Adds a new extension to this container. Adding an extension of name 'foo' will:
        • add 'foo' dynamic property
        • add 'foo' dynamic method that accepts a closure that is a configuration script block
        The extension will be exposed as extension.getClass() unless the extension itself declares a preferred public type via the HasPublicType protocol.
        Parameters:
        name - The name for the extension
        extension - Any object
        Throws:
        java.lang.IllegalArgumentException - When an extension with the given name already exists
      • create

        <T> T create​(java.lang.Class<T> publicType,
                     java.lang.String name,
                     java.lang.Class<? extends T> instanceType,
                     java.lang.Object... constructionArguments)
        Creates and adds a new extension to this container. A new instance of the given instanceType will be created using the given constructionArguments. The extension will be exposed as publicType. The new instance will have been dynamically made ExtensionAware, which means that you can cast it to ExtensionAware.
        Type Parameters:
        T - the extension public type
        Parameters:
        publicType - The extension public type
        name - The name for the extension
        instanceType - The extension instance type
        constructionArguments - The arguments to be used to construct the extension instance
        Returns:
        The created instance
        Throws:
        java.lang.IllegalArgumentException - When an extension with the given name already exists.
        Since:
        3.5
        See Also:
        add(Class, String, Object)
      • create

        <T> T create​(TypeOf<T> publicType,
                     java.lang.String name,
                     java.lang.Class<? extends T> instanceType,
                     java.lang.Object... constructionArguments)
        Creates and adds a new extension to this container. A new instance of the given instanceType will be created using the given constructionArguments. The extension will be exposed as publicType. The new instance will have been dynamically made ExtensionAware, which means that you can cast it to ExtensionAware.
        Type Parameters:
        T - the extension public type
        Parameters:
        publicType - The extension public type
        name - The name for the extension
        instanceType - The extension instance type
        constructionArguments - The arguments to be used to construct the extension instance
        Returns:
        The created instance
        Throws:
        java.lang.IllegalArgumentException - When an extension with the given name already exists.
        Since:
        3.5
        See Also:
        add(Class, String, Object)
      • create

        <T> T create​(java.lang.String name,
                     java.lang.Class<T> type,
                     java.lang.Object... constructionArguments)
        Creates and adds a new extension to this container. A new instance of the given type will be created using the given constructionArguments. The extension will be exposed as type unless the extension itself declares a preferred public type via the HasPublicType protocol. The new instance will have been dynamically made ExtensionAware, which means that you can cast it to ExtensionAware.
        Parameters:
        name - The name for the extension
        type - The type of the extension
        constructionArguments - The arguments to be used to construct the extension instance
        Returns:
        The created instance
        Throws:
        java.lang.IllegalArgumentException - When an extension with the given name already exists.
        See Also:
        add(String, Object)
      • getExtensionsSchema

        ExtensionsSchema getExtensionsSchema()
        Provides access to the schema of all known extensions.
        Since:
        4.5
      • getByType

        <T> T getByType​(java.lang.Class<T> type)
                 throws UnknownDomainObjectException
        Looks for the extension of a given type (useful to avoid casting). If none found it will throw an exception.
        Parameters:
        type - extension type
        Returns:
        extension, never null
        Throws:
        UnknownDomainObjectException - When the given extension is not found.
      • getByType

        <T> T getByType​(TypeOf<T> type)
                 throws UnknownDomainObjectException
        Looks for the extension of a given type (useful to avoid casting). If none found it will throw an exception.
        Parameters:
        type - extension type
        Returns:
        extension, never null
        Throws:
        UnknownDomainObjectException - When the given extension is not found.
        Since:
        3.5
      • findByType

        @Nullable
        <T> T findByType​(java.lang.Class<T> type)
        Looks for the extension of a given type (useful to avoid casting). If none found null is returned.
        Parameters:
        type - extension type
        Returns:
        extension or null
      • findByType

        @Nullable
        <T> T findByType​(TypeOf<T> type)
        Looks for the extension of a given type (useful to avoid casting). If none found null is returned.
        Parameters:
        type - extension type
        Returns:
        extension or null
        Since:
        3.5
      • getByName

        java.lang.Object getByName​(java.lang.String name)
                            throws UnknownDomainObjectException
        Looks for the extension of a given name. If none found it will throw an exception.
        Parameters:
        name - extension name
        Returns:
        extension, never null
        Throws:
        UnknownDomainObjectException - When the given extension is not found.
      • findByName

        @Nullable
        java.lang.Object findByName​(java.lang.String name)
        Looks for the extension of a given name. If none found null is returned.
        Parameters:
        name - extension name
        Returns:
        extension or null
      • configure

        <T> void configure​(java.lang.Class<T> type,
                           Action<? super T> action)
        Looks for the extension of the specified type and configures it with the supplied action.
        Parameters:
        type - extension type
        action - the configure action
        Throws:
        UnknownDomainObjectException - if no extension is found.
      • configure

        <T> void configure​(TypeOf<T> type,
                           Action<? super T> action)
        Looks for the extension of the specified type and configures it with the supplied action.
        Parameters:
        type - extension type
        action - the configure action
        Throws:
        UnknownDomainObjectException - if no extension is found.
        Since:
        3.5
      • configure

        <T> void configure​(java.lang.String name,
                           Action<? super T> action)
        Looks for the extension with the specified name and configures it with the supplied action.
        Parameters:
        name - extension name
        action - the configure action
        Throws:
        UnknownDomainObjectException - if no extension is found.
        Since:
        4.0
      • getExtraProperties

        ExtraPropertiesExtension getExtraProperties()
        The extra properties extension in this extension container. This extension is always present in the container, with the name “ext”.
        Returns:
        The extra properties extension in this extension container.