KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > setup > forms > MessageQueueForm


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.setup.forms;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpSession JavaDoc;
27
28 import com.sslexplorer.core.CoreServlet;
29 import com.sslexplorer.notification.MessageSink;
30 import com.sslexplorer.notification.Notifier;
31 import com.sslexplorer.setup.MessageSinkItem;
32 import com.sslexplorer.setup.MessageTableItem;
33 import com.sslexplorer.table.AbstractTableItemTableModel;
34 import com.sslexplorer.table.forms.AbstractPagerForm;
35
36 /**
37  */

38 public class MessageQueueForm extends AbstractPagerForm {
39     private List JavaDoc<MessageSinkItem> messageSinks;
40     private String JavaDoc selectedSink;
41     
42     /**
43      */

44     public MessageQueueForm() {
45         super(new MessageQueueTableModel());
46     }
47     
48     /**
49      * @return List<MessageSinkItem>
50      */

51     public List JavaDoc<MessageSinkItem> getMessageSinks() {
52         return messageSinks;
53     }
54     
55     /**
56      * @param session
57      */

58     public void initialize(HttpSession JavaDoc session) {
59         super.initialize(session, "subject");
60         getModel().clear();
61         Notifier notifier = CoreServlet.getServlet().getNotifier();
62         synchronized(notifier) {
63             List JavaDoc messages = notifier.getMessages();
64             for(Iterator JavaDoc itr = messages.iterator(); itr.hasNext(); ) {
65                 Notifier.MessageWrapper next = (Notifier.MessageWrapper)itr.next();
66                 getModel().addItem(new MessageTableItem((next)));
67             }
68             List JavaDoc<MessageSink> messageSinks = CoreServlet.getServlet().getNotifier().getSinks();
69             List JavaDoc<MessageSinkItem> sinks = new ArrayList JavaDoc<MessageSinkItem>();
70             for(Iterator JavaDoc i = messageSinks.iterator(); i.hasNext(); ) {
71                 MessageSink ms = (MessageSink)i.next();
72                 sinks.add(new MessageSinkItem(ms));
73             }
74             setMessageSinks(sinks);
75             getPager().rebuild(null);
76         }
77     }
78
79     /**
80      * @param messageSinks
81      */

82     public void setMessageSinks(List JavaDoc<MessageSinkItem> messageSinks) {
83         this.messageSinks = messageSinks;
84     }
85     
86     /**
87      * @return String
88      */

89     public String JavaDoc getSelectedSink() {
90         return selectedSink;
91     }
92
93     /**
94      * @param selectedSink
95      */

96     public void setSelectedSink(String JavaDoc selectedSink) {
97         this.selectedSink = selectedSink;
98     }
99     
100     private static final class MessageQueueTableModel extends AbstractTableItemTableModel {
101
102         public int getColumnWidth(int col) {
103             return 0;
104         }
105
106         public String JavaDoc getId() {
107             return "mesageQueue.messages";
108         }
109
110         public int getColumnCount() {
111             return 4;
112         }
113
114         public String JavaDoc getColumnName(int col) {
115             switch(col) {
116                 case 0:
117                     return "subject";
118                 case 1:
119                     return "urgent";
120                 case 2:
121                     return "attempts";
122                 case 3:
123                     return "lastTime";
124                 default:
125                     return "";
126             }
127         }
128
129         public Class JavaDoc getColumnClass(int col) {
130             switch(col) {
131                 case 0:
132                     return Boolean JavaDoc.class;
133                 default:
134                     return String JavaDoc.class;
135             }
136         }
137     }
138 }
Popular Tags