01: /*
02: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.ubt.report.data.file.derived;
06:
07: import com.sun.portal.ubt.report.data.DataMiner;
08: import com.sun.portal.ubt.report.data.UBTActions;
09: import com.sun.portal.ubt.report.data.file.raw.ChannelWiseActionsMiner;
10: import com.sun.portal.ubt.report.data.file.aggregate.ChannelWiseActionsMinerAggregator;
11: import com.sun.portal.ubt.report.view.IllegalMinerException;
12:
13: import java.util.Iterator;
14: import java.util.Set;
15: import java.util.TreeMap;
16:
17: /**
18: *
19: */
20: public class ChannelWiseActionsDataSource extends UBTTableDataSource {
21: Set actions;
22:
23: public ChannelWiseActionsDataSource(DataMiner miner)
24: throws IllegalMinerException {
25: super (miner);
26: columnNames = new String[] { "Container", "Channel" };
27: if (!(miner instanceof ChannelWiseActionsMiner || miner instanceof ChannelWiseActionsMinerAggregator))
28: throw new IllegalMinerException();
29: Object data = miner.getData();
30: actions = UBTActions.getProviderValidSet();
31: Object[] objAr = actions.toArray();
32: String[] cols = new String[columnNames.length
33: + (objAr != null ? objAr.length : 0)];
34: int i = 0;
35: for (i = 0; i < columnNames.length; i++) {
36: cols[i] = columnNames[i];
37: }
38: for (int j = i; j < objAr.length + i; j++) {
39: cols[j] = (String) objAr[j - i];
40: }
41: columnNames = cols;
42: if (data instanceof TreeMap) {
43: this .data = toDoubleArray((TreeMap) data);
44: }
45:
46: }
47:
48: private Object[][] toDoubleArray(TreeMap treeMap) {
49: //container, Map(channel, (Map(action,count)))) =>
50: //container, channel 'count'for every action
51: Object[][] dataSource = new Object[0][0];
52: if (actions != null && actions.size() > 0) {
53: Set keySet = treeMap.keySet();
54: int rows = 0;
55: Iterator keyI = keySet.iterator();
56: while (keyI.hasNext()) {
57: rows += ((TreeMap) treeMap.get(keyI.next())).keySet()
58: .size();
59: }
60: dataSource = new Object[rows][columnNames.length];
61: Iterator containersI = keySet.iterator();
62: int i = 0;
63: while (containersI.hasNext()) {
64: Object container = containersI.next();
65: TreeMap channelMap = (TreeMap) treeMap.get(container);
66: Iterator channelsI = channelMap.keySet().iterator();
67: while (channelsI.hasNext()) {
68: Object channel = channelsI.next();
69: TreeMap actionMap = (TreeMap) channelMap
70: .get(channel);
71: Iterator actionsI = actionMap.keySet().iterator();
72: dataSource[i][0] = container;
73: dataSource[i][1] = channel;
74: while (actionsI.hasNext()) {
75: Object action = actionsI.next();
76: for (int k = 2; k < actions.size() + 2; k++)
77: if (action.equals(columnNames[k]))
78: dataSource[i][k] = actionMap
79: .get(action);
80: }
81: i++;
82: }
83: }
84: }
85: return dataSource;
86: }
87:
88: }
|