1 using System;
2 //using org.xmlBlaster.client.activex;
3
4 namespace demo
5 {
6 /// <summary>
7 /// Example how to access xmlBlaster using the ActiveX Bridge
8 /// to access the Java client library (Windows only)
9 /// </summary>
10 /// <remarks>
11 /// First you need to create and register the ActiveX Bridge
12 /// with the 'build' command below.
13 /// See: xmlBlaster\src\java\org\xmlBlaster\client\activex
14 /// See: build -DJRE_HOME=C:\PROGRA~1\Java\j2re1.5.0 -DJVM.target=1.4 activex
15 /// </remarks>
16 class HelloWorld3
17 {
18 internal HelloWorld3() {}
19
20 // TODO: Callback events never arrive
21 public string update(object ev)
22 {
23 Console.WriteLine("SUUUCEESS: Got update from xmlBlaster: " + ev.ToString());
24 return "<qos><state id='OK'/></qos>";
25 }
26
27 // TODO: Callback events never arrive
28 public string XmlScriptAccessSource_updateEventHandler(object ev)
29 {
30 Console.WriteLine("SUUUCEESSSSS: Got update from xmlBlaster: " + ev.ToString());
31 return "<qos><state id='OK'/></qos>";
32 }
33
34 internal void runTest()
35 {
36 // See registry:
37 // regedit -> HKEY_CLASSES_ROOT
38 // -> CLSID
39 // -> D824B185-AE3C-11D6-ABF5-00B0D07B8581
40 // -> XmlScriptAccess Bean Control
41 // org.xmlBlaster.client.activex.XmlScriptAccess
42
43 XmlScriptAccess.XmlScriptAccessClass xmlBlaster;
44 xmlBlaster = new XmlScriptAccess.XmlScriptAccessClass();
45 string[] argArr = { "-protocol", "SOCKET"/*,
46 "-trace", "true"*/ };
47 xmlBlaster.initArgs(argArr);
48 //Set obj = xmlBlaster.createPropertiesInstance();
49 //string request = "<xmlBlaster><connect/></xmlBlaster>";
50
51
52 XmlScriptAccess.XmlScriptAccessSource_updateEventHandler myClass1 = new XmlScriptAccess.XmlScriptAccessSource_updateEventHandler(this.update);
53 // Get the type referenced by the specified type handle.
54 Type myClass1Type = Type.GetTypeFromHandle(Type.GetTypeHandle(myClass1));
55 Console.WriteLine("The Names of the Attributes :"+myClass1Type.Attributes);
56
57 //System.Type type = XmlScriptAccess.XmlScriptAccessSource_updateEventHandler();
58 //System.Type type = System.Type.GetType("XmlScriptAccessSource_updateEventHandler"); //UpdateListener");
59 XmlScriptAccess.XmlScriptAccessSource_updateEventHandler.CreateDelegate(
60 myClass1Type, this, "update");
61
62 {
63 string request =
64 "<xmlBlaster>" +
65 " <connect/>" +
66 " <wait delay='1000' />" +
67 " <publish>" +
68 " <key oid='test'><airport name='london' /></key>" +
69 " <content>This is a simple script test</content>" +
70 " <qos/>" +
71 " </publish>" +
72 "</xmlBlaster>";
73 string response = xmlBlaster.sendRequest(request);
74 Console.WriteLine("Got response from xmlBlaster: " + response);
75 }
76 {
77 string request =
78 "<xmlBlaster>" +
79 " <subscribe><key oid='another.topix'></key><qos/></subscribe>" +
80 " <publish>" +
81 " <key oid='another.topix'/>" +
82 " <content>This is a simple script test</content>" +
83 " <qos/>" +
84 " </publish>" +
85 " <wait delay='1000'/>" +
86 "</xmlBlaster>";
87 string response = xmlBlaster.sendRequest(request);
88 Console.WriteLine("Got response from xmlBlaster: " + response);
89 }
90 {
91 string request =
92 "<xmlBlaster>" +
93 " <disconnect/>" +
94 "</xmlBlaster>";
95 string response = xmlBlaster.sendRequest(request);
96 Console.WriteLine("Got response from xmlBlaster: " + response);
97 }
98 }
99
100
101 [STAThread]
102 static void Main(string[] args) {
103 demo.HelloWorld3 hw = new demo.HelloWorld3();
104 hw.runTest();
105 }
106 }
107 }
syntax highlighted by Code2HTML, v. 0.9.1