KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > handlerflow > HandlerTracker


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.webservice.handlerflow;
23
24 import org.jboss.logging.Logger;
25
26 import javax.xml.rpc.handler.Handler JavaDoc;
27 import java.util.ArrayList JavaDoc;
28
29 public final class HandlerTracker
30 {
31    private static final Logger log = Logger.getLogger(HandlerTracker.class);
32
33    private static ArrayList JavaDoc protocol = new ArrayList JavaDoc();
34
35    // hide constructor
36
private HandlerTracker()
37    {
38    }
39
40    public static String JavaDoc[] getProtocol()
41    {
42       String JavaDoc[] arr = new String JavaDoc[protocol.size()];
43       protocol.toArray(arr);
44       return arr;
45    }
46
47    public static void trackInit(Handler JavaDoc handler)
48    {
49       String JavaDoc hName = handler.getClass().getName();
50       hName = hName.substring(hName.lastIndexOf(".") + 1);
51       String JavaDoc msg = hName + " init " + trackerInfo(handler);
52       protocol.add(msg);
53       log.info(msg);
54    }
55
56    public static void trackDestroy(Handler JavaDoc handler)
57    {
58       String JavaDoc hName = handler.getClass().getName();
59       hName = hName.substring(hName.lastIndexOf(".") + 1);
60       String JavaDoc msg = hName + " destroy " + trackerInfo(handler);
61       protocol.add(msg);
62       log.info(msg);
63    }
64
65    public static void trackHandleRequest(Handler JavaDoc handler)
66    {
67       String JavaDoc hName = handler.getClass().getName();
68       hName = hName.substring(hName.lastIndexOf(".") + 1);
69       String JavaDoc msg = hName + " handleRequest " + trackerInfo(handler);
70       protocol.add(msg);
71       log.info(msg);
72    }
73
74    public static void trackHandleResponse(Handler JavaDoc handler)
75    {
76       String JavaDoc hName = handler.getClass().getName();
77       hName = hName.substring(hName.lastIndexOf(".") + 1);
78       String JavaDoc msg = hName + " handleResponse " + trackerInfo(handler);
79       protocol.add(msg);
80       log.info(msg);
81    }
82
83    public static void trackHandleFault(Handler JavaDoc handler)
84    {
85       String JavaDoc hName = handler.getClass().getName();
86       hName = hName.substring(hName.lastIndexOf(".") + 1);
87       String JavaDoc msg = hName + " handleFault " + trackerInfo(handler);
88       protocol.add(msg);
89       log.info(msg);
90    }
91
92    public static void trackMessage(String JavaDoc msg)
93    {
94       protocol.add(msg);
95       log.info(msg);
96    }
97
98    public static void clear()
99    {
100       protocol.clear();
101       log.info("clear [tracker=" + HandlerTracker.class.hashCode() + "]");
102    }
103
104    private static String JavaDoc trackerInfo(Handler JavaDoc handler)
105    {
106       String JavaDoc hstr = "handler=" + handler.hashCode();
107       String JavaDoc tstr = "tracker=" + HandlerTracker.class.hashCode();
108       return "[" + hstr + "," + tstr + "]";
109    }
110 }
111
Popular Tags