Package org.silverpeas.core.persistence
Class EntityReference<T>
- java.lang.Object
-
- org.silverpeas.core.persistence.EntityReference<T>
-
- Type Parameters:
T
- the type of the entity on which this reference is about.
- Direct Known Subclasses:
CalendarReference
,PublicationNoteReference
,UserReference
,UserSessionReference
public abstract class EntityReference<T> extends Object
A reference to an entity in Silverpeas. An entity is a business object in Silverpeas that is persisted in a data source. Some times, instead of referring a peculiar entity, an object can refer an entity whatever its type; this is why it refers such objects with anEntityReference
instance. The type of the entity referred by a such reference is defined by the type of the reference itself; An entity reference must be concrete and its type carries the type of the entity it is upon. For example, you can implement a reference to a user by naming itUserReference<UserDetail>
.- Author:
- mmoquillon
-
-
Field Summary
Fields Modifier and Type Field Description static String
UNKNOWN_TYPE
-
Constructor Summary
Constructors Constructor Description EntityReference(String id)
Constructs a reference targeting the entity identified by the specified unique identifier.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object anotherReference)
abstract T
getEntity()
Gets the instance of the entity targeted by this reference.String
getId()
Gets the unique identifier of the entity referred by this reference.String
getType()
Gets the name of the entity type referred by this reference.static String
getType(Class aClass)
Extracts automatically the type from aClass
.static String
getType(String classSimpleName)
Extracts automatically the type from a simple name ofClass
.int
hashCode()
-
-
-
Field Detail
-
UNKNOWN_TYPE
public static final String UNKNOWN_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EntityReference
public EntityReference(String id)
Constructs a reference targeting the entity identified by the specified unique identifier.- Parameters:
id
- the unique identifier of the entity to refer.
-
-
Method Detail
-
getId
public final String getId()
Gets the unique identifier of the entity referred by this reference.- Returns:
- the unique identifier of the entity as a String.
-
getType
public final String getType()
Gets the name of the entity type referred by this reference. The name is returned in upper case. The name is different from the class name of both of the reference itself and of the referred entity, so any class name change shouldn't impact the type name here. The type name is in fact derived from the class name of the entity but by removing all extra technical terms in order to keep only the meaningful name of the business object. For example, for the entityUserDetail
, only the termUser
is kept and then set in upper case. Not all technical terms are detected; for instance, only the following technical terms are taken into account: Silverpeas, Detail, Interface, Silver, Content, Full, and Complete.- Returns:
- the meaningful name in upper case of the type of the referred entity.
-
getType
public static String getType(Class aClass)
Extracts automatically the type from aClass
.- Parameters:
aClass
- the class- Returns:
- the meaningful name in upper case of the type of the referred entity.
-
getType
public static String getType(String classSimpleName)
Extracts automatically the type from a simple name ofClass
.- Parameters:
classSimpleName
- the class simple name- Returns:
- the meaningful name in upper case of the type of the referred entity.
-
getEntity
public abstract T getEntity()
Gets the instance of the entity targeted by this reference.- Returns:
- the entity identified by this reference.
-
-