Class AsSupport

  • All Implemented Interfaces:
    As

    public class AsSupport
    extends Object
    implements As
    Version:
    $Id$
    Author:
    Fabrizio Giudici
    • Constructor Detail

      • AsSupport

        protected AsSupport()
        Constructor for use in subclassing.
      • AsSupport

        public AsSupport​(@Nonnull
                         Object owner,
                         @Nonnull
                         Object... rolesOrFactories)
        Constructor for use in composition. In addition to the mandatory owner, it's possible to pass a collection of pre-instantiated roles, or instances of RoleFactory that will be invoked to create additional roles.
        Parameters:
        owner - the owner
        rolesOrFactories - a collection of roles or factories for roles
    • Method Detail

      • as

        @Nonnull
        public <T> T as​(@Nonnull
                        Class<T> type)
        Returns an adapter to this object of the specified type. If the implementation can find multiple compliant adapters, only one will be returned.
        Specified by:
        as in interface As
        Returns:
        the adapter
      • as

        @Nonnull
        public <T> T as​(@Nonnull
                        Class<T> type,
                        @Nonnull
                        As.NotFoundBehaviour<T> notFoundBehaviour)
        Returns an adapter to this object of the specified type. If the implementation can find multiple compliant adapters, only one will be returned. If no adapter is found, the result provided by the given default behaviour will be returned. First, local roles are probed; then the owner, in case it directly implements the required role; at last, the delegate is invoked.
        Specified by:
        as in interface As
        notFoundBehaviour - the behaviour to apply when an adapter is not found
      • asMany

        @Nonnull
        public <T> Collection<T> asMany​(@Nonnull
                                        Class<T> type)
        Searches for multiple adapters of the given type and returns them. The list contains all the relevant local roles, as well as those retrieved by the delegate, in this order.
        Specified by:
        asMany in interface As
        Parameters:
        type - the adapter type
        Returns:
        a collection of adapters, possibly empty