001: /**
002: *
003: */package com.sun.esb.management.common.data;
004:
005: import java.io.IOException;
006: import java.net.MalformedURLException;
007: import java.net.URISyntaxException;
008: import java.util.Map;
009: import java.util.Set;
010:
011: import javax.management.openmbean.ArrayType;
012: import javax.management.openmbean.CompositeData;
013: import javax.management.openmbean.CompositeDataSupport;
014: import javax.management.openmbean.CompositeType;
015: import javax.management.openmbean.OpenDataException;
016: import javax.management.openmbean.OpenType;
017: import javax.management.openmbean.SimpleType;
018: import javax.management.openmbean.TabularData;
019: import javax.management.openmbean.TabularDataSupport;
020: import javax.management.openmbean.TabularType;
021: import javax.xml.parsers.ParserConfigurationException;
022:
023: import org.xml.sax.SAXException;
024:
025: import com.sun.esb.management.common.ManagementRemoteException;
026: import com.sun.esb.management.common.data.helper.NMRStatisticsDataReader;
027:
028: /**
029: * @author graj
030: *
031: */
032: public class NMRStatisticsDataCreator {
033:
034: /** nmr CompositeType item names */
035: static String[] NMR_STATS_ITEM_NAMES = { "InstanceName",
036: "ListActiveChannels", "ListActiveEndpoints" };
037:
038: /** nmr CompositeType item descriptions */
039: static String[] NMR_STATS_ITEM_DESCRIPTIONS = { "Instance Name",
040: "List of active delivery channels",
041: "List of active endpoints" };
042:
043: /** nmr stats table index */
044: static String[] NMR_STATS_TABLE_INDEX = new String[] { "InstanceName" };
045:
046: /** nmr stats active channels */
047: static String NMR_ACTIVE_CHANNELS = "ActiveChannels";
048:
049: /** nmr stats active endpoints */
050: static String NMR_ACTIVE_ENDPOINTS = "ActiveEndpoints";
051:
052: /**
053: *
054: */
055: public NMRStatisticsDataCreator() {
056: }
057:
058: /**
059: *
060: * @param data
061: * @return
062: * @throws ManagementRemoteException
063: */
064: public static TabularData createTabularData(
065: Map<String /* instanceName */, NMRStatisticsData> map)
066: throws ManagementRemoteException {
067: TabularData nmrStatsTable = null;
068:
069: try {
070: ArrayType activeChannelsArray = new ArrayType(1,
071: SimpleType.STRING);
072: ArrayType activeEndpointsArray = new ArrayType(1,
073: SimpleType.STRING);
074:
075: OpenType[] nmrStatsItemTypes = { SimpleType.STRING,
076: activeChannelsArray, activeEndpointsArray };
077: CompositeType NMRStatsEntriesType = new CompositeType(
078: "NMRStatistics", "NMR Statistics",
079: NMR_STATS_ITEM_NAMES, NMR_STATS_ITEM_DESCRIPTIONS,
080: nmrStatsItemTypes);
081:
082: TabularType nmrStatsType = new TabularType("NMRStats",
083: "NMR Statistic Information", NMRStatsEntriesType,
084: NMR_STATS_TABLE_INDEX);
085:
086: nmrStatsTable = new TabularDataSupport(nmrStatsType);
087:
088: Set<String> instances = map.keySet();
089: for (String instanceName : instances) {
090: NMRStatisticsData data = map.get(instanceName);
091: nmrStatsTable.put(getNMRStatistics(NMRStatsEntriesType,
092: data));
093: }
094:
095: } catch (OpenDataException e) {
096: throw new ManagementRemoteException(e);
097: }
098: return nmrStatsTable;
099:
100: }
101:
102: /**
103: * This method is used to provide query framework statistics from the
104: * given NMRStatisticsData
105: *
106: * @param NMRStatsEntriesType
107: * @param data
108: * @return
109: * @throws ManagementRemoteException
110: */
111: protected static CompositeData getNMRStatistics(
112: CompositeType NMRStatsEntriesType, NMRStatisticsData data)
113: throws ManagementRemoteException {
114: try {
115: Object[] values = { data.getInstanceName(),
116: data.getActiveChannelsArray(),
117: data.getActiveEndpointsArray() };
118:
119: return new CompositeDataSupport(NMRStatsEntriesType,
120: NMR_STATS_ITEM_NAMES, values);
121:
122: } catch (Exception ex) {
123: throw new ManagementRemoteException(ex);
124: }
125: }
126:
127: /**
128: * @param args
129: */
130: public static void main(String[] args) {
131: String uri = "C:/test/schema/nmrstatistics/NMRStatisticsData.xml";
132: try {
133:
134: Map<String /* instanceName */, NMRStatisticsData> map = null;
135: map = NMRStatisticsDataReader.parseFromFile(uri);
136: for (String instanceName : map.keySet()) {
137: System.out.println(map.get(instanceName)
138: .getDisplayString());
139: }
140: TabularData data = NMRStatisticsDataCreator
141: .createTabularData(map);
142: System.out.println(data);
143: } catch (MalformedURLException e) {
144: e.printStackTrace();
145: } catch (ManagementRemoteException e) {
146: e.printStackTrace();
147: } catch (ParserConfigurationException e) {
148: e.printStackTrace();
149: } catch (SAXException e) {
150: e.printStackTrace();
151: } catch (URISyntaxException e) {
152: e.printStackTrace();
153: } catch (IOException e) {
154: e.printStackTrace();
155: }
156: }
157:
158: }
|