Class MCRMetaElement

java.lang.Object
org.mycore.datamodel.metadata.MCRMetaElement
All Implemented Interfaces:
Cloneable, Iterable<MCRMetaInterface>

public class MCRMetaElement extends Object implements Iterable<MCRMetaInterface>, Cloneable
This class is designed to to have a basic class for all metadata. The class has inside a ArrayList that holds all metaddata elements for one XML tag. Furthermore, this class supports the linking of a document owing this metadata element to another document, the id of which is given in the xlink:href attribute of the MCRMetaLink representing the link. The class name of such a metadata element must be MCRMetaLink, and the metadata element is considered to be a folder of links.
Version:
$Revision$ $Date$
Author:
Jens Kupferschmidt, Mathias Hegner
  • Field Details

    • DEFAULT_LANGUAGE

      public static final String DEFAULT_LANGUAGE
    • DEFAULT_HERITABLE

      public static final boolean DEFAULT_HERITABLE
    • DEFAULT_NOT_INHERIT

      public static final boolean DEFAULT_NOT_INHERIT
  • Constructor Details

    • MCRMetaElement

      public MCRMetaElement()
      This is the constructor of the MCRMetaElement class. The default language for the element was set to MCR.Metadata.DefaultLang.
    • MCRMetaElement

      public MCRMetaElement(Class<? extends MCRMetaInterface> clazz, String tag, boolean heritable, boolean notinherit, List<? extends MCRMetaInterface> list)
      This is the constructor of the MCRMetaElement class.
      Parameters:
      tag - the name of this tag
      heritable - set this flag to true if all child objects of this element can inherit this data
      notinherit - set this flag to true if this element should not inherit from his parent object
      list - a list of MCRMeta... data lines to add in this element (can be null)
  • Method Details

    • getClassName

      public final String getClassName()
      This methode return the name of this metadata class as string.
      Returns:
      the name of this metadata class as string
    • getElement

      public final MCRMetaInterface getElement(int index)
      This method returns the instance of an element from the list with index i.
      Returns:
      the instance of an element, if index is out of range return null
    • getElementByName

      public final MCRMetaInterface getElementByName(String name)
      This method returns the instance of an element from the list with the given name
      Returns:
      the instance of the element with the given name or null if there is no such element
    • isHeritable

      public final boolean isHeritable()
      This methode return the heritable flag of this metadata as boolean value.
      Returns:
      the heritable flag of this metadata class
    • inheritsNot

      public final boolean inheritsNot()
      This methode return the nonherit flag of this metadata as boolean value.
      Returns:
      the notherit flag of this metadata class
    • getTag

      public final String getTag()
      This methode return the tag of this metadata class as string.
      Returns:
      the tag of this metadata class as string
    • setHeritable

      public void setHeritable(boolean heritable)
      This methode set the heritable flag for the metadata class.
      Parameters:
      heritable - the heritable flag as boolean value
    • setNotInherit

      public void setNotInherit(boolean notinherit)
      This methode set the notinherit flag for the metadata class.
      Parameters:
      notinherit - the notinherit flag as boolean value
    • setTag

      public void setTag(String tag)
      This methode set the tag for the metadata class.
      Parameters:
      tag - the tag for the metadata class
    • setClass

      public final void setClass(Class<? extends MCRMetaInterface> clazz)
      This methode set the element class for the metadata elements.
      Parameters:
      clazz - the class for the metadata elements
    • getClazz

      public Class<? extends MCRMetaInterface> getClazz()
    • size

      public final int size()
      size returns the number of elements in this instance.
      Returns:
      int the size of "list"
    • addMetaObject

      public final void addMetaObject(MCRMetaInterface obj)
      The method add a metadata object, that implements the MCRMetaInterface to this element.
      Parameters:
      obj - a metadata object
      Throws:
      MCRException - if the class name of the object is not the same like the name of all store metadata in this element.
    • removeElement

      public final boolean removeElement(int index)
      This method remove the instance of an element from the list with index i.
      Returns:
      true if the instance is removed, otherwise return else
    • removeMetaObject

      public final boolean removeMetaObject(MCRMetaInterface obj)
      The method remove a metadata object, that implements the MCRMetaInterface to this element.
      Parameters:
      obj - a metadata object
      Returns:
      true if this MCRMetaElement contained the specified MCRMetaInterface
      Throws:
      MCRException - if the class name of the object is not the same like the name of all store metadata in this element.
    • removeInheritedMetadata

      public final void removeInheritedMetadata()
      The method removes all inherited metadata objects of this MCRMetaElement.
    • setFromDOM

      public final void setFromDOM(Element element) throws MCRException
      This methode read the XML input stream part from a DOM part for the metadata of the document.
      Parameters:
      element - a relevant JDOM element for the metadata
      Throws:
      MCRException - if the class can't loaded
    • createXML

      public final Element createXML(boolean flag) throws MCRException
      This methode create a XML stream for all data in this class, defined by the MyCoRe XML MCRLangText definition for the given subtag.
      Parameters:
      flag - true if all inherited data should be include, else false
      Returns:
      a JDOM Element with the XML Element part
      Throws:
      MCRException - if the content of this class is not valid
    • createJSON

      public com.google.gson.JsonObject createJSON(boolean flag)
      Creates the JSON representation of this metadata element.
         {
            class: 'MCRMetaLangText',
            heritable: true,
            notinherit: false,
            data: [
              MCRMetaInterface.createJSON(),
              ...
            ]
         }
       
      Returns:
      a json gson representation of this metadata element
    • isValid

      public final boolean isValid()
      This methode check the validation of the content of this class. The methode returns true if
      • the classname is not null or empty
      • the tag is not null or empty
      • if the list is empty
      • the lang value was supported
      otherwise the methode return false
      Returns:
      a boolean value
    • validate

      public void validate() throws MCRException
      Validates this MCRMetaElement. This method throws an exception if:
      • the classname is not null or empty
      • the tag is not null or empty
      • if the list is empty
      • the lang value was supported
      Throws:
      MCRException - the MCRMetaElement is invalid
    • clone

      public final MCRMetaElement clone()
      This method make a clone of this class.
      Overrides:
      clone in class Object
    • debug

      public final void debug()
      This method put debug data to the logger (for the debug mode).
    • stream

      public Stream<MCRMetaInterface> stream()
      Streams the MCRMetaInterface of this element.
      Returns:
      stream of MCRMetaInterface's
    • iterator

      public Iterator<MCRMetaInterface> iterator()
      Specified by:
      iterator in interface Iterable<MCRMetaInterface>