Class ModelKnowledge<T,​TI extends TypeInformation<T>>

  • Type Parameters:
    T - The concrete type representation used by the caller (e.g. a Java Class or a deserialized Type instance).
    TI - The TypeInformation strategy used to inspect a T.

    public class ModelKnowledge<T,​TI extends TypeInformation<T>>
    extends Object
    Builds an in-memory knowledge base over the full set of known types: one inheritance Dag per AccessType, plus a per-type-name usage index (TypeUsage: Composition/Association/Property usage) tracking which types reference which other types (via ConsistsOf/IsRelatedTo relations) and which generic property types are embedded by which type.
    Author:
    Luca Frosini (ISTI - CNR)
    • Field Detail

      • typeInformation

        protected TI extends TypeInformation<T> typeInformation
        The type information.
      • staticTypeUsageByName

        protected Map<String,​TypeUsage> staticTypeUsageByName
        A single TypeUsage record per type name, covering every kind of type this knowledge base tracks -- Resources, Facets, IsRelatedTo/ConsistsOf relations, and Property-family types alike. A Resource's own TypeUsage.getCompositionUsage() (what it declares itself composed of) and TypeUsage.getAssociationUsage() (IsRelatedTo-family usage) live side by side in the very same record, keyed by that Resource's own name -- there is no risk of the two being confused since they are different fields, not different maps that need to be kept in sync by hand.
      • resolvedAssociations

        protected Map<String,​org.gcube.informationsystem.model.knowledge.ModelKnowledge.ResolvedAssociation> resolvedAssociations
        Tracks, per (source, relation, target) triple, which LinkedEntity is currently registered and whether it came from the side that actually declares the relation -- see registerAssociation(LinkedEntity, boolean, boolean).
    • Constructor Detail

      • ModelKnowledge

        public ModelKnowledge​(TI typeInformation)
        Creates a new instance.
        Parameters:
        typeInformation - The type information.
    • Method Detail

      • reset

        protected void reset()
        Resets the knowledge base.
      • addUsage

        protected void addUsage​(LinkedEntity linkedEntity,
                                boolean composition)
        Registers a usage of a linked entity under its source, relation, and target names.
        Parameters:
        linkedEntity - The linked entity.
        composition - true if this is Composition-family usage (ConsistsOf), false for Association-family usage (IsRelatedTo).
      • removeUsage

        protected void removeUsage​(LinkedEntity linkedEntity,
                                   boolean composition)
        Removes a previously registered usage of a linked entity from its source, relation, and target names -- the exact counterpart of addUsage(LinkedEntity, boolean).
        Parameters:
        linkedEntity - The linked entity.
        composition - true if this is Composition-family usage, false for Association-family usage.
      • addPropertyUsage

        protected void addPropertyUsage​(T t,
                                        Collection<PropertyDefinition> properties)
        Adds the property usage for a type.
        Parameters:
        t - The type.
        properties - The properties.
      • addPropertyUsage

        protected void addPropertyUsage​(String typeName,
                                        Collection<PropertyDefinition> properties)
        Adds the property usage under an explicitly named declaring type.

        Used for the fields a model level takes over from a structural one: the usage belongs to the level that declares them, not to each subtype that inherits them.

        Parameters:
        typeName - The name of the declaring type.
        properties - The properties.
      • addEntityMetadataUsage

        protected void addEntityMetadataUsage​(T t)
        Adds the entity metadata usage for a type.
        Parameters:
        t - The type.
      • addRelationMetadataUsage

        protected void addRelationMetadataUsage​(T t)
        Adds the relation metadata usage for a type.
        Parameters:
        t - The type.
      • addPropagationConstraintUsage

        protected void addPropagationConstraintUsage​(T t)
        Adds the propagation constraint usage for a type.
        Parameters:
        t - The type.
      • addAllType

        public void addAllType​(Collection<T> types)
        Adds all types to the knowledge base.
        Parameters:
        types - The types to add.
      • addType

        public void addType​(T t)
        Adds a type to the knowledge base.
        Parameters:
        t - The type to add.
      • getDag

        public Dag<T> getDag​(AccessType accessType)
        Returns the DAG for the given access type.
        Parameters:
        accessType - The access type.
        Returns:
        The DAG.
      • getModelTypesUsage

        public UsageKnowledge<?> getModelTypesUsage​(AccessType accessType)
        Returns the usage knowledge for the given model type.
        Parameters:
        accessType - The access type.
        Returns:
        The usage knowledge.
      • getERTypesUsage

        public UsageKnowledge<LinkedEntity> getERTypesUsage​(AccessType accessType)
        Returns the usage knowledge for the given entity/relation type.
        Parameters:
        accessType - The access type.
        Returns:
        The usage knowledge.
      • getResourceUsage

        public UsageKnowledge<LinkedEntity> getResourceUsage()
        Returns the IsRelatedTo-family usage of a Resource -- where it appears as source or target of an IsRelatedTo declaration. Does not include ConsistsOf-family usage; see getResourceCompositionUsage() for that.
        Returns:
        The resource association usage.
      • getResourceCompositionUsage

        public UsageKnowledge<LinkedEntity> getResourceCompositionUsage()
        Returns the ConsistsOf-family usage where a Resource is the source, i.e. what it declares itself composed of. Kept separate from getResourceUsage(), which tracks IsRelatedTo-family usage instead.
        Returns:
        The resource composition usage.
      • getIsRelatedToUsage

        public UsageKnowledge<LinkedEntity> getIsRelatedToUsage()
        Returns the "is related to" usage.
        Returns:
        The "is related to" usage.
      • getConsistsOfUsage

        public UsageKnowledge<LinkedEntity> getConsistsOfUsage()
        Returns the "consists of" usage.
        Returns:
        The "consists of" usage.
      • getTypeByName

        public T getTypeByName​(String typeName)
                        throws RuntimeException
        Returns the type if it is contained in the Knowledge
        Parameters:
        typeName - the type we are looking for
        Returns:
        the Type
        Throws:
        RuntimeException - if the type is not found.
      • getNodeByName

        public Node<T> getNodeByName​(String typeName)
                              throws RuntimeException
        Returns the node for the type if it is contained in the Knowledge
        Parameters:
        typeName - the type we are looking for
        Returns:
        the Type
        Throws:
        RuntimeException - if the type is not found.