Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Design Pattern & UML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 StatelessSessionFactory + Beyond ServiceLocator
lixj0571





发贴: 84
积分: 2
于 2003-03-25 13:10 user profilesend a private message to usersend email to lixj0571search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Applicability
This pattern is applicable when you have a lot of stateless session beans in your application and you want to have a uniform way of accessing them

Participants
* Service interface
- This is a dummy interface which all Specific Services should extend.
* SpecificService interface
- This interface contains the declaration of all the business methods that usually go into a remote/local interface
* SpecificSession interface
- This interface just extends the SpecificService and ( EJBObject OR EJBLocalObject)
* SpecificSessionHome interface
- Just like any other home interface
* SpecificSessionBean class
- Just like any other session bean, implements SessionBean
* ServiceLocator class
- This has static methods getEJBLocalHome()/getEJBHome() [ This one is used to have the ability to cache contexts and home interfaces(). See ServiceLocator Pattern. ]
* StatlessServiceFactory class
- This contains a static method getService() which takes an argument that indicates what service the client is looking for. The argument could be a JNDI name or some other constant, that could ultimately be mapped to a JNDI Name/Class.
* Client
- Client that uses the factory class to locate the service

Implementation
Here's the partial reference implementation for the above participants.

Service
public interface Service {
}

SpecificService
public interface HelloService extends Service {
public void sayHello() throws ...;
public void sayBye() throws ...;
}

SpecificSession
public interface Hello extends HelloService,EJBLocalHome {
}

SpecificSessionBean
public interface HelloBean implements SessionBean {
.. implemenation of methods provided in Hello Service
}

ServiceLocator
public class EJBHomeProvider {
public static EJBLocalHome getEJBLocalHome(String jndiName) {
/*
Logic for creating a Home interface.
Could have cached the context and home interface
*/
}
}

StatelessServiceFactory
public class StatelessServiceFactory {
public static Service getService(String jndiName) {
EJBLocalHome home = EJBHomeProvider.getEJBLocalHome(jndiName);
Hello helloObj= home.create();
return helloObj;
}
}

Client
public class SomeClient {
....
HelloService helloService = (HelloService)StatelessServiceFactory.getService(ServiceConstants.HELLO);
/* Here ServiceConstants could contain the list of all JNDI Names */
}

The above example can be extended to get any specific service. I think this pattern is more applicable with Local Stateless Session Beans and especially when there is excessive usage of many stateless session beans all over the application

Usually entity beans have overloaded create methods. And each type of entity bean could take different number of arugments in their create methods.

Hence it is not possible to completely avoid the invocation of create methods for entity beans.

(OR) even if we find a way to modify the getService method to take dynamic number or arguments in the form of an array or some other datastructure , it creates more confusion and is error prone than the problem it tries to solve.




话题树型展开
人气 标题 作者 字数 发贴时间
5808 StatelessSessionFactory + Beyond ServiceLocator lixj0571 3223 2003-03-25 13:10

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923