Class SingleTypeExtensionFactory<T,​E>

    • Constructor Detail

      • SingleTypeExtensionFactory

        public SingleTypeExtensionFactory​(Class<E> extensionType)
        Constructs a SingleTypeExtensionFactory for extensions of the given type. The extensionSubType will be the same as the given type.
        Parameters:
        extensionType - The extension type.
      • SingleTypeExtensionFactory

        public SingleTypeExtensionFactory​(Class<E> extensionType,
                                          Class<? extends E> extensionSubType)
        Constructs a SingleTypeExtensionFactory for extensions of the given sub-type which implement the given type.
        Parameters:
        extensionType - The extension type. Must be assignable from extensionSubType.
        extensionSubType - The specific extension sub-type.
    • Method Detail

      • getExtensionType

        public final Class<E> getExtensionType()
        Returns:
        The extension type.
      • getExtensionSubType

        public final Class<? extends E> getExtensionSubType()
        Returns:
        The specific extension sub-type.
      • getExtension

        public final E getExtension​(Object object,
                                    Class<?> extensionType)
        Gets an instance of an extension type for the specified object of type T. If this factory's extensionType is assignable from the given extensionType, the method calls getExtensionImpl(Object, Class). Otherwise null is returned.
        Specified by:
        getExtension in interface ExtensionFactory
        Parameters:
        object - The object to be extended.
        extensionType - The type of the requested extension.
        Returns:
        The extension object, or null if the given object is not extensible by this factory or if an error occurs during the call to getExtensionImpl(Object, Class).
      • getExtensionImpl

        protected E getExtensionImpl​(T object,
                                     Class<E> extensionType)
                              throws Throwable
        Creates an extension object for the given object. The new extension object must be an instance of the extensionSubType passed to the constructor. Called if, and only if this factory's extensionType is assignable from the given extensionType.

        The default implementation returns a new instance of extensionSubType, either created from its public no-arg constructor or its public 1-arg constructor which can take the given object. Clients may subclass and override this method in order to implement a more sophisticated instance creation.

        Parameters:
        object - The object to be extended.
        extensionType - The type of the requested extension.
        Returns:
        The extension object.
        Throws:
        Throwable - If an error occurs.