1 | /* |
2 | * jDTAUS Core RI Application Logger |
3 | * Copyright (C) 2005 Christian Schulte |
4 | * <cs@schulte.it> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2.1 of the License, or any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * |
20 | */ |
21 | package org.jdtaus.core.text.ri; |
22 | |
23 | import javax.swing.event.EventListenerList; |
24 | import org.jdtaus.core.container.ContainerFactory; |
25 | import org.jdtaus.core.text.MessageEvent; |
26 | import org.jdtaus.core.text.MessageListener; |
27 | import org.jdtaus.core.text.spi.ApplicationLogger; |
28 | |
29 | /** |
30 | * jDTAUS Core SPI {@code ApplicationLogger} reference implementation. |
31 | * |
32 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
33 | * @version $JDTAUS: DefaultApplicationLogger.java 8641 2012-09-27 06:45:17Z schulte $ |
34 | * |
35 | * @see org.jdtaus.core.container.Container |
36 | */ |
37 | public class DefaultApplicationLogger implements ApplicationLogger |
38 | { |
39 | //--Constructors------------------------------------------------------------ |
40 | |
41 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausConstructors |
42 | // This section is managed by jdtaus-container-mojo. |
43 | |
44 | /** Standard implementation constructor <code>org.jdtaus.core.text.ri.DefaultApplicationLogger</code>. */ |
45 | public DefaultApplicationLogger() |
46 | { |
47 | super(); |
48 | } |
49 | |
50 | // </editor-fold>//GEN-END:jdtausConstructors |
51 | |
52 | //------------------------------------------------------------Constructors-- |
53 | //--MessageEventSource------------------------------------------------------ |
54 | |
55 | /** Holds {@code MessageListener}s. */ |
56 | private final EventListenerList listeners = new EventListenerList(); |
57 | |
58 | public void addMessageListener( final MessageListener listener ) |
59 | { |
60 | if ( listener == null ) |
61 | { |
62 | throw new NullPointerException( "listener" ); |
63 | } |
64 | |
65 | this.listeners.add( MessageListener.class, listener ); |
66 | } |
67 | |
68 | public void removeMessageListener( final MessageListener listener ) |
69 | { |
70 | if ( listener == null ) |
71 | { |
72 | throw new NullPointerException( "listener" ); |
73 | } |
74 | |
75 | this.listeners.remove( MessageListener.class, listener ); |
76 | } |
77 | |
78 | public MessageListener[] getMessageListeners() |
79 | { |
80 | return (MessageListener[]) this.listeners.getListeners( |
81 | MessageListener.class ); |
82 | |
83 | } |
84 | |
85 | //------------------------------------------------------MessageEventSource-- |
86 | //--ApplicationLogger------------------------------------------------------- |
87 | |
88 | public void log( final MessageEvent e ) |
89 | { |
90 | if ( e == null ) |
91 | { |
92 | throw new NullPointerException( "e" ); |
93 | } |
94 | |
95 | final Object[] list = this.listeners.getListenerList(); |
96 | for ( int i = list.length - 2; i >= 0; i -= 2 ) |
97 | { |
98 | if ( list[i] == MessageListener.class ) |
99 | { |
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 | } |