com.xpn.xwiki.objects
Class BaseElement<R extends EntityReference>

java.lang.Object
  extended by 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: e3d0b2d8d8e2962e75ae1eea2e4a96e59d90f9ff $
See Also:
Serialized Form

Field Summary
protected  EntityReferenceSerializer<String> localEntityReferenceSerializer
          Used to convert a proper Document Reference to a string but without the wiki name.
protected  R referenceCache
          Full reference of this element.
 
Constructor Summary
BaseElement()
           
 
Method Summary
 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)
           
 DocumentReference getDocumentReference()
           
 long getId()
          Return an truncated MD5 hash of the local key computed in getLocalKey().
protected  String getLocalKey()
           
protected  EntityReferenceSerializer<String> getLocalUidStringEntityReferenceSerializer()
           
 String getName()
          Note that this method is used by Hibernate for saving an element.
 String getPrettyName()
           
 R getReference()
           
 int hashCode()
           
 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)
          Note that this method is used by Hibernate for loading an element.
 void setPrettyName(String name)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.xpn.xwiki.objects.ElementInterface
toString
 

Field Detail

referenceCache

protected R extends EntityReference referenceCache
Full reference of this element.

Since:
3.2M1

localEntityReferenceSerializer

protected EntityReferenceSerializer<String> localEntityReferenceSerializer
Used to convert a proper Document Reference to a string but without the wiki name.

Constructor Detail

BaseElement

public BaseElement()
Method Detail

getReference

public R getReference()
Specified by:
getReference in interface ElementInterface
Returns:
the reference of the element

createReference

protected R createReference()
Since:
3.2M1

getDocumentReference

public DocumentReference getDocumentReference()
Specified by:
getDocumentReference in interface ElementInterface
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 interface ElementInterface
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 interface ElementInterface

setName

public void setName(String name)
Note that this method is used by Hibernate for loading an element.

Specified by:
setName in interface ElementInterface
See Also:
ElementInterface.setName(java.lang.String)

getPrettyName

public String getPrettyName()

setPrettyName

public void setPrettyName(String name)

getLocalUidStringEntityReferenceSerializer

protected EntityReferenceSerializer<String> getLocalUidStringEntityReferenceSerializer()
Returns:
return the LocalUidStringEntityReferenceSerializer to compute ids.
Since:
4.0M1

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 in getLocalKey().

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object el)
Overrides:
equals in class Object

clone

public BaseElement clone()
Overrides:
clone in class Object

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 interface ElementInterface
Parameters:
previousElement - the previous version of the element
newElement - the next version of the element
configuration - the configuration of the merge Indicate how to deal with some conflicts use cases, etc.
context - the XWiki context
mergeResult - the merge report

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 interface ElementInterface
Parameters:
newElement - the element to apply
clean - 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


Copyright © 2004-2013 XWiki. All Rights Reserved.