Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One doubt about PlugIn class

Status
Not open for further replies.

pajarokillo

Programmer
May 3, 2004
30
0
0
ES
Hi, i have a factory class that initialize a connection pool, and i would like to known if is a good idea to create that factory class in the my PlugIn class and to put it in then context application and then i can use it in my action classes, for example

My factory class

public class MyFactoryImpl implements IMyFactory{
public MyFactoryImpl(){
Context initCtx = null;

//lookup my dataSource
initCtx = new InitialContext();
DataSource myDataSource = (DataSource) initCtx.lookup(dsName);

//initialize my connection pool
Pool.init(myDataSource);
}

public ICustomer createCustomer(){
Customer customer = new Customer();
}
}

My PlugIn class

public class MyPlugIn implements PlugIn {
public void init(ActionServlet servlet, ModuleConfig config){

//get the factory class
IMyFactory myFactory= new MyFactoryImpl();

//set the myFactory objetc in the context application
servlet.getServletContext().setAttribute(IConstants.MyFactory,myFactory);
}
}

and my client class

public class Client extends Action{
public execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception{
IMyFactory myFactory = (IMyFactory) getApplicationObject(IConstants.MyFactory);
Customer customer = myFactory.createCustomer();
}

}


It could generate something conflict between users that acces to the factory class?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top