Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SessionEventSupport |
|
| 1.8333333333333333;1,833 |
1 | package org.apache.maven.wagon.events; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.util.ArrayList; | |
23 | import java.util.Iterator; | |
24 | import java.util.List; | |
25 | ||
26 | /** | |
27 | * The class allows registration and deregistration of session listeners | |
28 | * | |
29 | * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> | |
30 | * @version $Id: SessionEventSupport.java 682051 2008-08-02 21:29:38Z hboutemy $ | |
31 | */ | |
32 | 53 | public final class SessionEventSupport |
33 | { | |
34 | /** | |
35 | * registered listeners | |
36 | */ | |
37 | 53 | private final List listeners = new ArrayList(); |
38 | ||
39 | /** | |
40 | * Adds the listener to the collection of listeners | |
41 | * who will be notified when any session event occurs | |
42 | * in this <code>Wagon</code> object. | |
43 | * <br/> | |
44 | * If listener is <code>null</code>, no exception is thrown and no action is performed | |
45 | * | |
46 | * @param listener the transfer listener | |
47 | * @see #removeSessionListener(SessionListener) | |
48 | * @see TransferListener | |
49 | */ | |
50 | public void addSessionListener( final SessionListener listener ) | |
51 | { | |
52 | 41 | if ( listener != null ) |
53 | { | |
54 | 41 | listeners.add( listener ); |
55 | } | |
56 | 41 | } |
57 | ||
58 | /** | |
59 | * Removes the session listener from the collection of listeners so | |
60 | * it no longer receives session events. | |
61 | * <br/> | |
62 | * If listener is <code>null</code> or specified listener was not added | |
63 | * to this <code>SessionEventSupport</code> object | |
64 | * no exception is thrown and no action is performed | |
65 | * | |
66 | * @param listener the session listener | |
67 | * @see #addSessionListener(org.apache.maven.wagon.events.SessionListener) | |
68 | */ | |
69 | public void removeSessionListener( final SessionListener listener ) | |
70 | { | |
71 | 3 | listeners.remove( listener ); |
72 | 3 | } |
73 | ||
74 | /** | |
75 | * Returns whether the specified instance of session | |
76 | * listener was added to the collection of listeners | |
77 | * who will be notified when an session event occurs | |
78 | * | |
79 | * @param listener the session listener | |
80 | * @return <code>true<code> | |
81 | * if given listener was added to the collection of listeners | |
82 | * <code>false</code> otherwise | |
83 | * @see org.apache.maven.wagon.events.SessionListener | |
84 | * @see #addSessionListener(org.apache.maven.wagon.events.SessionListener) | |
85 | */ | |
86 | public boolean hasSessionListener( final SessionListener listener ) | |
87 | { | |
88 | 9 | return listeners.contains( listener ); |
89 | } | |
90 | ||
91 | /** | |
92 | * Dispatches the given <code>SessionEvent</code> | |
93 | * to all registered listeners (calls method {@link SessionListener#sessionDisconnected(SessionEvent)} on all of | |
94 | * them}. The Event should be of type {@link SessionEvent#SESSION_DISCONNECTED} | |
95 | * | |
96 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
97 | */ | |
98 | public void fireSessionDisconnected( final SessionEvent sessionEvent ) | |
99 | { | |
100 | 22 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
101 | { | |
102 | 3 | final SessionListener listener = (SessionListener) iter.next(); |
103 | 3 | listener.sessionDisconnected( sessionEvent ); |
104 | 3 | } |
105 | 22 | } |
106 | ||
107 | /** | |
108 | * Dispatches the given <code>SessionEvent</code> | |
109 | * to all registered listeners (calls method {@link SessionListener#sessionDisconnecting(SessionEvent)} } on all of | |
110 | * them}. The Event should be of type {@link SessionEvent#SESSION_DISCONNECTING} | |
111 | * | |
112 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
113 | */ | |
114 | public void fireSessionDisconnecting( final SessionEvent sessionEvent ) | |
115 | { | |
116 | 23 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
117 | { | |
118 | 4 | final SessionListener listener = (SessionListener) iter.next(); |
119 | 4 | listener.sessionDisconnecting( sessionEvent ); |
120 | 4 | } |
121 | 23 | } |
122 | ||
123 | /** | |
124 | * Dispatches the given <code>SessionEvent</code> | |
125 | * to all registered listeners (calls method {@link SessionListener#sessionLoggedIn(SessionEvent)} on all of them}. | |
126 | * The Event should be of type {@link SessionEvent#SESSION_LOGGED_IN} | |
127 | * | |
128 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
129 | */ | |
130 | public void fireSessionLoggedIn( final SessionEvent sessionEvent ) | |
131 | { | |
132 | 1 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
133 | { | |
134 | 2 | final SessionListener listener = (SessionListener) iter.next(); |
135 | 2 | listener.sessionLoggedIn( sessionEvent ); |
136 | 2 | } |
137 | 1 | } |
138 | ||
139 | /** | |
140 | * Dispatches the given <code>SessionEvent</code> | |
141 | * to all registered listeners (calls method {@link SessionListener#sessionLoggedOff(SessionEvent)} on all of | |
142 | * them}. The Event should be of type {@link SessionEvent#SESSION_LOGGED_OFF} | |
143 | * | |
144 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
145 | */ | |
146 | public void fireSessionLoggedOff( final SessionEvent sessionEvent ) | |
147 | { | |
148 | 1 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
149 | { | |
150 | 2 | final SessionListener listener = (SessionListener) iter.next(); |
151 | 2 | listener.sessionLoggedOff( sessionEvent ); |
152 | 2 | } |
153 | 1 | } |
154 | ||
155 | /** | |
156 | * Dispatches the given <code>SessionEvent</code> | |
157 | * to all registered listeners (calls method {@link SessionListener#sessionOpened(SessionEvent)} on all of them}. | |
158 | * The Event should be of type {@link SessionEvent#SESSION_OPENED} | |
159 | * | |
160 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
161 | */ | |
162 | public void fireSessionOpened( final SessionEvent sessionEvent ) | |
163 | { | |
164 | 34 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
165 | { | |
166 | 14 | final SessionListener listener = (SessionListener) iter.next(); |
167 | 14 | listener.sessionOpened( sessionEvent ); |
168 | 14 | } |
169 | 34 | } |
170 | ||
171 | /** | |
172 | * Dispatches the given <code>SessionEvent</code> | |
173 | * to all registered listeners (calls method {@link SessionListener#sessionOpening(SessionEvent)} on all of them}. | |
174 | * The Event should be of type {@link SessionEvent#SESSION_OPENING} | |
175 | * | |
176 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
177 | */ | |
178 | public void fireSessionOpening( final SessionEvent sessionEvent ) | |
179 | { | |
180 | 36 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
181 | { | |
182 | 16 | final SessionListener listener = (SessionListener) iter.next(); |
183 | 16 | listener.sessionOpening( sessionEvent ); |
184 | 16 | } |
185 | 36 | } |
186 | ||
187 | /** | |
188 | * Dispatches the given <code>SessionEvent</code> | |
189 | * to all registered listeners (calls method {@link SessionListener#sessionConnectionRefused(SessionEvent)} on all | |
190 | * of them}. The Event should be of type {@link SessionEvent#SESSION_CONNECTION_REFUSED} | |
191 | * | |
192 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
193 | */ | |
194 | public void fireSessionConnectionRefused( final SessionEvent sessionEvent ) | |
195 | { | |
196 | 3 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
197 | { | |
198 | 4 | final SessionListener listener = (SessionListener) iter.next(); |
199 | 4 | listener.sessionConnectionRefused( sessionEvent ); |
200 | 4 | } |
201 | 3 | } |
202 | ||
203 | /** | |
204 | * Dispatches the given debug message | |
205 | * to all registered listeners (calls method {@link SessionListener#debug(String)} on all of them}. | |
206 | * | |
207 | * @param message the debug message which will be dispatched to listeners | |
208 | */ | |
209 | public void fireDebug( final String message ) | |
210 | { | |
211 | 1 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
212 | { | |
213 | 2 | final SessionListener listener = (SessionListener) iter.next(); |
214 | 2 | listener.debug( message ); |
215 | 2 | } |
216 | 1 | } |
217 | ||
218 | /** | |
219 | * Dispatches the given <code>SessionEvent</code> | |
220 | * to all registered listeners (calls method {@link SessionListener#sessionConnectionRefused(SessionEvent)} on all | |
221 | * of them}. The Event should be of type {@link SessionEvent#SESSION_ERROR_OCCURRED} and it is expected that | |
222 | * {@link SessionEvent#getException()} method will return not null value | |
223 | * | |
224 | * @param sessionEvent the SessionEvent which will be dispatched to listeners | |
225 | */ | |
226 | public void fireSessionError( final SessionEvent sessionEvent ) | |
227 | { | |
228 | 1 | for ( Iterator iter = listeners.iterator(); iter.hasNext(); ) |
229 | { | |
230 | 1 | final SessionListener listener = (SessionListener) iter.next(); |
231 | 1 | listener.sessionError( sessionEvent ); |
232 | 1 | } |
233 | 1 | } |
234 | } |