KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > logging > Trc


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.logging;
59
60 import java.io.PrintWriter JavaDoc;
61 import java.io.StringWriter JavaDoc;
62 import java.util.Collection JavaDoc;
63 import java.util.HashMap JavaDoc;
64 import java.util.Iterator JavaDoc;
65 import java.util.Map JavaDoc;
66 import java.util.StringTokenizer JavaDoc;
67
68 import javax.wsdl.Binding;
69 import javax.wsdl.BindingInput;
70 import javax.wsdl.BindingOperation;
71 import javax.wsdl.BindingOutput;
72 import javax.wsdl.Definition;
73 import javax.wsdl.Operation;
74 import javax.wsdl.Port;
75 import javax.wsdl.PortType;
76 import javax.wsdl.Service;
77
78 import org.apache.commons.logging.Log;
79 import org.apache.commons.logging.LogFactory;
80
81 /**
82  * Trc provides trace support for WSIF and is a wrapper around
83  * commons-logging. It adds value to commons-logging by providing
84  * entry/exit/exception trace; never throwing an exception back
85  * even if asked to trace something really stupid; and tracing
86  * references to large WSDL objects, unless specifically asked to
87  * trace out the entire object. Trc also provides brief() methods
88  * (called from deep() methods) which trace out WSDL objects (and
89  * others) in a consistent and helpful way. The goals of Trc are
90  * to not impact performance if trace is off; to provide a rich
91  * and easy-to-use API for WSIF; to enable creation of trace files
92  * that will help developers to easily diagnose problems in WSIF.
93  *
94  * @author Mark Whitlock <whitlock@apache.org>
95  */

96 public class Trc {
97     private static final String JavaDoc wsifPackageName = "org.apache.wsif";
98     private static Log log = LogFactory.getLog(wsifPackageName+".*");
99     public static boolean ON = log.isDebugEnabled();
100
101     private static Log traceLog = LogFactory.getLog(wsifPackageName+".logging.*");
102     /**
103      * traceTrace means "is trace itself being traced?"
104      */

105     private static boolean traceTrace = false;
106 // private static boolean traceTrace = traceLog.isDebugEnabled();
107

108     private final static String JavaDoc ENTRY = "ENTRY";
109     private final static String JavaDoc EXIT = "EXIT ";
110     private final static String JavaDoc EXCEPTION = "EXCEPTION";
111     private final static String JavaDoc EVENT = "EVENT";
112     
113     /**
114      * Private constructor ensures no one can instantiate this class.
115      */

116     private Trc() {
117         super();
118     }
119     
120     public static boolean isTraceEnabled() {
121         return log.isTraceEnabled();
122     }
123
124     public static boolean isDebugEnabled() {
125         return log.isDebugEnabled();
126     }
127
128     /**
129      * Traces entry into a method with no parameters.
130      */

131     public static void entry(Object JavaDoc that) {
132         try {
133             if (!ON)
134                 return;
135             traceIt(that, ENTRY, false, null);
136         } catch (Exception JavaDoc e) {
137             exceptionInTrace(e);
138         }
139     }
140
141     /**
142      * Traces entry into a method with one parameter.
143      */

144     public static void entry(Object JavaDoc that, Object JavaDoc p1) {
145         try {
146             if (!ON)
147                 return;
148             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1 });
149         } catch (Exception JavaDoc e) {
150             exceptionInTrace(e);
151         }
152     }
153
154     /**
155      * Traces entry into a method with two parameters.
156      */

157     public static void entry(Object JavaDoc that, Object JavaDoc p1, Object JavaDoc p2) {
158         try {
159             if (!ON)
160                 return;
161             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1, p2 });
162         } catch (Exception JavaDoc e) {
163             exceptionInTrace(e);
164         }
165     }
166
167     public static void entry(Object JavaDoc that, Object JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3) {
168         try {
169             if (!ON)
170                 return;
171             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1, p2, p3 });
172         } catch (Exception JavaDoc e) {
173             exceptionInTrace(e);
174         }
175     }
176
177     public static void entry(
178         Object JavaDoc that,
179         Object JavaDoc p1,
180         Object JavaDoc p2,
181         Object JavaDoc p3,
182         Object JavaDoc p4) {
183         try {
184             if (!ON)
185                 return;
186             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1, p2, p3, p4 });
187         } catch (Exception JavaDoc e) {
188             exceptionInTrace(e);
189         }
190     }
191
192     public static void entry(
193         Object JavaDoc that,
194         Object JavaDoc p1,
195         Object JavaDoc p2,
196         Object JavaDoc p3,
197         Object JavaDoc p4,
198         Object JavaDoc p5) {
199         try {
200             if (!ON)
201                 return;
202             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1, p2, p3, p4, p5 });
203         } catch (Exception JavaDoc e) {
204             exceptionInTrace(e);
205         }
206     }
207
208     public static void entry(
209         Object JavaDoc that,
210         Object JavaDoc p1,
211         Object JavaDoc p2,
212         Object JavaDoc p3,
213         Object JavaDoc p4,
214         Object JavaDoc p5,
215         Object JavaDoc p6) {
216         try {
217             if (!ON)
218                 return;
219             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1, p2, p3, p4, p5, p6 });
220         } catch (Exception JavaDoc e) {
221             exceptionInTrace(e);
222         }
223     }
224
225     public static void entry(
226         Object JavaDoc that,
227         Object JavaDoc p1,
228         Object JavaDoc p2,
229         Object JavaDoc p3,
230         Object JavaDoc p4,
231         Object JavaDoc p5,
232         Object JavaDoc p6,
233         Object JavaDoc p7) {
234         try {
235             if (!ON)
236                 return;
237             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1, p2, p3, p4, p5, p6, p7 });
238         } catch (Exception JavaDoc e) {
239             exceptionInTrace(e);
240         }
241     }
242
243     public static void entry(
244         Object JavaDoc that,
245         Object JavaDoc p1,
246         Object JavaDoc p2,
247         Object JavaDoc p3,
248         Object JavaDoc p4,
249         Object JavaDoc p5,
250         Object JavaDoc p6,
251         Object JavaDoc p7,
252         Object JavaDoc p8) {
253         try {
254             if (!ON)
255                 return;
256             traceIt(that, ENTRY, false, new Object JavaDoc[] { p1, p2, p3, p4, p5, p6, p7, p8 });
257         } catch (Exception JavaDoc e) {
258             exceptionInTrace(e);
259         }
260     }
261
262     public static void entry(
263         Object JavaDoc that,
264         Object JavaDoc p1,
265         Object JavaDoc p2,
266         Object JavaDoc p3,
267         Object JavaDoc p4,
268         Object JavaDoc p5,
269         Object JavaDoc p6,
270         Object JavaDoc p7,
271         Object JavaDoc p8,
272         Object JavaDoc p9) {
273         try {
274             if (!ON)
275                 return;
276             traceIt(
277                 that,
278                 ENTRY,
279                 false,
280                 new Object JavaDoc[] {
281                     p1,
282                     p2,
283                     p3,
284                     p4,
285                     p5,
286                     p6,
287                     p7,
288                     p8,
289                     p9 });
290         } catch (Exception JavaDoc e) {
291             exceptionInTrace(e);
292         }
293     }
294
295     public static void entry(
296         Object JavaDoc that,
297         Object JavaDoc p1,
298         Object JavaDoc p2,
299         Object JavaDoc p3,
300         Object JavaDoc p4,
301         Object JavaDoc p5,
302         Object JavaDoc p6,
303         Object JavaDoc p7,
304         Object JavaDoc p8,
305         Object JavaDoc p9,
306         Object JavaDoc p10) {
307         try {
308             if (!ON)
309                 return;
310             traceIt(
311                 that,
312                 ENTRY,
313                 false,
314                 new Object JavaDoc[] {
315                     p1,
316                     p2,
317                     p3,
318                     p4,
319                     p5,
320                     p6,
321                     p7,
322                     p8,
323                     p9,
324                     p10 });
325         } catch (Exception JavaDoc e) {
326             exceptionInTrace(e);
327         }
328     }
329
330     public static void entry(
331         Object JavaDoc that,
332         Object JavaDoc p1,
333         Object JavaDoc p2,
334         Object JavaDoc p3,
335         Object JavaDoc p4,
336         Object JavaDoc p5,
337         Object JavaDoc p6,
338         Object JavaDoc p7,
339         Object JavaDoc p8,
340         Object JavaDoc p9,
341         Object JavaDoc p10,
342         Object JavaDoc p11) {
343         try {
344             if (!ON)
345                 return;
346             traceIt(
347                 that,
348                 ENTRY,
349                 false,
350                 new Object JavaDoc[] {
351                     p1,
352                     p2,
353                     p3,
354                     p4,
355                     p5,
356                     p6,
357                     p7,
358                     p8,
359                     p9,
360                     p10,
361                     p11 });
362         } catch (Exception JavaDoc e) {
363             exceptionInTrace(e);
364         }
365     }
366
367     public static void entry(
368         Object JavaDoc that,
369         Object JavaDoc p1,
370         Object JavaDoc p2,
371         Object JavaDoc p3,
372         Object JavaDoc p4,
373         Object JavaDoc p5,
374         Object JavaDoc p6,
375         Object JavaDoc p7,
376         Object JavaDoc p8,
377         Object JavaDoc p9,
378         Object JavaDoc p10,
379         Object JavaDoc p11,
380         Object JavaDoc p12) {
381         try {
382             if (!ON)
383                 return;
384             traceIt(
385                 that,
386                 ENTRY,
387                 false,
388                 new Object JavaDoc[] {
389                     p1,
390                     p2,
391                     p3,
392                     p4,
393                     p5,
394                     p6,
395                     p7,
396                     p8,
397                     p9,
398                     p10,
399                     p11,
400                     p12 });
401         } catch (Exception JavaDoc e) {
402             exceptionInTrace(e);
403         }
404     }
405
406     public static void entry(
407         Object JavaDoc that,
408         Object JavaDoc p1,
409         Object JavaDoc p2,
410         Object JavaDoc p3,
411         Object JavaDoc p4,
412         Object JavaDoc p5,
413         Object JavaDoc p6,
414         Object JavaDoc p7,
415         Object JavaDoc p8,
416         Object JavaDoc p9,
417         Object JavaDoc p10,
418         Object JavaDoc p11,
419         Object JavaDoc p12,
420         Object JavaDoc p13) {
421         try {
422             if (!ON)
423                 return;
424             traceIt(
425                 that,
426                 ENTRY,
427                 false,
428                 new Object JavaDoc[] {
429                     p1,
430                     p2,
431                     p3,
432                     p4,
433                     p5,
434                     p6,
435                     p7,
436                     p8,
437                     p9,
438                     p10,
439                     p11,
440                     p12,
441                     p13 });
442         } catch (Exception JavaDoc e) {
443             exceptionInTrace(e);
444         }
445     }
446
447     public static void entry(
448         Object JavaDoc that,
449         Object JavaDoc p1,
450         Object JavaDoc p2,
451         Object JavaDoc p3,
452         Object JavaDoc p4,
453         Object JavaDoc p5,
454         Object JavaDoc p6,
455         Object JavaDoc p7,
456         Object JavaDoc p8,
457         Object JavaDoc p9,
458         Object JavaDoc p10,
459         Object JavaDoc p11,
460         Object JavaDoc p12,
461         Object JavaDoc p13,
462         Object JavaDoc p14) {
463         try {
464             if (!ON)
465                 return;
466             traceIt(
467                 that,
468                 ENTRY,
469                 false,
470                 new Object JavaDoc[] {
471                     p1,
472                     p2,
473                     p3,
474                     p4,
475                     p5,
476                     p6,
477                     p7,
478                     p8,
479                     p9,
480                     p10,
481                     p11,
482                     p12,
483                     p13,
484                     p14 });
485         } catch (Exception JavaDoc e) {
486             exceptionInTrace(e);
487         }
488     }
489
490     public static void entry(
491         Object JavaDoc that,
492         Object JavaDoc p1,
493         Object JavaDoc p2,
494         Object JavaDoc p3,
495         Object JavaDoc p4,
496         Object JavaDoc p5,
497         Object JavaDoc p6,
498         Object JavaDoc p7,
499         Object JavaDoc p8,
500         Object JavaDoc p9,
501         Object JavaDoc p10,
502         Object JavaDoc p11,
503         Object JavaDoc p12,
504         Object JavaDoc p13,
505         Object JavaDoc p14,
506         Object JavaDoc p15) {
507         try {
508             if (!ON)
509                 return;
510             traceIt(
511                 that,
512                 ENTRY,
513                 false,
514                 new Object JavaDoc[] {
515                     p1,
516                     p2,
517                     p3,
518                     p4,
519                     p5,
520                     p6,
521                     p7,
522                     p8,
523                     p9,
524                     p10,
525                     p11,
526                     p12,
527                     p13,
528                     p14,
529                     p15 });
530         } catch (Exception JavaDoc e) {
531             exceptionInTrace(e);
532         }
533     }
534
535     public static void entryExpandWsdl(Object JavaDoc that, Object JavaDoc[] parms) {
536         try {
537             if (!ON)
538                 return;
539             traceIt(that,ENTRY,true,parms);
540         } catch (Exception JavaDoc e) {
541             exceptionInTrace(e);
542         }
543     }
544
545     public static void entry(Object JavaDoc that, boolean b) {
546         if (ON)
547             entry(that, new Boolean JavaDoc(b));
548     }
549     public static void entry(Object JavaDoc that, int i) {
550         if (ON)
551             entry(that, new Integer JavaDoc(i));
552     }
553
554     /**
555      * Traces exit from a method.
556      */

557     public static void exit() {
558         try {
559             if (!ON)
560                 return;
561             traceIt(null,EXIT,false,null);
562         } catch (Exception JavaDoc e) {
563             exceptionInTrace(e);
564         }
565     }
566
567     /**
568      * Traces exit from a method that returns a value.
569      */

570     public static void exit(Object JavaDoc returnValue) {
571         try {
572             if (!ON)
573                 return;
574             traceIt(null, EXIT, false, new Object JavaDoc[] { returnValue });
575         } catch (Exception JavaDoc e) {
576             exceptionInTrace(e);
577         }
578     }
579
580     /**
581      * Traces exit from a method that returns a value.
582      */

583     public static void exit(boolean b) {
584         if (ON)
585             exit(new Boolean JavaDoc(b));
586     }
587     public static void exit(int i) {
588         if (ON)
589             exit(new Integer JavaDoc(i));
590     }
591
592     /**
593      * Traces exit from a method that returns a value.
594      */

595     public static void exitExpandWsdl(Object JavaDoc returnValue) {
596         try {
597             if (!ON)
598                 return;
599             traceIt(null, EXIT, true, new Object JavaDoc[] { returnValue });
600         } catch (Exception JavaDoc e) {
601             exceptionInTrace(e);
602         }
603     }
604
605     public static void exception(Throwable JavaDoc exception) {
606         try {
607             if (!ON)
608                 return;
609             log.debug(EXCEPTION, exception);
610         } catch (Exception JavaDoc e) {
611             exceptionInTrace(e);
612         }
613     }
614
615     public static void ignoredException(Throwable JavaDoc exception) {
616         try {
617             if (!ON)
618                 return;
619             traceIt(
620                 null,
621                 "Ignoring expected exception",
622                 false,
623                 new Object JavaDoc[] { exception.toString()});
624         } catch (Exception JavaDoc e) {
625             exceptionInTrace(e);
626         }
627     }
628
629     public static void exceptionInTrace(Exception JavaDoc exception) {
630         try {
631             log.debug("****** Exception in WSIF trace statement ******",exception);
632         } catch (Exception JavaDoc ignored) {
633             // exceptionInTrace(ignored);
634
// Not much else we can do here - we shouldn't call
635
// exceptionInTrace else we may recurse
636
}
637     }
638
639     public static void event(Object JavaDoc that, Object JavaDoc p1) {
640         try {
641             if (!ON)
642                 return;
643             traceIt(that, EVENT, false, new Object JavaDoc[] { p1 });
644         } catch (Exception JavaDoc e) {
645             exceptionInTrace(e);
646         }
647     }
648
649     public static void event(Object JavaDoc that, Object JavaDoc p1, Object JavaDoc p2) {
650         try {
651             if (!ON)
652                 return;
653             traceIt(that, EVENT, false, new Object JavaDoc[] { p1, p2 });
654         } catch (Exception JavaDoc e) {
655             exceptionInTrace(e);
656         }
657     }
658
659     public static void event(Object JavaDoc that, Object JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3) {
660         try {
661             if (!ON)
662                 return;
663             traceIt(that, EVENT, false, new Object JavaDoc[] { p1, p2, p3 });
664         } catch (Exception JavaDoc e) {
665             exceptionInTrace(e);
666         }
667     }
668
669     public static void event(
670         Object JavaDoc that,
671         Object JavaDoc p1,
672         Object JavaDoc p2,
673         Object JavaDoc p3,
674         Object JavaDoc p4) {
675         try {
676             if (!ON)
677                 return;
678             traceIt(that, EVENT, false, new Object JavaDoc[] { p1, p2, p3, p4 });
679         } catch (Exception JavaDoc e) {
680             exceptionInTrace(e);
681         }
682     }
683
684     public static void event(
685         Object JavaDoc that,
686         Object JavaDoc p1,
687         Object JavaDoc p2,
688         Object JavaDoc p3,
689         Object JavaDoc p4,
690         Object JavaDoc p5) {
691         try {
692             if (!ON)
693                 return;
694             traceIt(that, EVENT, false, new Object JavaDoc[] { p1, p2, p3, p4, p5 });
695         } catch (Exception JavaDoc e) {
696             exceptionInTrace(e);
697         }
698     }
699
700     public static void event(
701         Object JavaDoc that,
702         Object JavaDoc p1,
703         Object JavaDoc p2,
704         Object JavaDoc p3,
705         Object JavaDoc p4,
706         Object JavaDoc p5,
707         Object JavaDoc p6) {
708         try {
709             if (!ON)
710                 return;
711             traceIt(
712                 that,
713                 EVENT,
714                 false,
715                 new Object JavaDoc[] { p1, p2, p3, p4, p5, p6 });
716         } catch (Exception JavaDoc e) {
717             exceptionInTrace(e);
718         }
719     }
720
721     public static void event(
722         Object JavaDoc that,
723         Object JavaDoc p1,
724         Object JavaDoc p2,
725         Object JavaDoc p3,
726         Object JavaDoc p4,
727         Object JavaDoc p5,
728         Object JavaDoc p6,
729         Object JavaDoc p7) {
730         try {
731             if (!ON)
732                 return;
733             traceIt(
734                 that,
735                 EVENT,
736                 false,
737                 new Object JavaDoc[] { p1, p2, p3, p4, p5, p6, p7 });
738         } catch (Exception JavaDoc e) {
739             exceptionInTrace(e);
740         }
741     }
742
743     public static void event(
744         Object JavaDoc that,
745         Object JavaDoc p1,
746         Object JavaDoc p2,
747         Object JavaDoc p3,
748         Object JavaDoc p4,
749         Object JavaDoc p5,
750         Object JavaDoc p6,
751         Object JavaDoc p7,
752         Object JavaDoc p8) {
753         try {
754             if (!ON)
755                 return;
756             traceIt(
757                 that,
758                 EVENT,
759                 false,
760                 new Object JavaDoc[] { p1, p2, p3, p4, p5, p6, p7, p8 });
761         } catch (Exception JavaDoc e) {
762             exceptionInTrace(e);
763         }
764     }
765
766     public static void event(
767         Object JavaDoc that,
768         Object JavaDoc p1,
769         Object JavaDoc p2,
770         Object JavaDoc p3,
771         Object JavaDoc p4,
772         Object JavaDoc p5,
773         Object JavaDoc p6,
774         Object JavaDoc p7,
775         Object JavaDoc p8,
776         Object JavaDoc p9) {
777         try {
778             if (!ON)
779                 return;
780             traceIt(
781                 that,
782                 EVENT,
783                 false,
784                 new Object JavaDoc[] { p1, p2, p3, p4, p5, p6, p7, p8, p9 });
785         } catch (Exception JavaDoc e) {
786             exceptionInTrace(e);
787         }
788     }
789
790     public static void event(
791         Object JavaDoc that,
792         Object JavaDoc p1,
793         Object JavaDoc p2,
794         Object JavaDoc p3,
795         Object JavaDoc p4,
796         Object JavaDoc p5,
797         Object JavaDoc p6,
798         Object JavaDoc p7,
799         Object JavaDoc p8,
800         Object JavaDoc p9,
801         Object JavaDoc p10) {
802         try {
803             if (!ON)
804                 return;
805             traceIt(
806                 that,
807                 EVENT,
808                 false,
809                 new Object JavaDoc[] { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10 });
810         } catch (Exception JavaDoc e) {
811             exceptionInTrace(e);
812         }
813     }
814
815     public static String JavaDoc brief(Definition d) {
816         try {
817             if (!ON)
818                 return "";
819             if (d == null)
820                 return "null";
821             if (d.getQName() == null)
822                 return "UNNAMED," + Integer.toHexString(d.hashCode());
823             return d.getQName() + "," + Integer.toHexString(d.hashCode());
824         } catch (Exception JavaDoc e) {
825             exceptionInTrace(e);
826         }
827         return "";
828     }
829
830     public static String JavaDoc brief(PortType pt) {
831         try {
832             if (!ON)
833                 return "";
834             if (pt == null)
835                 return "null";
836             if (pt.getQName() == null)
837                 return "UNNAMED," + Integer.toHexString(pt.hashCode());
838             return pt.getQName() + "," + Integer.toHexString(pt.hashCode());
839         } catch (Exception JavaDoc e) {
840             exceptionInTrace(e);
841         }
842         return "";
843     }
844
845     public static String JavaDoc brief(Service s) {
846         try {
847             if (!ON)
848                 return "";
849             if (s == null)
850                 return "null";
851             if (s.getQName() == null)
852                 return "UNNAMED," + Integer.toHexString(s.hashCode());
853             return s.getQName() + "," + Integer.toHexString(s.hashCode());
854         } catch (Exception JavaDoc e) {
855             exceptionInTrace(e);
856         }
857         return "";
858     }
859
860     public static String JavaDoc brief(Port p) {
861         try {
862             if (!ON)
863                 return "";
864             if (p == null)
865                 return "null";
866             if (p.getName() == null)
867                 return "UNNAMED," + Integer.toHexString(p.hashCode());
868             return p.getName() + "," + Integer.toHexString(p.hashCode());
869         } catch (Exception JavaDoc e) {
870             exceptionInTrace(e);
871         }
872         return "";
873     }
874
875     public static String JavaDoc brief(BindingOperation bo) {
876         try {
877             if (!ON)
878                 return "";
879             if (bo == null)
880                 return "null";
881             if (bo.getName() == null)
882                 return "UNNAMED," + Integer.toHexString(bo.hashCode());
883             return bo.getName() + "," + Integer.toHexString(bo.hashCode());
884         } catch (Exception JavaDoc e) {
885             exceptionInTrace(e);
886         }
887         return "";
888     }
889
890     public static String JavaDoc brief(Operation o) {
891         try {
892             if (!ON)
893                 return "";
894             if (o == null)
895                 return "null";
896             if (o.getName() == null)
897                 return "UNNAMED," + Integer.toHexString(o.hashCode());
898             return o.getName() + "," + Integer.toHexString(o.hashCode());
899         } catch (Exception JavaDoc e) {
900             exceptionInTrace(e);
901         }
902         return "";
903     }
904
905     public static String JavaDoc brief(String JavaDoc name, Collection JavaDoc coll) {
906         try {
907             if (!ON)
908                 return "";
909             if (coll == null)
910                 return name + ":null";
911             if (coll.size() == 0)
912                 return name + ":size(0)";
913             return brief(name,coll.toArray());
914         } catch (Exception JavaDoc e) {
915             exceptionInTrace(e);
916         }
917         return "";
918     }
919
920     public static String JavaDoc brief(String JavaDoc name, Object JavaDoc[] objs) {
921         try {
922             if (!ON)
923                 return "";
924             if (objs == null)
925                 return name + ":null";
926             if (objs.length == 0)
927                 return name + ":size(0)";
928             int i;
929             StringBuffer JavaDoc buff = new StringBuffer JavaDoc("");
930             for (i = 0; i < objs.length; i++) {
931                 String JavaDoc s = (objs[i] == null) ? "null" : objs[i].toString();
932                 buff.append(" ");
933                 buff.append(name);
934                 buff.append("[");
935                 buff.append(i);
936                 buff.append("]:");
937                 buff.append(s);
938             }
939             return buff.toString();
940         } catch (Exception JavaDoc e) {
941             exceptionInTrace(e);
942         }
943         return "";
944     }
945
946     /**
947      * Emulates map.toString() except does a checkWsdl() on all
948      * the elements of the map.
949      */

