Project Report: fawkez

Packagesummary org.jcoderz.commons.logging

org.jcoderz.commons.logging.XmlPrinter

LineHitsNoteSource
1  /*
2   * $Id: XmlPrinter.java 1304 2009-03-24 09:15:55Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.logging;
34  
35  import java.io.PrintWriter;
36  import java.math.BigInteger;
37  import java.util.Calendar;
38  import java.util.Iterator;
39  import java.util.List;
40  import java.util.Set;
41  import java.util.TimeZone;
42  
43  import javax.xml.bind.JAXBContext;
44  import javax.xml.bind.JAXBException;
45  import javax.xml.bind.Marshaller;
46  
47  import org.apache.commons.pool.BaseKeyedPoolableObjectFactory;
48  import org.apache.commons.pool.impl.StackKeyedObjectPool;
49  import org.jcoderz.commons.util.Assert;
50  
51  
52  
53  /**
54   * This printer formats the log messages into an Xml format and prints the log
55   * messages as a sequence of xml elements.
56   *
57   */
58 (1)public final class XmlPrinter
59        extends LogPrinter
60  {
61     private final LogRecordTypesObjectPool mXmlObjectsPool;
62100(2)   private final ObjectFactory mObjectFactory = new ObjectFactory();
63     private final JAXBContext mJaxbContext;
64     private final Marshaller mMarshaller;
65  
66100    private static final class LogRecordTypesObjectPool
67           extends StackKeyedObjectPool
68     {
69        private LogRecordType borrowLogRecordType ()
70              throws LoggingException
71        {
72           try
73           {
7475             return (LogRecordType) borrowObject(LogRecordType.class);
75           }
760          catch (Exception ex)
77           {
780             throw new LoggingException("Error borrowing LogRecordType", ex);
79           }
80        }
81  
82        private LogRecordType borrowLogRecord ()
83              throws LoggingException
84        {
85           try
86           {
87100             return (LogRecordType) borrowObject(LogRecord.class);
88           }
890          catch (Exception ex)
90           {
910             throw new LoggingException("Error borrowing LogRecord", ex);
92           }
93        }
94  
95        private void returnLogRecord (final LogRecordType record)
96              throws LoggingException
97        {
98           try
99           {
10075             returnObject(LogRecordType.class, record);
101           }
1020          catch (Exception ex)
103           {
1040(3)            throw new LoggingException("Error returning LogRecordType", ex);
105100          }
106100       }
107  
108        private FrameType borrowFrame ()
109              throws LoggingException
110        {
111           try
112           {
113100             return (FrameType) borrowObject(FrameType.class);
114           }
1150          catch (Exception ex)
116           {
1170             throw new LoggingException("Error borrowing FrameType", ex);
118           }
119        }
120  
121        private void returnFrame (final FrameType frame)
122              throws LoggingException
123        {
124           try
125           {
12675             returnObject(FrameType.class, frame);
127           }
1280          catch (Exception ex)
129           {
1300(4)            throw new LoggingException("Error returning FrameType", ex);
131100          }
132100       }
133  
134        private ParameterType borrowParameter ()
135              throws LoggingException
136        {
137           try
138           {
13975             return (ParameterType) borrowObject(ParameterType.class);
140           }
1410          catch (Exception ex)
142           {
1430             throw new LoggingException("Error borrowing ParameterType", ex);
144           }
145        }
146  
147        private void returnParameter (final ParameterType parameter)
148              throws LoggingException
149        {
150           try
151           {
15275             returnObject(ParameterType.class, parameter);
153           }
1540          catch (Exception ex)
155           {
1560(5)            throw new LoggingException("Error returning ParameterType", ex);
157100          }
158100       }
159  
160        private CauseType borrowCause ()
161              throws LoggingException
162        {
163           try
164           {
16575             return (CauseType) borrowObject(CauseType.class);
166           }
1670          catch (Exception ex)
168           {
1690             throw new LoggingException("Error borrowing CauseType", ex);
170           }
171        }
172  
173        private void returnCause (final CauseType cause)
174              throws LoggingException
175        {
176           try
177           {
17875             returnObject(CauseType.class, cause);
179           }
1800          catch (Exception ex)
181           {
1820(6)            throw new LoggingException("Error returning CauseType", ex);
183100          }
184100       }
185  
186        private ExceptionType borrowException ()
187              throws LoggingException
188        {
189           try
190           {
19175             return (ExceptionType) borrowObject(ExceptionType.class);
192           }
1930          catch (Exception ex)
194           {
1950             throw new LoggingException("Error borrowing ExceptionType", ex);
196           }
197        }
198  
199        private void returnException (final ExceptionType ex)
200              throws LoggingException
201        {
202           try
203           {
20475             returnObject(ExceptionType.class, ex);
205           }
2060          catch (Exception ex1)
207           {
2080(7)            throw new LoggingException("Error returning ExceptionType", ex1);
209100          }
210100       }
211  
212        private StacktraceType borrowStacktrace ()
213              throws LoggingException
214        {
215           try
216           {
2170             return (StacktraceType) borrowObject(StacktraceType.class);
218           }
2190          catch (Exception ex)
220           {
2210             throw new LoggingException("Error borrowing StacktraceType", ex);
222           }
223        }
224  
225        private void returnStacktrace (final StacktraceType stacktrace)
226              throws LoggingException
227        {
228           try
229           {
2300             returnObject(StacktraceType.class, stacktrace);
231           }
2320          catch (Exception ex)
233           {
2340(8)            throw new LoggingException("Error returning StacktraceType", ex);
2350          }
2360       }
237  
238        private Calendar borrowCalendar ()
239              throws LoggingException
240        {
241           try
242           {
243100             return (Calendar) borrowObject(Calendar.class);
244           }
2450          catch (Exception ex)
246           {
2470             throw new LoggingException("Error borrowing Calendar", ex);
248           }
249        }
250  
251        private void returnCalendar (final Calendar cal)
252              throws LoggingException
253        {
254           try
255           {
25675             returnObject(Calendar.class, cal);
257           }
2580          catch (Exception ex)
259           {
2600(9)            throw new LoggingException("Error returning Calendar", ex);
261100          }
262100       }
263     }
264  
265     private static final class XmlObjectFactory
266           extends BaseKeyedPoolableObjectFactory
267     {
268        private final LogRecordTypesObjectPool mPool;
269        private final ObjectFactory mJaxbFactory;
270  
271        private XmlObjectFactory (
272              final ObjectFactory factory,
273              final LogRecordTypesObjectPool pool)
274100       {
275100          mPool = pool;
276100          mJaxbFactory = factory;
277100       }
278  
279        /**
280         * Makes an object for the key given by <code>key</code>.
281         * This accepts as keys classes of the jaxb objects used by this.
282         *
283         * @param key The class of the requested object.
284         *
285         * @return Instance of specified class.
286         *
287         * @see org.apache.commons.pool.BaseKeyedPoolableObjectFactory#makeObject(java.lang.Object)
288         */
289        public Object makeObject (Object key)
290              throws JAXBException
291        {
292           final Object rc;
293  
294100          if (key == LogRecordType.class)
295           {
296100             rc = mJaxbFactory.createLogRecordType();
297           }
29875          else if (key == LogRecord.class)
299           {
300100             rc = mJaxbFactory.createLogRecord();
301           }
30275          else if (key == FrameType.class)
303           {
304100             rc = mJaxbFactory.createFrameType();
305           }
306100          else if (key == StacktraceType.class)
307           {
3080             rc = mJaxbFactory.createStacktraceType();
309           }
310100          else if (key == ParameterType.class)
311           {
312100             rc = mJaxbFactory.createParameterType();
313           }
314100          else if (key == ExceptionType.class)
315           {
316100             rc = mJaxbFactory.createExceptionType();
317           }
318100          else if (key == CauseType.class)
319           {
320100             rc = mJaxbFactory.createCauseType();
321           }
32275          else if (key == Calendar.class)
323           {
324100             rc = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
325           }
326           else
327           {
3280             throw new IllegalArgumentException("Cannot make an object for "
329                    + key);
330           }
331100          return rc;
332        }
333  
334        /**
335         * Sets all required sub type fields of the supplied object.
336         *
337         * @param key The key of the object to activate.
338         * @param xmlObj The object to activate.
339         *
340         * @see org.apache.commons.pool.KeyedPoolableObjectFactory#activateObject(java.lang.Object, java.lang.Object)
341         */
342        public void activateObject (Object key, Object xmlObj)
343              throws LoggingException
344        {
34575          if ((key == LogRecordType.class) || (key == LogRecord.class))
346           {
347100             final LogRecordType logRecord = (LogRecordType) xmlObj;
348  
349              // set all required sub typed elements
350              // every log record has a source
351100             logRecord.setSource(mPool.borrowFrame());
352              // ... and a timestamp
353100             logRecord.setTimestamp(mPool.borrowCalendar());
354100          }
35580          else if (key == FrameType.class)
356           {
357              // nop
358           }
35960          else if (key == StacktraceType.class)
360           {
361              // nop
362           }
36380          else if (key == ParameterType.class)
364           {
365              // nop
366           }
36780          else if (key == ExceptionType.class)
368           {
369              // nop
370           }
37180          else if (key == CauseType.class)
372           {
373              // nop
374           }
37580          else if (key == Calendar.class)
376           {
377              // nop
378           }
379           else
380           {
3810             throw new IllegalArgumentException("Cannot make an object for "
382                    + key);
383           }
384100       }
385  
386        /**
387         * Sets all elements of the object to passivate to null and puts back
388         * into the pool all sub typed objects.
389         *
390         * @param key The key of the object, which is the type of the object.
391         * @param jaxbObj The jaxb object to passivate
392         *
393         * @see org.apache.commons.pool.KeyedPoolableObjectFactory#passivateObject(java.lang.Object, java.lang.Object)
394         */
395        public void passivateObject (Object key, Object jaxbObj)
396              throws LoggingException
397        {
39875          if ((key == LogRecordType.class) || (key == LogRecord.class))
399           {
400100             passivateLogRecord((LogRecordType) jaxbObj);
401           }
40275          else if (key == FrameType.class)
403           {
404100             passivateFrame((FrameType) jaxbObj);
405           }
40675          else if (key == StacktraceType.class)
407           {
4080             passivateStackTrace((StacktraceType) jaxbObj);
409           }
41075          else if (key == ParameterType.class)
411           {
412100             passivateParameter((ParameterType) jaxbObj);
413           }
41475          else if (key == ExceptionType.class)
415           {
416100             passivateException((ExceptionType) jaxbObj);
417           }
41875          else if (key == CauseType.class)
419           {
420100             passivateCause((CauseType) jaxbObj);
421           }
42280          else if (key == Calendar.class)
423           {
424              // nop
425           }
426           else
427           {
4280             throw new IllegalArgumentException("Cannot make an object for "
429                    + key);
430           }
431100       }
432  
433        /**
434         * Passivates an object of type <code>CauseType</code>.
435         *
436         * @param cause The CauseType object to passivate
437         *
438         * @throws Exception thrown by called methods.
439         */
440        private void passivateCause (final CauseType cause)
441              throws LoggingException
442        {
443100          final ExceptionType ex = cause.getException();
444100          cause.setException(null);
445  
446100          final LogRecordType record = cause.getNestedRecord();
447100          cause.setNestedRecord(null);
448  
449100          if (ex != null)
450           {
451100             mPool.returnException(ex);
452           }
453100          if (record != null)
454           {
455100             mPool.returnLogRecord(record);
456           }
457100       }
458  
459        /**
460         * Passivates an object of type <code>ExceptionType</code>.
461         *
462         * @param ex The ExceptionType object to passivate
463         *
464         * @throws Exception thrown by called methods.
465         */
466        private void passivateException (final ExceptionType ex)
467              throws LoggingException
468        {
469100          ex.setMessage(null);
470  
471100          final CauseType cause = ex.getCause();
472100          ex.setCause(null);
473  
474100          final StacktraceType stacktrace = ex.getStacktrace();
475100          ex.setStacktrace(null);
476  
477100          if (cause != null)
478           {
479100             mPool.returnCause(cause);
480           }
481100          if (stacktrace != null)
482           {
4830             mPool.returnStacktrace(stacktrace);
484           }
485100       }
486  
487        /**
488         * Passivates an object of type <code>ParameterType</code>.
489         *
490         * @param parameter The ParameterType object to passivate
491         */
492        private void passivateParameter (final ParameterType parameter)
493        {
494100          parameter.setName(null);
495100          parameter.getValue().clear();
496100       }
497  
498        /**
499         * Passivates an object of type <code>StacktraceType</code>.
500         *
501         * @param stacktrace The stacktrace object to passivate
502         *
503         * @throws Exception thrown by called methods.
504         */
505        private void passivateStackTrace (final StacktraceType stacktrace)
506              throws LoggingException
507        {
5080          for (final Iterator iter
5090                = stacktrace.getStacktraceElement().iterator(); iter.hasNext(); )
510           {
5110             mPool.returnFrame((FrameType) iter.next());
512           }
5130          stacktrace.getStacktraceElement().clear();
5140       }
515  
516        /**
517         * Passivates an object of type <code>LogRecordType</code>.
518         *
519         * @param logRecord The LogRecordType object to passivate
520         *
521         * @throws Exception thrown by called methods.
522         */
523        private void passivateLogRecord (final LogRecordType logRecord)
524              throws LoggingException
525        {
526100          logRecord.setBusinessImpact(null);
527100          logRecord.setCategory(null);
528100          logRecord.setInstanceId(null);
529100          logRecord.setLevel(null);
530100          logRecord.setMessage(null);
531100          logRecord.setNodeId(null);
532100          logRecord.setSolution(null);
533100          logRecord.setSymbol(null);
534100          logRecord.setTrackingNumber(null);
535  
536100          final Calendar cal = logRecord.getTimestamp();
537100          logRecord.setTimestamp(null);
538  
539100          final StacktraceType stack = logRecord.getStacktrace();
540100          logRecord.setStacktrace(null);
541  
542100          final FrameType source = logRecord.getSource();
543100          logRecord.setSource(null);
544  
545100          final CauseType cause = logRecord.getCause();
546100          logRecord.setCause(null);
547  
548100          if (cal != null)
549           {
550100             mPool.returnCalendar(cal);
551           }
552100          if (stack != null)
553           {
5540             mPool.returnStacktrace(stack);
555           }
556100          if (source != null)
557           {
558100             mPool.returnFrame(source);
559           }
560100          if (cause != null)
561           {
562100             mPool.returnCause(cause);
563           }
564100          for (final Iterator iter = logRecord.getParameter().iterator();
565100                iter.hasNext(); )
566           {
567100             mPool.returnParameter((ParameterType) iter.next());
568           }
569  
570100          logRecord.getParameter().clear();
571100       }
572  
573        /**
574         * Passivates an object of type <code>FrameType</code>.
575         *
576         * @param frame The FrameType object to passivate
577         *
578         * @throws Exception thrown by called methods.
579         */
580        private void passivateFrame (final FrameType frame)
581        {
582100          frame.setSourceMethod(null);
583100          frame.setSourceClass(null);
584100          frame.setSourceLine(null);
585100       }
586     }
587  
588     /**
589      * Creates a new instance of this. Allocates object pools and jaxb resources.
590      *
591      * @throws InstantiationException if an error occurs allocating the
592      * resources.
593      */
594     public XmlPrinter ()
595           throws InstantiationException
596     {
597100       super();
598        try
599        {
600100(10)         mJaxbContext = JAXBContext
601                 .newInstance("org.jcoderz.commons.logging");
602100          mMarshaller = mJaxbContext.createMarshaller();
603100(11)         mMarshaller.setProperty("jaxb.formatted.output",
604                 Boolean.valueOf(true));
605        }
6060       catch (JAXBException ex)
607        {
6080          final InstantiationException iex
609                 = new InstantiationException("Cannot initialize jaxb resources");
6100          iex.initCause(ex);
6110          throw iex;
612100       }
613100       mXmlObjectsPool = new LogRecordTypesObjectPool();
614100       mXmlObjectsPool.setFactory(
615              new XmlObjectFactory(mObjectFactory, mXmlObjectsPool));
616100    }
617  
618     /**
619      * Prints the log data using the supplied print writer in xml format.
620      *
621      * @param printer The PrintWriter to use for printing the data.
622      * @param logRecord The log data to format into xml and print using
623      *       <code>printer</code>.
624      *
625      * @see LogPrinter#print(PrintWriter, LogItem)
626      */
627     public void print (
628           final PrintWriter printer,
629           final LogItem logRecord)
630     {
631        try
632        {
633100          Assert.notNull(printer, "Printer");
634100          Assert.notNull(logRecord, "entry");
635100          Assert.notNull(logRecord.getType(), "logRecord.getType()");
636  
637100          LogItem logEntry = logRecord;
638100          CauseType parentsCause = null;
639100          LogRecordType rootRecord = null;
640  
641100          while (logEntry != null)
642           {
643100             if (! logEntry.isExceptionItem())
644              {
645                 final LogRecordType currentRecord;
646  
647100                if (rootRecord == null)
648                 {
649100                   currentRecord = mXmlObjectsPool.borrowLogRecord();
650100                   rootRecord = currentRecord;
651                 }
652                 else
653                 {
654100                   currentRecord = mXmlObjectsPool.borrowLogRecordType();
655                 }
656100                fillLogRecord(currentRecord, logEntry);
657  
658100                if (parentsCause != null)
659                 {
660100                   parentsCause.setNestedRecord(currentRecord);
661                 }
662100                logEntry = logEntry.getNestedItem();
663100                parentsCause = setCause(logEntry, currentRecord);
664100             }
665              else
666              {
667100                final ExceptionType currentException
668                       = mXmlObjectsPool.borrowException();
669100                fillException(currentException, logEntry);
670100                if (parentsCause != null)
671                 {
672100                   parentsCause.setException(currentException);
673                 }
674100                logEntry = logEntry.getNestedItem();
675100                parentsCause = setCause(logEntry, currentException);
676100             }
677           }
678100          if (rootRecord != null)
679           {
680100             mMarshaller.marshal(rootRecord, printer);
681100             mXmlObjectsPool.returnLogRecord(rootRecord);
682           }
683        }
6840       catch (Exception ex)
685        {
6860(12)         System.err.println("Error formatting log file entry into xml: " + ex);
6870(13)         ex.printStackTrace();
688100       }
689100    }
690  
691     private void fillLogRecord (
692           final LogRecordType logRecord,
693           final LogItem entry)
694     {
695100       logRecord.setNodeId(entry.getNodeId());
696100       logRecord.setInstanceId(entry.getInstanceId());
697100       logRecord.setLevel(entry.getLoggerLevel().toString());
698100       logRecord.setSymbol(entry.getSymbol());
699100       logRecord.setSymbolId(entry.getSymbolId());
700  
701        // the timestamp object is set when the log record is borrowed from the
702        // pool
703100       logRecord.getTimestamp().setTime(entry.getTimestamp().toUtilDate());
704  
705100       logRecord.setTrackingNumber(entry.getTrackingNumber());
706  
707100       logRecord.getSource().setSourceClass(
708              entry.getSourceClass());
709100       logRecord.getSource().setSourceMethod(
710              entry.getSourceMethod());
711100       logRecord.setThread(entry.getThreadId());
712100       logRecord.setThreadName(entry.getThreadName());
713100       logRecord.setMessage(entry.getMessage());
714100       logRecord.setSolution(entry.getSolution());
715100       logRecord.setBusinessImpact(
716              entry.getBusinessImpact().toString());
717100       logRecord.setCategory(
718              entry.getCategory().toString());
719  
720100       logRecord.setMessage(entry.getMessage());
721  
722100       final Set params = entry.getParameterNames();
723100       for (final Iterator iter = params.iterator(); iter.hasNext(); )
724        {
725100          final String parameterName = (String) iter.next();
726100          final ParameterType param
727                 = mXmlObjectsPool.borrowParameter();
728  
729100          param.setName(parameterName);
730100          final List values
731                 = entry.getParameterValues(parameterName);
732100          if (values != null)
733           {
734100             for (final Iterator valueIter = values.iterator();
735100                   valueIter.hasNext(); )
736              {
737100                param.getValue().add(valueIter.next().toString());
738              }
739           }
740100          logRecord.getParameter().add(param);
741100       }
742100       fillStacktrace(logRecord, entry);
743100    }
744  
745     /**
746      * Fills the stack trace according to the display options.
747      *
748      * @param logRecord The jaxb log record object to be filled,
749      * @param entry The log entry from which to get the information.
750      */
751     private void fillStacktrace (LogRecordType logRecord, LogItem entry)
752     {
753100       if (displayStackTrace(entry))
754        {
7550          logRecord.setStacktrace(getStackTrace(entry));
756        }
757100    }
758  
759     private void fillException (
760           final ExceptionType exception,
761           final LogItem entry)
762     {
763100       exception.setMessage(entry.getMessage());
764100       if (displayStackTrace(entry))
765        {
766100          exception.setStacktrace(getStackTrace(entry));
767        }
768100    }
769  
770     private StacktraceType getStackTrace (final LogItem entry)
771     {
772        final StacktraceType rc;
773100       if (entry.getStackTraceLines().isEmpty())
774        {
775100          rc = null;
776        }
777        else
778        {
7790          rc = mXmlObjectsPool.borrowStacktrace();
7800          fillStackTrace(rc, entry);
781        }
782100       return rc;
783     }
784  
785     private void fillStackTrace (
786           final StacktraceType stack,
787           final LogItem entry)
788     {
7890       for (final Iterator iter = entry.getStackTraceLines().iterator();
7900             iter.hasNext(); )
791        {
7920          final StackTraceInfo info = (StackTraceInfo) iter.next();
793  
794           // not interested in lines, which contain the exception message,
795           // this information is stored in other elements already.
7960          if (info.isLocationLine())
797           {
7980             final FrameType frame = mXmlObjectsPool.borrowFrame();
7990             frame.setSourceClass(info.getClassName());
8000             frame.setSourceMethod(info.getMethodName());
8010             if (info.getLine() != 0)
802              {
8030                frame.setSourceLine(BigInteger.valueOf(info.getLine()));
804              }
8050             stack.getStacktraceElement().add(frame);
8060          }
8070          else if (info.isMoreLine())
808           {
8090             Assert.assertTrue(info + " must be last line of a StackTrace,",
810                    ! iter.hasNext());
8110             fillMoreStackTrace(entry, stack, info);
812           }
8130       }
8140    }
815  
816     /**
817      * This fills the stack trace if a '...nnn more' line has been encountered.
818      * According to the display settings it might be necessary to take the stack
819      * trace lines of parent entries.
820      *
821      * @param entry The log file entry with the current stack trace line.
822      * @param stack The jaxb stack trace object, into which to fill the stack
823      * trace.
824      * @param info The current stack trace info from <code>entry</code>.
825      */
826     private void fillMoreStackTrace (
827           final LogItem entry,
828           final StacktraceType stack,
829           final StackTraceInfo info)
830     {
8310       final LogItem stackTraceEntry
832              = getEntryForMoreStackTrace(entry, info);
8330       if (stackTraceEntry == null)
834        {
8350          throw new IllegalStateException("Did not find correct stack trace to "
836                 + "display for " + entry);
837        }
8380       else if (entry == stackTraceEntry)
839        {
840           // in this case the stack trace has been displayed already and we can
841           // display the more line again.
8420          final FrameType frame = mXmlObjectsPool.borrowFrame();
8430          frame.setSourceClass(info.toString());
8440          frame.setSourceMethod("");
8450          stack.getStacktraceElement().add(frame);
8460       }
847        else
848        {
8490          fillStackTrace(stack, stackTraceEntry);
850        }
8510    }
852  
853     private CauseType setCause (
854           final LogItem entry,
855           final LogRecordType record)
856     {
857        final CauseType rc;
858100       if (entry != null)
859        {
860100          rc = mXmlObjectsPool.borrowCause();
861100          record.setCause(rc);
862        }
863        else
864        {
865100          rc = null;
866        }
867100       return rc;
868     }
869  
870     private CauseType setCause (
871           final LogItem entry,
872           final ExceptionType exception)
873     {
874        final CauseType rc;
875100       if (entry != null)
876        {
877100          rc = mXmlObjectsPool.borrowCause();
878100          exception.setCause(rc);
879        }
880        else
881        {
882100          rc = null;
883        }
884100       return rc;
885     }
886  }

