1 package org.apache.maven.wagon.events;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.wagon.Wagon;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class SessionEvent
43 extends WagonEvent
44 {
45
46
47
48
49 public static final int SESSION_CLOSED = 1;
50
51
52
53
54 public static final int SESSION_DISCONNECTING = 2;
55
56
57
58
59 public static final int SESSION_DISCONNECTED = 3;
60
61
62
63
64 public static final int SESSION_CONNECTION_REFUSED = 4;
65
66
67
68
69 public static final int SESSION_OPENING = 5;
70
71
72
73
74 public static final int SESSION_OPENED = 6;
75
76
77
78
79 public static final int SESSION_LOGGED_IN = 7;
80
81
82
83
84 public static final int SESSION_LOGGED_OFF = 8;
85
86
87
88
89 public static final int SESSION_ERROR_OCCURRED = 9;
90
91
92
93
94 private int eventType;
95
96 private Exception exception;
97
98
99
100
101
102
103
104 public SessionEvent( final Wagon wagon, final int eventType )
105 {
106 super( wagon );
107 this.eventType = eventType;
108
109 }
110
111
112
113
114
115
116
117 public SessionEvent( final Wagon wagon, final Exception exception )
118 {
119 super( wagon );
120 this.exception = exception;
121 this.eventType = SESSION_ERROR_OCCURRED;
122
123 }
124
125
126
127
128 public int getEventType()
129 {
130 return eventType;
131 }
132
133
134
135
136 public Exception getException()
137 {
138 return exception;
139 }
140
141
142
143
144 public void setEventType( final int eventType )
145 {
146 switch ( eventType )
147 {
148 case SessionEvent.SESSION_CLOSED:
149 case SessionEvent.SESSION_DISCONNECTED:
150 case SessionEvent.SESSION_DISCONNECTING:
151 case SessionEvent.SESSION_ERROR_OCCURRED:
152 case SessionEvent.SESSION_LOGGED_IN:
153 case SessionEvent.SESSION_LOGGED_OFF:
154 case SessionEvent.SESSION_OPENED:
155 case SessionEvent.SESSION_OPENING:
156 case SessionEvent.SESSION_CONNECTION_REFUSED:
157 break;
158 default :
159 throw new IllegalArgumentException( "Illegal event type: " + eventType );
160 }
161 this.eventType = eventType;
162 }
163
164
165
166
167 public void setException( final Exception exception )
168 {
169 this.exception = exception;
170 }
171
172 public String toString()
173 {
174 StringBuilder sb = new StringBuilder();
175
176 sb.append( "SessionEvent[" );
177
178 switch ( this.eventType )
179 {
180 case SessionEvent.SESSION_CLOSED:
181 sb.append( "CONNECTION_CLOSED" );
182 break;
183 case SessionEvent.SESSION_DISCONNECTED:
184 sb.append( "CONNECTION_DISCONNECTED" );
185 break;
186 case SessionEvent.SESSION_DISCONNECTING:
187 sb.append( "CONNECTION_DISCONNECTING" );
188 break;
189 case SessionEvent.SESSION_ERROR_OCCURRED:
190 sb.append( "CONNECTION_ERROR_OCCURRED" );
191 break;
192 case SessionEvent.SESSION_LOGGED_IN:
193 sb.append( "CONNECTION_LOGGED_IN" );
194 break;
195 case SessionEvent.SESSION_LOGGED_OFF:
196 sb.append( "CONNECTION_LOGGED_OFF" );
197 break;
198 case SessionEvent.SESSION_OPENED:
199 sb.append( "CONNECTION_OPENED" );
200 break;
201 case SessionEvent.SESSION_OPENING:
202 sb.append( "CONNECTION_OPENING" );
203 break;
204 case SessionEvent.SESSION_CONNECTION_REFUSED:
205 sb.append( "CONNECTION_CONNECTION_REFUSED" );
206 break;
207 default:
208 sb.append( eventType );
209 }
210 sb.append( "|" );
211
212 sb.append( this.getWagon().getRepository() ).append( "|" );
213 sb.append( this.source );
214
215 if ( exception != null )
216 {
217 sb.append( "|" );
218 sb.append( exception.getClass().getName() ).append( ":" );
219 sb.append( exception.getMessage() );
220 }
221
222 sb.append( "]" );
223
224 return sb.toString();
225 }
226 }