|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.boylesoftware.cb2.BLObject
Parent abstract class for Business Level Objects (the BLOs), that are software components in the CB2 architecture that represent various business entities and implement application's business logic.
This class provides API for BLO implementations as a set of protected methods. The public interface of a BLO implementation represents its business interface.
BLManager
,
BLOContainer
,
Serialized FormField Summary | |
protected BLOContainer |
bloc
Deprecated. use getBLOContainer or getBLO
protected methods instead. Exposing this variable makes possible for a
BLO to change it, which is illegal. |
protected org.apache.commons.logging.Log |
log
Log to be used in the BLO's methods. |
Constructor Summary | |
BLObject()
|
Method Summary | |
protected void |
activate()
Restore BLO after it has been recreated from the serialized form. |
protected void |
destroy()
Destroyes the BLO. |
protected ApplicationContext |
getApplicationContext()
Gets application context. |
protected BLObject |
getBLO(java.lang.String bloName)
Gets a BLO from the same or the shared BLO container. |
protected BLOContainer |
getBLOContainer()
Gets BLO container to which this BLO belongs. |
protected DAO |
getDAO()
Gets DAO for the default data source. |
protected DAO |
getDAO(java.lang.String dataSourceName)
Gets DAO for the specified data source. |
protected DAOConfig |
getDAOConfig()
Gets DAO config object for the default data source. |
protected DAOConfig |
getDAOConfig(java.lang.String dataSourceName)
Gets DAO config object for the specified data source. |
java.lang.String |
getDeploymentName()
Gets the BLO's deployment name as specified by name
attribute of the corresponding <blo> element in the
blo-config.xml file. |
protected java.lang.String |
getInitParameter(java.lang.String parameterName)
Gets a BLO initialization parameter. |
BLErrors |
getLastErrors()
Gets errors for the last BLO business method call. |
protected void |
init()
Initializes the BLO. |
protected boolean |
isRollbackOnly()
Checks if the current transaction is marked for rollback only. |
protected void |
setErrors(BLErrors errors)
Sets errors for the last BLO business method call. |
protected void |
setRollbackOnly()
Marks current transaction for rollback only, or does nothing if there is no current transaction. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected transient BLOContainer bloc
getBLOContainer
or getBLO
protected methods instead. Exposing this variable makes possible for a
BLO to change it, which is illegal.
protected transient org.apache.commons.logging.Log log
Constructor Detail |
public BLObject()
Method Detail |
protected void init() throws BLException
Shared BLOs are created and initialized when the BL Manager is
created and initialized, usually during application startup, making
init
methods of shared BLOs an ideal place for application
initialization code.
If init
method of a BLO throws an exception, it cancels
the whole BLO container initialization - BLO container cannot be created
and used unless all BLOs went through their init
methods
successfully.
BLOs are initialized in a transaction - one transaction to call
init
methods of all BLOs in the BLO container. If any of
the BLOs throws an exception, the whole transaction, which includes
anything done in init
methods of other BLOs that has
already been successfully called, gets rolled back.
Note, that BLOs are always initialized in the order their deployment
descriptors appear in the blo-config.xml
file. If one BLO
needs service of another BLO in its init
method, place
the other BLO's deployment descriptor above the deployment descriptor of
the first one in the blo-config.xml
- it will guarantee
that the other BLO will be initialized first.
BLException
- if the BLO cannot be initialized.protected void destroy()
Note, that the Shared BLO Container gets destroyed when the BL
Manager gets destroyed, usually at the application shutdown, making
destroy
methods of shared BLOs an ideal place for code,
which needs to be executed before the application goes down.
No database transaction is created for destroy
methods,
so it is not the best place to perform database operations.
BLOs are always destroyed in the reverse order their
deployment descriptors appear in the blo-config.xml
file
(reverse order from how they are initialized).
protected void activate() throws BLException
restoreUserSession
call. Subclasses
redefine this method to implement any logic specific to such an event.
The default implementation does nothing.
Note, that activation is performed in non-transactional context,
so avoid doing database related operations in activate
method implementations. Also, keep the method implementation short,
because it is called from a synchronized block, which prevents getting
and locking BLO containers for all user sessions in the
application.
BLOs are always activated in the order their deployment descriptors
appear in the blo-config.xml
file (the same order they are
initialized).
BLException
- if the instance cannot be restored. Throwing
exception cancels the whole user session restoration attempt - the
restoreUserSession
method on the BL Manager will throw an
exception to the caller.BLManager.restoreUserSession(java.lang.String, com.boylesoftware.cb2.BLOContainer)
public BLErrors getLastErrors()
BLErrors
object and sets it in the BLO via
setErrors
protected method. Then it returns to the caller
a special, method specific result indicating that there were errors and
the call was not successful. The caller then call
getLastErrors
method on the BLO to find out what were the
errors.
Calling this method resets the internal BLO variable that stores
BLErrors
object after last setErrors
call.
After it has been reset, all subsequent calls to
getLastErrors
will be returning an empty
BLErrors
object until another setErrors
call
sets new BLErrors
.
null
, but an empty errors object if there are no errors.protected final void setErrors(BLErrors errors)
BLErrors
object, sets it in the BLO using this
method, and then returns to the caller a special kind of result, which
tells the caller that there were errors and it should call
getLastErrors
on the BLO to find out what exactly it was.
If there was already a BLErrors
object set by an earlier
call, it is overwritten by this call.
errors
- the errors bundle.protected final java.lang.String getInitParameter(java.lang.String parameterName)
blo-config.xml
file via <init-param>
elements. They can be used to configure the BLO for the particular
application in which it is used, so the BLO implementation can be reused
in other applications with some functional changes.
parameterName
- the init parameter's name as specified by the
<param-name>
element.
null
if no such
init parameter is defined in the BLO's deployment descriptor.protected void setRollbackOnly() throws BLException
BLException
- could not mark current transaction for rollback
only.ApplicationContext.setRollbackOnly()
protected boolean isRollbackOnly() throws BLException
false
if there is no current transaction. This is a
convenience method, which calls application context's appropriate method
internally.
true
if the current transaction is marked for
rollback only.
BLException
- could not get the current transaction's status.ApplicationContext.isRollbackOnly()
protected DAOConfig getDAOConfig(java.lang.String dataSourceName)
<dao-config>
elements in the
blo-config.xml
file and are maintained by the BL Manager -
one for each configured data source.
A BLO may need this object if it wants to create its own custom DAO for some reason, which is supposed to be a rather rare case.
dataSourceName
- name of the data source as specified in the
application context configuration and dataSource
attribute
of the <dao-config>
element.
protected DAOConfig getDAOConfig()
null
if the
default source is not configured.protected DAO getDAO(java.lang.String dataSourceName)
The BL Manager maintains a single DAO instance for each configured
data source. The DAO's are built using DAO config objects created out
of <dao-config>
elements defined in the
blo-config.xml
file. This method allows to get reference to
the appropriate DAO, maintained by the BL Manager, to be used in a BLO's
business method.
dataSourceName
- name of the data source as specified in the
application context configuration and dataSource
attribute
of the <dao-config>
element.
protected DAO getDAO()
null
if the default data
source is not configured.protected final BLOContainer getBLOContainer()
getBLOContainer
method
provides access to the BLO container, which can be used to lookup other
BLOs that belong to the same user session as well as shared BLOs.
The BLO container's state is properly maintained by the BL Manager - there is no need to release the BLO container aquired via this protected method, the reference can be abandoned after it is no longer needed.
protected final BLObject getBLO(java.lang.String bloName)
this.getBLOContainer().getBLO(bloName)
.
bloName
- the BLO's deployment name.
protected final ApplicationContext getApplicationContext()
public final java.lang.String getDeploymentName()
name
attribute of the corresponding <blo>
element in the
blo-config.xml
file. This is the name, under which the BLO
can be looked up in a BLO container.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |