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.
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 Summary
FieldsModifier and TypeFieldDescriptionprotected Map<AccessType,Dag<T>> The DAGs of types.protected Map<String,AccessType> A map to locate types.protected Map<String,org.gcube.informationsystem.model.knowledge.ModelKnowledge.ResolvedAssociation> 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).A singleTypeUsagerecord per type name, covering every kind of type this knowledge base tracks -- Resources, Facets, IsRelatedTo/ConsistsOf relations, and Property-family types alike.protected TIThe type information. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllType(Collection<T> types) Adds all types to the knowledge base.protected voidAdds the entity metadata usage for a type.protected voidAdds 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 voidAdds the relation metadata usage for a type.voidAdds 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.Returns the "consists of" usage.getDag(AccessType accessType) Returns the DAG for the given access type.getERTypesUsage(AccessType accessType) Returns the usage knowledge for the given entity/relation type.Returns the facet usage.Returns the "is related to" usage.getModelTypesUsage(AccessType accessType) Returns the usage knowledge for the given model type.getNodeByName(String typeName) Returns the node for the type if it is contained in the KnowledgeReturns the property usage.Returns the ConsistsOf-family usage where a Resource is the source, i.e. what it declares itself composed of.Returns the IsRelatedTo-family usage of a Resource -- where it appears as source or target of an IsRelatedTo declaration.getTypeByName(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 Details
-
typeInformation
The type information. -
dags
The DAGs of types. -
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> 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). -
locate
A map to locate types.
-
-
Constructor Details
-
ModelKnowledge
Creates a new instance.- Parameters:
typeInformation- The type information.
-
-
Method Details
-
reset
protected void reset()Resets the knowledge base. -
addUsage
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
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
Adds the property usage for a type.- Parameters:
t- The type.properties- The properties.
-
addPropertyUsage
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
Adds the entity metadata usage for a type.- Parameters:
t- The type.
-
addRelationMetadataUsage
Adds the relation metadata usage for a type.- Parameters:
t- The type.
-
addPropagationConstraintUsage
Adds the propagation constraint usage for a type.- Parameters:
t- The type.
-
addAllType
Adds all types to the knowledge base.- Parameters:
types- The types to add.
-
addType
Adds a type to the knowledge base.- Parameters:
t- The type to add.
-
getDag
Returns the DAG for the given access type.- Parameters:
accessType- The access type.- Returns:
- The DAG.
-
getModelTypesUsage
Returns the usage knowledge for the given model type.- Parameters:
accessType- The access type.- Returns:
- The usage knowledge.
-
getERTypesUsage
Returns the usage knowledge for the given entity/relation type.- Parameters:
accessType- The access type.- Returns:
- The usage knowledge.
-
getPropertyUsage
Returns the property usage.- Returns:
- The property usage.
-
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
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
Returns the facet usage.- Returns:
- The facet usage.
-
getIsRelatedToUsage
Returns the "is related to" usage.- Returns:
- The "is related to" usage.
-
getConsistsOfUsage
Returns the "consists of" usage.- Returns:
- The "consists of" usage.
-
getTypeByName
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
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.
-