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: * @(#)ApplicationVerificationReport.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.Iterator;
035: import java.util.List;
036:
037: import javax.management.openmbean.CompositeData;
038: import javax.management.openmbean.TabularData;
039: import javax.management.openmbean.TabularType;
040: import javax.management.openmbean.SimpleType;
041: import javax.management.openmbean.OpenType;
042: import javax.management.openmbean.CompositeType;
043: import javax.management.openmbean.OpenDataException;
044:
045: import com.sun.esb.management.common.ManagementRemoteException;
046: import com.sun.esb.management.common.data.helper.VerificationDataCreator;
047:
048: /**
049: * Represents the application verification report
050: *
051: * @author graj
052: */
053: public class ApplicationVerificationReport implements Serializable {
054: static final long serialVersionUID = -1L;
055:
056: String serviceAssemblyName;
057:
058: String serviceAssemblyDescription;
059:
060: int numberOfServiceUnits;
061:
062: boolean allComponentsInstalled;
063:
064: List<String /* ComponentName */> missingComponentsList = new ArrayList<String /* ComponentName */>();
065:
066: List<EndpointInformation> endpointInformationList = new ArrayList<EndpointInformation>();
067:
068: String templateZipId;
069:
070: List<JavaEEVerifierReport> javaEEVerifierReports = new ArrayList<JavaEEVerifierReport>();
071:
072: /** Constructor - Creates an ApplicationVerificationReport */
073: public ApplicationVerificationReport() {
074: }
075:
076: /**
077: * Constructor - Creates an ApplicationVerificationReport
078: *
079: * @param compositeData
080: */
081: public ApplicationVerificationReport(CompositeData compositeData) {
082: ApplicationVerificationReport report = retrieveApplicationVerificationReport(compositeData);
083:
084: this .serviceAssemblyName = report.getServiceAssemblyName();
085: this .serviceAssemblyDescription = report
086: .getServiceAssemblyDescription();
087: this .numberOfServiceUnits = report.getNumberOfServiceUnits();
088: this .allComponentsInstalled = report
089: .areAllComponentsInstalled();
090: this .missingComponentsList = report.getMissingComponentsList();
091: this .endpointInformationList = report
092: .getEndpointInformationList();
093: this .templateZipId = report.getTemplateZipId();
094: this .javaEEVerifierReports = report.getJavaEEVerifierReports();
095: }
096:
097: /**
098: * Generate Composite Data for this object
099: * @return composite data of this object
100: */
101: public CompositeData generateCompositeData() {
102: CompositeData compositeData = null;
103: try {
104: compositeData = VerificationDataCreator
105: .createCompositeData(this );
106: } catch (ManagementRemoteException e) {
107: }
108: return compositeData;
109: }
110:
111: /**
112: * @return the serviceAssemblyName
113: */
114: public String getServiceAssemblyName() {
115: return this .serviceAssemblyName;
116: }
117:
118: /**
119: * @param serviceAssemblyName
120: * the serviceAssemblyName to set
121: */
122: public void setServiceAssemblyName(String serviceAssemblyName) {
123: this .serviceAssemblyName = serviceAssemblyName;
124: }
125:
126: /**
127: * @return the serviceAssemblyDescription
128: */
129: public String getServiceAssemblyDescription() {
130: return this .serviceAssemblyDescription;
131: }
132:
133: /**
134: * @param serviceAssemblyDescription
135: * the serviceAssemblyDescription to set
136: */
137: public void setServiceAssemblyDescription(
138: String serviceAssemblyDescription) {
139: this .serviceAssemblyDescription = serviceAssemblyDescription;
140: }
141:
142: /**
143: * @return the numberOfServiceUnits
144: */
145: public int getNumberOfServiceUnits() {
146: return this .numberOfServiceUnits;
147: }
148:
149: /**
150: * @param numberOfServiceUnits
151: * the numberOfServiceUnits to set
152: */
153: public void setNumberOfServiceUnits(int numberOfServiceUnits) {
154: this .numberOfServiceUnits = numberOfServiceUnits;
155: }
156:
157: /**
158: * @return the allComponentsInstalled
159: */
160: public boolean areAllComponentsInstalled() {
161: return this .allComponentsInstalled;
162: }
163:
164: /**
165: * @param allComponentsInstalled
166: * the allComponentsInstalled to set
167: */
168: public void setAllComponentsInstalled(boolean allComponentsInstalled) {
169: this .allComponentsInstalled = allComponentsInstalled;
170: }
171:
172: /**
173: * @return the missingComponentsList
174: */
175: public List<String /* ComponentName */> getMissingComponentsList() {
176: return this .missingComponentsList;
177: }
178:
179: /**
180: *
181: * @param collection
182: * @param componentType
183: * @return
184: */
185: @SuppressWarnings("unchecked")
186: static protected <Type> Type[] toArray(Collection<Type> collection,
187: Class<Type> componentType) {
188: // unchecked cast
189: Type[] array = (Type[]) java.lang.reflect.Array.newInstance(
190: componentType, collection.size());
191: int index = 0;
192: for (Type value : collection) {
193: array[index++] = value;
194: }
195: return array;
196: }
197:
198: /**
199: * @return the missingComponentsArray
200: */
201: public String[] getMissingComponentsArray() {
202: String[] result = toArray(this .missingComponentsList,
203: String.class);
204: return result;
205: }
206:
207: /**
208: * @param missingComponentsList
209: * the missingComponentsList to set
210: */
211: public void setMissingComponentsList(String[] missingComponentsArray) {
212: for (String componentName : missingComponentsArray) {
213: this .missingComponentsList.add(componentName);
214: }
215: }
216:
217: /**
218: * @param missingComponentsList
219: * the missingComponentsList to set
220: */
221: public void setMissingComponentsList(
222: List<String /* ComponentName */> missingComponentsArray) {
223: this .missingComponentsList = missingComponentsArray;
224: }
225:
226: /**
227: * @return the endpointInformationList
228: */
229: public List<EndpointInformation> getEndpointInformationList() {
230: return this .endpointInformationList;
231: }
232:
233: /**
234: * @param endpointInformationList
235: * the endpointInformationList to set
236: */
237: public void setEndpointInformationList(
238: EndpointInformation[] endpointInformationArray) {
239: for (EndpointInformation endpointInformation : endpointInformationArray) {
240: this .endpointInformationList.add(endpointInformation);
241: }
242: }
243:
244: /**
245: * @param endpointInformationList
246: * the endpointInformationList to set
247: */
248: public void setEndpointInformationList(
249: List<EndpointInformation> endpointInformationArray) {
250: this .endpointInformationList = endpointInformationArray;
251: }
252:
253: /**
254: * Sets the JavaEEVerifierReports
255: * @param javaEEVerifierReports the javaeeverifier reports
256: */
257: public void setJavaEEVerifierReports(
258: List<JavaEEVerifierReport> javaEEVerifierReports) {
259: this .javaEEVerifierReports = javaEEVerifierReports;
260: }
261:
262: /**
263: * Gets the JavaEEVerifierReports
264: * @return javaEEVerifierReport javaEEVerifier report
265: */
266: public List<JavaEEVerifierReport> getJavaEEVerifierReports() {
267: return javaEEVerifierReports;
268: }
269:
270: /**
271: * @return the templateZipId
272: */
273: public String getTemplateZipId() {
274: return this .templateZipId;
275: }
276:
277: /**
278: * @param templateZipId
279: * the templateZipId to set
280: */
281: public void setTemplateZipId(String templateZIPID) {
282: this .templateZipId = templateZIPID;
283: }
284:
285: /**
286: * @return the templateZipId
287: */
288: public String getTemplateDirectory() {
289: return this .templateZipId;
290: }
291:
292: /**
293: * @param templateZipId
294: * the templateZipId to set
295: */
296: public void setTemplateDirectory(String templateZIPID) {
297: this .templateZipId = templateZIPID;
298: }
299:
300: /**
301: * Return a displayable string of values
302: *
303: * @return
304: */
305: public String getDisplayString() {
306: StringBuffer buffer = new StringBuffer();
307: buffer.append("\n Service Assembly Name" + "="
308: + this .getServiceAssemblyName());
309: buffer.append("\n Service Assembly Description" + "="
310: + this .getServiceAssemblyDescription());
311: buffer.append("\n Number of Service Units" + "="
312: + this .getNumberOfServiceUnits());
313: buffer.append("\n Are All Components Installed" + "="
314: + this .areAllComponentsInstalled());
315: buffer.append("\n Template Directory or TemplateZipID" + "="
316: + this .getTemplateDirectory());
317: for (String missingComponentName : this
318: .getMissingComponentsList()) {
319: buffer.append("\n missing component name" + "="
320: + missingComponentName);
321: }
322: for (EndpointInformation information : this
323: .getEndpointInformationList()) {
324: buffer.append(information.getDisplayString());
325: }
326: for (JavaEEVerifierReport verifierReport : this
327: .getJavaEEVerifierReports()) {
328: buffer.append(verifierReport.getDisplayString());
329: }
330: return buffer.toString();
331: }
332:
333: /**
334: * retrieve report object from composite data
335: *
336: * @param compositeData
337: * @return
338: */
339: @SuppressWarnings("unchecked")
340: protected static ApplicationVerificationReport retrieveApplicationVerificationReport(
341: CompositeData compositeData) {
342: ApplicationVerificationReport report = new ApplicationVerificationReport();
343: // //////////////////////////////////////////
344: // CompositeType of verification report:
345: // String - "ServiceAssemblyName",
346: // String - "ServiceAssemblyDescription",
347: // Integer - "NumServiceUnits",
348: // Boolean - "AllComponentsInstalled",
349: // String[] - "MissingComponentsList",
350: // CompositeData[] - "EndpointInfo",
351: // String - "TemplateZIPID"
352: // CompositeData[] - "JavaEEVerifierReport"
353: // //////////////////////////////////////////
354: CompositeType compositeType = compositeData.getCompositeType();
355: for (Iterator<String> itemIterator = compositeType.keySet()
356: .iterator(); itemIterator.hasNext();) {
357: String item = (String) itemIterator.next();
358: if (true == item.equals("ServiceAssemblyName")) {
359: report.setServiceAssemblyName((String) compositeData
360: .get(item));
361: }
362: if (true == item.equals("ServiceAssemblyDescription")) {
363: report
364: .setServiceAssemblyDescription((String) compositeData
365: .get(item));
366: }
367: if (true == item.equals("NumServiceUnits")) {
368: Integer value = (Integer) compositeData.get(item);
369: report.setNumberOfServiceUnits(value.intValue());
370: }
371: if (true == item.equals("AllComponentsInstalled")) {
372: Boolean value = (Boolean) compositeData.get(item);
373: report.setAllComponentsInstalled(value.booleanValue());
374: }
375: if (true == item.equals("TemplateZIPID")) {
376: report.setTemplateZipId((String) compositeData
377: .get(item));
378: }
379: if (true == item.equals("MissingComponentsList")) {
380: String[] missingComponentNames = (String[]) compositeData
381: .get(item);
382: report.setMissingComponentsList(missingComponentNames);
383: }
384: if (true == item.equals("EndpointInfo")) {
385: List<EndpointInformation> list = retrieveEndpointInformationList((CompositeData[]) compositeData
386: .get(item));
387: report.setEndpointInformationList(list);
388: }
389: if (true == item.equals("JavaEEVerifierReport")) {
390: List<JavaEEVerifierReport> list = retrieveJavaEEVerifierReports((CompositeData[]) compositeData
391: .get(item));
392: report.setJavaEEVerifierReports(list);
393: }
394: }
395: return report;
396: }
397:
398: /**
399: * Retrieve endpoing infoemation from composite data
400: *
401: * @param compositeDataArray
402: * @return
403: */
404: @SuppressWarnings("unchecked")
405: protected static List<EndpointInformation> retrieveEndpointInformationList(
406: CompositeData[] compositeDataArray) {
407: List<EndpointInformation> result = new ArrayList<EndpointInformation>();
408: // //////////////////////////////////////////
409: // CompositeType of each EndpointInfo:
410: // String - "EndpointName",
411: // String - "ServiceUnitName",
412: // String - "ComponentName",
413: // String - "Status"
414: // //////////////////////////////////////////
415:
416: for (CompositeData compositeData : compositeDataArray) {
417: EndpointInformation information = null;
418: if (compositeData.values().size() > 0) {
419: information = new EndpointInformation();
420: } else {
421: // If no values, skip parsing this element
422: continue;
423: }
424: CompositeType compositeType = compositeData
425: .getCompositeType();
426: for (Iterator<String> itemIterator = compositeType.keySet()
427: .iterator(); itemIterator.hasNext();) {
428: String item = (String) itemIterator.next();
429: if (true == item.equals("EndpointName")) {
430: information.setEndpointName((String) compositeData
431: .get(item));
432: }
433: if (true == item.equals("ServiceUnitName")) {
434: information
435: .setServiceUnitName((String) compositeData
436: .get(item));
437: }
438: if (true == item.equals("ComponentName")) {
439: information.setComponentName((String) compositeData
440: .get(item));
441: }
442: if (true == item.equals("Status")) {
443: information.setStatus((String) compositeData
444: .get(item));
445: }
446: if (true == item.equals("MissingApplicationVariables")) {
447: information
448: .setMissingApplicationVariables((String[]) compositeData
449: .get(item));
450: }
451: if (true == item
452: .equals("MissingApplicationConfigurations")) {
453: information
454: .setMissingApplicationConfigurations((String[]) compositeData
455: .get(item));
456: }
457: }
458: if (information != null) {
459: result.add(information);
460: }
461: }
462:
463: return result;
464: }
465:
466: /**
467: * This method is used to retrieve the list of JavaEEVerification reports
468: * from the verifier report
469: * @param compositeDataArray
470: * @return
471: */
472: protected static List<JavaEEVerifierReport> retrieveJavaEEVerifierReports(
473: CompositeData[] compositeDataArray) {
474: List<JavaEEVerifierReport> result = new ArrayList<JavaEEVerifierReport>();
475: // //////////////////////////////////////////
476: // CompositeType of each EndpointInfo:
477: // String - "ServiceUnitName",
478: // TabularData - "JavaEEVerifierReport",
479: // //////////////////////////////////////////
480:
481: for (CompositeData compositeData : compositeDataArray) {
482: JavaEEVerifierReport report = null;
483: if (compositeData.values().size() > 0) {
484: report = new JavaEEVerifierReport();
485: } else {
486: // If no values, skip parsing this element
487: continue;
488: }
489: CompositeType compositeType = compositeData
490: .getCompositeType();
491: for (Iterator<String> itemIterator = compositeType.keySet()
492: .iterator(); itemIterator.hasNext();) {
493: String item = (String) itemIterator.next();
494: if (true == item.equals("ServiceUnitName")) {
495: report.setServiceUnitName((String) compositeData
496: .get(item));
497: }
498: if (true == item.equals("JavaEEVerifierReport")) {
499: report
500: .setJavaEEVerifierReport((TabularData) compositeData
501: .get(item));
502: }
503: }
504: if (report != null) {
505: result.add(report);
506: }
507: }
508:
509: return result;
510: }
511:
512: /**
513: * This method is used to get the CompositeType for
514: * JavaEEVerifierReport
515: * @return CompositeType the type for JavaEEVerifier Report
516: */
517: public static CompositeType getJavaEEVerifierReportCompositeType()
518: throws OpenDataException {
519: TabularType reportTableType = new TabularType(
520: "JavaEEVerifierTableType",
521: "Java EE Verification Report Table Type",
522: JavaEEVerifierReport.getReportItemCompositeType(),
523: new String[] { "Reference Class", "Reference By",
524: "JNDI Name" });
525:
526: String[] javaEEVerifierReportItemNames = new String[] {
527: "ServiceUnitName", "JavaEEVerifierReport" };
528:
529: String[] javaEEVerifierReportItemDesc = new String[] {
530: "Service Unit Name", "Java EE Verifier Report" };
531:
532: OpenType[] javaEEVerifierReportItemTypes = new OpenType[] {
533: SimpleType.STRING, reportTableType };
534:
535: CompositeType javaEEVerifierReport = new CompositeType(
536: "JavaEEVerifierReport", "Java EE Verifier Report",
537: javaEEVerifierReportItemNames,
538: javaEEVerifierReportItemDesc,
539: javaEEVerifierReportItemTypes);
540:
541: return javaEEVerifierReport;
542: }
543:
544: }
|