1 /*------------------------------------------------------------------------------
2 Name: EmailConnection.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Handles connection to xmlBlaster with plain emails
6 Author: xmlBlaster@marcelruff.info
7 ------------------------------------------------------------------------------*/
8 package org.xmlBlaster.client.protocol.xmlrpc;
9
10 import org.xmlBlaster.util.Global;
11 import org.xmlBlaster.util.XmlBlasterException;
12 import org.xmlBlaster.util.def.MethodName;
13 import org.xmlBlaster.util.plugin.PluginInfo;
14 import org.xmlBlaster.util.xbformat.I_ProgressListener;
15 import org.xmlBlaster.util.xbformat.MsgInfo;
16 import org.xmlBlaster.util.xbformat.XmlScriptParser;
17 import org.xmlBlaster.util.MsgUnitRaw;
18
19 /**
20 *
21 */
22 public class XmlScriptSerializer {
23
24 private final Global glob;
25 private String secretSessionId = "unknown";
26
27 private I_ProgressListener progressListener; // currently not used.
28
29 private XmlScriptParser parser;
30
31 /**
32 * Called by plugin loader which calls init(Global, PluginInfo) thereafter.
33 */
34 public XmlScriptSerializer(Global glob, PluginInfo pluginInfo) throws XmlBlasterException {
35 this.glob = glob;
36 parser = new XmlScriptParser();
37 parser.init(glob, null, pluginInfo);
38 }
39
40 public void setSecretSessionId(String secretSessionId) {
41 this.secretSessionId = secretSessionId;
42 }
43
44 /**
45 * Login to the server.
46 * <p />
47 * @param connectQos The encrypted connect QoS
48 * @exception XmlBlasterException if login fails
49 */
50 public String getConnect(String connectQos) throws XmlBlasterException {
51 return getLiteral(connectQos, MethodName.CONNECT, MsgInfo.INVOKE_BYTE);
52 }
53
54 /**
55 * Does a logout and removes the callback server.
56 * <p />
57 * @param sessionId The client sessionId
58 */
59 public String getDisconnect(String qos) throws XmlBlasterException {
60 return getLiteral(qos, MethodName.DISCONNECT, MsgInfo.INVOKE_BYTE);
61 }
62
63 /**
64 */
65 public String getSubscribe(String xmlKey_literal, String qos_literal) throws XmlBlasterException {
66 return getLiteral(xmlKey_literal, qos_literal, MethodName.SUBSCRIBE);
67 }
68
69 /**
70 *
71 */
72 public final String getUnSubscribe(String xmlKey_literal, String qos_literal) throws XmlBlasterException {
73 return getLiteral(xmlKey_literal, qos_literal, MethodName.UNSUBSCRIBE);
74 }
75
76 /**
77 *
78 */
79 public String getPublish(MsgUnitRaw msgUnit) throws XmlBlasterException {
80 return getLiteral(msgUnit, MethodName.PUBLISH);
81 }
82
83 /**
84 *
85 */
86 public String getPublishArr(MsgUnitRaw[] msgUnitArr) throws XmlBlasterException {
87 return getLiteral(msgUnitArr, MethodName.PUBLISH_ARR, MsgInfo.INVOKE_BYTE);
88 }
89
90 /**
91 *
92 */
93 public String getPublishOneway(MsgUnitRaw[] msgUnitArr) throws XmlBlasterException {
94 return getLiteral(msgUnitArr, MethodName.PUBLISH_ONEWAY, MsgInfo.INVOKE_BYTE);
95 }
96
97 /**
98 *
99 */
100 public String getErase(String xmlKey_literal, String qos_literal) throws XmlBlasterException {
101 return getLiteral(xmlKey_literal, qos_literal, MethodName.ERASE);
102 }
103
104 /**
105 * Synchronous access a message.
106 * <p />
107 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.get.html">The interface.get requirement</a>
108 */
109 public String getGet(String xmlKey_literal, String qos_literal) throws XmlBlasterException {
110 return getLiteral(xmlKey_literal, qos_literal, MethodName.GET);
111 }
112
113 /**
114 * Check server.
115 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
116 */
117 public String getPing(String qos) throws XmlBlasterException {
118 return getLiteral(qos, MethodName.PING, MsgInfo.INVOKE_BYTE);
119 }
120
121 public String getPingResponse(String qos) throws XmlBlasterException {
122 return getLiteral(qos, MethodName.PING, MsgInfo.RESPONSE_BYTE);
123 }
124
125 public String getUpdateResponse(String ok) throws XmlBlasterException {
126 return getLiteral(ok, MethodName.UPDATE, MsgInfo.RESPONSE_BYTE);
127 }
128
129 public String getUpdateException(String ex) throws XmlBlasterException {
130 return getLiteral(ex, MethodName.UPDATE, MsgInfo.EXCEPTION_BYTE);
131 }
132
133 private String getLiteral(String qos, MethodName methodName, byte typeByte) throws XmlBlasterException {
134 MsgUnitRaw[] msgArr = { new MsgUnitRaw(null, (byte[])null, qos) };
135 return getLiteral(msgArr, methodName, typeByte);
136 }
137
138 private String getLiteral(String key, String qos, MethodName methodName) throws XmlBlasterException {
139 MsgUnitRaw[] msgArr = { new MsgUnitRaw(key, (byte[])null, qos) };
140 return getLiteral(msgArr, methodName, MsgInfo.INVOKE_BYTE);
141 }
142
143 private String getLiteral(MsgUnitRaw[] msgArr, MethodName methodName, byte typeByte) throws XmlBlasterException {
144 MsgInfo msgInfo = new MsgInfo(this.glob, typeByte, methodName, secretSessionId, progressListener);
145 msgInfo.addMessage(msgArr);
146 msgInfo.createRequestId(null);
147 return parser.toLiteral(msgInfo);
148 }
149
150 private String getLiteral(MsgUnitRaw msgUnit, MethodName methodName) throws XmlBlasterException {
151 return getLiteral(new MsgUnitRaw[] { msgUnit }, methodName, MsgInfo.INVOKE_BYTE);
152 }
153
154 }
syntax highlighted by Code2HTML, v. 0.9.1