Red Hat Web Application Framework 6.1 用户手册

下载
页码 230
112
Chapter 10. Kernel Tutorial
}
m_dataObject = s.retrieve(oid);
if (m_dataObject == null) {
throw new DataObjectNotFoundException
("Could not retrieve a DataObject with " +
"OID = " + oid.toString());
}
initialize();
}
/**
* Constructor. Creates a new DomainObject instance to encapsulate
* a given data object.
*
* @param dataObject The data object to encapsulate in the new domain
* object.
* @see com.arsdigita.persistence.Session#retrieve(String)
**/
public DomainObject(DataObject dataObject) {
m_dataObject = dataObject;
initialize();
}
(2)
/**
* Returns the base data object type for this domain object class.
* Intended to be overridden by subclasses whenever the subclass will
* only work if their primary data object is of a certain base type.
*
* @return The fully qualified name ("modelName.typeName") of the base
* data object type for this domain object class,
* or null if there is no restriction on the data object type for
* the primary data object encapsulated by this class.
**/
protected String getBaseDataObjectType() {
return null;
}
/**
* Called from all of the DomainObject constructors
* to initialize or validate the new domain object or its
* encapsulated data object.
This was introduced in order to
* support efficient validation of the encapsulated data object’s
* type.
If the validation is typically performed in class
* constructors, then redundant validation is performed in
* superclass constructors.
This validation now occurs here.
**/
protected void initialize() {
if (m_dataObject == null) {
throw new RuntimeException
("Cannot create a DomainObject with
(3)
a null data object");
}
String baseTypeName = getBaseDataObjectType();
if (baseTypeName == null) {
return;
}
// ensure data object is instance of baseTypeName
// or a subtype thereof.
ObjectType.verifySubtype(baseTypeName,
m_dataObject.getObjectType());