Package com.xpn.xwiki.objects
Class BaseElement<R extends EntityReference>
- java.lang.Object
-
- com.xpn.xwiki.objects.BaseElement<R>
-
- All Implemented Interfaces:
ElementInterface
,Serializable
- Direct Known Subclasses:
BaseCollection
,BaseProperty
public abstract class BaseElement<R extends EntityReference> extends Object implements ElementInterface, Serializable
Base class for representing an element having a name (either a reference of a free form name) and a pretty name.- Version:
- $Id: 25ce8c546899d726a29f8d24e0d7c5252103084a $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DocumentReference
documentReference
Reference to the document in which this element is defined (for elements where this make sense, for example for an XClass or a XObject).protected XWikiDocument
ownerDocument
The owner document, if this element was obtained from a document.protected R
referenceCache
Full reference of this element.
-
Constructor Summary
Constructors Constructor Description BaseElement()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
apply(ElementInterface newElement, boolean clean)
Apply the provided element so that the current one contains the same informations and indicate if it was necessary to modify it in any way.BaseElement
clone()
protected R
createReference()
boolean
equals(Object el)
void
fromXML(String source)
protected void
fromXML(org.dom4j.Element oel)
DocumentReference
getDocumentReference()
long
getId()
Return an truncated MD5 hash of the local key computed ingetLocalKey()
.protected EntityReferenceSerializer<String>
getLocalEntityReferenceSerializer()
protected ContextualLocalizationManager
getLocalization()
protected String
getLocalKey()
protected EntityReferenceSerializer<String>
getLocalUidStringEntityReferenceSerializer()
protected MergeManager
getMergeManager()
String
getName()
XWikiDocument
getOwnerDocument()
String
getPrettyName()
R
getReference()
protected XWikiContext
getXWikiContext()
Get XWiki context from execution context.int
hashCode()
protected String
localizePlain(String key, Object... parameters)
protected String
localizePlainOrKey(String key, Object... parameters)
MergeManagerResult<ElementInterface,Object>
merge(ElementInterface previousElement, ElementInterface newElement, MergeConfiguration configuration, XWikiContext context)
Apply a 3 ways merge on the current element based on provided previous and new version of the element.void
merge(ElementInterface previousElement, ElementInterface newElement, MergeConfiguration configuration, XWikiContext context, MergeResult mergeResult)
Apply a 3 ways merge on the current element based on provided previous and new version of the element.void
setDocumentReference(DocumentReference reference)
void
setId(long id)
Dummy function, do hibernate is always happy.void
setName(String name)
void
setOwnerDocument(XWikiDocument ownerDocument)
Set the owner document of this element.void
setPrettyName(String name)
String
toString()
protected org.dom4j.Element
toXML()
String
toXMLString(boolean format)
-
-
-
Field Detail
-
referenceCache
protected R extends EntityReference referenceCache
Full reference of this element.- Since:
- 3.2M1
-
documentReference
protected DocumentReference documentReference
Reference to the document in which this element is defined (for elements where this make sense, for example for an XClass or a XObject).- Since:
- 5.3M1
-
ownerDocument
protected transient XWikiDocument ownerDocument
The owner document, if this element was obtained from a document.- Since:
- 5.3M1
-
-
Method Detail
-
getMergeManager
protected MergeManager getMergeManager()
- Returns:
- a merge manager instance.
- Since:
- 11.8RC1
-
getReference
public R getReference()
- Specified by:
getReference
in interfaceElementInterface
- Returns:
- the reference of the element
-
createReference
protected R createReference()
- Since:
- 3.2M1
-
getDocumentReference
public DocumentReference getDocumentReference()
- Specified by:
getDocumentReference
in interfaceElementInterface
- Returns:
- the reference to the document in which this element is defined (for elements where this make sense, for example for an XClass or a XObject).
-
getName
public String getName()
Note that this method is used by Hibernate for saving an element.
- Specified by:
getName
in interfaceElementInterface
- Returns:
- the free form name (for elements which don't point to a reference, for example for instances of
BaseProperty
). - See Also:
ElementInterface.getName()
-
setDocumentReference
public void setDocumentReference(DocumentReference reference)
- Specified by:
setDocumentReference
in interfaceElementInterface
-
setName
public void setName(String name)
Note that this method is used by Hibernate for loading an element.
- Specified by:
setName
in interfaceElementInterface
- See Also:
ElementInterface.setName(java.lang.String)
-
getPrettyName
public String getPrettyName()
-
setPrettyName
public void setPrettyName(String name)
-
getLocalUidStringEntityReferenceSerializer
protected EntityReferenceSerializer<String> getLocalUidStringEntityReferenceSerializer()
- Returns:
- the component used to build uid string for the getId() hash
- Since:
- 4.0M1
-
getLocalEntityReferenceSerializer
protected EntityReferenceSerializer<String> getLocalEntityReferenceSerializer()
- Returns:
- the component used to convert a proper Document Reference to a string but without the wiki name.
- Since:
- 6.3M1
-
getLocalization
protected ContextualLocalizationManager getLocalization()
-
getLocalKey
protected String getLocalKey()
- Returns:
- a unique identifier representing this element reference to be used for
hashCode()
. - Since:
- 4.0M1
-
getId
public long getId()
Return an truncated MD5 hash of the local key computed ingetLocalKey()
.- Returns:
- the identifier used by hibernate for storage.
- Since:
- 4.0M1
-
setId
public void setId(long id)
Dummy function, do hibernate is always happy.- Parameters:
id
- the identifier assigned by hibernate.- Since:
- 4.0M1
-
clone
public BaseElement clone()
-
merge
public void merge(ElementInterface previousElement, ElementInterface newElement, MergeConfiguration configuration, XWikiContext context, MergeResult mergeResult)
Description copied from interface:ElementInterface
Apply a 3 ways merge on the current element based on provided previous and new version of the element.All 3 elements are supposed to have the same class and reference.
- Specified by:
merge
in interfaceElementInterface
- Parameters:
previousElement
- the previous version of the elementnewElement
- the next version of the elementconfiguration
- the configuration of the merge Indicate how to deal with some conflicts use cases, etc.context
- the XWiki contextmergeResult
- the merge report
-
merge
public MergeManagerResult<ElementInterface,Object> merge(ElementInterface previousElement, ElementInterface newElement, MergeConfiguration configuration, XWikiContext context)
Description copied from interface:ElementInterface
Apply a 3 ways merge on the current element based on provided previous and new version of the element.All 3 elements are supposed to have the same class and reference.
Note that the current element is modified only if
MergeConfiguration.isProvidedVersionsModifiables()
returnstrue
.- Specified by:
merge
in interfaceElementInterface
- Parameters:
previousElement
- the previous version of the elementnewElement
- the next version of the elementconfiguration
- the configuration of the merge Indicate how to deal with some conflicts use cases, etc.context
- the XWiki context
-
apply
public boolean apply(ElementInterface newElement, boolean clean)
Description copied from interface:ElementInterface
Apply the provided element so that the current one contains the same informations and indicate if it was necessary to modify it in any way.- Specified by:
apply
in interfaceElementInterface
- Parameters:
newElement
- the element to applyclean
- true if informations that are not in the new element should be removed (for example class properties not in the new class)- Returns:
- true if the element has been modified
-
setOwnerDocument
public void setOwnerDocument(XWikiDocument ownerDocument)
Set the owner document of this element.- Parameters:
ownerDocument
- The owner document.- Since:
- 5.3M1
-
getOwnerDocument
public XWikiDocument getOwnerDocument()
- Returns:
- the owner document of this element.
- Since:
- 5.3M1
-
getXWikiContext
protected XWikiContext getXWikiContext()
Get XWiki context from execution context.- Returns:
- the XWiki context for the current thread
- Since:
- 9.0RC1
-
fromXML
protected void fromXML(org.dom4j.Element oel) throws XWikiException
- Throws:
XWikiException
-
fromXML
public void fromXML(String source) throws XWikiException
- Parameters:
source
- the XML to read- Throws:
XWikiException
- when failing to parse XML
-
toXML
protected org.dom4j.Element toXML()
-
toXMLString
public String toXMLString(boolean format)
- Parameters:
format
- true if the XML should be formated- Returns:
- the XML as a String
- Since:
- 9.0RC1
-
toString
public String toString()
- Specified by:
toString
in interfaceElementInterface
- Overrides:
toString
in classObject
-
-