]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/Message.java
6bfe1eaaa7b591c09c8cae49224a7b45aa02b88b
[OpenSRF.git] / src / java / org / opensrf / Message.java
1 package org.opensrf;
2 import org.opensrf.util.*;
3
4
5 public class Message implements OSRFSerializable {
6
7     /** Message types */
8     public static final String REQUEST = "REQUEST";
9     public static final String STATUS = "STATUS";
10     public static final String RESULT = "RESULT";
11     public static final String CONNECT = "CONNECT";
12     public static final String DISCONNECT = "DISCONNECT";
13
14     /** Message ID.  This number is used to relate requests to responses */
15     private int id;
16     /** type of message. */
17     private String type;
18     /** message payload */
19     private Object payload;
20     /** message locale */
21     private String locale;
22
23     /** Create a registry for the osrfMessage object */
24     private static OSRFRegistry registry = 
25         OSRFRegistry.registerObject(
26             "osrfMessage", 
27             OSRFRegistry.WireProtocol.HASH, 
28             new String[] {"threadTrace", "type", "payload", "locale"});
29
30     /**
31      * @param id This message's ID
32      * @param type The type of message
33      */
34     public Message(int id, String type) {
35         setId(id);
36         setString(type);
37     }
38
39     /**
40      * @param id This message's ID
41      * @param type The type of message
42      * @param payload The message payload
43      */
44     public Message(int id, String type, Object payload) {
45         this(id, type);
46         setPayload(payload);
47     }
48
49     /**
50      * @param id This message's ID
51      * @param type The type of message
52      * @param payload The message payload
53      * @param locale The message locale
54      */
55     public Message(int id, String type, Object payload, String locale) {
56         this(id, type, payload);
57         setPayload(payload);
58         setLocale(locale);
59     }
60
61
62     public int getId() {
63         return id;
64     }   
65     public String getType() {
66         return type;
67     }
68     public Object getPayload() {
69         return payload;
70     }
71     public String getLocale() {
72         return locale;
73     }
74     public void setId(int id) {
75         this.id = id;
76     }
77     public void setString(String type) {
78         this.type = type;
79     }
80     public void setPayload(Object p) {
81         payload = p;
82     }
83     public void setLocale(String l) {
84         locale = l;
85     }
86
87     /**
88      * Implements the generic get() API required by OSRFSerializable
89      */
90     public Object get(String field) {
91         if("threadTrace".equals(field))
92             return getId();
93         if("type".equals(field))
94             return getType().toString();
95         if("payload".equals(field))
96             return getPayload();
97         if("locale".equals(field))
98             return getLocale();
99         return null;
100     }
101
102     /**
103      * @return The osrfMessage registry.
104      */
105     public OSRFRegistry getRegistry() {
106         return registry;
107     }
108 }
109
110