KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > rmi > RmiTrace


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

18 package org.apache.geronimo.interop.rmi;
19
20 import org.apache.geronimo.interop.util.StringUtil;
21
22
23 public class RmiTrace {
24     public static final boolean ENABLED = true;
25     public static final boolean CONNECT = true;
26
27     public RmiTrace() {
28     }
29
30     public static void receive(String JavaDoc host, byte[] data) {
31         dump(formatReceiveHeader(host), data);
32     }
33
34     public static void send(String JavaDoc host, byte[] data) {
35         dump(formatSendHeader(host), data);
36     }
37
38     public static void dump(String JavaDoc header, byte[] data) {
39         traceRmiHeader(header);
40         StringBuffer JavaDoc dataBuffer = new StringBuffer JavaDoc(44);
41         StringBuffer JavaDoc textBuffer = new StringBuffer JavaDoc(20);
42         for (int i = 0; i < data.length; i++) {
43             int d = (data[i] + 0x100) & 0xff;
44             String JavaDoc h = StringUtil.padLeft(Integer.toHexString(d).toUpperCase(), '0', 2);
45             dataBuffer.append(h);
46             if (i % 4 == 3 && i % 20 != 19) {
47                 dataBuffer.append(' ');
48             }
49             char c = (char) d;
50             if (c < 32 || c > 127) {
51                 c = '.';
52             }
53             textBuffer.append(c);
54             if (i % 20 == 19) {
55                 traceRmi(StringUtil.padRight(dataBuffer.toString(), ' ', 44), textBuffer.toString());
56                 dataBuffer.setLength(0);
57                 textBuffer.setLength(0);
58             }
59         }
60         if (dataBuffer.length() != 0) {
61             traceRmi(StringUtil.padRight(dataBuffer.toString(), ' ', 44), textBuffer.toString());
62         }
63     }
64
65     // format methods
66

67     protected static String JavaDoc formatReceiveHeader(String JavaDoc host) {
68         String JavaDoc msg;
69         msg = "RmiTrace.formatReceiveHeader(): host: " + host;
70         return msg;
71     }
72
73     protected static String JavaDoc formatSendHeader(String JavaDoc host) {
74         String JavaDoc msg;
75         msg = "RmiTrace.formatSendHeader(): host: " + host;
76         return msg;
77     }
78
79
80     // log methods
81

82     public static void traceConnect(String JavaDoc endpoint) {
83         System.out.println("RmiTrace.traceConnect(): endpoint: " + endpoint);
84     }
85
86     public static void traceDisconnect(String JavaDoc endpoint) {
87         System.out.println("RmiTrace.traceDisconnect(): endpoint: " + endpoint);
88     }
89
90     protected static void traceRmiHeader(String JavaDoc header) {
91         System.out.println("RmiTrace.traceRmiHeader(): header: " + header);
92     }
93
94     protected static void traceRmi(String JavaDoc data, String JavaDoc text) {
95         System.out.println("RmiTrace.traceRmi(): data: " + data + ", text: " + text);
96     }
97
98 }
99
Popular Tags