📄 jbpmejbservicelocator.java
字号:
package org.jbpm.ejb;
import java.rmi.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
/**
* fetches the jbpm ejb service objects from a local or remote JNDI repository.
* See also <a href="http://java.sun.com/j2se/1.3/docs/api/javax/naming/Context.html">
* http://java.sun.com/j2se/1.3/docs/api/javax/naming/Context.html</a>
*/
public class JbpmEjbServiceLocator {
private Hashtable environment = null;
public JbpmEjbServiceLocator() {
}
public JbpmEjbServiceLocator( Hashtable environment ) {
this.environment = environment;
}
/**
* retrieves an ExecutionServiceRemote object from a JNDI registry.
* throws EjbDeploymentException when this service locator was not able to return a ExecutionServiceRemote.
*/
public ExecutionServiceRemote getExecutionServiceRemote() throws EjbDeploymentException {
ExecutionServiceRemote executionService = null;
InitialContext initialContext = getInitialContext();
String jndiName = "java/JbpmExecutionService";
try {
Object executionServiceHomeObject = initialContext.lookup( jndiName );
ExecutionServiceRemoteHome executionServiceHome = (ExecutionServiceRemoteHome) PortableRemoteObject.narrow( executionServiceHomeObject, ExecutionServiceRemoteHome.class );
executionService = executionServiceHome.create();
} catch (ClassCastException e) {
e.printStackTrace();
throw new EjbDeploymentException( "couldn't create a ExecutionServiceRemote object : object under jndi-name '" + jndiName + "' was not castable to a ExecutionServiceRemoteHome", e );
} catch (RemoteException e) {
e.printStackTrace();
throw new EjbDeploymentException( "couldn't create a ExecutionServiceRemote object from jndi-name '" + jndiName + "'", e );
} catch (NamingException e) {
e.printStackTrace();
throw new EjbDeploymentException( "couldn't create a ExecutionServiceRemote object : no object was registered with jndi-name '" + jndiName + "'", e );
} catch (CreateException e) {
e.printStackTrace();
throw new EjbDeploymentException( "couldn't create a ExecutionServiceRemote", e );
}
return executionService;
}
/**
* @throws EjbRuntimeException if the executionServiceRemote could not be removed from the container.
*/
public void release( ExecutionServiceRemote executionServiceRemote ) {
try {
executionServiceRemote.remove();
} catch (RemoteException e) {
e.printStackTrace();
throw new EjbRuntimeException( "couldn't remove executionServiceRemote because of a RemoteException", e );
} catch (RemoveException e) {
e.printStackTrace();
throw new EjbRuntimeException( "couldn't remove executionServiceRemote because of a RemoveException", e );
}
}
private InitialContext getInitialContext() throws EjbDeploymentException {
InitialContext initialContext = null;
try {
if ( environment!=null ) {
initialContext = new InitialContext( environment );
} else {
initialContext = new InitialContext();
}
} catch (NamingException e) {
e.printStackTrace();
throw new EjbDeploymentException( "couldn't get the initial context", e );
}
return initialContext;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -