A SERVICE OF

logo

Chapter 10. Kernel Tutorial 115
* Called from base class constructors (DomainObject constructors).
*/
protected void initialize() {
super.initialize();
if (isNew()) {
String typeName =
getObjectType().getModel().getName() +
"." + getObjectType().getName();
set("objectType", typeName);
}
}
10.2.2. Conventions
1. Everydomain object witha public constructorshould havea public final static String
BASE_DATA_OBJECT_TYPE variable with the value equal to the primary data object type used
by the domain object. The common use for the BASE_DATA_OBJECT_TYPE variable is to con-
struct an OIDfor the data object given its numeric id. For convenience, you can provide a no-arg
constructor that willdispatch tothe object typeconstructor with theBASE_DATA_OBJECT_TYPE
variable.
2. The protected method getBaseDataObjectType is required to provide proper data object
type checking. In the common case, the method returns the BASE_DATA_OBJECT_TYPE vari-
able. The DomainObject initialize method ensures that the data object used to create a
DomainObject is equal to that type or a subtype of the object type returned by this method.
For example, if you try to instantiate an ACSObject with a data object that is not a subtype of
the ACSObjectdata object type, you will get an exception. By default, this method returns null,
which disables the type checking
10.2.3. Examples
10.2.3.1. Creating Messages
By default, a new Message has a MIME type of text/plain, so creating and storing simple text
messages is straightforward:
Party from; Message msg = new Message(from, "the subject", "the body");
msg.save();
To create a message in a different format, like text/html, the API provides a method to set the
MIME type when the Message is created:
Message msg = new Message(from, subject);
msg.setBody("
p this is the body /p ", MessageType.TEXT_HTML);
msg.save();
Finally, a Message can also be instantiated by retrieving it from the database by supplying its unique
ID:
Message msg = new Message(new BigDecimal(1234));