Findings in this File

c (1) 58 : 0 Type Javadoc comment is missing an @author tag.
w (2) 62 : 0 class org.jcoderz.commons.logging.XmlPrinter defines fields that are used only as locals
i (3) 104 : 0 method org.jcoderz.commons.logging.XmlPrinter$LogRecordTypesObjectPool.returnLogRecord(LogRecordType) throws exception with static message string
i (4) 130 : 0 method org.jcoderz.commons.logging.XmlPrinter$LogRecordTypesObjectPool.returnFrame(FrameType) throws exception with static message string
i (5) 156 : 0 method org.jcoderz.commons.logging.XmlPrinter$LogRecordTypesObjectPool.returnParameter(ParameterType) throws exception with static message string
i (6) 182 : 0 method org.jcoderz.commons.logging.XmlPrinter$LogRecordTypesObjectPool.returnCause(CauseType) throws exception with static message string
i (7) 208 : 0 method org.jcoderz.commons.logging.XmlPrinter$LogRecordTypesObjectPool.returnException(ExceptionType) throws exception with static message string
i (8) 234 : 0 method org.jcoderz.commons.logging.XmlPrinter$LogRecordTypesObjectPool.returnStacktrace(StacktraceType) throws exception with static message string
i (9) 260 : 0 method org.jcoderz.commons.logging.XmlPrinter$LogRecordTypesObjectPool.returnCalendar(Calendar) throws exception with static message string
w (10) 600 : 0 class org.jcoderz.commons.logging.XmlPrinter defines fields that are used only as locals
w (11) 603 : 0 method new org.jcoderz.commons.logging.XmlPrinter() needlessly boxes a boolean constant
d (12) 686 : 10 System.out.print is used
d (13) 687 : 10 Avoid printStackTrace(); use a logger call instead.