📄 remotebusinessobject.java
字号:
package Jt.apps;
import Jt.*;
import Jt.jndi.*;
import Jt.ejb.examples.bmp.*;
//Example of a remote object that implements business logic.
//Interfaces with an Entity Bean via its Local Home
//interface.
public class RemoteBusinessObject extends JtObject {
private static final long serialVersionUID = 1L;
private transient JtJNDIAdapter jndiAdapter = null;
private transient MemberLocalHome memberLocalHome = null;
private boolean realized = false;
private transient MemberLocal memberLocal = null;
private String firstname, lastname;
public static final String FIND = "FIND";
public static final String MODIFY = "MODIFY";
public static final String DELETE = "DELETE";
public static final String DISABLE = "DISABLE";
public static final String CREATE = "CREATE";
public void setFirstname (String newFirstname) {
firstname = newFirstname;
}
public String getFirstname() {
return firstname;
}
public void setLastname (String newLastname) {
lastname = newLastname;
}
public String getLastname() {
return lastname;
}
/**
* Process object messages.
*/
public Object processMessage (Object event) {
String msgid = null;
JtMessage e = (JtMessage) event;
Object content;
if (e == null)
return null;
msgid = (String) e.getMsgId ();
if (msgid == null)
return null;
content = e.getMsgContent(); // email (table key)
// Reset the object exception after each
// operation.
this.setObjException(null);
if (msgid.equals (RemoteBusinessObject.DISABLE)) {
if (!realized) {
realized = true;
realizeObject ();
}
return (disable ((String) content));
}
if (msgid.equals (RemoteBusinessObject.DELETE)) {
if (!realized) {
realized = true;
realizeObject ();
}
return (delete ((String) content));
}
if (msgid.equals (RemoteBusinessObject.CREATE)) {
if (!realized) {
realized = true;
realizeObject ();
}
return (create ((String) content, firstname, lastname));
}
if (msgid.equals (RemoteBusinessObject.FIND)) {
if (!realized) {
realized = true;
realizeObject ();
}
return (find ((String) content));
}
if (msgid.equals (RemoteBusinessObject.MODIFY)) {
if (!realized) {
realized = true;
realizeObject ();
}
return (modify (e));
}
return (super.processMessage (event));
}
private void realizeObject() {
JtFactory factory = new JtFactory (); // Jt Factory
JtMessage msg = new JtMessage (JtJNDIAdapter.JtLOOKUP);
jndiAdapter = (JtJNDIAdapter) factory.createObject (JtJNDIAdapter.JtCLASS_NAME, "jndiAdapter");
msg.setMsgContent ("LocalBMPEntityExample");
memberLocalHome = (MemberLocalHome) factory.sendMessage (jndiAdapter, msg);
//System.out.println ("memberLocalHome:" + memberLocalHome);
}
private Object disable (String email) {
if (find (email) == null) {
return (null);
}
memberLocal.setStatus (-1);
memberLocal.setDirty(true);
return (null);
}
private Object create (String email, String firstname, String lastname) {
String reply = null;
if (memberLocalHome == null) {
handleError ("Local Home Interface is null");
return (null);
}
memberLocal = null;
try {
memberLocal = memberLocalHome.create (email, firstname, lastname);
if (memberLocal == null)
return (null);
reply = "OK";
} catch (Exception ex) {
handleException (ex);
}
return (reply);
}
private Object delete (String email) {
String reply = null;
if (memberLocalHome == null) {
handleError ("Local Home Interface is null");
return (null);
}
memberLocal = null;
try {
memberLocal = memberLocalHome.findByPrimaryKey (email);
if (memberLocal != null)
memberLocal.remove ();
reply = "OK";
} catch (Exception ex) {
handleException (ex);
}
return (reply);
}
public void modifyEJB (JtValueObject valueObject) {
JtMessage msg;
String tmp;
//Object out;
Integer I;
//this.valueObject = valueObject;
if (valueObject == null)
return;
msg = new JtMessage (JtValueObject.JtGET);
msg.setMsgData ("firstname");
tmp = (String) valueObject.processMessage (msg);
if (tmp != null)
memberLocal.setFirstname (tmp);
msg.setMsgData ("lastname");
tmp = (String) valueObject.processMessage (msg);
if (tmp != null)
setLastname (tmp);
msg.setMsgData ("location");
tmp = (String) valueObject.processMessage (msg);
if (tmp != null)
memberLocal.setLocation (tmp);
msg.setMsgData ("comments");
tmp = (String) valueObject.processMessage (msg);
if (tmp != null)
memberLocal.setComments (tmp);
msg.setMsgData ("subject");
tmp = (String) valueObject.processMessage (msg);
if (tmp != null)
memberLocal.setSubject (tmp);
msg.setMsgData ("status");
I = (Integer) valueObject.processMessage (msg);
if (I != null)
memberLocal.setStatus(I.intValue());
msg.setMsgData ("email_flag");
I = (Integer) valueObject.processMessage (msg);
if (I != null)
memberLocal.setEmail_flag(I.intValue());
memberLocal.setDirty(true);
}
private Object modify (JtMessage imsg) {
String reply = null;
String email;
JtValueObject valueObject;
if (imsg == null)
return (null);
email = (String) imsg.getMsgContent ();
valueObject = (JtValueObject) imsg.getMsgData ();
if (email == null || valueObject == null)
return (null);
if (memberLocalHome == null) {
handleError ("Local Home Interface is null");
return (null);
}
memberLocal = null;
try {
memberLocal = memberLocalHome.findByPrimaryKey (email);
if (memberLocal == null)
return (null);
//memberLocal.setValueObject (valueObject);
modifyEJB (valueObject);
reply = "OK";
} catch (Exception ex) {
handleException (ex);
}
return (reply);
}
private Object find (String email) {
JtValueObject member = null;
if (memberLocalHome == null) {
handleError ("find: Local Home Interface is null");
return (null);
}
memberLocal = null;
try {
memberLocal = memberLocalHome.findByPrimaryKey (email);
if (memberLocal == null) {
handleError ("find: findByPrimaryKey failed");
return (null);
}
member = (JtValueObject) memberLocal.getValueObject ();
} catch (javax.ejb.FinderException fe) {
// this exception is expected.
//handleException (fe);
} catch (Exception ex) {
handleException (ex);
}
return (member);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -