001/*
002 * Copyright (c) 2006-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.kepler.ssh;
031
032//////////////////////////////////////////////////////////////////////////
033//// PortEvent
034
035/**
036 * An event that is published by SSH package whenever - a session is opened or
037 * closed
038 * 
039 * @author Norbert Podhorszki
040 * @version $Id: SshEvent.java 24234 2010-05-06 05:21:26Z welker $
041 */
042public class SshEvent {
043        /**
044         * Create a new ssh event with the given parameters. This constructor is
045         * used when an ssh activity is performed.
046         * 
047         * @param event
048         *            The type of event.
049         * @param target
050         *            The remote target involved.
051         */
052        public SshEvent(int event, String target) {
053                _event = event;
054                _target = target;
055                if (_event < EVENT_BOTTOM)
056                        event = EVENT_BOTTOM; // should be an exception
057                if (_event > EVENT_TOP)
058                        event = EVENT_TOP; // should be an exception
059        }
060
061        // /////////////////////////////////////////////////////////////////
062        // // public methods ////
063
064        /**
065         * Return the target as string.
066         * 
067         * @return The target.
068         */
069        public String getTarget() {
070                return _target;
071        }
072
073        /**
074         * Return the type of event.
075         * 
076         * @return The int event.
077         */
078        public int getEvent() {
079                return _event;
080        }
081
082        /**
083         * Return a string representation of this event.
084         * 
085         * @return A user-readable string describing the event.
086         */
087        public String toString() {
088                return new String("SshEvent for target " + _target + ": "
089                                + _eventNames[_event - EVENT_BOTTOM]);
090        }
091
092        // event min value
093        private static int EVENT_BOTTOM = 1;
094        // event type: a session is opened
095        public static int SESSION_OPENED = 1;
096        // event type: a session is closed
097        public static int SESSION_CLOSED = 2;
098        // event max value
099        private static int EVENT_TOP = 2;
100
101        private String[] _eventNames = { "Session opened", "Session closed" };
102
103        // /////////////////////////////////////////////////////////////////
104        // // private variables ////
105
106        // The target
107        private String _target;
108
109        // The event type
110        private int _event;
111
112}