jtsessionfacadeejb.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 403 行
JAVA
403 行
package Jt.ejb;
import javax.ejb.*;
import java.util.*;
import Jt.*;
/**
* Jt implementation of the J2EE Session Facade pattern.
* Provides an EJB interface to the Jt API. This bean is invoked by
* JtEJBAdapter and JtBusinessDelegate. By using JtEJBAdapter, J2EE
* clients are able to transparently manipulate remote Jt objects.
*
* @ejb:bean type="Stateful"
* name="JtSessionFacade"
* jndi-name="JtSessionFacade"
* display-name="Jt Session Facade"
*/
public class JtSessionFacadeEJB implements SessionBean {
private static final long serialVersionUID = 1L;
private Hashtable sessionTable = new Hashtable ();
private JtFactory factory;
// Implement the methods in the SessionBean interface
public void ejbActivate() {
}
public void ejbRemove() {
}
public void ejbPassivate() {
}
/**
* Sets the session context.
*
* @param ctx session context
*/
public void setSessionContext(SessionContext ctx)
throws javax.ejb.EJBException, java.rmi.RemoteException
{
}
public void ejbCreate () {
}
private String calculateSessionID (Object shadow) {
String sessionID;
// The following should provide an unique session ID.
// It is highly unlikely that two clients will have the same sessionid
// If needed, A stronger mechanism may be used
// This method is being deprecated.
for (;;) {
sessionID = "JtSESSION" + shadow + (new Date()).getTime();
if (sessionTable.get (sessionID) == null)
break;
}
return (sessionID);
}
/**
* Creates an independent session. Each client session is able to manipulate
* Jt objects without interfering with each other. Each session is assigned an
* unique session ID. This method is being deprecated.
*
*
* @ejb.interface-method
*/
public Object createSession ()
throws JtException
{
JtObject shadow;
Object session;
shadow = new JtObject ();
session = calculateSessionID (shadow);
sessionTable.put (session, shadow);
shadow.handleTrace ("JtSessionFacadeEJB.createSession:session:" + session);
return (session);
}
/**
* Removes a session (being deprecated)
*
* @ejb.interface-method
*/
public void removeSession (Object session)
throws JtException
{
JtObject shadow;
if (session == null)
throw new JtException ("JtSessionFacadeEJB.removeSession:invalid session:" + session);
shadow = (JtObject) sessionTable.get (session);
if (shadow == null) {
throw new JtException ("JtSessionFacadeEJB.removeSession:invalid session:" + session);
}
shadow.handleTrace ("JtSessionFacadeEJB.removeSession:session:" + session);
sessionTable.remove (session);
}
/**
* Creates a Jt object within the specified session
*
* @ejb.interface-method
*/
public Object createObject (Object session, Object class_name, Object obj_id)
throws JtException
{
JtFactory shadow;
Object output;
Exception ex;
/*
if (session == null)
throw new JtException ("JtSessionFacadeEJB.createObject:invalid session:" + session);
shadow = (JtObject) sessionTable.get (session);
if (shadow == null) {
throw new JtException ("JtSessionFacadeEJB.createObject:invalid session:" + session);
}
*/
if (factory == null) {
factory = new JtFactory ();
//factory.setLogging (true);
//factory.setLogLevel(JtObject.JtMIN_LOG_LEVEL);
}
shadow = factory;
//shadow.handleTrace ("JtSessionFacadeEJB.createObject:session:" + session);
shadow.setObjException (null);
output = shadow.createObject (class_name, obj_id);
// Check for exceptions
ex = (Exception) shadow.getObjException ();
if (ex != null)
throw new JtException (ex.getMessage ());
if (output == null)
return (null);
return (output.toString());
}
/**
* Removes an object
*
* @ejb.interface-method
*/
public void removeObject (Object session, Object obj_id)
throws JtException
{
JtFactory shadow;
Exception ex;
/*
if (session == null)
throw new JtException ("JtSessionFacadeEJB.removeObject:invalid session:" + session);
shadow = (JtObject) sessionTable.get (session);
if (shadow == null) {
throw new JtException ("JtSessionFacadeEJB.removeObject:invalid session:" + session);
}
shadow.handleTrace ("JtSessionFacadeEJB.removeObject:session:" + session);
*/
if (factory == null)
factory = new JtFactory ();
shadow = factory;
shadow.setObjException (null);
shadow.removeObject (obj_id);
// Check for exceptions
ex = (Exception) shadow.getObjException ();
if (ex != null)
throw new JtException (ex.getMessage ());
}
/**
* Sends a message to an object
*
* @ejb.interface-method
*/
public Object sendMessage (Object session, Object obj_id, Object msg_id)
throws JtException
{
JtFactory shadow;
Object output;
Exception ex;
/*
if (session == null)
throw new JtException ("JtSessionFacadeEJB.sendMessage:invalid session:" + session);
shadow = (JtObject) sessionTable.get (session);
if (shadow == null)
throw new JtException ("JtSessionFacadeEJB.sendMessage:invalid session:" + session);
*/
if (factory == null)
factory = new JtFactory ();
shadow = factory;
shadow.handleTrace ("JtSessionFacadeEJB.sendMessage:this:" + this);
//shadow.handleTrace ("JtSessionFacadeEJB.sendMessage:session:" + session);
shadow.setObjException (null);
output = shadow.sendMessage (obj_id, msg_id);
// Check for exceptions
ex = (Exception) shadow.getValue (obj_id, "objException");
if (ex != null) {
//shadow.handleException(ex);
throw new JtException (ex.getMessage ());
}
ex = (Exception) shadow.getObjException ();
if (ex != null) {
//shadow.handleException(ex);
throw new JtException (ex.getMessage ());
}
return (output);
}
/**
* Gets the value of an attribute
*
* @ejb.interface-method
*/
public Object getValue (Object session, Object obj_id, Object att)
throws JtException
{
JtFactory shadow;
Object output;
Exception ex;
/*
if (session == null)
throw new JtException ("JtSessionFacadeEJB.getValue:invalid session:" + session);
shadow = (JtObject) sessionTable.get (session);
if (shadow == null)
throw new JtException ("JtSessionFacadeEJB.getValue:invalid session:" + session);
shadow.handleTrace ("JtSessionFacadeEJB.getValue:session:" + session);
*/
if (factory == null)
factory = new JtFactory ();
shadow = factory;
shadow.setObjException (null);
output = shadow.getValue (obj_id, att);
ex = (Exception) shadow.getObjException ();
if (ex != null)
throw new JtException (ex.getMessage ());
return (output);
}
/**
* Sets the value of an attribute
*
* @ejb.interface-method
*/
public void setValue (Object session, Object obj_id, Object att, Object value)
throws JtException
{
JtFactory shadow;
Exception ex;
/*
if (session == null)
throw new JtException ("JtSessionFacadeEJB.setValue:invalid session:" + session);
shadow = (JtObject) sessionTable.get (session);
if (shadow == null)
throw new JtException ("JtSessionFacadeEJB.setValue:invalid session:" + session);
shadow.handleTrace ("JtSessionFacadeEJB.setValue:session:" + session);
*/
if (factory == null)
factory = new JtFactory ();
shadow = factory;
shadow.setObjException (null);
shadow.setValue (obj_id, att, value);
ex = (Exception) shadow.getObjException ();
if (ex != null)
throw new JtException (ex.getMessage ());
}
/**
* Defines the log file (debugging purposes only)
* @ejb.interface-method
*/
public void setLogFile(Object session, String newLogFile)
throws JtException
{
JtObject shadow;
if (session == null)
throw new JtException ("JtSessionFacadeEJB.setLogFile:invalid session:" + session);
shadow = (JtObject) sessionTable.get (session);
if (shadow == null) {
shadow = new JtObject ();
sessionTable.put (session, shadow);
}
//shadow.handleTrace ("JtEJB.setLogFile:session:" + session);
shadow.setLogFile (newLogFile);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?