>Both Fortress through the Container interface and Merlin through the Kernel >interface allow external objects to lookup hosted components. For example, >with Fortress, you can get a DefaultContainer and then get a hold on the >ServiceManager.
Do we have a concrete working example in Merlin where we are getting hold of components thru the Kernel interface? I really need something like that esp in a webapp. >Finally, I'd like to plug my own little project, JingDAO >(http://jingdao.sf.net) I was interested in jingdao but couldn't proceed due to lack of more concrete working examples, so for now I decided to proceed with making my DAO Factory a component. Thanks Vikas -----Original Message----- From: Farr, Aaron [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 10, 2004 2:43 PM To: 'Avalon framework users' Subject: RE: Accessing components from Non components > -----Original Message----- > From: Vikas Phonsa [mailto:[EMAIL PROTECTED] > > But what is the typical direction for Non components accessing the > Components. Do you just create regular instances of Component classes and > use those ? Would that defeat any of Avalon's purposes ? Question: How should non-components access components? Answer: Through the container. Reality: There's more than one way to do it. Here are two ways: 1. Direct access to components via the container 2. Mapping components to JNDI lookups Both Fortress through the Container interface and Merlin through the Kernel interface allow external objects to lookup hosted components. For example, with Fortress, you can get a DefaultContainer and then get a hold on the ServiceManager. I prefer to setup the container in a ServletContextListener which isolates the initialization code and then place a copy of the ServiceManager or Kernel or whatever in the ServletContext. You can then access the components as follows: public abstract class ComponentAction extends Action{ protected Object getComponent(String key) throws Exception { ServletContext ctxt = getServlet().getServletContext(); ServiceManager manager = (ServiceManager) ctxt.getAttribute("sm"); return manager.lookup(key); } } MyAction extends ComponentAction { public ActionMapping execute(.....){ BusinessRuleOne brOne = (BusinessRuleOne) getComponent("brOne"); ... } } Note that when all your business rule objects and DAO's are components, the need for a factory and manager classes can disappear completely -- the container IS the factory/manager class. Moreover, using a setup above allows you to change your lookup strategy to something like JNDI: public abstract class ComponentAction extends Action{ protected Object getComponent(String key) throws Exception { InitialContext context = new InitialContext(); return context.lookup(key); } } There was once a component which allowed JNDI exporting via AltRMI of components, so that all you needed to do was look them up via the component name. However, I think the extension is broken at the moment (it won't be hard to update). Finally, I'd like to plug my own little project, JingDAO (http://jingdao.sf.net). It allows you to host Avalon or Pico components and works well in a servlet environment. In this case, the DaoManager IS a component and the DaoContainer can be used by non-components. We just launched a new struts-based application which uses JingDAO and it's performing well. If you have more questions or need more examples, just say so. J. Aaron Farr SONY ELECTRONICS DDP-CIM (724) 696-7653 --------------------------------------------------------------------- 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]
