`
13594135
  • 浏览: 190325 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

OpenEjb连接工厂

    博客分类:
  • ejb
阅读更多
public class BeanFactory {
	/**
	 * 上下文
	 */
	private static Context context;  
	
     //权限模块ejb接口
	private static com.techqy.bbjy.carve.session.IPermission  permission;
	 /**
	 * 初始化上下文 
	 * @return
	 * @throws NamingException
	 * @create by SZQ at 2009-6-11
	 */
    private static Context loadContext() throws NamingException {
		if (context != null)
			return context;
		synchronized (new byte[0]) {
			if (context != null)
				return context;
			Hashtable<String, String> props = new Hashtable<String, String>();
			
		/*********************远程ejb连接上下文********************
			props.put(Context.INITIAL_CONTEXT_FACTORY,
				 "org.apache.openejb.client.RemoteInitialContextFactory");
			props.put(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201");
		*************************************************************/
		//本地ejb连接上下文
			props.put("java.naming.factory.initial",
					"org.apache.openejb.client.LocalInitialContextFactory");
			context = new InitialContext(props);
		}
		return context;
	}
	/**
	 * 查找本地接口	  
	 * @param name 本地接口名称	 *             
	 * @return   本地接口 
	 * @throws NamingException
	 * @create by SZQ at 2009-6-11
	 */
	public static Object lookup(String name) throws NamingException {
		return loadContext().lookup(name);
	}

	/**
	 * 获取权限本地接口 
	 * @return 权限本地接口
	 * @throws NamingException
	 * @create by SZQ at 2009-6-11
	 */
	public static IPermission getPermissionBean() throws NamingException {
		return (permission != null)? permission
					:(IPermission) lookup("PermissionImplBeanLocal");
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics