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 DocumentReferencedocumentReferenceReference to the document in which this element is defined (for elements where this make sense, for example for an XClass or a XObject).protected XWikiDocumentownerDocumentThe owner document, if this element was obtained from a document.protected RreferenceCacheFull reference of this element.
-
Constructor Summary
Constructors Constructor Description BaseElement()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanapply(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.BaseElementclone()protected RcreateReference()booleanequals(Object el)voidfromXML(String source)protected voidfromXML(org.dom4j.Element oel)DocumentReferencegetDocumentReference()longgetId()Return an truncated MD5 hash of the local key computed ingetLocalKey().protected EntityReferenceSerializer<String>getLocalEntityReferenceSerializer()protected ContextualLocalizationManagergetLocalization()protected StringgetLocalKey()protected EntityReferenceSerializer<String>getLocalUidStringEntityReferenceSerializer()protected MergeManagergetMergeManager()StringgetName()XWikiDocumentgetOwnerDocument()StringgetPrettyName()RgetReference()protected XWikiContextgetXWikiContext()Get XWiki context from execution context.inthashCode()protected StringlocalizePlain(String key, Object... parameters)protected StringlocalizePlainOrKey(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.voidmerge(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.voidsetDocumentReference(DocumentReference reference)voidsetId(long id)Dummy function, do hibernate is always happy.voidsetName(String name)voidsetOwnerDocument(XWikiDocument ownerDocument)Set the owner document of this element.voidsetPrettyName(String name)StringtoString()protected org.dom4j.ElementtoXML()StringtoXMLString(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:
getReferencein interfaceElementInterface- Returns:
- the reference of the element
-
createReference
protected R createReference()
- Since:
- 3.2M1
-
getDocumentReference
public DocumentReference getDocumentReference()
- Specified by:
getDocumentReferencein 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:
getNamein 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:
setDocumentReferencein interfaceElementInterface
-
setName
public void setName(String name)
Note that this method is used by Hibernate for loading an element.
- Specified by:
setNamein 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:ElementInterfaceApply 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:
mergein 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:ElementInterfaceApply 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:
mergein 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:ElementInterfaceApply 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:
applyin 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:
toStringin interfaceElementInterface- Overrides:
toStringin classObject
-
-