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.i18n.I18n;
029 import org.apache.directory.server.ldap.LdapSession;
030
031
032 public class SessionsModel implements TableModel
033 {
034 final String[] columns = new String[]
035 { "client address", "client port", "server address", "server port" };
036 final Class<?>[] columnClasses = new Class[]
037 { String.class, Integer.class, String.class, Integer.class };
038 final LdapSession[] sessions;
039
040
041 SessionsModel( LdapSession[] sessions )
042 {
043 this.sessions = sessions;
044 }
045
046
047 LdapSession getLdapSession( int row )
048 {
049 return sessions[row];
050 }
051
052
053 public int getRowCount()
054 {
055 return sessions.length;
056 }
057
058
059 public int getColumnCount()
060 {
061 return columns.length;
062 }
063
064
065 public String getColumnName( int columnIndex )
066 {
067 return columns[columnIndex];
068 }
069
070
071 public Class<?> getColumnClass( int columnIndex )
072 {
073 return columnClasses[columnIndex];
074 }
075
076
077 public boolean isCellEditable( int rowIndex, int columnIndex )
078 {
079 return false;
080 }
081
082
083 public Object getValueAt( int rowIndex, int columnIndex )
084 {
085 LdapSession session = sessions[rowIndex];
086
087 switch ( columnIndex )
088 {
089 case ( 0 ):
090 return ( ( InetSocketAddress ) session.getIoSession().getRemoteAddress() ).getHostName();
091 case ( 1 ):
092 return new Integer( ( ( InetSocketAddress ) session.getIoSession().getRemoteAddress() ).getPort() );
093 case ( 2 ):
094 return ( ( InetSocketAddress ) session.getIoSession().getLocalAddress() ).getHostName();
095 case ( 3 ):
096 return new Integer( ( ( InetSocketAddress ) session.getIoSession().getLocalAddress() ).getPort() );
097 default:
098 throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_658, ( columns.length - 1 ) ) );
099 }
100 }
101
102
103 public void setValueAt( Object aValue, int rowIndex, int columnIndex )
104 {
105 throw new UnsupportedOperationException();
106 }
107
108
109 public void addTableModelListener( TableModelListener l )
110 {
111 }
112
113
114 public void removeTableModelListener( TableModelListener l )
115 {
116 }
117 }