001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)NMRStatisticsData.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.esb.management.common.data;
030:
031: import java.io.Serializable;
032: import java.util.ArrayList;
033: import java.util.Collection;
034: import java.util.HashMap;
035: import java.util.Iterator;
036: import java.util.List;
037: import java.util.Map;
038:
039: import javax.management.openmbean.CompositeData;
040: import javax.management.openmbean.CompositeType;
041: import javax.management.openmbean.TabularData;
042: import javax.xml.parsers.ParserConfigurationException;
043: import javax.xml.transform.TransformerException;
044:
045: import com.sun.esb.management.common.ManagementRemoteException;
046: import com.sun.esb.management.common.data.helper.NMRStatisticsDataWriter;
047:
048: /**
049: * @author graj
050: *
051: */
052: public class NMRStatisticsData implements Serializable {
053: static final long serialVersionUID = -1L;
054:
055: public static final String INSTANCENAME_KEY = "InstanceName";
056:
057: public static final String ACTIVECHANNELS_KEY = "ListActiveChannels";
058:
059: public static final String ACTIVEENDPOINTS_KEY = "ListActiveEndpoints";
060:
061: String instanceName;
062:
063: List<String /*active channels*/> activeChannelsList = new ArrayList<String /*active channels*/>();
064:
065: List<String /*active endpoints*/> activeEndpointsList = new ArrayList<String /*active endpoints*/>();
066:
067: /**
068: * Generate Tabular Data for this object
069: *
070: * @param map
071: * @return tabular data of this object
072: */
073: static public TabularData generateTabularData(
074: Map<String /* instanceName */, NMRStatisticsData> map) {
075: TabularData tabularData = null;
076: try {
077: tabularData = NMRStatisticsDataCreator
078: .createTabularData(map);
079: } catch (ManagementRemoteException e) {
080: }
081: return tabularData;
082: }
083:
084: /**
085: * Retrieves the NMR Statistics Data
086: *
087: * @param tabularData
088: * @return NMR Statistics Data
089: */
090: @SuppressWarnings("unchecked")
091: static public Map<String /* instanceName */, NMRStatisticsData> retrieveDataMap(
092: TabularData tabularData) {
093: NMRStatisticsData data = null;
094: Map<String /* instanceName */, NMRStatisticsData> map = null;
095: map = new HashMap<String /* instanceName */, NMRStatisticsData>();
096: for (Iterator dataIterator = tabularData.values().iterator(); dataIterator
097: .hasNext();) {
098: CompositeData compositeData = (CompositeData) dataIterator
099: .next();
100: CompositeType compositeType = compositeData
101: .getCompositeType();
102: data = new NMRStatisticsData();
103: for (Iterator<String> itemIterator = compositeType.keySet()
104: .iterator(); itemIterator.hasNext();) {
105: String item = (String) itemIterator.next();
106: if (true == item
107: .equals(NMRStatisticsData.INSTANCENAME_KEY)) {
108: String value = (String) compositeData.get(item);
109: data.setInstanceName(value);
110: }
111: if (true == item
112: .equals(NMRStatisticsData.ACTIVECHANNELS_KEY)) {
113: String[] values = (String[]) compositeData
114: .get(item);
115: data.setActiveChannelsList(values);
116: }
117: if (true == item
118: .equals(NMRStatisticsData.ACTIVEENDPOINTS_KEY)) {
119: String[] values = (String[]) compositeData
120: .get(item);
121: data.setActiveEndpointsList(values);
122: }
123: }
124: map.put(data.getInstanceName(), data);
125: }
126: return map;
127: }
128:
129: /**
130: * Converts a NMR Statistics Data to an XML String
131: *
132: * @param map
133: * @return XML string representing a NMR Statistics Datum
134: * @throws ManagementRemoteException
135: */
136: static public String convertDataMapToXML(
137: Map<String /* instanceName */, NMRStatisticsData> map)
138: throws ManagementRemoteException {
139: String xmlText = null;
140: try {
141: xmlText = NMRStatisticsDataWriter.serialize(map);
142: } catch (ParserConfigurationException e) {
143: throw new ManagementRemoteException(e);
144: } catch (TransformerException e) {
145: throw new ManagementRemoteException(e);
146: }
147:
148: return xmlText;
149:
150: }
151:
152: /**
153: * @return the instanceName
154: */
155: public String getInstanceName() {
156: return this .instanceName;
157: }
158:
159: /**
160: * @param instanceName the instanceName to set
161: */
162: public void setInstanceName(String instanceName) {
163: this .instanceName = instanceName;
164: }
165:
166: /**
167: * @return the activeChannelList
168: */
169: public List<String> getActiveChannelsList() {
170: return this .activeChannelsList;
171: }
172:
173: /**
174: *
175: * @return the activeChannel array
176: */
177: public String[] getActiveChannelsArray() {
178: String[] result = toArray(this .activeChannelsList, String.class);
179: return result;
180: }
181:
182: /**
183: * @param activeChannelList the activeChannelList to set
184: */
185: public void setActiveChannelsList(List<String> activeChannelList) {
186: this .activeChannelsList = activeChannelList;
187: }
188:
189: /**
190: * @param activeChannelsArray
191: * the activeChannelsArray to set
192: */
193: public void setActiveChannelsList(String[] activeChannelsArray) {
194: for (String activeChannel : activeChannelsArray) {
195: this .activeChannelsList.add(activeChannel);
196: }
197: }
198:
199: /**
200: * @return the activeEndpoints
201: */
202: public List<String> getActiveEndpointsList() {
203: return this .activeEndpointsList;
204: }
205:
206: /**
207: * @param activeEndpoints the activeEndpoints to set
208: */
209: public void setActiveEndpointsList(List<String> activeEndpoints) {
210: this .activeEndpointsList = activeEndpoints;
211: }
212:
213: /**
214: *
215: * @return the activeChannel array
216: */
217: public String[] getActiveEndpointsArray() {
218: String[] result = toArray(this .activeEndpointsList,
219: String.class);
220: return result;
221: }
222:
223: /**
224: * @param activeEndpointsArray
225: * the activeEndpointsArray to set
226: */
227: public void setActiveEndpointsList(String[] activeEndpointsArray) {
228: for (String activeEndpoint : activeEndpointsArray) {
229: this .activeEndpointsList.add(activeEndpoint);
230: }
231: }
232:
233: /**
234: *
235: * @param collection
236: * @param componentType
237: * @return
238: */
239: @SuppressWarnings("unchecked")
240: static protected <Type> Type[] toArray(Collection<Type> collection,
241: Class<Type> componentType) {
242: // unchecked cast
243: Type[] array = (Type[]) java.lang.reflect.Array.newInstance(
244: componentType, collection.size());
245: int index = 0;
246: for (Type value : collection) {
247: array[index++] = value;
248: }
249: return array;
250: }
251:
252: /**
253: *
254: * @return
255: */
256: public String getDisplayString() {
257: StringBuffer buffer = new StringBuffer();
258: buffer.append("\n Instance Name" + "="
259: + this .getInstanceName());
260: if ((this .getActiveChannelsList() != null)
261: && (this .getActiveChannelsList().size() > 0)) {
262: buffer.append("\n Active Channels List:");
263: for (String channel : this .getActiveChannelsList()) {
264: buffer.append("\n Active Channel" + "=" + channel);
265: }
266: }
267: if ((this .getActiveEndpointsList() != null)
268: && (this .getActiveEndpointsList().size() > 0)) {
269: buffer.append("\n Active Endpoints List:");
270: for (String endpoint : this .getActiveEndpointsList()) {
271: buffer.append("\n Active Endpoint" + "=" + endpoint);
272: }
273: }
274: buffer.append("\n ========================================\n");
275: return buffer.toString();
276:
277: }
278:
279: /**
280: * @param args
281: */
282: public static void main(String[] args) {
283: }
284:
285: }
|