950     public static String JavaDoc brief(Map JavaDoc map) {
951         try {
952             if (!ON)
953                 return "";
954             if (map == null)
955                 return "<null>";
956             if (map.isEmpty())
957                 return "size(0)";
958
959             StringBuffer JavaDoc result = new StringBuffer JavaDoc("{");
960             boolean first = true;
961             Iterator JavaDoc it = map.keySet().iterator();
962
963             while (it.hasNext()) {
964                 String JavaDoc n = (String JavaDoc) it.next();
965                 Object JavaDoc value = map.get(n);
966                 if (value == null)
967                     value = "<null>";
968                 Object JavaDoc v2 = checkWsdl(value);
969
970                 if (!first)
971                     result.append(", ");
972                 first = false;
973                 result.append(n);
974                 result.append("=");
975                 result.append(v2.toString());
976             }
977
978             result.append("}");
979             return result.toString();
980         } catch (Exception JavaDoc e) {
981             exceptionInTrace(e);
982         }
983         return "";
984     }
985     
986     private static void checkWsdl(Object JavaDoc[] parms) {
987         if (parms == null)
988             return;
989         for (int i = 0; i < parms.length; i++)
990             parms[i] = checkWsdl(parms[i]);
991     }
992
993     private static Object JavaDoc checkWsdl(Object JavaDoc o) {
994         String JavaDoc str = null;
995         boolean found = false;
996
997         if (o instanceof Definition) {
998             found = true;
999             Definition d = (Definition) o;
1000            if (d == null)
1001                str = "definition(NULL)";
1002            else if (d.getQName() == null)
1003                str = "definition(UNNAMED";
1004            else
1005                str = "definition(" + d.getQName();
1006        } else if (o instanceof Service) {
1007            found = true;
1008            Service s = (Service) o;
1009            if (s == null)
1010                str = "service(NULL)";
1011            else if (s.getQName() == null)
1012                str = "service(UNNAMED";
1013            else
1014                str = "service(" + s.getQName();
1015        } else if (o instanceof Port) {
1016            found = true;
1017            Port p = (Port) o;
1018            if (p == null)
1019                str = "port(NULL)";
1020            else if (p.getName() == null)
1021                str = "port(UNNAMED";
1022            else
1023                str = "port(" + p.getName();
1024        } else if (o instanceof PortType) {
1025            found = true;
1026            PortType pt = (PortType) o;
1027            if (pt == null)
1028                str = "portType(NULL)";
1029            else if (pt.getQName() == null)
1030                str = "portType(UNNAMED";
1031            else
1032                str = "portType(" + pt.getQName();
1033        } else if (o instanceof Operation) {
1034            found = true;
1035            Operation op = (Operation) o;
1036            if (op == null)
1037                str = "operation(NULL)";
1038            else if (op.getName() == null)
1039                str = "operation(UNNAMED";
1040            else
1041                str = "operation(" + op.getName();
1042        } else if (o instanceof Binding) {
1043            found = true;
1044            Binding b = (Binding) o;
1045            if (b == null)
1046                str = "binding(NULL)";
1047            else if (b.getQName() == null)
1048                str = "binding(UNNAMED";
1049            else
1050                str = "binding(" + b.getQName();
1051        } else if (o instanceof BindingOperation) {
1052            found = true;
1053            BindingOperation bo = (BindingOperation) o;
1054            if (bo == null)
1055                str = "bindingOperation(NULL)";
1056            else if (bo.getName() == null)
1057                str = "bindingOperation(UNNAMED";
1058            else
1059                str = "bindingOperation(" + bo.getName();
1060        } else if (o instanceof BindingInput) {
1061            found = true;
1062            BindingInput bi = (BindingInput) o;
1063            if (bi == null)
1064                str = "bindingInput(NULL)";
1065            else if (bi.getName() == null)
1066                str = "bindingInput(UNNAMED";
1067            else
1068                str = "bindingInput(" + bi.getName();
1069        } else if (o instanceof BindingOutput) {
1070            found = true;
1071            BindingOutput bo = (BindingOutput) o;
1072            if (bo == null)
1073                str = "bindingOutput(NULL)";
1074            else if (bo.getName() == null)
1075                str = "bindingOutput(UNNAMED";
1076            else
1077                str = "bindingOutput(" + bo.getName();
1078        } else if (o instanceof Map JavaDoc) {
1079            Map JavaDoc map = (Map JavaDoc) o;
1080            HashMap JavaDoc newMap = null;
1081            Iterator JavaDoc it = map.keySet().iterator();
1082            while (it.hasNext()) {
1083                Object JavaDoc key = it.next();
1084                if (key == null)
1085                    continue;
1086                Object JavaDoc value = map.get(key);
1087                if (value == null)
1088                    continue;
1089                Object JavaDoc alt = checkWsdl(value);
1090                if (!value.equals(alt)) {
1091                    if (newMap == null)
1092                        newMap = new HashMap JavaDoc(map);
1093                    newMap.put(key, alt);
1094                }
1095            }
1096            if (newMap != null)
1097                return newMap;
1098            return map;
1099        }
1100
1101        if (!found)
1102            return o;
1103        if (o != null)
1104            str = str + "," + Integer.toHexString(o.hashCode()) + ")";
1105        return str;
1106    }
1107
1108    /**
1109     * This method calculates the name of the WSIF method that is
1110     * being traced. This could be passed as a parameter to the Trc
1111     * call, but making Trc simpler to invoke encourages developers
1112     * to add trace to the code and avoids confusing the code with
1113     * lengthy trace statements. We are able to calculate the method
1114     * name here by parsing a stack trace. This is slow but only happens
1115     * when trace is on. Hopefully this will be a fraction of the
1116     * time it takes to write the trace to disk.
1117     */

