KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > interop > testclient > InteropCallback


1 /*
2 * Copyright 1999-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 *
16 */

17 package org.apache.sandesha.interop.testclient;
18
19 import org.apache.sandesha.Constants;
20 import org.apache.sandesha.storage.Callback;
21 import org.apache.sandesha.storage.CallbackData;
22
23 /**
24  * This Callback is used to write the results of various points in the Sandesha engine.
25  *
26  * @author Chamikara Jayalath
27  */

28 public class InteropCallback extends Callback {
29
30     private ResponseWriter writer = null;
31     private boolean testFinished = false;
32
33     public synchronized void setTestFinished(boolean finished) {
34         this.testFinished = finished;
35     }
36
37     public synchronized boolean isTestFinished() {
38         return testFinished;
39     }
40
41     public InteropCallback(ResponseWriter writer) {
42         this.writer = writer;
43     }
44
45     public synchronized void onIncomingMessage(CallbackData result) {
46
47         String JavaDoc action = result.getAction();
48         String JavaDoc msgType = action;
49         if (action != null) {
50             if (action.equals(Constants.WSRM.ACTION_CREATE_SEQUENCE))
51                 msgType = "Create Sequence";
52             else if (action.equals(Constants.WSRM.ACTION_CREATE_SEQUENCE_RESPONSE))
53                 msgType = "Create Sequence Response";
54             else if (action.equals(Constants.WSRM.ACTION_TERMINATE_SEQUENCE))
55                 msgType = "Terminate Sequence";
56             else if (action.equals(Constants.WSRM.SEQUENCE_ACKNOWLEDGEMENT_ACTION))
57                 msgType = "Sequence Acknowledgement";
58         } else {
59             msgType = "";
60
61         }
62
63         String JavaDoc entry = "";
64         if (result.getMessageId() != null && result.getMessageId() != "")
65             entry = "<br /><font color='green' size='2' > Received " + msgType + " Message. ID : " +
66                     result.getMessageId() + "</font>"; // + result.getSequenceId() + " </font>";
67
else
68             entry = "<br /><font color='green' size='2' > Received " + msgType + "</font>";
69
70
71         boolean b = writer.write(entry);
72         if (!b)
73             setTestFinished(true);
74     }
75
76     public synchronized void onOutgoingMessage(CallbackData result) {
77
78         int type = result.getMessageType();
79         String JavaDoc msgType = null;
80
81         if (type == Constants.MSG_TYPE_CREATE_SEQUENCE_REQUEST)
82             msgType = "Create Sequence";
83         else if (type == Constants.MSG_TYPE_CREATE_SEQUENCE_RESPONSE)
84             msgType = "Create Sequence Response";
85         else if (type == Constants.MSG_TYPE_TERMINATE_SEQUENCE)
86             msgType = "Terminate Sequence";
87         else if (type == Constants.MSG_TYPE_ACKNOWLEDGEMENT)
88             msgType = "Sequence Acknowledgement";
89         else if (type == Constants.MSG_TYPE_SERVICE_REQUEST)
90             msgType = "Service Request";
91         else if (type == Constants.MSG_TYPE_SERVICE_RESPONSE)
92             msgType = "Service Response";
93
94         String JavaDoc entry = "";
95         if (result.getMessageId() != null && result.getMessageId() != "")
96             entry = "<br /><font color='blue' size='2' > Sent " + msgType + " Message. ID : " +
97                     result.getMessageId() + "</font>";// + result.getSequenceId() + " </font>";
98
else {
99             entry = "<br /><font color='blue' size='2' > Sent " + msgType + "</font>";
100         }
101
102         boolean b = writer.write(entry);
103         if (!b)
104             setTestFinished(true);
105
106         if (result.getMessageType() == 6)
107             setTestFinished(true);
108
109     }
110
111     public synchronized void onError(Exception JavaDoc exp) {
112         String JavaDoc message = "Error Occured During the Interop Test";
113         if (exp.getMessage() != null) {
114             message = exp.getMessage();
115         }
116         String JavaDoc entry = "<br /><font color='red' size='2' > Error : " + message + "</font>";
117         boolean b = writer.write(entry);
118         if (!b)
119             setTestFinished(true);
120     }
121
122 }
123
Popular Tags