Kitto.Metadata
Base layer of the metadata system. Defines the persistent tree object (TKMetadata) and node (TKMetadataItem) that models, views and layouts derive from, the catalog that loads, caches and saves them from YAML files (TKMetadataCatalog), and the registry that maps type ids to metadata classes (TKMetadataRegistry).
TKMetadata class
A metadata object is a tree object (often persistent) that is managed by a catalog. There are catalogs for models, views, layouts.
property Catalog: TKMetadataCatalog read FCatalog;The catalog that owns and manages this metadata object.
function GetResourceURI: string;Returns a string URI that uniquely identifies the object, to be used for access control or other purposes.
function GetACURI: string;Returns a string URI that (non necessarily uniquely) identifies the object for access control purposes.
function IsAccessGranted(const AMode: string): Boolean;Returns true if access is granted to the resource representing the metadata object in the specified mode. This is a shortcut to calling TKConfig.Instance.IsAccessGranted (possibly multiple times for cascading, and "or"ing the results).
procedure CheckAccessGranted(const AMode: string);Calls IsAccessGranted and raises an exception if the method returns False. This is a shortcut to calling TKConfig.Instance.CheckAccessGranted. (possibly multiple times for
procedure Assign(const ASource: TEFTree;Makes the current object a copy of the specified tree.
TKMetadataItem class
A metadata node: a tree node (contained in a metadata object or another item) that participates in access control via a resource URI.
function GetResourceURI: string;Returns a string URI that uniquely identifies the object, to be used for access control and other purposes.
function GetACURI: string;Returns a string URI that (non necessarily uniquely) identifies the object for access control purposes. By default, returns the same value as GetResourceURI.
function IsAccessGranted(const AMode: string): Boolean;Returns True if access is granted to the resource representing the metadata object in the specified mode. This is a shortcut to calling TKConfig.Instance.IsAccessGranted (possibly multiple times for cascading, and "or"ing the results).
procedure CheckAccessGranted(const AMode: string);Calls IsAccessGranted and raises an exception if the method returns False. This is a shortcut to calling TKConfig.Instance.CheckAccessGranted. (possibly multiple times for
TKMetadataCatalog class
A catalog of metadata objects backed by a directory of YAML files. Indexes the files, loads objects lazily on demand, caches them, and persists changes. Also tracks non-persistent and dynamically-created objects. Access is serialized (thread-safe) through Synchronize.
function FindNonpersistentObject(const ANode: TEFNode): TKMetadata;Returns the non-persistent object created from ANode, or nil.
procedure AddNonpersistentObject(const AObject: TKMetadata;Registers AObject as the non-persistent object created from ANode.
procedure DeleteNonpersistentObject(const ANode: TEFNode);Removes the non-persistent object associated with ANode (does not free it).
function FindDynamicObject(const AName: string): TKMetadata;Returns the dynamically-created object registered under AName, or nil.
procedure AddDynamicObject(const AObject: TKMetadata;Registers AObject as a dynamically-created object under AName.
procedure DeleteDynamicObject(const AName: string);Removes the dynamically-created object registered under AName (does not free it).
property Path: string read FPath write SetPath;The directory path holding the catalog's YAML files.
function GetFullFileName(const AName: string): string;Returns the full file name for the specified persistent name.
procedure Open;Closes and reopens the catalog, rebuilds the index and invalidates all objects.
Upon calling this method, any reference to an object loaded by the catalog is no longer valid.
function IsOpen: Boolean;Returns true if the catalog is open.
Currently returns False if the catalog is open but empty.
procedure Refresh;Rebuilds the index preserving any objects already created. An object that is no longer part of the rebuilt index, though (for example when a file is deleted from the outside), is destroyed anyway.
If the catalog is not open, calling this method raises an exception.
procedure Close;Closes the catalog and frees all objects.
property ObjectCount: Integer read GetObjectCount;Number of objects in the catalog's index.
property Objects[I: Integer]: TKMetadata read GetObject;The catalog's objects, by index (loaded on demand).
function FindObject(const AName: string): TKMetadata;Returns the object with the given name (persistent, dynamic or on-the-fly created), or nil.
function FindObject(const ANames: TStringDynArray): TKMetadata;Returns the first existing object among the given names, or nil.
function FindObjectByPredicate(const APredicate: TPredicate): TKMetadata;Returns the first object satisfying APredicate, or nil.
function ObjectByName(const AName: string): TKMetadata;Returns the object with the given name; raises if not found.
function ObjectByName(const ANames: TStringDynArray): TKMetadata;Returns the first existing object among the given names; raises if none.
function ObjectByNode(const ANode: TEFNode): TKMetadata;Returns the object referenced by ANode; raises if not found.
function FindObjectByNode(const ANode: TEFNode): TKMetadata;Returns the object referenced by ANode, or nil. A node with an expanded string value references an object by name; a node with children yields a non-persistent object built from the node's contents.
procedure AddObject(const AObject: TKMetadata);Adds AObject (which must have a persistent name) to the catalog.
procedure RemoveObject(const AObject: TKMetadata);Removes AObject from the index (does not free it).
procedure DeleteObject(const AIndex: Integer);Removes and frees the object at the given index.
procedure MarkObjectAsDisposed(const AObject: TKMetadata);Marks the object as disposed and removes it from the index (but doesn't free it). The file is then deleted when SaveAll is called.
Parameters:
AObject— Object to be disposed.
procedure SaveAll;Saves all modified objects in the catalog and disposes all objects marked for disposition.
procedure SaveObject(const AObject: TKMetadata);Saves the given object to its YAML file.
TKMetadataRegistry class
Registry mapping type ids to metadata classes, with fallback and system-class lookup semantics.
function GetClass(const AId1, AId2: string): TKMetadataClass;Returns a reference to the class identified by Id1; falls back to Id2 if the first one is not found. Looks for system classes as well.
The search sequence is:<br />Id1 user class<br />Id2 user class <br />Id1 system class<br />Id2 system class<br />Error
Parameters:
AId1— Id of the primary?class requested.AId2— Id of the?fallback class.
function FindClass(const AId1, AId2: string): TKMetadataClass;Like GetClass, but returns nil instead of raiseing errors if no class found.
