com.buildforge.services.common.dbo
Class MessageDBO

java.lang.Object
  extended by com.buildforge.services.common.dbo.DBObject
      extended by com.buildforge.services.common.dbo.MessageDBO

public class MessageDBO
extends DBObject

Database information describing an internationalized message. Internationalized messages rely on a Localizer to perform the actual rendering of the message. To set which Localizer should be used, call setLocalizer(Localizer).


Nested Class Summary
static class MessageDBO.Severity
          Identifies the severity of a message.
 
Field Summary
static java.lang.Class<MessageDBO> CLASS
          Reference to this class so we can avoid the expensive ".class" construct.
static java.lang.String[] EMPTY
          Empty array to substitute when a null argument is provided.
static java.lang.String TYPE_KEY
           
 
Constructor Summary
MessageDBO()
           
MessageDBO(MessageDBO.Severity severity, java.lang.String messageKey, java.lang.String... args)
           
 
Method Summary
 MessageDBO fromArray(java.lang.Object[] data)
          Deserialize the database object's settings from a request array.
 java.lang.String[] getArgs()
           
 java.lang.String getDataKey()
           
 int getIndirectionMask()
           
static Localizer getLocalizer()
          Gets the implementation that should be used for localizing messages.
 java.lang.String getMessageKey()
           
 int getProcessId()
           
 MessageDBO.Severity getSeverity()
           
 int getTimestamp()
           
 java.lang.String getType()
           
 java.lang.String getTypeKey()
          Retrieve the key that should be used to look up the display name for a data type.
 int getUserId()
           
static MessageDBO inUse(java.lang.String objectType, java.lang.String objectName, java.lang.String referencingType, java.lang.String referencingName)
           
static MessageDBO inUse(java.lang.String objectType, java.lang.String objectName, java.lang.String referencingType, java.lang.String referencingName, java.lang.String parentType, java.lang.String parentName)
           
 boolean isLive()
          Checks whether or not the object is live.
static MessageDBO message(int indirectionMask, java.lang.String key, java.lang.String... args)
           
static void sanityCheckProcessId(int processId)
           
static void sanityCheckUserId(int userId)
           
 void setArgs(java.util.List<java.lang.String> args)
           
 void setArgs(java.lang.String[] args)
           
 void setDataKey(java.lang.String dataKey)
           
 void setIndirect(int bit)
           
 void setIndirectionMask(int mask)
           
static void setLocalizer(Localizer localizer)
          Sets the implementation that should be used for localizing messages.
 void setMessageKey(java.lang.String messageKey)
           
 void setProcessId(int processId)
           
 void setSeverity(MessageDBO.Severity severity)
           
 void setTimestamp()
           
 void setTimestamp(int timestamp)
           
 void setType(java.lang.String type)
           
 void setUserId(int userId)
           
 java.lang.Object[] toArray()
          Serializes this database object as an array of objects.
 java.lang.String toString()
          Renders the information contained by this internationalized message.
 java.lang.String translate()
          Requests a translated rendering of this message, using the current localizer.
 
Methods inherited from class com.buildforge.services.common.dbo.DBObject
badId, badName, checkDead, checkLive, collision, collision
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_KEY

public static final java.lang.String TYPE_KEY
See Also:
Constant Field Values

CLASS

public static final java.lang.Class<MessageDBO> CLASS
Reference to this class so we can avoid the expensive ".class" construct.


EMPTY

public static final java.lang.String[] EMPTY
Empty array to substitute when a null argument is provided.

Constructor Detail

MessageDBO

public MessageDBO()

MessageDBO

public MessageDBO(MessageDBO.Severity severity,
                  java.lang.String messageKey,
                  java.lang.String... args)
Method Detail

getTypeKey

public java.lang.String getTypeKey()
Description copied from class: DBObject
Retrieve the key that should be used to look up the display name for a data type.

Specified by:
getTypeKey in class DBObject
Returns:
the type key for this object's class

isLive

