KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tunnels > forms > TunnelsForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.tunnels.forms;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import com.sslexplorer.agent.DefaultAgentManager;
27 import com.sslexplorer.policyframework.LaunchSession;
28 import com.sslexplorer.policyframework.LaunchSessionFactory;
29 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
30 import com.sslexplorer.policyframework.ResourceUtil;
31 import com.sslexplorer.policyframework.forms.AbstractResourcesForm;
32 import com.sslexplorer.security.SessionInfo;
33 import com.sslexplorer.security.User;
34 import com.sslexplorer.tunnels.Tunnel;
35 import com.sslexplorer.tunnels.TunnelDatabase;
36 import com.sslexplorer.tunnels.TunnelDatabaseFactory;
37 import com.sslexplorer.tunnels.TunnelItemModel;
38 import com.sslexplorer.tunnels.TunnelPlugin;
39 import com.sslexplorer.tunnels.TunnelingService;
40
41 /**
42  * Implementation of {@link AbstractResourcesForm} suitable for listing <i>SSL
43  * Tunnels</i>.
44  *
45  * @author James Robinson <a HREF="mailto: james@3sp.com">&lt;james@3sp.com&gt;</a>
46  */

47 public class TunnelsForm extends AbstractResourcesForm {
48
49     /**
50      * Constructor.
51      *
52      */

53     public TunnelsForm() {
54         super(new TunnelItemModel("tunnel"));
55     }
56
57     /**
58      * Initialise.
59      *
60      * @param session session
61      * @param user user
62      * @param defaultSortColumnId default sort column id
63      * @throws Exception on any error
64      */

65     public void initialise(SessionInfo session, User user, String JavaDoc defaultSortColumnId) throws Exception JavaDoc {
66         super.initialize(session.getHttpSession(), defaultSortColumnId);
67         TunnelDatabase sdb = TunnelDatabaseFactory.getInstance();
68         List JavaDoc tunnels = session.getNavigationContext() == SessionInfo.MANAGEMENT_CONSOLE_CONTEXT ? sdb.getTunnels(session.getUser()
69                         .getRealm().getRealmID()) : ResourceUtil.getGrantedResource(session, TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE);
70
71         if (DefaultAgentManager.getInstance().hasActiveAgent(session)) {
72             Set JavaDoc activeTunnels = ((TunnelingService) DefaultAgentManager.getInstance().getService(TunnelingService.class))
73                             .getActiveTunnels(session);
74             for (Iterator JavaDoc it = tunnels.iterator(); it.hasNext();) {
75                 Tunnel tunnel = (Tunnel) it.next();
76                 if (tunnel != null && tunnel.getResourceId() >= 0) {
77                     Integer JavaDoc id = new Integer JavaDoc(tunnel.getResourceId());
78                     LaunchSession launchSession = activeTunnels.contains(id) ? LaunchSessionFactory.getInstance()
79                                     .getFirstLaunchSessionForResource(session, tunnel) : null;
80                     TunnelItem ti = new TunnelItem(tunnel, PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(
81                                     tunnel, user.getRealm()), launchSession);
82                     ti.setFavoriteType(getFavoriteType(tunnel.getResourceId()));
83                     getModel().addItem(ti);
84                 }
85             }
86         } else {
87             Iterator JavaDoc i = tunnels.iterator();
88             while (i.hasNext()) {
89                 Tunnel tunnel = (Tunnel) i.next();
90                 if (tunnel != null) {
91                     TunnelItem ti = new TunnelItem(tunnel, PolicyDatabaseFactory.getInstance().getPoliciesAttachedToResource(
92                                     tunnel, user.getRealm()), null);
93                     ti.setFavoriteType(getFavoriteType(ti.getTunnel().getResourceId()));
94                     getModel().addItem(ti);
95                 }
96             }
97         }
98
99         checkSort();
100         getPager().rebuild(getFilterText());
101     }
102 }
103
Popular Tags