Class ModelKnowledge<T,TI extends TypeInformation<T>>
- java.lang.Object
-
- org.gcube.informationsystem.model.knowledge.ModelKnowledge<T,TI>
-
- Type Parameters:
T- The concrete type representation used by the caller (e.g. a JavaClassor a deserializedTypeinstance).TI- TheTypeInformationstrategy used to inspect aT.
public class ModelKnowledge<T,TI extends TypeInformation<T>> extends Object
Builds an in-memory knowledge base over the full set of known types: one inheritanceDagperAccessType, plus a per-type-name usage index (TypeUsage: Composition/Association/Property usage) tracking which types reference which other types (viaConsistsOf/IsRelatedTorelations) and which generic property types are embedded by which type.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<AccessType,Dag<T>>dagsThe DAGs of types.protected Map<String,AccessType>locateA map to locate types.protected Map<String,org.gcube.informationsystem.model.knowledge.ModelKnowledge.ResolvedAssociation>resolvedAssociationsTracks, per (source, relation, target) triple, whichLinkedEntityis currently registered and whether it came from the side that actually declares the relation -- seeregisterAssociation(LinkedEntity, boolean, boolean).protected Map<String,TypeUsage>staticTypeUsageByNameA singleTypeUsagerecord per type name, covering every kind of type this knowledge base tracks -- Resources, Facets, IsRelatedTo/ConsistsOf relations, and Property-family types alike.protected TItypeInformationThe type information.
-
Constructor Summary
Constructors Constructor Description ModelKnowledge(TI typeInformation)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAllType(Collection<T> types)Adds all types to the knowledge base.protected voidaddEntityMetadataUsage(T t)Adds the entity metadata usage for a type.protected voidaddPropagationConstraintUsage(T t)Adds the propagation constraint usage for a type.protected voidaddPropertyUsage(String typeName, Collection<PropertyDefinition> properties)Adds the property usage under an explicitly named declaring type.protected voidaddPropertyUsage(T t, Collection<PropertyDefinition> properties)Adds the property usage for a type.protected voidaddRelationMetadataUsage(T t)Adds the relation metadata usage for a type.voidaddType(T t)Adds a type to the knowledge base.protected voidaddUsage(LinkedEntity linkedEntity, boolean composition)Registers a usage of a linked entity under its source, relation, and target names.UsageKnowledge<LinkedEntity>getConsistsOfUsage()Returns the "consists of" usage.Dag<T>getDag(AccessType accessType)Returns the DAG for the given access type.UsageKnowledge<LinkedEntity>getERTypesUsage(AccessType accessType)Returns the usage knowledge for the given entity/relation type.UsageKnowledge<LinkedEntity>getFacetUsage()Returns the facet usage.UsageKnowledge<LinkedEntity>getIsRelatedToUsage()Returns the "is related to" usage.UsageKnowledge<?>getModelTypesUsage(AccessType accessType)Returns the usage knowledge for the given model type.Node<T>getNodeByName(String typeName)Returns the node for the type if it is contained in the KnowledgeUsageKnowledge<Map.Entry<String,PropertyDefinition>>getPropertyUsage()Returns the property usage.UsageKnowledge<LinkedEntity>getResourceCompositionUsage()Returns the ConsistsOf-family usage where a Resource is the source, i.e.UsageKnowledge<LinkedEntity>getResourceUsage()Returns the IsRelatedTo-family usage of a Resource -- where it appears as source or target of an IsRelatedTo declaration.TgetTypeByName(String typeName)Returns the type if it is contained in the Knowledgeprotected voidremoveUsage(LinkedEntity linkedEntity, boolean composition)Removes a previously registered usage of a linked entity from its source, relation, and target names -- the exact counterpart ofaddUsage(LinkedEntity, boolean).protected voidreset()Resets the knowledge base.
-
-
-
Field Detail
-
typeInformation
protected TI extends TypeInformation<T> typeInformation
The type information.
-
dags
protected Map<AccessType,Dag<T>> dags
The DAGs of types.
-
staticTypeUsageByName
protected Map<String,TypeUsage> staticTypeUsageByName
A singleTypeUsagerecord 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 ownTypeUsage.getCompositionUsage()(what it declares itself composed of) andTypeUsage.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, whichLinkedEntityis currently registered and whether it came from the side that actually declares the relation -- seeregisterAssociation(LinkedEntity, boolean, boolean).
-
locate
protected Map<String,AccessType> locate
A map to locate types.
-
-
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-trueif this is Composition-family usage (ConsistsOf),falsefor 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 ofaddUsage(LinkedEntity, boolean).- Parameters:
linkedEntity- The linked entity.composition-trueif this is Composition-family usage,falsefor 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.
-
getPropertyUsage
public UsageKnowledge<Map.Entry<String,PropertyDefinition>> getPropertyUsage()
Returns the property usage.- Returns:
- The property usage.
-
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; seegetResourceCompositionUsage()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 fromgetResourceUsage(), which tracks IsRelatedTo-family usage instead.- Returns:
- The resource composition usage.
-
getFacetUsage
public UsageKnowledge<LinkedEntity> getFacetUsage()
Returns the facet usage.- Returns:
- The facet 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.
-
-