    001// Copyright 2022 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007//     http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014
    015package org.apache.tapestry5.internal.services;
    016
    017import java.util.Set;
    018
    019import org.apache.tapestry5.annotations.Component;
    020import org.apache.tapestry5.annotations.InjectComponent;
    021import org.apache.tapestry5.annotations.InjectPage;
    022import org.apache.tapestry5.commons.services.InvalidationEventHub;
    023import org.apache.tapestry5.internal.structure.ComponentPageElement;
    024import org.apache.tapestry5.model.MutableComponentModel;
    025import org.apache.tapestry5.plastic.PlasticField;
    026
    027
    028/**
    029 * Internal service that registers direct dependencies between components (including components, pages and
    030 * base classes). Even though methods receive {@link ComponentPageElement} parameters, dependencies
    031 * are tracked using their fully qualified classs names.
    032 *
    033 * @since 5.8.3
    034 */
    035public interface ComponentDependencyRegistry {
    036
    037    /**
    038     * Enum class defining the types of dependency components, pages and mixins can
    039     * have among them.
    040     */
    041    public static enum DependencyType
    042    {
    043
    044        /**
    045         * Simple usage of components and mixins in components and pages
    046         */
    047        USAGE,
    048
    049        /**
    050         * Superclass/subclass dependency.
    051         */
    052        SUPERCLASS,
    053
    054        /**
    055         * Dependency by usage of the {@linkplain InjectPage} annotation.
    056         */
    057        INJECT_PAGE;
    058    }
    059
    060    /**
    061     * Name of the file where the dependency information is stored between webapp runs.
    062     */
    063    String FILENAME = "tapestryComponentDependencies.json";
    064
    065    /**
    066     * Register all the dependencies of a given class.
    067     */
    068    void register(Class<?> clasz);
    069
    070    /**
    071     * Register all the dependencies of a given component.
    072     */
    073    void register(ComponentPageElement componentPageElement);
    074
    075    /**
    076     * Register a dependency of a component class with another through annotations
    077     * such as {@link InjectPage}, {@link InjectComponent} and {@link Component}.
    078     */
    079    void register(PlasticField plasticField, MutableComponentModel componentModel);
    080
    081    /**
    082     * Clears all dependency information for a given component.
    083     */
    084    void clear(String className);
    085
    086    /**
    087     * Clears all dependency information for a given component.
    088     */
    089    void clear(ComponentPageElement componentPageElement);
    090
    091    /**
    092     * Clears all dependency information.
    093     */
    094    void clear();
    095
    096    /**
    097     * Returns the fully qualified names of the direct dependencies of a given component.
    098     */
    099    Set<String> getDependents(String className);
    100
    101    /**
    102     * Returns the fully qualified names of the direct dependencies of a given component
    103     * and a given dependency type.
    104     * @see DependencyType
    105     */
    106    Set<String> getDependencies(String className, DependencyType type);
    107
    108    /**
    109     * Signs up this registry to invalidation events from a given hub.
    110     */
    111    void listen(InvalidationEventHub invalidationEventHub);
    112
    113    /**
    114     * Writes the current component dependency data to a file so it can be reused in a new run later.
    115     * @see #FILENAME
    116     */
    117    void writeFile();
    118
    119    /**
    120     * Tells whether this registry already contans a given class name.
    121     */
    122    boolean contains(String className);
    123
    124    /**
    125     * Returns the set of all class names in the registry.
    126     */
    127    Set<String> getClassNames();
    128
    129    /**
    130     * Returns the set of all root classes (i.e. ones with no dependencies).
    131     */
    132    Set<String> getRootClasses();
    133
    134    /**
    135     * Returns whether stored dependency information is present.
    136     */
    137    boolean isStoredDependencyInformationPresent();
    138
    139    /**
    140     * Tells this service to ignore invalidations in this thread.
    141     */
    142    void disableInvalidations();
    143
    144    /**
    145     * Tells this service to stop ignoring invalidations in this thread.
    146     */
    147    void enableInvalidations();
    148
    149}