Class BaseContext

    • Constructor Detail

      • BaseContext

        public BaseContext()
        Constructor. Generates a random context id.
    • Method Detail

      • getParent

        @Nullable
        public BaseContext getParent()
        Get the parent context, if there is one.
        Returns:
        the parent context or null
      • setParent

        protected void setParent​(@Nullable
                                 BaseContext newParent)
        Set the context parent.
        Parameters:
        newParent - the new context parent
      • getSubcontext

        @Nullable
        public <T extends BaseContext> T getSubcontext​(@Nonnull
                                                       Class<T> clazz)
        Get a subcontext of the current context.
        Type Parameters:
        T - the type of subcontext being operated on
        Parameters:
        clazz - the class type to obtain
        Returns:
        the held instance of the class, or null
      • getSubcontext

        @Nullable
        public <T extends BaseContext> T getSubcontext​(@Nonnull
                                                       Class<T> clazz,
                                                       boolean autocreate)
        Get a subcontext of the current context.
        Type Parameters:
        T - the type of subcontext being operated on
        Parameters:
        clazz - the class type to obtain
        autocreate - flag indicating whether the subcontext instance should be auto-created
        Returns:
        the held instance of the class, or null
      • getSubcontext

        @Nullable
        public BaseContext getSubcontext​(@Nonnull @NotEmpty
                                         String className,
                                         boolean autocreate)
                                  throws ClassNotFoundException
        Get a subcontext of the current context.

        As of V3.4.0, if autocreate is false, this method will respond to a ClassNotFoundException by attempting to locate a matching subcontext based on the simple class name of the children and return the first match. If no match is found, it will proceed with the throw, but a future version of the API will eliminate that from the signature and simply return a null.

        Parameters:
        className - the name of the class type to obtain
        autocreate - flag indicating whether the subcontext instance should be auto-created
        Returns:
        the held instance of the class, or null
        Throws:
        ClassNotFoundException - if the named class does not exist
      • addSubcontext

        @Nonnull
        public BaseContext addSubcontext​(@Nonnull
                                         BaseContext subContext)
        Add a subcontext to the current context.
        Parameters:
        subContext - the subcontext to add
        Returns:
        the context added
      • addSubcontext

        @Nonnull
        public BaseContext addSubcontext​(@Nonnull
                                         BaseContext subcontext,
                                         boolean replace)
        Add a subcontext to the current context.
        Parameters:
        subcontext - the subcontext to add
        replace - flag indicating whether to replace the existing instance of the subcontext if present
        Returns:
        the context added
      • removeSubcontext

        public void removeSubcontext​(@Nonnull
                                     BaseContext subcontext)
        Remove a subcontext from the current context.
        Parameters:
        subcontext - the subcontext to remove
      • removeSubcontext

        public <T extends BaseContext> void removeSubcontext​(@Nonnull
                                                             Class<T> clazz)
        Remove the subcontext from the current context which corresponds to the supplied class.
        Type Parameters:
        T - the type of subcontext being operated on
        Parameters:
        clazz - the subcontext class to remove
      • containsSubcontext

        public <T extends BaseContext> boolean containsSubcontext​(@Nonnull
                                                                  Class<T> clazz)
        Return whether the current context currently contains an instance of the specified subcontext class.
        Type Parameters:
        T - the type of subcontext being operated on
        Parameters:
        clazz - the class to check
        Returns:
        true if the current context contains an instance of the class, false otherwise
      • clearSubcontexts

        public void clearSubcontexts()
        Clear the subcontexts of the current context.
      • createSubcontext

        @Nonnull
        protected <T extends BaseContext> T createSubcontext​(@Nonnull
                                                             Class<T> clazz)
        Create an instance of the specified subcontext class.
        Type Parameters:
        T - the type of subcontext
        Parameters:
        clazz - the class of the subcontext instance to create
        Returns:
        the new subcontext instance