Coverage Report - org.apache.maven.wagon.events.SessionEvent
 
Classes in this File Line Coverage Branch Coverage Complexity
SessionEvent
44%
24/55
45%
10/22
3,857
 
 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 org.apache.maven.wagon.Wagon;
 23  
 
 24  
 /**
 25  
  * SessionEvent is used for notifying SessionListeners about
 26  
  * occurrences of various situations related.
 27  
  * <p/>
 28  
  * The session event is emitted by <code>Wagon</code> objects when
 29  
  * <p/>
 30  
  * <ul>
 31  
  * <li>Before connection to the repository will be opened</li>
 32  
  * <li>After connection to the repository was opened</li>
 33  
  * <li>After wagon has logged-in to the repository</li>
 34  
  * <li>After wagon has logged-off from the repository</li>
 35  
  * <li>Before connection to the repository will be closed</li>
 36  
  * <li>After connection to the repository was closed</li>
 37  
  * </ul>
 38  
  *
 39  
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
 40  
  * @version $Id: SessionEvent.java 682051 2008-08-02 21:29:38Z hboutemy $
 41  
  */
 42  
 public class SessionEvent
 43  
     extends WagonEvent
 44  
 {
 45  
 
 46  
     /**
 47  
      * A SESSION was closed.
 48  
      */
 49  
     public static final int SESSION_CLOSED = 1;
 50  
 
 51  
     /**
 52  
      * A SESSION is about to be disconnected.
 53  
      */
 54  
     public static final int SESSION_DISCONNECTING = 2;
 55  
 
 56  
     /**
 57  
      * A SESSION was disconnected (not currently used).
 58  
      */
 59  
     public static final int SESSION_DISCONNECTED = 3;
 60  
 
 61  
     /**
 62  
      * A SESSION was refused.
 63  
      */
 64  
     public static final int SESSION_CONNECTION_REFUSED = 4;
 65  
 
 66  
     /**
 67  
      * A SESSION is about to be opened.
 68  
      */
 69  
     public static final int SESSION_OPENING = 5;
 70  
 
 71  
     /**
 72  
      * A SESSION was opened.
 73  
      */
 74  
     public static final int SESSION_OPENED = 6;
 75  
 
 76  
     /**
 77  
      * A SESSION was opened.
 78  
      */
 79  
     public static final int SESSION_LOGGED_IN = 7;
 80  
 
 81  
     /**
 82  
      * A SESSION was opened.
 83  
      */
 84  
     public static final int SESSION_LOGGED_OFF = 8;
 85  
 
 86  
     /**
 87  
      * A SESSION was opened.
 88  
      */
 89  
     public static final int SESSION_ERROR_OCCURRED = 9;
 90  
 
 91  
     /**
 92  
      * The type of the event. One of the SESSSION_XXX constants
 93  
      */
 94  
     private int eventType;
 95  
 
 96  
     private Exception exception;
 97  
 
 98  
     /**
 99  
      * Creates new instance of SessionEvent
 100  
      *
 101  
      * @param wagon     <code>Wagon<code> object which created this event
 102  
      * @param eventType the type of the event
 103  
      */
 104  
     public SessionEvent( final Wagon wagon, final int eventType )
 105  
     {
 106  121
         super( wagon );
 107  121
         this.eventType = eventType;
 108  
 
 109  121
     }
 110  
 
 111  
     /**
 112  
      * Creates new instance of SessionEvent. Sets event type to <code>SESSION_ERROR_OCCURRED</code>
 113  
      *
 114  
      * @param wagon     <code>Wagon<code> object which created this event
 115  
      * @param exception the exception
 116  
      */
 117  
     public SessionEvent( final Wagon wagon, final Exception exception )
 118  
     {
 119  2
         super( wagon );
 120  2
         this.exception = exception;
 121  2
         this.eventType = SESSION_ERROR_OCCURRED;
 122  
 
 123  2
     }
 124  
 
 125  
     /**
 126  
      * @return Returns the type.
 127  
      */
 128  
     public int getEventType()
 129  
     {
 130  11
         return eventType;
 131  
     }
 132  
 
 133  
     /**
 134  
      * @return Returns the exception.
 135  
      */
 136  
     public Exception getException()
 137  
     {
 138  3
         return exception;
 139  
     }
 140  
 
 141  
     /**
 142  
      * @param eventType The eventType to set.
 143  
      */
 144  
     public void setEventType( final int eventType )
 145  
     {
 146  10
         switch ( eventType )
 147  
         {
 148  
 
 149  
             case SessionEvent.SESSION_CLOSED:
 150  1
                 break;
 151  
             case SessionEvent.SESSION_DISCONNECTED:
 152  1
                 break;
 153  
             case SessionEvent.SESSION_DISCONNECTING:
 154  1
                 break;
 155  
             case SessionEvent.SESSION_ERROR_OCCURRED:
 156  1
                 break;
 157  
             case SessionEvent.SESSION_LOGGED_IN:
 158  1
                 break;
 159  
             case SessionEvent.SESSION_LOGGED_OFF:
 160  1
                 break;
 161  
             case SessionEvent.SESSION_OPENED:
 162  1
                 break;
 163  
             case SessionEvent.SESSION_OPENING:
 164  1
                 break;
 165  
             case SessionEvent.SESSION_CONNECTION_REFUSED:
 166  1
                 break;
 167  
             default :
 168  1
                 throw new IllegalArgumentException( "Illegal event type: " + eventType );
 169  
         }
 170  9
         this.eventType = eventType;
 171  9
     }
 172  
 
 173  
     /**
 174  
      * @param exception The exception to set.
 175  
      */
 176  
     public void setException( final Exception exception )
 177  
     {
 178  2
         this.exception = exception;
 179  2
     }
 180  
 
 181  
     public String toString()
 182  
     {
 183  0
         StringBuffer sb = new StringBuffer();
 184  
 
 185  0
         sb.append( "SessionEvent[" );
 186  
 
 187  0
         switch ( this.eventType )
 188  
         {
 189  
             case SessionEvent.SESSION_CLOSED:
 190  0
                 sb.append( "CONNECTION_CLOSED" );
 191  0
                 break;
 192  
             case SessionEvent.SESSION_DISCONNECTED:
 193  0
                 sb.append( "CONNECTION_DISCONNECTED" );
 194  0
                 break;
 195  
             case SessionEvent.SESSION_DISCONNECTING:
 196  0
                 sb.append( "CONNECTION_DISCONNECTING" );
 197  0
                 break;
 198  
             case SessionEvent.SESSION_ERROR_OCCURRED:
 199  0
                 sb.append( "CONNECTION_ERROR_OCCURRED" );
 200  0
                 break;
 201  
             case SessionEvent.SESSION_LOGGED_IN:
 202  0
                 sb.append( "CONNECTION_LOGGED_IN" );
 203  0
                 break;
 204  
             case SessionEvent.SESSION_LOGGED_OFF:
 205  0
                 sb.append( "CONNECTION_LOGGED_OFF" );
 206  0
                 break;
 207  
             case SessionEvent.SESSION_OPENED:
 208  0
                 sb.append( "CONNECTION_OPENED" );
 209  0
                 break;
 210  
             case SessionEvent.SESSION_OPENING:
 211  0
                 sb.append( "CONNECTION_OPENING" );
 212  0
                 break;
 213  
             case SessionEvent.SESSION_CONNECTION_REFUSED:
 214  0
                 sb.append( "CONNECTION_CONNECTION_REFUSED" );
 215  0
                 break;
 216  
             default:
 217  0
                 sb.append( eventType );
 218  
         }
 219  0
         sb.append( "|" );
 220  
 
 221  0
         sb.append( this.getWagon().getRepository() ).append( "|" );
 222  0
         sb.append( this.source );
 223  
 
 224  0
         if ( exception != null )
 225  
         {
 226  0
             sb.append( "|" );
 227  0
             sb.append( exception.getClass().getName() ).append( ":" );
 228  0
             sb.append( exception.getMessage() );
 229  
         }
 230  
 
 231  0
         sb.append( "]" );
 232  
 
 233  0
         return sb.toString();
 234  
     }
 235  
 }