public boolean isLive()
Description copied from class: DBObject
Checks whether or not the object is live. Note that this is not valid for object types that do not have a unique identifier. Those for which no reasonable implementation exists should always return false.

Specified by:
isLive in class DBObject
Returns:
true iff liveness is a valid concept for this object, and the object is live; otherwise, false is returned.

getLocalizer

public static Localizer getLocalizer()
Gets the implementation that should be used for localizing messages.


setLocalizer

public static void setLocalizer(Localizer localizer)
Sets the implementation that should be used for localizing messages.

Parameters:
localizer - the Localizer to use for rendering translated messages, or null to use Localizer.Generic.

getArgs

public java.lang.String[] getArgs()

getDataKey

public java.lang.String getDataKey()

getIndirectionMask

public int getIndirectionMask()

getMessageKey

public java.lang.String getMessageKey()

getProcessId

public int getProcessId()

getSeverity

public MessageDBO.Severity getSeverity()

getTimestamp

public int getTimestamp()

getType

public java.lang.String getType()

getUserId

public int getUserId()

translate

public java.lang.String translate()
Requests a translated rendering of this message, using the current localizer.

Returns:
the translated message, or null if the

setArgs

public void setArgs(java.lang.String[] args)

setArgs

public void setArgs(java.util.List<java.lang.String> args)

setDataKey

public void setDataKey(java.lang.String dataKey)

setIndirect

public void setIndirect(int bit)

setIndirectionMask

public void setIndirectionMask(int mask)

setMessageKey

public void setMessageKey(java.lang.String messageKey)

setProcessId

public void setProcessId(int processId)

setSeverity

public void setSeverity(MessageDBO.Severity severity)

setTimestamp

public void setTimestamp(int timestamp)

setTimestamp

public void setTimestamp()

setType

public void setType(java.lang.String type)

setUserId

public void setUserId(int userId)

sanityCheckUserId

public static void sanityCheckUserId(int userId)
                              throws APIException
Throws:
APIException

sanityCheckProcessId

public static void sanityCheckProcessId(int processId)
                                 throws APIException
Throws:
APIException

toString

public java.lang.String toString()
Renders the information contained by this internationalized message. This is a rendering of the raw data from this message object as a simple list of its fields and their contents.

For example, an error report that an invalid project ID was specified might render as:
Message[timestamp=1177384261, userId=42, processId=0, severity=ERROR, type=, messageKey=GenericInvalid, args={Project|ID}, indirectionMask=3, dataKey=null]

Clearly, this is not the ideal way to render the message for an end user. The TextFormatter class in the server and the APIClientConnection class in the client both implement the localizer interface, which may be used to render the message for a given locale.

Overrides:
toString in class java.lang.Object

fromArray

public MessageDBO fromArray(java.lang.Object[] data)
                     throws APIException
Description copied from class: DBObject
Deserialize the database object's settings from a request array. This method is used to reconstruct a database object from the array that was created by DBObject.toArray().

Specified by:
fromArray in class DBObject
Parameters:
data - the object list that renders this object
Returns:
this object, for convenience
Throws:
APIException - if there is something wrong with the serialized data that interferes with the reconstruction of the object. The most obvious reason for this would be if the serialized array contains the wrong number of fields or otherwise does not match the serialized form for this type of database object.

toArray

public java.lang.Object[] toArray()
Description copied from class: DBObject
Serializes this database object as an array of objects. As specified in the description for Protocol, all supported protocols transfer database objects in this form.

Specified by:
toArray in class DBObject

inUse

public static MessageDBO inUse(java.lang.String objectType,
                               java.lang.String objectName,
                               java.lang.String referencingType,
                               java.lang.String referencingName,
                               java.lang.String parentType,
                               java.lang.String parentName)

inUse

public static MessageDBO inUse(java.lang.String objectType,
                               java.lang.String objectName,
                               java.lang.String referencingType,
                               java.lang.String referencingName)

message

public static MessageDBO message(int indirectionMask,
                                 java.lang.String key,
                                 java.lang.String... args)