001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 2002 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "WSIF" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 2001, 2002, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.wsif.logging;
059:
060: import java.io.PrintWriter;
061: import java.io.StringWriter;
062: import java.util.Collection;
063: import java.util.HashMap;
064: import java.util.Iterator;
065: import java.util.Map;
066: import java.util.StringTokenizer;
067:
068: import javax.wsdl.Binding;
069: import javax.wsdl.BindingInput;
070: import javax.wsdl.BindingOperation;
071: import javax.wsdl.BindingOutput;
072: import javax.wsdl.Definition;
073: import javax.wsdl.Operation;
074: import javax.wsdl.Port;
075: import javax.wsdl.PortType;
076: import javax.wsdl.Service;
077:
078: import org.apache.commons.logging.Log;
079: import org.apache.commons.logging.LogFactory;
080:
081: /**
082: * Trc provides trace support for WSIF and is a wrapper around
083: * commons-logging. It adds value to commons-logging by providing
084: * entry/exit/exception trace; never throwing an exception back
085: * even if asked to trace something really stupid; and tracing
086: * references to large WSDL objects, unless specifically asked to
087: * trace out the entire object. Trc also provides brief() methods
088: * (called from deep() methods) which trace out WSDL objects (and
089: * others) in a consistent and helpful way. The goals of Trc are
090: * to not impact performance if trace is off; to provide a rich
091: * and easy-to-use API for WSIF; to enable creation of trace files
092: * that will help developers to easily diagnose problems in WSIF.
093: *
094: * @author Mark Whitlock <whitlock@apache.org>
095: */
096: public class Trc {
097: private static final String wsifPackageName = "org.apache.wsif";
098: private static Log log = LogFactory.getLog(wsifPackageName + ".*");
099: public static boolean ON = log.isDebugEnabled();
100:
101: private static Log traceLog = LogFactory.getLog(wsifPackageName
102: + ".logging.*");
103: /**
104: * traceTrace means "is trace itself being traced?"
105: */
106: private static boolean traceTrace = false;
107: // private static boolean traceTrace = traceLog.isDebugEnabled();
108:
109: private final static String ENTRY = "ENTRY";
110: private final static String EXIT = "EXIT ";
111: private final static String EXCEPTION = "EXCEPTION";
112: private final static String EVENT = "EVENT";
113:
114: /**
115: * Private constructor ensures no one can instantiate this class.
116: */
117: private Trc() {
118: super ();
119: }
120:
121: public static boolean isTraceEnabled() {
122: return log.isTraceEnabled();
123: }
124:
125: public static boolean isDebugEnabled() {
126: return log.isDebugEnabled();
127: }
128:
129: /**
130: * Traces entry into a method with no parameters.
131: */
132: public static void entry(Object that) {
133: try {
134: if (!ON)
135: return;
136: traceIt(that, ENTRY, false, null);
137: } catch (Exception e) {
138: exceptionInTrace(e);
139: }
140: }
141:
142: /**
143: * Traces entry into a method with one parameter.
144: */
145: public static void entry(Object that, Object p1) {
146: try {
147: if (!ON)
148: return;
149: traceIt(that, ENTRY, false, new Object[] { p1 });
150: } catch (Exception e) {
151: exceptionInTrace(e);
152: }
153: }
154:
155: /**
156: * Traces entry into a method with two parameters.
157: */
158: public static void entry(Object that, Object p1, Object p2) {
159: try {
160: if (!ON)
161: return;
162: traceIt(that, ENTRY, false, new Object[] { p1, p2 });
163: } catch (Exception e) {
164: exceptionInTrace(e);
165: }
166: }
167:
168: public static void entry(Object that, Object p1, Object p2,
169: Object p3) {
170: try {
171: if (!ON)
172: return;
173: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3 });
174: } catch (Exception e) {
175: exceptionInTrace(e);
176: }
177: }
178:
179: public static void entry(Object that, Object p1, Object p2,
180: Object p3, Object p4) {
181: try {
182: if (!ON)
183: return;
184: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4 });
185: } catch (Exception e) {
186: exceptionInTrace(e);
187: }
188: }
189:
190: public static void entry(Object that, Object p1, Object p2,
191: Object p3, Object p4, Object p5) {
192: try {
193: if (!ON)
194: return;
195: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
196: p5 });
197: } catch (Exception e) {
198: exceptionInTrace(e);
199: }
200: }
201:
202: public static void entry(Object that, Object p1, Object p2,
203: Object p3, Object p4, Object p5, Object p6) {
204: try {
205: if (!ON)
206: return;
207: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
208: p5, p6 });
209: } catch (Exception e) {
210: exceptionInTrace(e);
211: }
212: }
213:
214: public static void entry(Object that, Object p1, Object p2,
215: Object p3, Object p4, Object p5, Object p6, Object p7) {
216: try {
217: if (!ON)
218: return;
219: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
220: p5, p6, p7 });
221: } catch (Exception e) {
222: exceptionInTrace(e);
223: }
224: }
225:
226: public static void entry(Object that, Object p1, Object p2,
227: Object p3, Object p4, Object p5, Object p6, Object p7,
228: Object p8) {
229: try {
230: if (!ON)
231: return;
232: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
233: p5, p6, p7, p8 });
234: } catch (Exception e) {
235: exceptionInTrace(e);
236: }
237: }
238:
239: public static void entry(Object that, Object p1, Object p2,
240: Object p3, Object p4, Object p5, Object p6, Object p7,
241: Object p8, Object p9) {
242: try {
243: if (!ON)
244: return;
245: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
246: p5, p6, p7, p8, p9 });
247: } catch (Exception e) {
248: exceptionInTrace(e);
249: }
250: }
251:
252: public static void entry(Object that, Object p1, Object p2,
253: Object p3, Object p4, Object p5, Object p6, Object p7,
254: Object p8, Object p9, Object p10) {
255: try {
256: if (!ON)
257: return;
258: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
259: p5, p6, p7, p8, p9, p10 });
260: } catch (Exception e) {
261: exceptionInTrace(e);
262: }
263: }
264:
265: public static void entry(Object that, Object p1, Object p2,
266: Object p3, Object p4, Object p5, Object p6, Object p7,
267: Object p8, Object p9, Object p10, Object p11) {
268: try {
269: if (!ON)
270: return;
271: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
272: p5, p6, p7, p8, p9, p10, p11 });
273: } catch (Exception e) {
274: exceptionInTrace(e);
275: }
276: }
277:
278: public static void entry(Object that, Object p1, Object p2,
279: Object p3, Object p4, Object p5, Object p6, Object p7,
280: Object p8, Object p9, Object p10, Object p11, Object p12) {
281: try {
282: if (!ON)
283: return;
284: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
285: p5, p6, p7, p8, p9, p10, p11, p12 });
286: } catch (Exception e) {
287: exceptionInTrace(e);
288: }
289: }
290:
291: public static void entry(Object that, Object p1, Object p2,
292: Object p3, Object p4, Object p5, Object p6, Object p7,
293: Object p8, Object p9, Object p10, Object p11, Object p12,
294: Object p13) {
295: try {
296: if (!ON)
297: return;
298: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
299: p5, p6, p7, p8, p9, p10, p11, p12, p13 });
300: } catch (Exception e) {
301: exceptionInTrace(e);
302: }
303: }
304:
305: public static void entry(Object that, Object p1, Object p2,
306: Object p3, Object p4, Object p5, Object p6, Object p7,
307: Object p8, Object p9, Object p10, Object p11, Object p12,
308: Object p13, Object p14) {
309: try {
310: if (!ON)
311: return;
312: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
313: p5, p6, p7, p8, p9, p10, p11, p12, p13, p14 });
314: } catch (Exception e) {
315: exceptionInTrace(e);
316: }
317: }
318:
319: public static void entry(Object that, Object p1, Object p2,
320: Object p3, Object p4, Object p5, Object p6, Object p7,
321: Object p8, Object p9, Object p10, Object p11, Object p12,
322: Object p13, Object p14, Object p15) {
323: try {
324: if (!ON)
325: return;
326: traceIt(that, ENTRY, false, new Object[] { p1, p2, p3, p4,
327: p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15 });
328: } catch (Exception e) {
329: exceptionInTrace(e);
330: }
331: }
332:
333: public static void entryExpandWsdl(Object that, Object[] parms) {
334: try {
335: if (!ON)
336: return;
337: traceIt(that, ENTRY, true, parms);
338: } catch (Exception e) {
339: exceptionInTrace(e);
340: }
341: }
342:
343: public static void entry(Object that, boolean b) {
344: if (ON)
345: entry(that, new Boolean(b));
346: }
347:
348: public static void entry(Object that, int i) {
349: if (ON)
350: entry(that, new Integer(i));
351: }
352:
353: /**
354: * Traces exit from a method.
355: */
356: public static void exit() {
357: try {
358: if (!ON)
359: return;
360: traceIt(null, EXIT, false, null);
361: } catch (Exception e) {
362: exceptionInTrace(e);
363: }
364: }
365:
366: /**
367: * Traces exit from a method that returns a value.
368: */
369: public static void exit(Object returnValue) {
370: try {
371: if (!ON)
372: return;
373: traceIt(null, EXIT, false, new Object[] { returnValue });
374: } catch (Exception e) {
375: exceptionInTrace(e);
376: }
377: }
378:
379: /**
380: * Traces exit from a method that returns a value.
381: */
382: public static void exit(boolean b) {
383: if (ON)
384: exit(new Boolean(b));
385: }
386:
387: public static void exit(int i) {
388: if (ON)
389: exit(new Integer(i));
390: }
391:
392: /**
393: * Traces exit from a method that returns a value.
394: */
395: public static void exitExpandWsdl(Object returnValue) {
396: try {
397: if (!ON)
398: return;
399: traceIt(null, EXIT, true, new Object[] { returnValue });
400: } catch (Exception e) {
401: exceptionInTrace(e);
402: }
403: }
404:
405: public static void exception(Throwable exception) {
406: try {
407: if (!ON)
408: return;
409: log.debug(EXCEPTION, exception);
410: } catch (Exception e) {
411: exceptionInTrace(e);
412: }
413: }
414:
415: public static void ignoredException(Throwable exception) {
416: try {
417: if (!ON)
418: return;
419: traceIt(null, "Ignoring expected exception", false,
420: new Object[] { exception.toString() });
421: } catch (Exception e) {
422: exceptionInTrace(e);
423: }
424: }
425:
426: public static void exceptionInTrace(Exception exception) {
427: try {
428: log.debug(
429: "****** Exception in WSIF trace statement ******",
430: exception);
431: } catch (Exception ignored) {
432: // exceptionInTrace(ignored);
433: // Not much else we can do here - we shouldn't call
434: // exceptionInTrace else we may recurse
435: }
436: }
437:
438: public static void event(Object that, Object p1) {
439: try {
440: if (!ON)
441: return;
442: traceIt(that, EVENT, false, new Object[] { p1 });
443: } catch (Exception e) {
444: exceptionInTrace(e);
445: }
446: }
447:
448: public static void event(Object that, Object p1, Object p2) {
449: try {
450: if (!ON)
451: return;
452: traceIt(that, EVENT, false, new Object[] { p1, p2 });
453: } catch (Exception e) {
454: exceptionInTrace(e);
455: }
456: }
457:
458: public static void event(Object that, Object p1, Object p2,
459: Object p3) {
460: try {
461: if (!ON)
462: return;
463: traceIt(that, EVENT, false, new Object[] { p1, p2, p3 });
464: } catch (Exception e) {
465: exceptionInTrace(e);
466: }
467: }
468:
469: public static void event(Object that, Object p1, Object p2,
470: Object p3, Object p4) {
471: try {
472: if (!ON)
473: return;
474: traceIt(that, EVENT, false, new Object[] { p1, p2, p3, p4 });
475: } catch (Exception e) {
476: exceptionInTrace(e);
477: }
478: }
479:
480: public static void event(Object that, Object p1, Object p2,
481: Object p3, Object p4, Object p5) {
482: try {
483: if (!ON)
484: return;
485: traceIt(that, EVENT, false, new Object[] { p1, p2, p3, p4,
486: p5 });
487: } catch (Exception e) {
488: exceptionInTrace(e);
489: }
490: }
491:
492: public static void event(Object that, Object p1, Object p2,
493: Object p3, Object p4, Object p5, Object p6) {
494: try {
495: if (!ON)
496: return;
497: traceIt(that, EVENT, false, new Object[] { p1, p2, p3, p4,
498: p5, p6 });
499: } catch (Exception e) {
500: exceptionInTrace(e);
501: }
502: }
503:
504: public static void event(Object that, Object p1, Object p2,
505: Object p3, Object p4, Object p5, Object p6, Object p7) {
506: try {
507: if (!ON)
508: return;
509: traceIt(that, EVENT, false, new Object[] { p1, p2, p3, p4,
510: p5, p6, p7 });
511: } catch (Exception e) {
512: exceptionInTrace(e);
513: }
514: }
515:
516: public static void event(Object that, Object p1, Object p2,
517: Object p3, Object p4, Object p5, Object p6, Object p7,
518: Object p8) {
519: try {
520: if (!ON)
521: return;
522: traceIt(that, EVENT, false, new Object[] { p1, p2, p3, p4,
523: p5, p6, p7, p8 });
524: } catch (Exception e) {
525: exceptionInTrace(e);
526: }
527: }
528:
529: public static void event(Object that, Object p1, Object p2,
530: Object p3, Object p4, Object p5, Object p6, Object p7,
531: Object p8, Object p9) {
532: try {
533: if (!ON)
534: return;
535: traceIt(that, EVENT, false, new Object[] { p1, p2, p3, p4,
536: p5, p6, p7, p8, p9 });
537: } catch (Exception e) {
538: exceptionInTrace(e);
539: }
540: }
541:
542: public static void event(Object that, Object p1, Object p2,
543: Object p3, Object p4, Object p5, Object p6, Object p7,
544: Object p8, Object p9, Object p10) {
545: try {
546: if (!ON)
547: return;
548: traceIt(that, EVENT, false, new Object[] { p1, p2, p3, p4,
549: p5, p6, p7, p8, p9, p10 });
550: } catch (Exception e) {
551: exceptionInTrace(e);
552: }
553: }
554:
555: public static String brief(Definition d) {
556: try {
557: if (!ON)
558: return "";
559: if (d == null)
560: return "null";
561: if (d.getQName() == null)
562: return "UNNAMED," + Integer.toHexString(d.hashCode());
563: return d.getQName() + ","
564: + Integer.toHexString(d.hashCode());
565: } catch (Exception e) {
566: exceptionInTrace(e);
567: }
568: return "";
569: }
570:
571: public static String brief(PortType pt) {
572: try {
573: if (!ON)
574: return "";
575: if (pt == null)
576: return "null";
577: if (pt.getQName() == null)
578: return "UNNAMED," + Integer.toHexString(pt.hashCode());
579: return pt.getQName() + ","
580: + Integer.toHexString(pt.hashCode());
581: } catch (Exception e) {
582: exceptionInTrace(e);
583: }
584: return "";
585: }
586:
587: public static String brief(Service s) {
588: try {
589: if (!ON)
590: return "";
591: if (s == null)
592: return "null";
593: if (s.getQName() == null)
594: return "UNNAMED," + Integer.toHexString(s.hashCode());
595: return s.getQName() + ","
596: + Integer.toHexString(s.hashCode());
597: } catch (Exception e) {
598: exceptionInTrace(e);
599: }
600: return "";
601: }
602:
603: public static String brief(Port p) {
604: try {
605: if (!ON)
606: return "";
607: if (p == null)
608: return "null";
609: if (p.getName() == null)
610: return "UNNAMED," + Integer.toHexString(p.hashCode());
611: return p.getName() + ","
612: + Integer.toHexString(p.hashCode());
613: } catch (Exception e) {
614: exceptionInTrace(e);
615: }
616: return "";
617: }
618:
619: public static String brief(BindingOperation bo) {
620: try {
621: if (!ON)
622: return "";
623: if (bo == null)
624: return "null";
625: if (bo.getName() == null)
626: return "UNNAMED," + Integer.toHexString(bo.hashCode());
627: return bo.getName() + ","
628: + Integer.toHexString(bo.hashCode());
629: } catch (Exception e) {
630: exceptionInTrace(e);
631: }
632: return "";
633: }
634:
635: public static String brief(Operation o) {
636: try {
637: if (!ON)
638: return "";
639: if (o == null)
640: return "null";
641: if (o.getName() == null)
642: return "UNNAMED," + Integer.toHexString(o.hashCode());
643: return o.getName() + ","
644: + Integer.toHexString(o.hashCode());
645: } catch (Exception e) {
646: exceptionInTrace(e);
647: }
648: return "";
649: }
650:
651: public static String brief(String name, Collection coll) {
652: try {
653: if (!ON)
654: return "";
655: if (coll == null)
656: return name + ":null";
657: if (coll.size() == 0)
658: return name + ":size(0)";
659: return brief(name, coll.toArray());
660: } catch (Exception e) {
661: exceptionInTrace(e);
662: }
663: return "";
664: }
665:
666: public static String brief(String name, Object[] objs) {
667: try {
668: if (!ON)
669: return "";
670: if (objs == null)
671: return name + ":null";
672: if (objs.length == 0)
673: return name + ":size(0)";
674: int i;
675: StringBuffer buff = new StringBuffer("");
676: for (i = 0; i < objs.length; i++) {
677: String s = (objs[i] == null) ? "null" : objs[i]
678: .toString();
679: buff.append(" ");
680: buff.append(name);
681: buff.append("[");
682: buff.append(i);
683: buff.append("]:");
684: buff.append(s);
685: }
686: return buff.toString();
687: } catch (Exception e) {
688: exceptionInTrace(e);
689: }
690: return "";
691: }
692:
693: /**
694: * Emulates map.toString() except does a checkWsdl() on all
695: * the elements of the map.
696: */
697: public static String brief(Map map) {
698: try {
699: if (!ON)
700: return "";
701: if (map == null)
702: return "<null>";
703: if (map.isEmpty())
704: return "size(0)";
705:
706: StringBuffer result = new StringBuffer("{");
707: boolean first = true;
708: Iterator it = map.keySet().iterator();
709:
710: while (it.hasNext()) {
711: String n = (String) it.next();
712: Object value = map.get(n);
713: if (value == null)
714: value = "<null>";
715: Object v2 = checkWsdl(value);
716:
717: if (!first)
718: result.append(", ");
719: first = false;
720: result.append(n);
721: result.append("=");
722: result.append(v2.toString());
723: }
724:
725: result.append("}");
726: return result.toString();
727: } catch (Exception e) {
728: exceptionInTrace(e);
729: }
730: return "";
731: }
732:
733: private static void checkWsdl(Object[] parms) {
734: if (parms == null)
735: return;
736: for (int i = 0; i < parms.length; i++)
737: parms[i] = checkWsdl(parms[i]);
738: }
739:
740: private static Object checkWsdl(Object o) {
741: String str = null;
742: boolean found = false;
743:
744: if (o instanceof Definition) {
745: found = true;
746: Definition d = (Definition) o;
747: if (d == null)
748: str = "definition(NULL)";
749: else if (d.getQName() == null)
750: str = "definition(UNNAMED";
751: else
752: str = "definition(" + d.getQName();
753: } else if (o instanceof Service) {
754: found = true;
755: Service s = (Service) o;
756: if (s == null)
757: str = "service(NULL)";
758: else if (s.getQName() == null)
759: str = "service(UNNAMED";
760: else
761: str = "service(" + s.getQName();
762: } else if (o instanceof Port) {
763: found = true;
764: Port p = (Port) o;
765: if (p == null)
766: str = "port(NULL)";
767: else if (p.getName() == null)
768: str = "port(UNNAMED";
769: else
770: str = "port(" + p.getName();
771: } else if (o instanceof PortType) {
772: found = true;
773: PortType pt = (PortType) o;
774: if (pt == null)
775: str = "portType(NULL)";
776: else if (pt.getQName() == null)
777: str = "portType(UNNAMED";
778: else
779: str = "portType(" + pt.getQName();
780: } else if (o instanceof Operation) {
781: found = true;
782: Operation op = (Operation) o;
783: if (op == null)
784: str = "operation(NULL)";
785: else if (op.getName() == null)
786: str = "operation(UNNAMED";
787: else
788: str = "operation(" + op.getName();
789: } else if (o instanceof Binding) {
790: found = true;
791: Binding b = (Binding) o;
792: if (b == null)
793: str = "binding(NULL)";
794: else if (b.getQName() == null)
795: str = "binding(UNNAMED";
796: else
797: str = "binding(" + b.getQName();
798: } else if (o instanceof BindingOperation) {
799: found = true;
800: BindingOperation bo = (BindingOperation) o;
801: if (bo == null)
802: str = "bindingOperation(NULL)";
803: else if (bo.getName() == null)
804: str = "bindingOperation(UNNAMED";
805: else
806: str = "bindingOperation(" + bo.getName();
807: } else if (o instanceof BindingInput) {
808: found = true;
809: BindingInput bi = (BindingInput) o;
810: if (bi == null)
811: str = "bindingInput(NULL)";
812: else if (bi.getName() == null)
813: str = "bindingInput(UNNAMED";
814: else
815: str = "bindingInput(" + bi.getName();
816: } else if (o instanceof BindingOutput) {
817: found = true;
818: BindingOutput bo = (BindingOutput) o;
819: if (bo == null)
820: str = "bindingOutput(NULL)";
821: else if (bo.getName() == null)
822: str = "bindingOutput(UNNAMED";
823: else
824: str = "bindingOutput(" + bo.getName();
825: } else if (o instanceof Map) {
826: Map map = (Map) o;
827: HashMap newMap = null;
828: Iterator it = map.keySet().iterator();
829: while (it.hasNext()) {
830: Object key = it.next();
831: if (key == null)
832: continue;
833: Object value = map.get(key);
834: if (value == null)
835: continue;
836: Object alt = checkWsdl(value);
837: if (!value.equals(alt)) {
838: if (newMap == null)
839: newMap = new HashMap(map);
840: newMap.put(key, alt);
841: }
842: }
843: if (newMap != null)
844: return newMap;
845: return map;
846: }
847:
848: if (!found)
849: return o;
850: if (o != null)
851: str = str + "," + Integer.toHexString(o.hashCode()) + ")";
852: return str;
853: }
854:
855: /**
856: * This method calculates the name of the WSIF method that is
857: * being traced. This could be passed as a parameter to the Trc
858: * call, but making Trc simpler to invoke encourages developers
859: * to add trace to the code and avoids confusing the code with
860: * lengthy trace statements. We are able to calculate the method
861: * name here by parsing a stack trace. This is slow but only happens
862: * when trace is on. Hopefully this will be a fraction of the
863: * time it takes to write the trace to disk.
864: */
865: private static void appendMethodName(StringBuffer buff) {
866: Exception e = new Exception();
867: StringWriter sw = new StringWriter();
868: PrintWriter pw = new PrintWriter(sw);
869: e.printStackTrace(pw);
870: String stack = sw.getBuffer().toString();
871:
872: if (traceTrace)
873: traceLog.debug("TRACE stack=" + stack);
874:
875: // The next while loop tries to find the method that called
876: // Trc. The line with the method name will be after the last
877: // call to Trc.
878: StringTokenizer st1 = new StringTokenizer(stack, System
879: .getProperty("line.separator", "\n"));
880: boolean foundWsifLogging = false;
881: String tok1 = null;
882: while (st1.hasMoreTokens()) {
883: tok1 = st1.nextToken();
884:
885: if (tok1.indexOf(wsifPackageName + ".logging") != -1) {
886: foundWsifLogging = true;
887: continue;
888: }
889:
890: if (foundWsifLogging)
891: break;
892: }
893: if (traceTrace)
894: traceLog.debug("TRACE token=" + tok1);
895:
896: // Now find the first word which contains a (. This should be
897: // prefixed by the method name. If there isn't a (, which
898: // is unlikely, use the whole line.
899: StringTokenizer st2 = new StringTokenizer(tok1);
900: String tok2 = null;
901: while (st2.hasMoreTokens()) {
902: tok2 = st2.nextToken();
903: if (tok2.indexOf("(") != -1)
904: break;
905: }
906: if (tok2.indexOf("(") == -1)
907: tok2 = tok1;
908:
909: // Indent the method name by the number of WSIF calls
910: // higher up the stack. This improves readability. There
911: // were various other ways of calculating the indentation
912: // but this seemed the most reliable (and simplest).
913: buff.append(" ");
914: while (st1.hasMoreTokens()) {
915: if (st1.nextToken().indexOf(wsifPackageName) != -1)
916: buff.append(" ");
917: }
918:
919: // Strip off the (... parameters...). I expect there will
920: // always be a ( in the token, but this code copes even if
921: // there isn't.
922: int idx = tok2.indexOf("(");
923: if (idx != -1)
924: tok2 = tok2.substring(0, idx);
925: if (traceTrace)
926: traceLog.debug("TRACE token=" + tok2);
927:
928: // Now strip off the WSIF package name off the front of
929: // the class name. All WSIF class names are unique, so
930: // the package name just takes up more space in the trace
931: // and provides no added value. If Trc was not called from
932: // WSIF (unlikely) then output the whole
933: // packagename.classname.methodname.
934: String result = null;
935: if (tok2.startsWith(wsifPackageName)) {
936: StringTokenizer st3 = new StringTokenizer(tok2, ".");
937: String previous = null;
938: while (st3.hasMoreTokens()) {
939: previous = result;
940: result = st3.nextToken();
941: }
942: if (previous != null)
943: result = previous + "." + result;
944: } else
945: result = tok2;
946:
947: if (traceTrace)
948: traceLog.debug("TRACE appending result=" + result);
949: buff.append(result);
950: }
951:
952: private static void traceIt(Object that, String type,
953: boolean expandWsdl, Object[] parms) {
954:
955: boolean isEvent = false;
956: if (EVENT.equals(type))
957: isEvent = true;
958:
959: if (!expandWsdl)
960: checkWsdl(parms);
961:
962: StringBuffer sb = new StringBuffer(type);
963: if (isEvent)
964: sb.append(" ");
965: appendMethodName(sb);
966:
967: if (that != null) {
968: sb.append("<");
969: sb.append(Integer.toHexString(that.hashCode()));
970: sb.append(">");
971: }
972:
973: if (isEvent)
974: sb.append(" ");
975: else
976: sb.append("(");
977:
978: if (parms != null)
979: for (int i = 0; i < parms.length; i++) {
980: if (i != 0 && !isEvent)
981: sb.append(", ");
982: sb.append(parms[i] == null ? "<null>" : parms[i]
983: .toString());
984: }
985: if (!isEvent)
986: sb.append(")");
987:
988: log.debug(sb);
989: }
990: }
|