Class TypeUsageBuilder
- java.lang.Object
-
- org.gcube.informationsystem.model.knowledge.TypeUsageBuilder
-
public class TypeUsageBuilder extends Object
Builds aTypeUsagefor aTypefrom aModelKnowledgeand attaches it to the type as an additional property (seeType.setAdditionalProperty(String, Object)) rather than as a new field on theTypehierarchy itself. This way aType's JSON shape is identical whether or not usage was requested -- existing consumers that don't know about it are unaffected (Typealready declares@JsonIgnoreProperties(ignoreUnknown = true)) -- and the sameattach(Type, ModelKnowledge)call (or, for a whole knowledge base at once,attachAll(ModelKnowledge)) is reusable by any caller that already has aTypeand aModelKnowledge: today's documentation generator, and potentially a future opt-in enrichment on a live type-lookup service.Deliberately a separate class from
TypeUsageitself:TypeUsageis plain data, andModelKnowledgealready storesTypeUsageinstances internally (seeModelKnowledge.staticTypeUsageByName) -- ifTypeUsagealso knew how to read from aModelKnowledge, the two classes would depend on each other in both directions. This class depends on bothTypeandModelKnowledgeandTypeUsage; neither of those depends on this one.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Field Summary
Fields Modifier and Type Field Description static StringSTATIC_USAGE_PROPERTY_NAMEThe property name a builtTypeUsageis attached under.
-
Constructor Summary
Constructors Constructor Description TypeUsageBuilder()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidattach(Type type, ModelKnowledge<Type,?> modelKnowledge)Builds theTypeUsagefortypefrommodelKnowledgeand attaches it totypeitself as an additional property.static voidattachAll(ModelKnowledge<Type,?> modelKnowledge)Attaches usage to every type known tomodelKnowledge(every type in every DAG ofAccessType.getModelTypes()), one pass over the whole knowledge base.static TypeUsagefrom(Type type)
-
-
-
Field Detail
-
STATIC_USAGE_PROPERTY_NAME
public static final String STATIC_USAGE_PROPERTY_NAME
The property name a builtTypeUsageis attached under.- See Also:
- Constant Field Values
-
-
Method Detail
-
attach
public static void attach(Type type, ModelKnowledge<Type,?> modelKnowledge)
Builds theTypeUsagefortypefrommodelKnowledgeand attaches it totypeitself as an additional property. A no-op for anyAccessTypenot inAccessType.getModelTypes()(nothing to attach).- Parameters:
type- The type to enrich, mutated in place.modelKnowledge- The knowledge base to source usage data from.
-
from
public static TypeUsage from(Type type)
- Parameters:
type- The type to read from.- Returns:
- The attached
TypeUsage, ornullif none was attached.
-
attachAll
public static void attachAll(ModelKnowledge<Type,?> modelKnowledge)
Attaches usage to every type known tomodelKnowledge(every type in every DAG ofAccessType.getModelTypes()), one pass over the whole knowledge base.Deliberately not done per-type as each type is added (
ModelKnowledge.addType()): usage is an aggregate view that keeps changing as later types are added (seeModelKnowledge.registerAssociation()'s source-vs-target fallback), so it only settles once the knowledge base is complete. Call this once, after every type has been added -- from then on, everyTypeextracted frommodelKnowledgealready carries itsTypeUsage, with no further per-type call needed at the call site.- Parameters:
modelKnowledge- The complete knowledge base to enrich every type of.
-
-