001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.ui.web.admin.loginterface;
013:
014: import java.rmi.RemoteException;
015: import java.util.ArrayList;
016: import java.util.Collection;
017: import java.util.Collections;
018: import java.util.HashMap;
019: import java.util.Iterator;
020:
021: import org.ejbca.core.model.log.LogEntry;
022: import org.ejbca.ui.web.admin.rainterface.SortBy;
023:
024: /**
025: * A class representing a set of log entry view representations.
026: * @author TomSelleck
027: * @version $Id: LogEntriesView.java,v 1.4 2007/12/04 18:43:35 jeklund Exp $
028: */
029: public class LogEntriesView implements java.io.Serializable {
030:
031: /** Creates a new instance of LogEntriesView */
032: public LogEntriesView(SubjectDNProxy dnproxy,
033: String[] localinfoeventnames,
034: String[] localerroreventnames,
035: String[] localsystemeventnames, String[] localmodulenames,
036: HashMap caidtonamemap) {
037: logentryviews = new ArrayList();
038: sortby = new SortBy(SortBy.TIME, SortBy.DECENDING);
039: this .dnproxy = dnproxy;
040: this .localinfoeventnames = localinfoeventnames;
041: this .localerroreventnames = localerroreventnames;
042: this .localsystemeventnames = localsystemeventnames;
043: this .localmodulenames = localmodulenames;
044: this .caidtonamemap = caidtonamemap;
045: }
046:
047: // Public methods.
048:
049: /**
050: * Methods that sets the sorting preference and sortorder.
051: *
052: * @param sortby should be one of the constants defined in org.ejbca.ui.web.admin.rainterface.Sortby.
053: * @param sortorder should be one of the constants defined in org.ejbca.ui.web.admin.rainterface.Sortby.
054: */
055: public void sortBy(int sortby, int sortorder) {
056: this .sortby.setSortBy(sortby);
057: this .sortby.setSortOrder(sortorder);
058:
059: Collections.sort(logentryviews);
060: }
061:
062: /**
063: * Method that returns a given number of sorted logentryviews
064: *
065: * @param index the startingpoint of the data.
066: * @param size the number of logentryviews to return
067: * @return an array of LogEntryView.
068: **/
069: public LogEntryView[] getEntries(int index, int size) {
070: int endindex;
071: LogEntryView[] returnval;
072:
073: if (index > logentryviews.size())
074: index = logentryviews.size() - 1;
075: if (index < 0)
076: index = 0;
077:
078: endindex = index + size;
079: if (endindex > logentryviews.size())
080: endindex = logentryviews.size();
081:
082: returnval = new LogEntryView[endindex - index];
083:
084: int end = endindex - index;
085: for (int i = 0; i < end; i++) {
086: returnval[i] = (LogEntryView) logentryviews.get(index + i);
087: }
088:
089: return returnval;
090: }
091:
092: /**
093: * Method that clears the internal data and adds a collection of logentries.
094: */
095: public void setEntries(Collection logentries)
096: throws RemoteException {
097: LogEntryView logentryview;
098: Iterator i;
099: this .logentryviews.clear();
100: if (logentries != null && logentries.size() > 0) {
101: i = logentries.iterator();
102: while (i.hasNext()) {
103: LogEntry nextentry = (LogEntry) i.next();
104: logentryview = new LogEntryView(nextentry, dnproxy,
105: localinfoeventnames, localerroreventnames,
106: localsystemeventnames, localmodulenames,
107: caidtonamemap);
108: logentryview.setSortBy(this .sortby);
109: logentryviews.add(logentryview);
110: }
111: Collections.sort(logentryviews);
112: }
113: }
114:
115: /**
116: * Method that returns the number of available logentryviews.
117: */
118: public int size() {
119: return logentryviews.size();
120: }
121:
122: // Private fields
123: private ArrayList logentryviews;
124: private SortBy sortby;
125: private SubjectDNProxy dnproxy;
126: private String[] localinfoeventnames;
127: private String[] localerroreventnames;
128: private String[] localsystemeventnames;
129: private String[] localmodulenames;
130: private HashMap caidtonamemap;
131: }
|