java服务定位器(2)

/**
* 通过IBM内部方式得到EJB的本地home接口
*
* @param jndiHomeName
* @throws ServiceLocatorException
*/
public EJBLocalHome getLocalHomeOnly4IBM(String jndiHomeName)
throws ServiceLocatorException {
EJBLocalHome home = null;

try {
if (handlers.containsKey(jndiHomeName)) {
home = (EJBLocalHome) handlers.get(jndiHomeName);
} else {
home = (EJBLocalHome) context.lookup("local:ejb/"
+ jndiHomeName);
handlers.put(jndiHomeName, home);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return home;
}

/**
* 得到EJB的远程home接口
*
* @param jndiHomeName
* @param className
* @throws ServiceLocatorException
*/
public EJBHome getRemoteHome(String jndiHomeName, Class className)
throws ServiceLocatorException {
EJBHome home = null;
try {
if (handlers.containsKey(jndiHomeName)) {
home = (EJBHome) handlers.get(jndiHomeName);
} else {
Object objref = context.lookup("java:comp/env/" + jndiHomeName);
Object obj = PortableRemoteObject.narrow(objref, className);
home = (EJBHome) obj;
handlers.put(jndiHomeName, home);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}

return home;
}

/**
* 得到队列工厂
*
* @param qConnFactoryName
* @throws ServiceLocatorException
*/
public QueueConnectionFactory getQueueConnectionFactory(
String qConnFactoryName) throws ServiceLocatorException {
QueueConnectionFactory factory = null;
try {
if (handlers.containsKey(qConnFactoryName)) {
factory = (QueueConnectionFactory) handlers
.get(qConnFactoryName);
} else {
factory = (QueueConnectionFactory) context
.lookup(qConnFactoryName);
handlers.put(qConnFactoryName, factory);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return factory;
}

/**
* 得到队列
*
* @param queueName
* @throws ServiceLocatorException
*/
public Queue getQueue(String queueName) throws ServiceLocatorException {
Queue queue = null;
try {
if (handlers.containsKey(queueName)) {
queue = (Queue) handlers.get(queueName);
} else {
queue = (Queue) context.lookup(queueName);
handlers.put(queueName, queue);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}

return queue;
}

你可能感兴趣的:(java,ejb,IBM)