dateservice.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 116 行
JAVA
116 行
/**
* DateService - Class invoked via the Web service adapter and proxy.
* It returns the date & time
*/
package Jt.examples;
import java.util.*;
import Jt.*;
public class DateService extends JtObject {
public static final String JtCLASS_NAME = DateService.class.getName();
private static final long serialVersionUID = 1L;
public static final String GET_DATE = "GET_DATE";
public static final String GET_TIME = "GET_TIME";
public static final String GET_DATE_TIME = "GET_DATE_TIME";
public DateService() {
}
// Process object messages
public Object processMessage (Object event) {
String msgid = null;
JtMessage e = (JtMessage) event;
JtList col;
JtMessage msg;
Date date;
if (e == null)
return null;
msgid = (String) e.getMsgId ();
if (msgid == null)
return null;
//content = e.getMsgContent();
if (msgid.equals (JtObject.JtREMOVE)) {
return (null);
}
// Message1
if (msgid.equals (DateService.GET_DATE)) {
return (new Date ());
//return (dt);
}
if (msgid.equals (DateService.GET_TIME)) {
return (new Long ((new Date ()).getTime ()));
}
if (msgid.equals (DateService.GET_DATE_TIME)) {
col = new JtList ();
date = new Date ();
msg = new JtMessage (JtList.JtADD);
msg.setMsgContent(date);
sendMessage (col, msg);
msg = new JtMessage (JtList.JtADD);
msg.setMsgContent(new Long (date.getTime()));
sendMessage (col, msg);
return (col);
}
return (super.processMessage(event));
//handleError ("DateService.processMessage: invalid message id:" + msgid);
//return (null);
}
// Test program
public static void main(String[] args) {
JtFactory main = new JtFactory ();
JtMessage msg1, msg2;
//Integer count;
msg1 = new JtMessage ();
msg2 = new JtMessage ();
msg1.setMsgId (DateService.GET_DATE);
main.createObject (DateService.JtCLASS_NAME, "template");
// Send JtMessage1
System.out.println (main.sendMessage ("template", msg1));
// Send JtMessage2
main.sendMessage ("template", msg2);
main.removeObject ("template");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?