| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SessionListenerSupport |
|
| 1.6666666666666667;1.667 |
| 1 | /* | |
| 2 | * Copyright 2004-2007 the original author or authors. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.maven.wagon; | |
| 17 | ||
| 18 | import java.util.HashSet; | |
| 19 | import java.util.Set; | |
| 20 | ||
| 21 | import org.apache.maven.wagon.Wagon; | |
| 22 | import org.apache.maven.wagon.events.SessionEvent; | |
| 23 | import org.apache.maven.wagon.events.SessionListener; | |
| 24 | ||
| 25 | /** | |
| 26 | * Support for sending messages to Maven session listeners. Automates the collection of listeners and the iteration over | |
| 27 | * that collection when an event is fired. | |
| 28 | * | |
| 29 | * @author Ben Hale | |
| 30 | */ | |
| 31 | class SessionListenerSupport { | |
| 32 | ||
| 33 | private Wagon wagon; | |
| 34 | ||
| 35 | 0 | private Set<SessionListener> listeners = new HashSet<SessionListener>(); |
| 36 | ||
| 37 | /** | |
| 38 | * Creates a new instance | |
| 39 | * | |
| 40 | * @param wagon | |
| 41 | * The wagon that events will come from | |
| 42 | */ | |
| 43 | 0 | public SessionListenerSupport(Wagon wagon) { |
| 44 | 0 | this.wagon = wagon; |
| 45 | 0 | } |
| 46 | ||
| 47 | /** | |
| 48 | * Adds a listener to the collection | |
| 49 | * | |
| 50 | * @param listener | |
| 51 | * The listener to add | |
| 52 | */ | |
| 53 | public void addListener(SessionListener listener) { | |
| 54 | 0 | listeners.add(listener); |
| 55 | 0 | } |
| 56 | ||
| 57 | /** | |
| 58 | * Removes a listener from the collection | |
| 59 | * | |
| 60 | * @param listener | |
| 61 | * The listener to remove | |
| 62 | */ | |
| 63 | public void removeListener(SessionListener listener) { | |
| 64 | 0 | listeners.remove(listener); |
| 65 | 0 | } |
| 66 | ||
| 67 | /** | |
| 68 | * Whether the collection already contains a listener | |
| 69 | * | |
| 70 | * @param listener | |
| 71 | * The listener to check for | |
| 72 | * @return Whether the collection contains a listener | |
| 73 | */ | |
| 74 | public boolean hasListener(SessionListener listener) { | |
| 75 | 0 | return listeners.contains(listener); |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * Sends a session opening event to all listeners | |
| 80 | * | |
| 81 | * @see SessionEvent#SESSION_OPENING | |
| 82 | */ | |
| 83 | public void fireSessionOpening() { | |
| 84 | 0 | SessionEvent event = new SessionEvent(wagon, SessionEvent.SESSION_OPENING); |
| 85 | 0 | for (SessionListener listener : listeners) { |
| 86 | 0 | listener.sessionOpening(event); |
| 87 | } | |
| 88 | 0 | } |
| 89 | ||
| 90 | /** | |
| 91 | * Sends a session opened event to all listeners | |
| 92 | * | |
| 93 | * @see SessionEvent#SESSION_OPENED | |
| 94 | */ | |
| 95 | public void fireSessionOpened() { | |
| 96 | 0 | SessionEvent event = new SessionEvent(wagon, SessionEvent.SESSION_OPENED); |
| 97 | 0 | for (SessionListener listener : listeners) { |
| 98 | 0 | listener.sessionOpened(event); |
| 99 | } | |
| 100 | 0 | } |
| 101 | ||
| 102 | /** | |
| 103 | * Sends a session disconnecting event to all listeners | |
| 104 | * | |
| 105 | * @see SessionEvent#SESSION_DISCONNECTING | |
| 106 | */ | |
| 107 | public void fireSessionDisconnecting() { | |
| 108 | 0 | SessionEvent event = new SessionEvent(wagon, SessionEvent.SESSION_DISCONNECTING); |
| 109 | 0 | for (SessionListener listener : listeners) { |
| 110 | 0 | listener.sessionDisconnecting(event); |
| 111 | } | |
| 112 | 0 | } |
| 113 | ||
| 114 | /** | |
| 115 | * Sends a session disconnected event to all listeners | |
| 116 | * | |
| 117 | * @see SessionEvent#SESSION_DISCONNECTED | |
| 118 | */ | |
| 119 | public void fireSessionDisconnected() { | |
| 120 | 0 | SessionEvent event = new SessionEvent(wagon, SessionEvent.SESSION_DISCONNECTED); |
| 121 | 0 | for (SessionListener listener : listeners) { |
| 122 | 0 | listener.sessionDisconnected(event); |
| 123 | } | |
| 124 | 0 | } |
| 125 | ||
| 126 | /** | |
| 127 | * Sends a session connection refused event to all listeners | |
| 128 | * | |
| 129 | * @see SessionEvent#SESSION_CONNECTION_REFUSED | |
| 130 | */ | |
| 131 | public void fireSessionConnectionRefused() { | |
| 132 | 0 | SessionEvent event = new SessionEvent(wagon, SessionEvent.SESSION_CONNECTION_REFUSED); |
| 133 | 0 | for (SessionListener listener : listeners) { |
| 134 | 0 | listener.sessionConnectionRefused(event); |
| 135 | } | |
| 136 | 0 | } |
| 137 | ||
| 138 | /** | |
| 139 | * Sends a session logged in event to all listeners | |
| 140 | * | |
| 141 | * @see SessionEvent#SESSION_LOGGED_IN | |
| 142 | */ | |
| 143 | public void fireSessionLoggedIn() { | |
| 144 | 0 | SessionEvent event = new SessionEvent(wagon, SessionEvent.SESSION_LOGGED_IN); |
| 145 | 0 | for (SessionListener listener : listeners) { |
| 146 | 0 | listener.sessionLoggedIn(event); |
| 147 | } | |
| 148 | 0 | } |
| 149 | ||
| 150 | /** | |
| 151 | * Sends a session logged off event to all listeners | |
| 152 | * | |
| 153 | * @see SessionEvent#SESSION_LOGGED_OFF | |
| 154 | */ | |
| 155 | public void fireSessionLoggedOff() { | |
| 156 | 0 | SessionEvent event = new SessionEvent(wagon, SessionEvent.SESSION_LOGGED_OFF); |
| 157 | 0 | for (SessionListener listener : listeners) { |
| 158 | 0 | listener.sessionLoggedOff(event); |
| 159 | } | |
| 160 | 0 | } |
| 161 | ||
| 162 | /** | |
| 163 | * Sends a session error event to all listeners | |
| 164 | * | |
| 165 | * @param e | |
| 166 | * The session error | |
| 167 | */ | |
| 168 | public void fireSessionError(Exception e) { | |
| 169 | 0 | SessionEvent event = new SessionEvent(wagon, e); |
| 170 | 0 | for (SessionListener listener : listeners) { |
| 171 | 0 | listener.sessionError(event); |
| 172 | } | |
| 173 | 0 | } |
| 174 | } |