All getters/setters etc are in an abstract BaseAction, so all a concrete action
needs to do is:
SearchService searchSvc = getSearchService(possiblyAnSpecifyingParamButUsuallyNot);
To initialize you'd have one or more context listeners (hacked up example):
public class InitializeServices implements ServletContextListener
{
// a static service
// get the database factory
String factoryClassName =
servletContext.getInitParameter(SystemParameters.INIT_DAO_FACTORY_CLASS);
// instantiate the database
DAOFactory daof = AbstractDAOFactory.getDAOFactory(factoryClassName);
// set the connector
daof.setDataSource(SystemParameters.DATASOURCE);
// initialize database search service
SearchService.setDaoFactory((SearchDAOFactory)daof);
// a static lookup service
// set initial context
lookupService = new LookupService(servletContext);
// services can be looked-up at request time or at create
lookupService.locateAll();
sc.setAttribute(AttributeNames.APP_SERVICE_LOCATER, lookupService);
}
The easiest is the static service, the base action just returns a getInstance().
The lookup service would call getService(serviceIdentifier) and return an interface.
The description of the ServiceLocater can be found in Core J2EE Patterns
(Alur,Crupi,Malks) and at
http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html

Rick DeBay

On Wed, 25 Feb 2004 10:56 , Anderson, James H [IT]
<[EMAIL PROTECTED]> sent:

>Could you provide a little more detail?
>
>Thanks,
>
>jim
>
>-----Original Message-----
>From: [EMAIL PROTECTED] [EMAIL PROTECTED]','','','')">[EMAIL PROTECTED]
>Sent: Wednesday, February 25, 2004 10:54 AM
>To: Struts Users Mailing List
>Subject: Re: Common Services across Different Actions.
>
>
>I like to use a ServiceLocater (created and initialized at application
>start)
>exposed through the BaseAction.
>
>Rick DeBay
>
>On Wed, 25 Feb 2004 17:50 , Kommineni, Sateesh \(GE Consumer &
>Industrial\)
>[EMAIL PROTECTED]> sent:
>
>>
>>Hi All,
>>
>>   In our Application we have identified few common Services which we
>are
>planning to develop as reusable components.
>>
>>   The approaches we identified are
>>
>>  1) Representing each service as a Plug-in so that we can initialize
>all the
>Service when the Web App is initialized .
>>
>>  2) Create a BaseAction and have all the resources available in that
>Action
>class . Sub Class all your Custom Actions from the BaseAction.
>>
>>Is there any Other Approach that we are missing here  
>>
>>Thanks a lot
>>Sateesh
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to