1118    private static void appendMethodName(StringBuffer JavaDoc buff) {
1119        Exception JavaDoc e = new Exception JavaDoc();
1120        StringWriter JavaDoc sw = new StringWriter JavaDoc();
1121        PrintWriter JavaDoc pw = new PrintWriter JavaDoc(sw);
1122        e.printStackTrace(pw);
1123        String JavaDoc stack = sw.getBuffer().toString();
1124        
1125        if (traceTrace)
1126            traceLog.debug("TRACE stack=" + stack);
1127
1128        // The next while loop tries to find the method that called
1129
// Trc. The line with the method name will be after the last
1130
// call to Trc.
1131
StringTokenizer JavaDoc st1 =
1132            new StringTokenizer JavaDoc(
1133                stack,
1134                System.getProperty("line.separator", "\n"));
1135        boolean foundWsifLogging = false;
1136        String JavaDoc tok1 = null;
1137        while (st1.hasMoreTokens()) {
1138            tok1 = st1.nextToken();
1139
1140            if (tok1.indexOf(wsifPackageName + ".logging") != -1) {
1141                foundWsifLogging = true;
1142                continue;
1143            }
1144
1145            if (foundWsifLogging)
1146                break;
1147        }
1148        if (traceTrace)
1149            traceLog.debug("TRACE token=" + tok1);
1150
1151        // Now find the first word which contains a (. This should be
1152
// prefixed by the method name. If there isn't a (, which
1153
// is unlikely, use the whole line.
1154
StringTokenizer JavaDoc st2 = new StringTokenizer JavaDoc(tok1);
1155        String JavaDoc tok2 = null;
1156        while (st2.hasMoreTokens()) {
1157            tok2 = st2.nextToken();
1158            if (tok2.indexOf("(") != -1)
1159                break;
1160        }
1161        if (tok2.indexOf("(") == -1)
1162            tok2 = tok1;
1163
1164        // Indent the method name by the number of WSIF calls
1165
// higher up the stack. This improves readability. There
1166
// were various other ways of calculating the indentation
1167
// but this seemed the most reliable (and simplest).
1168
buff.append(" ");
1169        while (st1.hasMoreTokens()) {
1170            if (st1.nextToken().indexOf(wsifPackageName) != -1)
1171                buff.append(" ");
1172        }
1173
1174        // Strip off the (... parameters...). I expect there will
1175
// always be a ( in the token, but this code copes even if
1176
// there isn't.
1177
int idx = tok2.indexOf("(");
1178        if (idx != -1)
1179            tok2 = tok2.substring(0, idx);
1180        if (traceTrace)
1181            traceLog.debug("TRACE token=" + tok2);
1182
1183        // Now strip off the WSIF package name off the front of
1184
// the class name. All WSIF class names are unique, so
1185
// the package name just takes up more space in the trace
1186
// and provides no added value. If Trc was not called from
1187
// WSIF (unlikely) then output the whole
1188
// packagename.classname.methodname.
1189
String JavaDoc result = null;
1190        if (tok2.startsWith(wsifPackageName)) {
1191            StringTokenizer JavaDoc st3 = new StringTokenizer JavaDoc(tok2, ".");
1192            String JavaDoc previous = null;
1193            while (st3.hasMoreTokens()) {
1194                previous = result;
1195                result = st3.nextToken();
1196            }
1197            if (previous != null)
1198                result = previous + "." + result;
1199        } else
1200            result = tok2;
1201
1202        if (traceTrace)
1203            traceLog.debug("TRACE appending result=" + result);
1204        buff.append(result);
1205    }
1206        
1207    private static void traceIt(
1208        Object JavaDoc that,
1209        String JavaDoc type,
1210        boolean expandWsdl,
1211        Object JavaDoc[] parms) {
1212
1213        boolean isEvent = false;
1214        if (EVENT.equals(type))
1215            isEvent = true;
1216
1217        if (!expandWsdl)
1218            checkWsdl(parms);
1219
1220        StringBuffer JavaDoc sb = new StringBuffer JavaDoc(type);
1221        if (isEvent) sb.append(" ");
1222        appendMethodName(sb);
1223
1224        if (that != null) {
1225            sb.append("<");
1226            sb.append(Integer.toHexString(that.hashCode()));
1227            sb.append(">");
1228        }
1229
1230        if (isEvent)
1231            sb.append(" ");
1232        else
1233            sb.append("(");
1234
1235        if (parms != null)
1236            for (int i = 0; i < parms.length; i++) {
1237                if (i != 0 && !isEvent)
1238                    sb.append(", ");
1239                sb.append(parms[i] == null ? "<null>" : parms[i].toString());
1240            }
1241        if (!isEvent)
1242            sb.append(")");
1243
1244        log.debug(sb);
1245    }
1246}
Popular Tags