1 | /* |
2 | * jDTAUS Core Utilities |
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.util; |
22 | |
23 | import java.util.Locale; |
24 | import org.jdtaus.core.container.ContainerFactory; |
25 | import org.jdtaus.core.logging.spi.Logger; |
26 | import org.jdtaus.core.text.MessageEvent; |
27 | import org.jdtaus.core.text.MessageListener; |
28 | |
29 | /** |
30 | * {@code MessageListener} logging messages to a system logger. |
31 | * |
32 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
33 | * @version $JDTAUS: MessageLogger.java 8743 2012-10-07 03:06:20Z schulte $ |
34 | * |
35 | * @see #onMessage(MessageEvent) |
36 | */ |
37 | public final class MessageLogger implements MessageListener |
38 | { |
39 | //--MessageListener--------------------------------------------------------- |
40 | |
41 | /** |
42 | * {@inheritDoc} |
43 | * <p>This method logs all messages given by the event using the |
44 | * corresponding log level.</p> |
45 | * |
46 | * @param event the event holding messages. |
47 | */ |
48 | public void onMessage( final MessageEvent event ) |
49 | { |
50 | if ( event != null ) |
51 | { |
52 | for ( int i = 0; i < event.getMessages().length; i++ ) |
53 | { |
54 | switch ( event.getType() ) |
55 | { |
56 | case MessageEvent.ERROR: |
57 | this.getLogger().error( event.getMessages()[i].getText( |
58 | this.getLocale() ) ); |
59 | |
60 | break; |
61 | |
62 | case MessageEvent.INFORMATION: |
63 | case MessageEvent.NOTIFICATION: |
64 | this.getLogger().info( event.getMessages()[i].getText( |
65 | this.getLocale() ) ); |
66 | |
67 | break; |
68 | |
69 | case MessageEvent.WARNING: |
70 | this.getLogger().warn( event.getMessages()[i].getText( |
71 | this.getLocale() ) ); |
72 | |
73 | break; |
74 | |
75 | default: |
76 | this.getLogger().warn( |
77 | this.getUnknownMessageEventTypeMessage( |
78 | this.getLocale(), |
79 | new Integer( event.getType() ) ) ); |
80 | |
81 | } |
82 | } |
83 | } |
84 | } |
85 | |
86 | //---------------------------------------------------------MessageListener-- |
87 | //--MessageLogger----------------------------------------------------------- |
88 | |
89 | /** Creates a new {@code MessageLogger} instance. */ |
90 | public MessageLogger() |
91 | { |
92 | super(); |
93 | } |
94 | |
95 | //-----------------------------------------------------------MessageLogger-- |
96 | //--Dependencies------------------------------------------------------------ |
97 | |
98 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies |
99 | // This section is managed by jdtaus-container-mojo. |
100 | |
101 | /** |
102 | * Gets the configured <code>Logger</code> implementation. |
103 | * |
104 | * @return The configured <code>Logger</code> implementation. |
105 | */ |
106 | private Logger getLogger() |
107 | { |
108 | return (Logger) ContainerFactory.getContainer(). |
109 | getDependency( this, "Logger" ); |
110 | |
111 | } |
112 | |
113 | /** |
114 | * Gets the configured <code>Locale</code> implementation. |
115 | * |
116 | * @return The configured <code>Locale</code> implementation. |
117 | */ |
118 | private Locale getLocale() |
119 | { |
120 | return (Locale) ContainerFactory.getContainer(). |
121 | getDependency( this, "Locale" ); |
122 | |
123 | } |
124 | |
125 | // </editor-fold>//GEN-END:jdtausDependencies |
126 | |
127 | //------------------------------------------------------------Dependencies-- |
128 | //--Messages---------------------------------------------------------------- |
129 | |
130 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages |
131 | // This section is managed by jdtaus-container-mojo. |
132 | |
133 | /** |
134 | * Gets the text of message <code>unknownMessageEventType</code>. |
135 | * <blockquote><pre>Meldung unbekannten Typs {0,number} ignoriert.</pre></blockquote> |
136 | * <blockquote><pre>Ignored message event of unknown type {0,number}.</pre></blockquote> |
137 | * |
138 | * @param locale The locale of the message instance to return. |
139 | * @param unknownEventType The unknown event type. |
140 | * |
141 | * @return Message stating that an unknown message event got ignored. |
142 | */ |
143 | private String getUnknownMessageEventTypeMessage( final Locale locale, |
144 | final java.lang.Number unknownEventType ) |
145 | { |
146 | return ContainerFactory.getContainer(). |
147 | getMessage( this, "unknownMessageEventType", locale, |
148 | new Object[] |
149 | { |
150 | unknownEventType |
151 | }); |
152 | |
153 | } |
154 | |
155 | // </editor-fold>//GEN-END:jdtausMessages |
156 | |
157 | //----------------------------------------------------------------Messages-- |
158 | } |