001/* 002 * jDTAUS Core Utilities 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.lang.util; 022 023import org.jdtaus.core.container.ContainerFactory; 024import org.jdtaus.core.lang.ExceptionEvent; 025import org.jdtaus.core.lang.ExceptionListener; 026import org.jdtaus.core.logging.spi.Logger; 027 028/** 029 * {@code ExceptionListener} logging exceptions. 030 * 031 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 032 * @version $JDTAUS: ExceptionLogger.java 8641 2012-09-27 06:45:17Z schulte $ 033 * 034 * @see #onException(ExceptionEvent) 035 */ 036public final class ExceptionLogger implements ExceptionListener 037{ 038 //--Constructors------------------------------------------------------------ 039 040// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausConstructors 041 // This section is managed by jdtaus-container-mojo. 042 043// </editor-fold>//GEN-END:jdtausConstructors 044 045 //------------------------------------------------------------Constructors-- 046 //--Dependencies------------------------------------------------------------ 047 048// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies 049 // This section is managed by jdtaus-container-mojo. 050 051 /** 052 * Gets the configured <code>Logger</code> implementation. 053 * 054 * @return The configured <code>Logger</code> implementation. 055 */ 056 private Logger getLogger() 057 { 058 return (Logger) ContainerFactory.getContainer(). 059 getDependency( this, "Logger" ); 060 061 } 062 063// </editor-fold>//GEN-END:jdtausDependencies 064 065 //------------------------------------------------------------Dependencies-- 066 //--Properties-------------------------------------------------------------- 067 068// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausProperties 069 // This section is managed by jdtaus-container-mojo. 070 071// </editor-fold>//GEN-END:jdtausProperties 072 073 //--------------------------------------------------------------Properties-- 074 //--ExceptionListener------------------------------------------------------- 075 076 /** 077 * {@inheritDoc} 078 * <p>This method logs details of the event's exception to a logger.</p> 079 * 080 * @param event the event holding the exception. 081 */ 082 public void onException( final ExceptionEvent event ) 083 { 084 if ( event != null ) 085 { 086 this.getLogger().error( event.getException() ); 087 } 088 } 089 090 //-------------------------------------------------------ExceptionListener-- 091}