View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.ldap.gui;
21  
22  
23  import java.net.InetSocketAddress;
24  
25  import javax.swing.event.TableModelListener;
26  import javax.swing.table.TableModel;
27  
28  import org.apache.directory.server.ldap.LdapSession;
29  
30  
31  public class SessionsModel implements TableModel
32  {
33      final String[] columns = new String[]
34          { "client address", "client port", "server address", "server port" };
35      final Class<?>[] columnClasses = new Class[]
36          { String.class, Integer.class, String.class, Integer.class };
37      final LdapSession[] sessions;
38  
39  
40      SessionsModel( LdapSession[] sessions )
41      {
42          this.sessions = sessions;
43      }
44  
45  
46      LdapSession getLdapSession( int row )
47      {
48          return sessions[row];
49      }
50  
51  
52      public int getRowCount()
53      {
54          return sessions.length;
55      }
56  
57  
58      public int getColumnCount()
59      {
60          return columns.length;
61      }
62  
63  
64      public String getColumnName( int columnIndex )
65      {
66          return columns[columnIndex];
67      }
68  
69  
70      public Class<?> getColumnClass( int columnIndex )
71      {
72          return columnClasses[columnIndex];
73      }
74  
75  
76      public boolean isCellEditable( int rowIndex, int columnIndex )
77      {
78          return false;
79      }
80  
81  
82      public Object getValueAt( int rowIndex, int columnIndex )
83      {
84          LdapSession session = sessions[rowIndex];
85  
86          switch ( columnIndex )
87          {
88              case ( 0 ):
89                  return ( ( InetSocketAddress ) session.getIoSession().getRemoteAddress() ).getHostName();
90              case ( 1 ):
91                  return new Integer( ( ( InetSocketAddress ) session.getIoSession().getRemoteAddress() ).getPort() );
92              case ( 2 ):
93                  return ( ( InetSocketAddress ) session.getIoSession().getLocalAddress() ).getHostName();
94              case ( 3 ):
95                  return new Integer( ( ( InetSocketAddress ) session.getIoSession().getLocalAddress() ).getPort() );
96              default:
97                  throw new IndexOutOfBoundsException( "column index max is " + ( columns.length - 1 ) );
98          }
99      }
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 }