Class TypeUsageBuilder
TypeUsage for a Type from a ModelKnowledge and attaches it
to the type as an additional property (see Type.setAdditionalProperty(String, Object))
rather than as a new field on the Type hierarchy itself. This way a Type's
JSON shape is identical whether or not usage was requested -- existing consumers that don't
know about it are unaffected (Type already declares
@JsonIgnoreProperties(ignoreUnknown = true)) -- and the same attach(Type, ModelKnowledge) call (or, for a whole knowledge base at once, attachAll(ModelKnowledge))
is reusable by any caller that already has a Type and a ModelKnowledge:
today's documentation generator, and potentially a future opt-in enrichment on a live
type-lookup service.
Deliberately a separate class from TypeUsage itself: TypeUsage is plain
data, and ModelKnowledge already stores TypeUsage instances internally (see
ModelKnowledge.staticTypeUsageByName) -- if TypeUsage also knew how to read
from a ModelKnowledge, the two classes would depend on each other in both directions.
This class depends on both Type and ModelKnowledge and TypeUsage;
neither of those depends on this one.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 TypeUsage
-
Field Details
-
STATIC_USAGE_PROPERTY_NAME
The property name a builtTypeUsageis attached under.- See Also:
-
-
Constructor Details
-
TypeUsageBuilder
public TypeUsageBuilder()
-
-
Method Details
-
attach
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
- Parameters:
type- The type to read from.- Returns:
- The attached
TypeUsage, ornullif none was attached.
-
attachAll
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.
-