Download CB2 Framework User Manual
Transcript
2.3. THE BUSINESS LEVEL
39
The application context then creates an instance of org.apache.commons.dbcp.BasicDataSource and
sets all ‘property’ properties on it as on a Java bean thus configuring it.
2.3
The Business Level
The buisness logic of the application is implemented in the BLOs. For our simple address book
application we are going to need just one BLO, but usually many BLOs are created during application
development, each covering its own piece of the business logic. Quite often BLOs are not that isolated
and depend on each other calling each other’s service, communicating. BLO implementations extend
com.boylesoftware.cb2.BLObject abstract class and are provided with an internal service interface
– a number of protected methods supposed to be called from the BLO’s user-defined methods to
access such subsystems as, say, application context or the DAO. Also, there is a number of callback
methods invoked by the framework during the BLO’s life-cycle. Beside those, a BLO implements
custom business methods providing its clients with an API.
We recommend to call BLO classes with noun expressions naming a business entity or service
and suffix the name with “BLO”. Our only BLO class will be AddressBookBLO for the address book
business entity:
package com.boylesoftware.cb2.examples.addressbook;
import com.boylesoftware.cb2.BLObject;
/**
* BLO that represents the address book business entity.
*/
public class AddressBookBLO
extends BLObject {
//...
}
Now we shall discuss various aspects of a BLO implementation. Note, that a complete source
code of AddressBookBLO can be downloaded along with the source code of the Address Book sample
application.
2.3.1
BLO Life-cycle
The business level has a notion of user sessions. In a web-application the framework automatically
keeps the list of BL user sessions synchronized with the servlet container’s sessions, that is whenever
a new HTTP session is created by the servlet engine a corresponding user session is created in the
business level, and whenever an HTTP session dies the corresponding BL user session is destroyed.
Although every HTTP session has a corresponding user session in the BL and the process of maintaining the two types of sessions synchronized is completely automatic, technically they are not the
same – HTTP session is represented by a javax.servlet.http.HttpSession object, is maintained by