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: * @(#)VerificationDataCreator.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.helper;
030:
031: import java.io.IOException;
032: import java.net.MalformedURLException;
033: import java.net.URISyntaxException;
034: import java.util.ArrayList;
035: import java.util.HashMap;
036: import java.util.List;
037: import java.util.Map;
038:
039: import javax.management.openmbean.ArrayType;
040: import javax.management.openmbean.CompositeData;
041: import javax.management.openmbean.CompositeDataSupport;
042: import javax.management.openmbean.CompositeType;
043: import javax.management.openmbean.OpenDataException;
044: import javax.management.openmbean.OpenType;
045: import javax.management.openmbean.SimpleType;
046: import javax.management.openmbean.TabularType;
047: import javax.xml.parsers.ParserConfigurationException;
048:
049: import org.xml.sax.SAXException;
050:
051: import com.sun.esb.management.common.ManagementRemoteException;
052: import com.sun.esb.management.common.data.ApplicationVerificationReport;
053: import com.sun.esb.management.common.data.JavaEEVerifierReport;
054: import com.sun.esb.management.common.data.EndpointInformation;
055:
056: /**
057: * Creates Composite Data out of an ApplicationVerificationReport object
058: *
059: * @author graj
060: */
061: public class VerificationDataCreator {
062:
063: /** EndpointInfo CompositeType items */
064: protected static String[] endpointDataItemNames = { "EndpointName",
065: "ServiceUnitName", "ComponentName", "Status",
066: "MissingApplicationVariables",
067: "MissingApplicationConfigurations" };
068:
069: /** EndpointInfo CompositeType descriptions */
070: protected static String[] endpointDataItemDescriptions = {
071: "Endpoint Name", "Service Unit Name", "Component Name",
072: "Status of the endpoint", "Missing Application Variables",
073: "Missing Application Configurations" };
074:
075: /** Constructor - Create a new VerificationDataCreator */
076: private VerificationDataCreator() {
077: }
078:
079: /**
080: * This method is used to compose the verification report
081: * @return Composite Data out of an ApplicationVerificationReport object
082: * @throws ManagementRemoteException
083: */
084: public static CompositeData createCompositeData(
085: ApplicationVerificationReport report)
086: throws ManagementRemoteException {
087: try {
088: ArrayList<String> verifierReportItemNames = new ArrayList<String>();
089: verifierReportItemNames.add("ServiceAssemblyName");
090: verifierReportItemNames.add("ServiceAssemblyDescription");
091: verifierReportItemNames.add("NumServiceUnits");
092: verifierReportItemNames.add("AllComponentsInstalled");
093: verifierReportItemNames.add("MissingComponentsList");
094: verifierReportItemNames.add("EndpointInfo");
095: verifierReportItemNames.add("TemplateZIPID");
096:
097: ArrayList<String> verifierReportItemDescriptions = new ArrayList<String>();
098: verifierReportItemDescriptions
099: .add("Name of the Service Assembly");
100: verifierReportItemDescriptions
101: .add("Description of the Service Assembly");
102: verifierReportItemDescriptions
103: .add("Number of Service Units");
104: verifierReportItemDescriptions
105: .add("Are all necessary components installed");
106: verifierReportItemDescriptions
107: .add("List of missing components");
108: verifierReportItemDescriptions
109: .add("Information about the endpoints");
110: verifierReportItemDescriptions
111: .add("Id for the zip file with configuration templates");
112:
113: ArrayList<OpenType> verifierReportItemTypes = new ArrayList<OpenType>();
114: verifierReportItemTypes.add(SimpleType.STRING);
115: verifierReportItemTypes.add(SimpleType.STRING);
116: verifierReportItemTypes.add(SimpleType.INTEGER);
117: verifierReportItemTypes.add(SimpleType.BOOLEAN);
118: verifierReportItemTypes.add(new ArrayType(1,
119: SimpleType.STRING));
120: verifierReportItemTypes.add(new ArrayType(1,
121: getEndpointInfoType()));
122: verifierReportItemTypes.add(SimpleType.STRING);
123:
124: ArrayList verifierReportValues = new ArrayList();
125: verifierReportValues.add(report.getServiceAssemblyName());
126: verifierReportValues.add(report
127: .getServiceAssemblyDescription());
128: verifierReportValues.add(report.getNumberOfServiceUnits());
129: verifierReportValues.add(new Boolean(report
130: .getMissingComponentsList().size() == 0));
131: verifierReportValues
132: .add(report.getMissingComponentsArray());
133: verifierReportValues.add(getEndpointsInformation(report));
134: verifierReportValues.add(report.getTemplateZipId());
135:
136: //try to get the JavaEEVerifierReport item
137: if (report.getJavaEEVerifierReports() != null
138: && report.getJavaEEVerifierReports().size() > 0) {
139: verifierReportItemNames.add("JavaEEVerificationReport");
140: verifierReportItemDescriptions
141: .add("Java EE Verification Report");
142: verifierReportItemTypes.add(new ArrayType(1, report
143: .getJavaEEVerifierReportCompositeType()));
144:
145: int i = 0;
146: CompositeData[] cDataArray = new CompositeData[report
147: .getJavaEEVerifierReports().size()];
148: for (JavaEEVerifierReport verifierReport : report
149: .getJavaEEVerifierReports()) {
150: cDataArray[i++] = verifierReport.getCompositeData();
151: }
152: verifierReportValues.add(cDataArray);
153: }
154:
155: CompositeType verifierReportType = new CompositeType(
156: "VerifierReportType",
157: "Type of the verification report",
158: (String[]) verifierReportItemNames
159: .toArray(new String[] {}),
160: (String[]) verifierReportItemDescriptions
161: .toArray(new String[] {}),
162: (OpenType[]) verifierReportItemTypes
163: .toArray(new OpenType[] {}));
164:
165: return new CompositeDataSupport(verifierReportType,
166: (String[]) verifierReportItemNames
167: .toArray(new String[] {}),
168: (Object[]) verifierReportValues
169: .toArray(new Object[] {}));
170: } catch (OpenDataException ode) {
171: throw new ManagementRemoteException(ode.getMessage());
172: }
173:
174: }
175:
176: /**
177: * This method is used to get information about the status of
178: * the endpoint
179: * @param report
180: * @returns the endpointinfo
181: * @throws ManagementRemoteException if the endpoint info type could not be obtained
182: */
183: protected static CompositeData[] getEndpointsInformation(
184: ApplicationVerificationReport report)
185: throws ManagementRemoteException {
186: Map<String, EndpointInformation> endpointInfoMap = null;
187: CompositeData[] endpointArray = null;
188: try {
189:
190: OpenType[] endpointDataItemTypes = { SimpleType.STRING,
191: SimpleType.STRING, SimpleType.STRING,
192: SimpleType.STRING,
193: new ArrayType(1, SimpleType.STRING),
194: new ArrayType(1, SimpleType.STRING) };
195:
196: CompositeType endpointInfoType = new CompositeType(
197: "EndpointInfoType",
198: "Provides information about an endpoint",
199: endpointDataItemNames,
200: endpointDataItemDescriptions, endpointDataItemTypes);
201:
202: endpointInfoMap = new HashMap<String, EndpointInformation>();
203: List<EndpointInformation> endpointInfoList = report
204: .getEndpointInformationList();
205: for (EndpointInformation info : endpointInfoList) {
206: if (info != null) {
207: endpointInfoMap.put(info.getEndpointName(), info);
208: }
209: }
210: endpointArray = new CompositeData[endpointInfoMap.keySet()
211: .size()];
212: int counter = 0;
213: for (Object key : endpointInfoMap.keySet()) {
214: EndpointInformation info = (EndpointInformation) endpointInfoMap
215: .get(key);
216: Object[] endpointValues = new Object[6];
217: endpointValues[0] = info.getEndpointName();
218: endpointValues[1] = info.getServiceUnitName();
219: endpointValues[2] = info.getComponentName();
220: endpointValues[3] = info.getStatus();
221: endpointValues[4] = info
222: .getMissingApplicationVariables();
223: endpointValues[5] = info
224: .getMissingApplicationConfigurations();
225: CompositeData endpointData = new CompositeDataSupport(
226: endpointInfoType, endpointDataItemNames,
227: endpointValues);
228: endpointArray[counter++] = endpointData;
229: }
230: } catch (OpenDataException ode) {
231: throw new ManagementRemoteException(ode.getMessage());
232: }
233: return endpointArray;
234: }
235:
236: /**
237: * This method is used to return the endpoint info CompositeType
238: * @returns CompositeType endpointInfoType.
239: * @throws ManagementRemoteException if the composite type could not be created.
240: */
241: protected static CompositeType getEndpointInfoType()
242: throws ManagementRemoteException {
243: try {
244:
245: OpenType[] endpointDataItemTypes = { SimpleType.STRING,
246: SimpleType.STRING, SimpleType.STRING,
247: SimpleType.STRING,
248: new ArrayType(1, SimpleType.STRING),
249: new ArrayType(1, SimpleType.STRING) };
250:
251: return new CompositeType("EndpointInfoType",
252: "Provides information about an endpoint",
253: endpointDataItemNames,
254: endpointDataItemDescriptions, endpointDataItemTypes);
255: } catch (OpenDataException e) {
256: throw new ManagementRemoteException(e.getMessage());
257: }
258: }
259:
260: /**
261: * @param args
262: */
263: public static void main(String[] args) {
264: String uri = "C:/test/schema/verification/ApplicationVerificationReport.xml";
265: try {
266: ApplicationVerificationReport report = ApplicationVerificationReportReader
267: .parseFromFile(uri);
268: System.out.println(report.getDisplayString());
269: CompositeData data = VerificationDataCreator
270: .createCompositeData(report);
271: System.out.println(data);
272: } catch (MalformedURLException e) {
273: // TODO Auto-generated catch block
274: e.printStackTrace();
275: } catch (ManagementRemoteException e) {
276: // TODO Auto-generated catch block
277: e.printStackTrace();
278: } catch (ParserConfigurationException e) {
279: // TODO Auto-generated catch block
280: e.printStackTrace();
281: } catch (SAXException e) {
282: // TODO Auto-generated catch block
283: e.printStackTrace();
284: } catch (URISyntaxException e) {
285: // TODO Auto-generated catch block
286: e.printStackTrace();
287: } catch (IOException e) {
288: // TODO Auto-generated catch block
289: e.printStackTrace();
290: }
291:
292: }
293:
294: /**
295: * JavaEE Verifier Item Names
296: */
297:
298: String[] JAVAEE_VERIFIER_ITEM_NAMES = new String[] {
299: "Ear Filename", "Reference By", "Reference Class",
300: "JNDI Name", "JNDI Class Type", "Message", "Status" };
301:
302: /**
303: * JavaEE Verifier Item Descriptions
304: */
305: String[] JAVAEE_VERIFIER_ITEM_DESCRIPTIONS = new String[] {
306: "Ear File Name", "Reference By", "Reference Class",
307: "Jndi Name", "Jndi Class", "Message", "Status"
308:
309: };
310:
311: /**
312: * JavaEE Verifier Item Types
313: */
314: OpenType[] JAVAEE_VERIFIER_ITEM_TYPES = new OpenType[] {
315: SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,
316: SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,
317: SimpleType.INTEGER };
318:
319: }
|