Class MCRObjectStructure

java.lang.Object
org.mycore.datamodel.metadata.MCRObjectStructure

public class MCRObjectStructure extends Object
This class implements code for the inheritance of metadata of linked objects and the linking of derivates onto an MCRObject. These links are described by the MCRMetaLink class. For links to another object, there are "locators" in use only, and the href variable gives the ID of the linked object, while the label and title attributes can be used freely. Subtag name = " <child>" means a child link from a "parent" object (collected in the "children" and "parents" section of the "structure" part, respectively). The child inherits all heritable metadata of the parent. If the parent itself is a child of another parent, the heritable metadata of this "grand parent" is inherited by the child as well. This mechanism recursively traces the full inheritance hierarchy. So if the grand parent itself has a parent, this grand parent parent's heritable metadata will be inherited and so on. Note, that it is impossible to inherit metadata from multiple parents. In cases of multiple inheritance request, an exception is thrown. A child link cannot occur twice from the same object to the same href (preventing from doubled links). Not supported by this class are links from or to a defined place of a document (inner structure and combination of inner and outer structures of the objects). This will possibly be done in a later extension of MCRMetaLink and MCRObjectStructure.
Version:
$Revision$ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
Author:
Mathias Hegner, Jens Kupferschmidt
  • Constructor Details

    • MCRObjectStructure

      public MCRObjectStructure()
      The constructor initializes NL (non-static, in order to enable different NL's for different objects) and the link vectors the elements of which are MCRMetaLink's.
  • Method Details

    • clear

      public final void clear()
      This method clean the data lists parent, children and derivates of this class.
    • clearChildren

      public final void clearChildren()
      This method clean the data lists children of this class.
    • clearDerivates

      public final void clearDerivates()
      This method clean the data lists derivate of this class.
    • getParent

      public final MCRMetaLinkID getParent()
      The method returns the parent link.
      Returns:
      MCRMetaLinkID the corresponding link
    • getParentID

      public final MCRObjectID getParentID()
      The method return the parent reference as a MCRObjectID.
      Returns:
      the parent MCRObjectID or null if there is no parent present
    • setParent

      public final void setParent(MCRMetaLinkID parent)
      This method set the parent value from a given MCRMetaLinkID.
      Parameters:
      parent - the MCRMetaLinkID to set
    • setParent

      public final void setParent(MCRObjectID parentID)
    • setParent

      public final void setParent(String parentID)
    • removeParent

      public final void removeParent()
      Removes the parent reference. Use this method with care!
    • addChild

      public final boolean addChild(MCRMetaLinkID child)
      The method appends a child ID to the child link list if and only if it is not already contained in the list, preventing from doubly-linked objects. If the link could be added a "true" will be returned, otherwise "false".
      Parameters:
      child - the MCRMetaLinkID of the child
      Returns:
      boolean true, if successfully done
    • removeChild

      public final boolean removeChild(MCRObjectID href)
      removes a child link to another object. If the link was found a "true" will be returned, otherwise "false".
      Parameters:
      href - the MCRObjectID of the child
      Returns:
      boolean true, if successfully completed
    • containsChild

      public final boolean containsChild(MCRObjectID childId)
      Checks if the child is in the children vector.
      Parameters:
      childId - child to check
    • removeDerivate

      public final boolean removeDerivate(MCRObjectID href)
      removes a derivate link. If the link was found a "true" will be returned, otherwise "false".
      Parameters:
      href - the MCRObjectID of the child
      Returns:
      boolean true, if successfully completed
    • getChildren

      public final List<MCRMetaLinkID> getChildren()
      Returns all children in this structure
    • addDerivate

      public final boolean addDerivate(MCRMetaEnrichedLinkID derivate)
      addDerivate methode append the given derivate link data to the derivate vector. If the link could be added a "true" will be returned, otherwise "false".
      Parameters:
      derivate - the link to be added as MCRMetaLinkID
    • addOrUpdateDerivate

      public final boolean addOrUpdateDerivate(MCRMetaEnrichedLinkID derivateLink)
      Adds or updates the derivate link. Returns true if the derivate is added or updated. Returns false when nothing is done.
      Parameters:
      derivateLink - the link to add or update
      Returns:
      true when the structure is changed
    • containsDerivate

      public final boolean containsDerivate(MCRObjectID derivateId)
      Checks if the derivate is in the derivate vector.
      Parameters:
      derivateId - derivate to check
    • getDerivateLink

      public final MCRMetaEnrichedLinkID getDerivateLink(MCRObjectID derivateId)
      Returns the derivate link by id or null.
    • getDerivates

      public List<MCRMetaEnrichedLinkID> getDerivates()
      Returns:
      a list with all related derivate ids encapsulated within a MCRMetaLinkID
    • setFromDOM

      public final void setFromDOM(Element element)
      While the preceding methods dealt with the structure's copy in memory only, the following three will affect the operations to or from datastore too. Thereby setFromDOM will read the structure data from an XML input stream (the "structure" entry).
      Parameters:
      element - the structure node list
    • createXML

      public final Element createXML() throws MCRException
      createXML is the inverse of setFromDOM and converts the structure's memory copy into XML.
      Returns:
      the structure XML
      Throws:
      MCRException - if the content of this class is not valid
    • createJSON

      public com.google.gson.JsonObject createJSON()
      Creates the JSON representation of this structure.
         {
           parent: MCRMetaLink.createJSON(),
           children: [
            MCRMetaLink.createJSON()
            ...
           ],
           derivates: [
             MCRMetaLink.createJSON()
              ...
           ]
         }
       
      Returns:
      a json gson representation of this structure
    • debug

      public final void debug()
      The method print all informations about this MCRObjectStructure.
    • isValid

      public final boolean isValid()
      isValid checks whether all of the MCRMetaLink's in the link vectors are valid or not.
      Returns:
      boolean true, if structure is valid
    • validate

      public void validate() throws MCRException
      Validates this MCRObjectStructure. This method throws an exception if:
      • the parent is not null but invalid
      • one of the children is invalid
      • one of the derivates is invalid
      Throws:
      MCRException - the MCRObjectStructure is invalid