001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.ubt.report.view.chart;
006:
007: import com.sun.portal.ubt.report.data.DataMiner;
008: import com.sun.portal.ubt.report.data.file.raw.UserIdentityMiner;
009: import com.sun.portal.ubt.report.data.file.derived.UserIdentityDataSource;
010: import com.sun.portal.ubt.report.data.file.derived.UBTTableDataSource;
011: import com.sun.portal.ubt.report.data.file.aggregate.UserIdentityMinerAggregator;
012: import com.sun.portal.ubt.report.view.IllegalMinerException;
013: import com.sun.portal.ubt.report.util.UBTReportResourceBundle;
014:
015: import java.util.Vector;
016: import java.util.Arrays;
017: import java.util.Locale;
018:
019: import org.jfree.chart.JFreeChart;
020: import org.jfree.chart.ChartFactory;
021: import org.jfree.chart.plot.PlotOrientation;
022: import org.jfree.data.category.CategoryDataset;
023: import org.jfree.data.category.DefaultIntervalCategoryDataset;
024:
025: /**
026: *
027: */
028: public class UserIdentityChart implements UBTChartI {
029: DataMiner miner;
030: public static final String XAxisLabel = "RDN";
031: public static final String YAxisLabel = "NoUsers";
032: public static final String PortalUserDomain = "PortalUserDomain";
033: UBTTableDataSource dataSource;
034: private UBTReportResourceBundle reportsResource;
035:
036: public UserIdentityChart(DataMiner miner, Locale locale)
037: throws IllegalMinerException {
038: if (!(miner instanceof UserIdentityMiner || miner instanceof UserIdentityMinerAggregator))
039: throw new IllegalMinerException();
040: this .miner = miner;
041: reportsResource = new UBTReportResourceBundle(locale);
042: }
043:
044: private JFreeChart createChart(String server, String domain)
045: throws IllegalMinerException {
046: CategoryDataset dataset = createDataSet(server, domain);
047: JFreeChart chart = ChartFactory.createBarChart(reportsResource
048: .getReportProperty(PortalUserDomain)
049: + " " + domain, reportsResource
050: .getReportProperty(XAxisLabel), // X-Axis label
051: reportsResource.getReportProperty(YAxisLabel), // Y-Axis label
052: dataset, // Dataset
053: PlotOrientation.VERTICAL,// Orientation
054: true, false, false // Show legend
055: );
056: UBTChartUtil.customizeChart(chart);
057: return chart;
058: }
059:
060: private CategoryDataset createDataSet(String server, String domain) {
061: Object[][] data = dataSource.getData();
062: String[] rdns; //chaannels
063: String[] users = { "" };
064: Number[][] startValues;
065: Vector rdnsVector = new Vector();
066: Vector rdnsValues = new Vector();
067: int count = 0;
068: String prevRdn = null;
069: for (int i = 0; i < data.length; i++) {
070: if (!server.equals(data[i][0])
071: || !domain.equals(data[i][1]))
072: continue;
073: if (prevRdn == null || data[i][2].equals(prevRdn)) {
074: count++;
075: } else {
076: rdnsValues.add(new Integer(count));
077: rdnsVector.add(prevRdn);
078: count = 1;
079: }
080: prevRdn = (String) data[i][2];
081: }
082: rdnsValues.add(new Integer(count));
083: rdnsVector.add(prevRdn);
084: rdns = new String[rdnsVector.size()];
085: copy(rdnsVector.toArray(), rdns);
086:
087: startValues = new Number[rdns.length][1];
088: for (int i = 0; i < startValues.length; i++) {
089: Arrays.fill(startValues[i], new Integer(0));
090: }
091: for (int i = 0; i < rdns.length; i++) {
092: startValues[i][0] = (Integer) rdnsValues.get(i);
093: }
094: return new DefaultIntervalCategoryDataset(rdns, users,
095: startValues, startValues);
096: }
097:
098: private void copy(Object[] objArray, String[] series) {
099: for (int i = 0; i < objArray.length; i++) {
100: series[i] = (String) objArray[i];
101: }
102: }
103:
104: public Vector getChart() {
105: Vector charts = new Vector();
106: try {
107: dataSource = new UserIdentityDataSource(miner);
108: } catch (IllegalMinerException e) {
109: }
110: Object[][] data = dataSource.getData();
111: String prevServer = null;
112: String prevDomain = null;
113: int i = 0;
114: for (int k = 0; k < data.length; k++) {
115: if ((prevServer == null && prevDomain == null)
116: || (prevServer != null && !prevServer
117: .equals(data[k][0]))
118: || (prevDomain != null && !prevDomain
119: .equals(data[k][1]))) {
120: try {
121: charts.add(i, new UBTChartRenderer(createChart(
122: (String) data[k][0], (String) data[k][1])));
123: } catch (IllegalMinerException e) {
124: //drop through, this would have been caught earlier
125: }
126: i++;
127: }
128: prevServer = (String) data[k][0];
129: prevDomain = (String) data[k][1];
130: }
131: return charts;
132: }
133: }
|