001/* 002 * jDTAUS Core RI Application Logger 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.text.ri; 022 023import javax.swing.event.EventListenerList; 024import org.jdtaus.core.container.ContainerFactory; 025import org.jdtaus.core.text.MessageEvent; 026import org.jdtaus.core.text.MessageListener; 027import org.jdtaus.core.text.spi.ApplicationLogger; 028 029/** 030 * jDTAUS Core SPI {@code ApplicationLogger} reference implementation. 031 * 032 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 033 * @version $JDTAUS: DefaultApplicationLogger.java 8641 2012-09-27 06:45:17Z schulte $ 034 * 035 * @see org.jdtaus.core.container.Container 036 */ 037public class DefaultApplicationLogger implements ApplicationLogger 038{ 039 //--Constructors------------------------------------------------------------ 040 041// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausConstructors 042 // This section is managed by jdtaus-container-mojo. 043 044 /** Standard implementation constructor <code>org.jdtaus.core.text.ri.DefaultApplicationLogger</code>. */ 045 public DefaultApplicationLogger() 046 { 047 super(); 048 } 049 050// </editor-fold>//GEN-END:jdtausConstructors 051 052 //------------------------------------------------------------Constructors-- 053 //--MessageEventSource------------------------------------------------------ 054 055 /** Holds {@code MessageListener}s. */ 056 private final EventListenerList listeners = new EventListenerList(); 057 058 public void addMessageListener( final MessageListener listener ) 059 { 060 if ( listener == null ) 061 { 062 throw new NullPointerException( "listener" ); 063 } 064 065 this.listeners.add( MessageListener.class, listener ); 066 } 067 068 public void removeMessageListener( final MessageListener listener ) 069 { 070 if ( listener == null ) 071 { 072 throw new NullPointerException( "listener" ); 073 } 074 075 this.listeners.remove( MessageListener.class, listener ); 076 } 077 078 public MessageListener[] getMessageListeners() 079 { 080 return (MessageListener[]) this.listeners.getListeners( 081 MessageListener.class ); 082 083 } 084 085 //------------------------------------------------------MessageEventSource-- 086 //--ApplicationLogger------------------------------------------------------- 087 088 public void log( final MessageEvent e ) 089 { 090 if ( e == null ) 091 { 092 throw new NullPointerException( "e" ); 093 } 094 095 final Object[] list = this.listeners.getListenerList(); 096 for ( int i = list.length - 2; i >= 0; i -= 2 ) 097 { 098 if ( list[i] == MessageListener.class ) 099 { 100 ( (MessageListener) list[i + 1] ).onMessage( e ); 101 } 102 } 103 104 final MessageListener[] messageListener = this.getMessageListener(); 105 for ( int i = messageListener.length - 1; i >= 0; i-- ) 106 { 107 messageListener[i].onMessage( e ); 108 } 109 } 110 111 //-------------------------------------------------------ApplicationLogger-- 112 //--Dependencies------------------------------------------------------------ 113 114// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies 115 // This section is managed by jdtaus-container-mojo. 116 117 /** 118 * Gets the configured <code>MessageListener</code> implementation. 119 * 120 * @return The configured <code>MessageListener</code> implementation. 121 */ 122 private MessageListener[] getMessageListener() 123 { 124 return (MessageListener[]) ContainerFactory.getContainer(). 125 getDependency( this, "MessageListener" ); 126 127 } 128 129// </editor-fold>//GEN-END:jdtausDependencies 130 131 //------------------------------------------------------------Dependencies-- 132}