Package org.mycore.datamodel.metadata
Class MCRObjectStructure
java.lang.Object
org.mycore.datamodel.metadata.MCRObjectStructure
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 Summary
ConstructorDescriptionThe 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 Summary
Modifier and TypeMethodDescriptionfinal 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.final boolean
addDerivate
(MCRMetaEnrichedLinkID derivate) addDerivate methode append the given derivate link data to the derivate vector.final boolean
addOrUpdateDerivate
(MCRMetaEnrichedLinkID derivateLink) Adds or updates the derivate link.final void
clear()
This method clean the data lists parent, children and derivates of this class.final void
This method clean the data lists children of this class.final void
This method clean the data lists derivate of this class.final boolean
containsChild
(MCRObjectID childId) Checks if the child is in the children vector.final boolean
containsDerivate
(MCRObjectID derivateId) Checks if the derivate is in the derivate vector.com.google.gson.JsonObject
Creates the JSON representation of this structure.final Element
createXML is the inverse of setFromDOM and converts the structure's memory copy into XML.final void
debug()
The method print all informations about this MCRObjectStructure.final List<MCRMetaLinkID>
Returns all children in this structurefinal MCRMetaEnrichedLinkID
getDerivateLink
(MCRObjectID derivateId) Returns the derivate link by id or null.final MCRMetaLinkID
The method returns the parent link.final MCRObjectID
The method return the parent reference as a MCRObjectID.final boolean
isValid()
isValid checks whether all of the MCRMetaLink's in the link vectors are valid or not.final boolean
removeChild
(MCRObjectID href) removes a child link to another object.final boolean
removeDerivate
(MCRObjectID href) removes a derivate link.final void
Removes the parent reference.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.final void
final void
setParent
(MCRMetaLinkID parent) This method set the parent value from a given MCRMetaLinkID.final void
setParent
(MCRObjectID parentID) void
validate()
Validates this MCRObjectStructure.
-
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
The method returns the parent link.- Returns:
- MCRMetaLinkID the corresponding link
-
getParentID
The method return the parent reference as a MCRObjectID.- Returns:
- the parent MCRObjectID or null if there is no parent present
-
setParent
This method set the parent value from a given MCRMetaLinkID.- Parameters:
parent
- the MCRMetaLinkID to set
-
setParent
-
setParent
-
removeParent
public final void removeParent()Removes the parent reference. Use this method with care! -
addChild
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
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
Checks if the child is in the children vector.- Parameters:
childId
- child to check
-
removeDerivate
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
Returns all children in this structure -
addDerivate
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
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
Checks if the derivate is in the derivate vector.- Parameters:
derivateId
- derivate to check
-
getDerivateLink
Returns the derivate link by id or null. -
getDerivates
- Returns:
- a list with all related derivate ids encapsulated within a
MCRMetaLinkID
-
setFromDOM
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
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
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
-