KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > loginterface > LogEntriesView


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.web.admin.loginterface;
15
16 import java.rmi.RemoteException JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import org.ejbca.core.model.log.LogEntry;
24 import org.ejbca.ui.web.admin.rainterface.SortBy;
25
26
27 /**
28  * A class representing a set of log entry view representations.
29  * @author TomSelleck
30  * @version $Id: LogEntriesView.java,v 1.3 2006/12/20 08:33:31 anatom Exp $
31  */

32 public class LogEntriesView implements java.io.Serializable JavaDoc {
33  
34     /** Creates a new instance of LogEntriesView */
35     public LogEntriesView(SubjectDNProxy dnproxy , String JavaDoc[] localinfoeventnames, String JavaDoc[] localerroreventnames, String JavaDoc[] localmodulenames, HashMap JavaDoc caidtonamemap) {
36       logentryviews = new ArrayList JavaDoc();
37       sortby = new SortBy(SortBy.TIME, SortBy.DECENDING);
38       this.dnproxy = dnproxy;
39       this.localinfoeventnames=localinfoeventnames;
40       this.localerroreventnames=localerroreventnames;
41       this.localmodulenames=localmodulenames;
42       this.caidtonamemap=caidtonamemap;
43     }
44     
45     // Public methods.
46

47     /**
48      * Methods that sets the sorting preference and sortorder.
49      *
50      * @param sortby should be one of the constants defined in org.ejbca.ui.web.admin.rainterface.Sortby.
51      * @param sortorder should be one of the constants defined in org.ejbca.ui.web.admin.rainterface.Sortby.
52      */

53     public void sortBy(int sortby, int sortorder) {
54       this.sortby.setSortBy(sortby);
55       this.sortby.setSortOrder(sortorder);
56       
57       Collections.sort(logentryviews);
58     }
59     
60     /**
61      * Method that returns a given number of sorted logentryviews
62      *
63      * @param index the startingpoint of the data.
64      * @param size the number of logentryviews to return
65      * @return an array of LogEntryView.
66      **/

67     public LogEntryView[] getEntries(int index, int size) {
68       int endindex;
69       LogEntryView[] returnval;
70    
71       if(index > logentryviews.size()) index = logentryviews.size()-1;
72       if(index < 0) index =0;
73       
74       endindex = index + size;
75       if(endindex > logentryviews.size()) endindex = logentryviews.size();
76       
77       returnval = new LogEntryView[endindex-index];
78       
79       int end = endindex - index;
80       for(int i = 0; i < end; i++){
81         returnval[i] = (LogEntryView) logentryviews.get(index+i);
82       }
83       
84       return returnval;
85     }
86     
87     /**
88      * Method that clears the internal data and adds a collection of logentries.
89      */

90     public void setEntries(Collection JavaDoc logentries) throws RemoteException JavaDoc{
91       LogEntryView logentryview;
92       Iterator JavaDoc i;
93       this.logentryviews.clear();
94       if(logentries!=null && logentries.size() > 0){
95         i=logentries.iterator();
96         while(i.hasNext()){
97           LogEntry nextentry = (LogEntry) i.next();
98           logentryview = new LogEntryView(nextentry, dnproxy, localinfoeventnames, localerroreventnames, localmodulenames, caidtonamemap);
99           logentryview.setSortBy(this.sortby);
100           logentryviews.add(logentryview);
101         }
102         Collections.sort(logentryviews);
103       }
104     }
105     
106     /**
107      * Method that returns the number of available logentryviews.
108      */

109     public int size(){
110       return logentryviews.size();
111     }
112     // Private fields
113
private ArrayList JavaDoc logentryviews;
114     private SortBy sortby;
115     private SubjectDNProxy dnproxy;
116     private String JavaDoc[] localinfoeventnames;
117     private String JavaDoc[] localerroreventnames;
118     private String JavaDoc[] localmodulenames;
119     private HashMap JavaDoc caidtonamemap;
120 }
121
Popular Tags