001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.server.ldap.gui;
021    
022    
023    import java.net.InetSocketAddress;
024    
025    import javax.swing.event.TableModelListener;
026    import javax.swing.table.TableModel;
027    
028    import org.apache.directory.server.ldap.LdapSession;
029    
030    
031    public class SessionsModel implements TableModel
032    {
033        final String[] columns = new String[]
034            { "client address", "client port", "server address", "server port" };
035        final Class<?>[] columnClasses = new Class[]
036            { String.class, Integer.class, String.class, Integer.class };
037        final LdapSession[] sessions;
038    
039    
040        SessionsModel( LdapSession[] sessions )
041        {
042            this.sessions = sessions;
043        }
044    
045    
046        LdapSession getLdapSession( int row )
047        {
048            return sessions[row];
049        }
050    
051    
052        public int getRowCount()
053        {
054            return sessions.length;
055        }
056    
057    
058        public int getColumnCount()
059        {
060            return columns.length;
061        }
062    
063    
064        public String getColumnName( int columnIndex )
065        {
066            return columns[columnIndex];
067        }
068    
069    
070        public Class<?> getColumnClass( int columnIndex )
071        {
072            return columnClasses[columnIndex];
073        }
074    
075    
076        public boolean isCellEditable( int rowIndex, int columnIndex )
077        {
078            return false;
079        }
080    
081    
082        public Object getValueAt( int rowIndex, int columnIndex )
083        {
084            LdapSession session = sessions[rowIndex];
085    
086            switch ( columnIndex )
087            {
088                case ( 0 ):
089                    return ( ( InetSocketAddress ) session.getIoSession().getRemoteAddress() ).getHostName();
090                case ( 1 ):
091                    return new Integer( ( ( InetSocketAddress ) session.getIoSession().getRemoteAddress() ).getPort() );
092                case ( 2 ):
093                    return ( ( InetSocketAddress ) session.getIoSession().getLocalAddress() ).getHostName();
094                case ( 3 ):
095                    return new Integer( ( ( InetSocketAddress ) session.getIoSession().getLocalAddress() ).getPort() );
096                default:
097                    throw new IndexOutOfBoundsException( "column index max is " + ( columns.length - 1 ) );
098            }
099        }
100    
101    
102        public void setValueAt( Object aValue, int rowIndex, int columnIndex )
103        {
104            throw new UnsupportedOperationException();
105        }
106    
107    
108        public void addTableModelListener( TableModelListener l )
109        {
110        }
111    
112    
113        public void removeTableModelListener( TableModelListener l )
114        {
115        }
116    }