Class Metadata

java.lang.Object
org.rapidcontext.core.storage.StorableObject
org.rapidcontext.core.storage.Metadata

public class Metadata extends StorableObject
An object metadata container. Used for basic introspection of objects inside storages.
Version:
1.0
  • Field Details

    • KEY_CATEGORY

      public static final String KEY_CATEGORY
      The dictionary key for the object category, i.e. the type of object being described. The value stored is a string, using one of the predefined constant type values.
      See Also:
    • KEY_CLASS

      public static final String KEY_CLASS
      The dictionary key for the Java class of the object. The value stored is the actual Class of the object.
      See Also:
    • KEY_PATH

      public static final String KEY_PATH
      The dictionary key for the object path. The value stored is a path object.
      See Also:
    • KEY_STORAGES

      public static final String KEY_STORAGES
      The dictionary key for the storage paths. The value is an array with path objects for all storages containing the path.
      See Also:
    • KEY_MIMETYPE

      public static final String KEY_MIMETYPE
      The dictionary key for the object MIME type. The value stored is the MIME type of the object (prior to loading) if known.
      See Also:
    • KEY_MODIFIED

      public static final String KEY_MODIFIED
      The dictionary key for the last modified date. The value stored is a Date object.
      See Also:
    • KEY_SIZE

      public static final String KEY_SIZE
      The dictionary key for the size (in bytes) of the stored data. The value stored is a Long value.
      See Also:
    • CATEGORY_INDEX

      public static final String CATEGORY_INDEX
      The index category value.
      See Also:
    • CATEGORY_OBJECT

      public static final String CATEGORY_OBJECT
      The object category value.
      See Also:
    • CATEGORY_BINARY

      public static final String CATEGORY_BINARY
      The binary category value.
      See Also:
  • Constructor Details

    • Metadata

      public Metadata(Path path, Metadata meta)
      Creates a new metadata container with modified path information.
      Parameters:
      path - the absolute object path
      meta - the metadata container to copy
    • Metadata

      public Metadata(Class<?> clazz, Path path, Path storagePath)
      Creates a new metadata container.
      Parameters:
      clazz - the object class
      path - the absolute object path
      storagePath - the absolute storage path
  • Method Details

    • category

      public static String category(Class<?> clazz)
      Returns the object category based on the class. This method checks if the class inherits from the Index or Binary classes, otherwise it returns the object class.
      Parameters:
      clazz - the object class
      Returns:
      the object category
    • merge

      public static Metadata merge(Metadata meta1, Metadata meta2)
      Merges two metadata containers. If either of the two values is null, the other will be returned. Otherwise, a new metadata container is created as a merged copy of two. The first will serve as the base, adding additional storage paths from the second as needed. For index objects, the last modified date will be adjusted to the maximum of the two objects.
      Parameters:
      meta1 - the first metadata object
      meta2 - the second metadata object
      Returns:
      the merged metadata container
    • isIndex

      public boolean isIndex()
      Checks if the object category is an index.
      Returns:
      true if the object category is an index, or false otherwise
    • isObject

      public boolean isObject()
      Checks if the object category is an object.
      Returns:
      true if the object category is an object, or false otherwise
    • isObject

      public boolean isObject(Class<?> clazz)
      Checks if the object category is an object of the specified class (or a subclass).
      Parameters:
      clazz - the object class
      Returns:
      true if the object category is a matching object, or false otherwise
    • isBinary

      public boolean isBinary()
      Checks if the object category is binary.
      Returns:
      true if the object category is binary, or false otherwise
    • category

      public String category()
      Returns the category for the object.
      Returns:
      the category for the object
      See Also:
    • classInstance

      public Class<?> classInstance()
      Returns the class for the object.
      Returns:
      the class for the object
    • className

      public String className()
      Returns the class name for the object.
      Returns:
      the class name for the object
    • path

      public Path path()
      Returns the absolute object path.
      Overrides:
      path in class StorableObject
      Returns:
      the absolute object path
    • storages

      public Array storages()
      Returns an array with the root paths to all storages containing this object.
      Returns:
      an array with path objects for storage roots
    • mimeType

      public String mimeType()
      Returns the MIME type for the object.
      Returns:
      the MIME type for the object, or null
    • mimeType

      protected Metadata mimeType(String mime)
      Sets the MIME type for the object.
      Parameters:
      mime - the MIME type, or null for unknown
      Returns:
      this metadata object (for chaining)
    • modified

      public Date modified()
      Returns the last modified date for the object.
      Returns:
      the last modified date for the object
    • modified

      protected Metadata modified(Date date)
      Sets the last modified date for the object.
      Parameters:
      date - the date to set, or null for now
      Returns:
      this metadata object (for chaining)
    • size

      public long size()
      Returns the size (in bytes) of the object.
      Returns:
      the size (in bytes) of the object, or zero (0) if unknown
    • size

      protected Metadata size(long size)
      Sets the size (in bytes) of the object.
      Parameters:
      size - the size to set
      Returns:
      this metadata object (for chaining)
    • serialize

      public Dict serialize()
      Returns a serialized representation of this object. Used when persisting to permanent storage or when accessing the object from outside pure Java. Returns a shallow copy of the contained dictionary.
      Overrides:
      serialize in class StorableObject
      Returns:
      the serialized representation of this object