0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common Development
0008: * and Distribution License("CDDL") (collectively, the "License"). You
0009: * may not use this file except in compliance with the License. You can obtain
0010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
0011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
0012: * language governing permissions and limitations under the License.
0013: *
0014: * When distributing the software, include this License Header Notice in each
0015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
0016: * Sun designates this particular file as subject to the "Classpath" exception
0017: * as provided by Sun in the GPL Version 2 section of the License file that
0018: * accompanied this code. If applicable, add the following below the License
0019: * Header, with the fields enclosed by brackets [] replaced by your own
0020: * identifying information: "Portions Copyrighted [year]
0021: * [name of copyright owner]"
0022: *
0023: * Contributor(s):
0024: *
0025: * If you wish your version of this file to be governed by only the CDDL or
0026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
0027: * elects to include this software in this distribution under the [CDDL or GPL
0028: * Version 2] license." If you don't indicate a single choice of license, a
0029: * recipient has the option to distribute your version of this file under
0030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
0031: * its licensees as provided above. However, if you add GPL Version 2 code
0032: * and therefore, elected the GPL Version 2 license, then the option applies
0033: * only if the new code is made subject to such option by the copyright
0034: * holder.
0035: */
0036:
0037: package com.sun.jbi.cli.commands;
0038:
0039: import com.sun.enterprise.util.i18n.StringManager;
0040: import com.sun.enterprise.cli.framework.*;
0041: import com.sun.jbi.cli.commands.JBICommandConstants;
0042: import com.sun.enterprise.cli.framework.CLILogger;
0043: import com.sun.jbi.ui.common.JBITimeUtil;
0044: import com.sun.jbi.ui.common.JBIComponentInfo;
0045: import com.sun.jbi.ui.common.ServiceAssemblyInfo;
0046: import com.sun.jbi.ui.common.ServiceUnitInfo;
0047: import com.sun.jbi.ui.common.JBIStatisticsItemNames;
0048:
0049: import javax.management.openmbean.TabularData;
0050: import javax.management.openmbean.CompositeData;
0051: import javax.management.openmbean.CompositeType;
0052: import javax.management.openmbean.OpenType;
0053: import javax.management.openmbean.CompositeDataSupport;
0054: import javax.management.openmbean.SimpleType;
0055: import javax.management.openmbean.ArrayType;
0056:
0057: import java.util.Iterator;
0058: import java.util.List;
0059: import java.util.Map;
0060: import java.util.Set;
0061: import java.util.TreeSet;
0062: import java.util.Properties;
0063: import java.util.HashMap;
0064: import java.util.ArrayList;
0065: import java.util.Hashtable;
0066: import java.util.Enumeration;
0067: import java.util.regex.Pattern;
0068: import java.util.regex.Matcher;
0069: import java.util.StringTokenizer;
0070:
0071: import java.io.File;
0072: import java.io.FileReader;
0073: import java.io.FileWriter;
0074: import java.io.BufferedReader;
0075: import java.io.BufferedWriter;
0076: import java.io.PrintWriter;
0077: import java.io.FileInputStream;
0078: import java.io.IOException;
0079: import java.io.FileNotFoundException;
0080:
0081: import org.w3c.dom.Document;
0082: import org.w3c.dom.Node;
0083: import org.w3c.dom.NodeList;
0084: import org.w3c.dom.NamedNodeMap;
0085: import javax.xml.parsers.ParserConfigurationException;
0086: import javax.xml.parsers.DocumentBuilderFactory;
0087: import javax.xml.parsers.DocumentBuilder;
0088: import org.xml.sax.SAXException;
0089:
0090: import java.lang.Long;
0091: import java.lang.Short;
0092: import java.lang.Boolean;
0093: import java.lang.Integer;
0094:
0095: /**
0096: * Will start the JBI component on the specified target.
0097: * @version $Revision: 1.14 $
0098: */
0099: public abstract class JBICommand extends
0100: com.sun.enterprise.cli.commands.JBICommand {
0101: static String[] mValidStates = { "started", "stopped", "shutdown" };
0102:
0103: static String[] mVariableTypes = { JBICommandConstants.STRING_TYPE,
0104: JBICommandConstants.BOOLEAN_TYPE,
0105: JBICommandConstants.NUMBER_TYPE,
0106: JBICommandConstants.PASSWORD_TYPE };
0107:
0108: static final String CONFIG_COMMAND_FILENAME_ANT = "configure.xml";
0109: static final String CONFIG_COMMAND_FILENAME_ASADMIN = "configure.txt";
0110: static final String CONFIG_PROPERTIES_FILENAME = "connection.properties";
0111:
0112: // Hash that is used when converting the configure.xml (ant syntax) to file
0113: // to configue.txt (asadmin syntax).
0114: static Hashtable mCommandConversionTbl = new Hashtable();
0115: static {
0116: mCommandConversionTbl
0117: .put(
0118: "create-app-variable",
0119: "create-jbi-application-variable --component=component.name properties.file.name");
0120: mCommandConversionTbl
0121: .put(
0122: "create-app-configuration",
0123: "create-jbi-application-configuration --component=component.name --configname=config.name properties.file.name");
0124: mCommandConversionTbl.put("deploy-application",
0125: "deploy-jbi-service-assembly deploy.file");
0126: }
0127:
0128: // Hash that is used when converting the conversion.properties from
0129: // ant syntax to asadmin syntax.
0130: static Hashtable mConnectionConversionTbl = new Hashtable();
0131: static {
0132: mConnectionConversionTbl.put("jbi.username", "AS_ADMIN_USER");
0133: mConnectionConversionTbl.put("jbi.password",
0134: "AS_ADMIN_PASSWORD");
0135: mConnectionConversionTbl.put("jbi.host", "AS_ADMIN_HOST");
0136: mConnectionConversionTbl.put("jbi.port", "AS_ADMIN_PORT");
0137: mConnectionConversionTbl.put("jbi.secure", "AS_ADMIN_SECURE");
0138: mConnectionConversionTbl.put("jbi.target", "AS_ADMIN_TARGET");
0139: }
0140:
0141: JBIComponentInfo mInfo = null;
0142:
0143: private static final StringManager _strMgr = StringManager
0144: .getManager("com.sun.jbi.cli.resources");
0145:
0146: /**
0147: * Overloaded method that will first use the StringManager to look for
0148: * the property value, If not found there, the super class getLocalizedString
0149: * method will used. This needs to be implemented for multimode to work.
0150: * @param key The properties key
0151: * @return The property value (localized string)
0152: */
0153: protected String getLocalizedString(String key) {
0154: String localizedString = _strMgr.getStringWithDefault(key,
0155: "unabletofind");
0156: if (localizedString.equalsIgnoreCase("unabletofind")) {
0157: localizedString = super .getLocalizedString(key);
0158: }
0159: return localizedString;
0160: }
0161:
0162: /**
0163: * Overloaded method that will first use the StringManager to look for
0164: * the property value, If not found there, the super class getLocalizedString
0165: * method will used. This needs to be implemented for multimode to work.
0166: * @param key The properties key
0167: * @param args[] The array of arguments
0168: * @return The property value (localized string)
0169: */
0170: protected String getLocalizedString(String key, Object[] args) {
0171: String localizedString = _strMgr.getStringWithDefault(key,
0172: "unabletofind", args);
0173: if (localizedString.equalsIgnoreCase("unabletofind")) {
0174: localizedString = super .getLocalizedString(key, args);
0175: }
0176: return localizedString;
0177: }
0178:
0179: /**
0180: * Will insert the default type [STRING] into the properties string
0181: * if one is not present.
0182: * @param properties The properties to analyize and update
0183: */
0184: protected Properties insertType(Properties properties) {
0185: Properties returnProperties = new Properties();
0186: Set keys = properties.keySet();
0187: TreeSet<String> sortedKeys = new TreeSet<String>(keys);
0188: for (String key : sortedKeys) {
0189: String value = (String) properties.get(key);
0190: Boolean typeFound = false;
0191: for (int i = 0; i < mVariableTypes.length; i++) {
0192: if (value.toUpperCase().startsWith(mVariableTypes[i])) {
0193: typeFound = true;
0194: break;
0195: }
0196: }
0197: if (!(typeFound)) {
0198: value = JBICommandConstants.STRING_TYPE
0199: + (String) properties.get(key);
0200: }
0201: returnProperties.put(key, value);
0202: }
0203: return returnProperties;
0204: }
0205:
0206: /**
0207: * Will display the descriptor result (xml file)
0208: * @param descriptor string (xml format)
0209: */
0210: protected void displayDescriptor(String descriptor) {
0211: displayMessage(descriptor, 0);
0212: }
0213:
0214: /**
0215: * Will return the command name
0216: * @return the command name
0217: */
0218: public String getName() {
0219: return name;
0220: }
0221:
0222: /**
0223: * Will process the NMR TabularData object to display the NMR
0224: * information to the screen.
0225: * @param data The TabularData containing the CompositData to display
0226: */
0227: protected void processNMRResults(TabularData data) {
0228: displayOptionHeader("JBINMRStatisticsHeader", 0);
0229:
0230: if ((data == null) || (data.size() == 0) || (data.isEmpty())) {
0231: String msg = getLocalizedString("JBIErrorRetrievingNMRStats");
0232: displayMessage(msg, 0);
0233: }
0234:
0235: else {
0236: String msg = "";
0237: Iterator iterator = data.values().iterator();
0238: while (iterator.hasNext()) {
0239: CompositeData compData = (CompositeData) iterator
0240: .next();
0241: String[] activeChannels = (String[]) compData
0242: .get(JBIStatisticsItemNames.NMR_STATS_ACTIVE_CHANNELS);
0243: String[] activeEndpoints = (String[]) compData
0244: .get(JBIStatisticsItemNames.NMR_STATS_ACTIVE_ENDPOINTS);
0245: // String[] activeChannels = {"sun-http-binding","sun-bpel-engine","sun-javaee-engine"};
0246: // String[] activeEndpoints = {"http://localhost/SynchronousSample,service1,endpoint1","http://localhost/New,service1,endpoint2","http://localhost/Old,service1,endpoint3"};
0247:
0248: // Display the Instance Name
0249: String instanceName = (String) compData
0250: .get(JBIStatisticsItemNames.INSTANCE_NAME);
0251: msg = getLocalizedString("JBIStatsNMRInstanceName",
0252: new Object[] { instanceName });
0253: displayMessage(msg, 0);
0254:
0255: msg = getLocalizedString(
0256: "JBIStatsNMRTotalActiveChannels",
0257: new Object[] { activeChannels.length });
0258: displayMessage(msg, 0);
0259:
0260: msg = getLocalizedString(
0261: "JBIStatsNMRTotalActiveEndpoints",
0262: new Object[] { activeEndpoints.length });
0263: displayMessage(msg, 0);
0264:
0265: if (activeChannels != null) {
0266: displayOptionHeader(
0267: "JBIStatsNMRActiveChannelsHeader", 4);
0268: for (int i = 0; i < activeChannels.length; i++) {
0269: displayMessage(activeChannels[i], 4);
0270: }
0271: }
0272:
0273: if (activeEndpoints != null) {
0274: displayOptionHeader(
0275: "JBIStatsNMRActiveEndpointsHeader", 4);
0276: for (int i = 0; i < activeEndpoints.length; i++) {
0277: displayMessage(activeEndpoints[i], 4);
0278: }
0279: }
0280: }
0281: displayMessage(" ", 0);
0282: }
0283: }
0284:
0285: /**
0286: * Will process the Component TabularData object to display the Component
0287: * information to the screen.
0288: * @param data The TabularData containing the CompositData to display
0289: * @param componentName The Component name
0290: */
0291: protected void processComponentResults(TabularData data,
0292: String componentName) {
0293: if ((data == null) || (data.size() == 0) || (data.isEmpty())) {
0294: String msg = getLocalizedString("JBIErrorRetrievingComponentStats");
0295: displayMessage(msg, 0);
0296: }
0297:
0298: else {
0299: String msg = "";
0300: Iterator iterator = data.values().iterator();
0301: while (iterator.hasNext()) {
0302:
0303: CompositeData compData = (CompositeData) iterator
0304: .next();
0305: CompositeType compType = compData.getCompositeType();
0306: Set compItemSet = compType.keySet();
0307:
0308: displayOptionHeader("JBIComponentStatisticsHeader", 0);
0309:
0310: msg = getLocalizedString("JBIStatsCompComponentLabel",
0311: new Object[] { componentName });
0312: displayMessage(msg, 0);
0313:
0314: String instanceName = (String) compData
0315: .get(JBIStatisticsItemNames.INSTANCE_NAME);
0316: msg = getLocalizedString("JBIStatsCompInstanceLabel",
0317: new Object[] { instanceName });
0318: displayMessage(msg, 0);
0319:
0320: displayCompositeUpTime(compData,
0321: JBIStatisticsItemNames.COMPONENT_UPTIME,
0322: "JBIStatsCompontUpTime", 0);
0323:
0324: displayCompositeItem(
0325: compData,
0326: JBIStatisticsItemNames.NUMBER_OF_ACTIVATED_ENDPOINTS,
0327: "JBINumberOfActiveEndpoints", 0);
0328:
0329: displayOptionHeader("JBIShowReceivedStatisticsHeader",
0330: 4);
0331: displayCompositeItem(
0332: compData,
0333: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_REQUESTS,
0334: "JBINumberOfReceivedRequests", 4);
0335: displayCompositeItem(
0336: compData,
0337: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_REPLIES,
0338: "JBINumberOfReceivedReplies", 4);
0339: displayCompositeItem(
0340: compData,
0341: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_DONES,
0342: "JBINumberOfReceivedDones", 4);
0343: displayCompositeItem(
0344: compData,
0345: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_FAULTS,
0346: "JBINumberOfReceivedFaults", 4);
0347: displayCompositeItem(
0348: compData,
0349: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_ERRORS,
0350: "JBINumberOfReceivedErrors", 4);
0351:
0352: displayOptionHeader("JBIShowSentStatisticsHeader", 4);
0353: displayCompositeItem(compData,
0354: JBIStatisticsItemNames.NUMBER_OF_SENT_REQUESTS,
0355: "JBINumberOfSentRequests", 4);
0356: displayCompositeItem(compData,
0357: JBIStatisticsItemNames.NUMBER_OF_SENT_REPLIES,
0358: "JBINumberOfSentReplies", 4);
0359: displayCompositeItem(compData,
0360: JBIStatisticsItemNames.NUMBER_OF_SENT_DONES,
0361: "JBINumberOfSentDones", 4);
0362: displayCompositeItem(compData,
0363: JBIStatisticsItemNames.NUMBER_OF_SENT_FAULTS,
0364: "JBINumberOfSentFaults", 4);
0365: displayCompositeItem(compData,
0366: JBIStatisticsItemNames.NUMBER_OF_SENT_ERRORS,
0367: "JBINumberOfSentErrors", 4);
0368:
0369: displayOptionHeader("JBIShowExchangesStatisticsHeader",
0370: 4);
0371: displayCompositeItem(
0372: compData,
0373: JBIStatisticsItemNames.NUMBER_OF_COMPLETED_EXCHANGES,
0374: "JBINumberOfCompletedExchanges", 4);
0375: displayCompositeItem(
0376: compData,
0377: JBIStatisticsItemNames.NUMBER_OF_ACTIVE_EXCHANGES,
0378: "JBINumberOfActiveExchanges", 4);
0379: displayCompositeItem(
0380: compData,
0381: JBIStatisticsItemNames.NUMBER_OF_ERROR_EXCHANGES,
0382: "JBINumberOfErrorExchanges", 4);
0383: }
0384: displayMessage(" ", 0);
0385: }
0386: }
0387:
0388: /**
0389: * Will process the Framework TabularData object to display the Framework
0390: * information to the screen.
0391: * @param data The TabularData containing the CompositData to display
0392: */
0393: protected void processFrameworkResults(TabularData data) {
0394: if ((data == null) || (data.size() == 0) || (data.isEmpty())) {
0395: String msg = getLocalizedString("JBIErrorRetrievingFrameworkStats");
0396: displayMessage(msg, 0);
0397: } else {
0398: String msg = "";
0399: Iterator iterator = data.values().iterator();
0400: while (iterator.hasNext()) {
0401:
0402: CompositeData compData = (CompositeData) iterator
0403: .next();
0404: CompositeType compType = compData.getCompositeType();
0405: Set compItemSet = compType.keySet();
0406:
0407: displayOptionHeader("JBIFrameworkStatisticsHeader", 0);
0408:
0409: displayCompositeItem(compData,
0410: JBIStatisticsItemNames.INSTANCE_NAME,
0411: "JBIStatsFrameworkInstanceLabel", 0);
0412:
0413: displayCompositeItem(compData,
0414: JBIStatisticsItemNames.FRAMEWORK_STARTUP_TIME,
0415: "JBIStatsFrameworkStartupTime", 0);
0416:
0417: displayCompositeUpTime(compData,
0418: JBIStatisticsItemNames.FRAMEWORK_UPTIME,
0419: "JBIStatsFrameworkUpTime", 0);
0420: }
0421: displayMessage(" ", 0);
0422: }
0423: }
0424:
0425: /**
0426: * Will process the Endpoint TabularData object to display the Endpoint
0427: * information to the screen.
0428: * @param data The TabularData containing the CompositData to display
0429: * @param endpointName The Endpoint name
0430: */
0431: protected void processEndpointResults(TabularData data,
0432: String endpointName) {
0433: if ((data == null) || (data.size() == 0) || (data.isEmpty())) {
0434: String msg = getLocalizedString("JBIErrorRetrievingEndpointStats");
0435: displayMessage(msg, 0);
0436: } else {
0437: String msg = "";
0438: Iterator iterator = data.values().iterator();
0439: while (iterator.hasNext()) {
0440:
0441: CompositeData compData = (CompositeData) iterator
0442: .next();
0443: CompositeType compType = compData.getCompositeType();
0444: Set compItemSet = compType.keySet();
0445:
0446: displayOptionHeader("JBIEndpointStatisticsHeader", 0);
0447:
0448: msg = getLocalizedString("JBIStatsEndpointName",
0449: new Object[] { endpointName });
0450: displayMessage(msg, 0);
0451:
0452: // Display the Endpoint Type (Provider or Consumer)
0453: String compTypeName = compData.getCompositeType()
0454: .getTypeName();
0455: if (compTypeName
0456: .compareTo(JBICommandConstants.PROVIDER_ENDPOINT_TYPE_NAME) == 0)
0457: msg = getLocalizedString("JBIStatsEndpointProviderType");
0458: else if (compTypeName
0459: .compareTo(JBICommandConstants.COMSUMER_ENDPOINT_TYPE_NAME) == 0)
0460: msg = getLocalizedString("JBIStatsEndpointConsumerType");
0461: displayMessage(msg, 0);
0462:
0463: displayCompositeItem(compData,
0464: JBIStatisticsItemNames.INSTANCE_NAME,
0465: "JBIStatsEndpointInstanceName", 0);
0466:
0467: if (compTypeName
0468: .compareTo(JBICommandConstants.PROVIDER_ENDPOINT_TYPE_NAME) == 0) {
0469: displayOptionHeader("JBIShowTimeStatisticsHeader",
0470: 4);
0471: displayCompositeItem(
0472: compData,
0473: JBIStatisticsItemNames.PROVIDER_ENDPOINT_ACTIVATION_TIME,
0474: "JBIStatsEndpointActivationTime", 4);
0475: displayCompositeUpTime(
0476: compData,
0477: JBIStatisticsItemNames.PROVIDER_ENDPOINT_UPTIME,
0478: "JBIStatsEndpointUpTime", 4);
0479:
0480: displayOptionHeader(
0481: "JBIShowReceivedStatisticsHeader", 4);
0482: displayCompositeItem(
0483: compData,
0484: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_DONES,
0485: "JBIStatsEndpointNumReceivedDones", 4);
0486: displayCompositeItem(
0487: compData,
0488: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_FAULTS,
0489: "JBIStatsEndpointNumReceivedFaults", 4);
0490: displayCompositeItem(
0491: compData,
0492: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_ERRORS,
0493: "JBIStatsEndpointNumReceivedErrors", 4);
0494:
0495: displayOptionHeader("JBIShowSentStatisticsHeader",
0496: 4);
0497: displayCompositeItem(
0498: compData,
0499: JBIStatisticsItemNames.NUMBER_OF_SENT_REPLIES,
0500: "JBIStatsEndpointSentRepliesProvider", 4);
0501: displayCompositeItem(
0502: compData,
0503: JBIStatisticsItemNames.NUMBER_OF_SENT_DONES,
0504: "JBIStatsEndpointNumSentDonesProvider", 4);
0505: displayCompositeItem(
0506: compData,
0507: JBIStatisticsItemNames.NUMBER_OF_SENT_FAULTS,
0508: "JBIStatsEndpointNumSentFaultsProvider", 4);
0509: displayCompositeItem(
0510: compData,
0511: JBIStatisticsItemNames.NUMBER_OF_SENT_ERRORS,
0512: "JBIStatsEndpointNumSentErrorsProvider", 4);
0513:
0514: displayOptionHeader("JBIShowMessageExchangeHeader",
0515: 4);
0516: displayCompositeItem(
0517: compData,
0518: JBIStatisticsItemNames.MESSAGE_EXCHANGE_RESPONSE_TIME,
0519: "JBIStatsEndpointMEResponseTimeAvg", 4);
0520: displayCompositeItem(
0521: compData,
0522: JBIStatisticsItemNames.MESSAGE_EXCHANGE_COMPONENT_TIME,
0523: "JBIStatsEndpointMEComponentTimeAvg", 4);
0524: displayCompositeItem(
0525: compData,
0526: JBIStatisticsItemNames.MESSAGE_EXCHANGE_DELIVERY_CHANNEL_TIME,
0527: "JBIStatsEndpointMEDeliveryChannelTimeAvg",
0528: 4);
0529: displayCompositeItem(
0530: compData,
0531: JBIStatisticsItemNames.MESSAGE_EXCHANGE_NMR_TIME,
0532: "JBIStatsEndpointMEMessageServiceTimeAvg",
0533: 4);
0534: }
0535:
0536: else {
0537:
0538: displayOptionHeader(
0539: "JBIShowReceivedStatisticsHeader", 4);
0540: displayCompositeItem(
0541: compData,
0542: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_DONES,
0543: "JBIStatsEndpointNumReceivedDones", 4);
0544: displayCompositeItem(
0545: compData,
0546: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_FAULTS,
0547: "JBIStatsEndpointNumReceivedFaults", 4);
0548: displayCompositeItem(
0549: compData,
0550: JBIStatisticsItemNames.NUMBER_OF_RECEIVED_ERRORS,
0551: "JBIStatsEndpointNumReceivedErrors", 4);
0552:
0553: displayOptionHeader("JBIShowSentStatisticsHeader",
0554: 4);
0555: displayCompositeItem(
0556: compData,
0557: JBIStatisticsItemNames.NUMBER_OF_SENT_REQUESTS,
0558: "JBIStatsEndpointSentRequestConsumer", 4);
0559: displayCompositeItem(
0560: compData,
0561: JBIStatisticsItemNames.NUMBER_OF_SENT_DONES,
0562: "JBIStatsEndpointNumSentDonesConsumer", 4);
0563: displayCompositeItem(
0564: compData,
0565: JBIStatisticsItemNames.NUMBER_OF_SENT_FAULTS,
0566: "JBIStatsEndpointNumSentFaultsConsumer", 4);
0567: displayCompositeItem(
0568: compData,
0569: JBIStatisticsItemNames.NUMBER_OF_SENT_ERRORS,
0570: "JBIStatsEndpointNumSentErrorsConsumer", 4);
0571:
0572: displayOptionHeader("JBIShowMessageExchangeHeader",
0573: 4);
0574: displayCompositeItem(
0575: compData,
0576: JBIStatisticsItemNames.MESSAGE_EXCHANGE_RESPONSE_TIME,
0577: "JBIStatsEndpointMEResponseTimeAvg", 4);
0578: displayCompositeItem(
0579: compData,
0580: JBIStatisticsItemNames.MESSAGE_EXCHANGE_DELIVERY_CHANNEL_TIME,
0581: "JBIStatsEndpointMEDeliveryChannelTimeAvg",
0582: 4);
0583: displayCompositeItem(
0584: compData,
0585: JBIStatisticsItemNames.MESSAGE_EXCHANGE_NMR_TIME,
0586: "JBIStatsEndpointMEMessageServiceTimeAvg",
0587: 4);
0588: }
0589:
0590: if (compItemSet
0591: .contains(JBIStatisticsItemNames.OJC_PERFORMANCE_STATS)) {
0592: TabularData pfTbData = (TabularData) compData
0593: .get(JBIStatisticsItemNames.OJC_PERFORMANCE_STATS);
0594: int loopCount = 0;
0595: for (Iterator pfTbIter = pfTbData.values()
0596: .iterator(); pfTbIter.hasNext();) {
0597: if (loopCount == 0) {
0598: displayOptionHeader(
0599: "JBIShowPerformanceInstrumentationHeader",
0600: 4);
0601: } else {
0602: displayMessage(" ", 0);
0603: }
0604: CompositeData pfCompData = (CompositeData) pfTbIter
0605: .next();
0606: printCompositeData(pfCompData, 0, 4, 4);
0607: loopCount++;
0608: }
0609: }
0610: }
0611: displayMessage(" ", 0);
0612: }
0613: }
0614:
0615: /**
0616: * Will process the Service Assembly TabularData object to display the Service
0617: * Assembly information to the screen.
0618: * @param data The TabularData containing the CompositData to display
0619: * @param saName The Service Assembly name
0620: */
0621: protected void processServiceAssemblyResults(TabularData data,
0622: String saName) {
0623: if ((data == null) || (data.size() == 0) || (data.isEmpty())) {
0624: String msg = getLocalizedString("JBIErrorRetrievingServiceAssemblyStats");
0625: displayMessage(msg, 0);
0626: } else {
0627: String msg = "";
0628: Iterator iterator = data.values().iterator();
0629: while (iterator.hasNext()) {
0630:
0631: CompositeData compData = (CompositeData) iterator
0632: .next();
0633: CompositeType compType = compData.getCompositeType();
0634: Set compItemSet = compType.keySet();
0635:
0636: displayOptionHeader(
0637: "JBIServiceAssemblyStatisticsHeader", 0);
0638:
0639: displayCompositeItem(compData,
0640: JBIStatisticsItemNames.SERVICE_ASSEMBLY_NAME,
0641: "JBIStatsServiceAssemblyName", 0);
0642:
0643: displayCompositeItem(compData,
0644: JBIStatisticsItemNames.INSTANCE_NAME,
0645: "JBIStatsServiceAssemblyInstanceName", 0);
0646:
0647: displayCompositeItem(
0648: compData,
0649: JBIStatisticsItemNames.SERVICE_ASSEMBLY_LAST_STARTUP_TIME,
0650: "JBIStatsServiceAssemblyLastStartupTime", 0);
0651:
0652: displayCompositeItem(
0653: compData,
0654: JBIStatisticsItemNames.SERVICE_ASSEMBLY_STARTUP_TIME,
0655: "JBIStatsServiceAssemblyStartupTimeAvg", 0);
0656:
0657: displayCompositeItem(
0658: compData,
0659: JBIStatisticsItemNames.SERVICE_ASSEMBLY_STOP_TIME,
0660: "JBIStatsServiceAssemblyStopTimeAvg", 0);
0661:
0662: displayCompositeItem(
0663: compData,
0664: JBIStatisticsItemNames.SERVICE_ASSEMBLY_SHUTDOWN_TIME,
0665: "JBIStatsServiceAssemblyShutdownTimeAvg", 0);
0666:
0667: if (compItemSet
0668: .contains(JBIStatisticsItemNames.SERVICE_ASSEMBLY_SU_STATISTICS)) {
0669: CompositeData[] suStats = (CompositeData[]) compData
0670: .get(JBIStatisticsItemNames.SERVICE_ASSEMBLY_SU_STATISTICS);
0671:
0672: for (int i = 0; i < suStats.length; ++i) {
0673: CompositeData suCompData = suStats[i];
0674: CompositeType suCompType = suCompData
0675: .getCompositeType();
0676: Set suCompItemSet = suCompType.keySet();
0677:
0678: displayOptionHeader(
0679: "JBIServiceUnitStatisticsHeader", 4);
0680:
0681: displayCompositeItem(
0682: suCompData,
0683: JBIStatisticsItemNames.SERVICE_UNIT_NAME,
0684: "JBIStatsServiceUnitName", 4);
0685:
0686: displayCompositeItem(
0687: suCompData,
0688: JBIStatisticsItemNames.SERVICE_UNIT_STARTUP_TIME,
0689: "JBIStatsServiceUnitStartupTimeAvg", 4);
0690:
0691: displayCompositeItem(
0692: suCompData,
0693: JBIStatisticsItemNames.SERVICE_UNIT_STOP_TIME,
0694: "JBIStatsServiceUnitStopTimeAvg", 4);
0695:
0696: displayCompositeItem(
0697: suCompData,
0698: JBIStatisticsItemNames.SERVICE_UNIT_SHUTDOWN_TIME,
0699: "JBIStatsServiceUnitShutdownTimeAvg", 4);
0700: }
0701: }
0702: }
0703: displayMessage(" ", 0);
0704: }
0705: }
0706:
0707: /**
0708: * Will process the Verify CompositData results.
0709: * @param compData The CompositeData
0710: */
0711: protected void processVerifyResults(CompositeData compData) {
0712: if (compData == null) {
0713: String msg = getLocalizedString("JBIErrorProcessingVerifyResults");
0714: displayMessage(msg, 0);
0715: } else {
0716: CompositeType compType = compData.getCompositeType();
0717: Set compItemSet = compType.keySet();
0718:
0719: displayOptionHeader("JBIVerifyApplicationHeader", 0);
0720:
0721: displayCompositeItem(compData, "ServiceAssemblyName",
0722: "JBIVerifyServiceAssemblyName", 0);
0723:
0724: displayCompositeItem(compData,
0725: "ServiceAssemblyDescription",
0726: "JBIVerifyServiceAssemblyDescription", 0);
0727:
0728: displayCompositeItem(compData, "NumServiceUnits",
0729: "JBIVerifyNumberOfServiceUnits", 0);
0730:
0731: displayCompositeItem(compData, "AllComponentsInstalled",
0732: "JBIVerifyAllComponentsInstalled", 0);
0733:
0734: displayCompositeItem(compData, "TemplateZIPID",
0735: "JBIVerifyTemplateZiped", 0);
0736:
0737: // Display the components that are missing or have not been installed yet
0738: boolean allComponentsInstalled = ((Boolean) compData
0739: .get("AllComponentsInstalled")).booleanValue();
0740: if (!allComponentsInstalled) {
0741: String[] missingComponents = (String[]) compData
0742: .get("MissingComponentsList");
0743: displayOptionHeader("JBIVerifyMissingComponentsHeader",
0744: 4);
0745: for (int i = 0; i < missingComponents.length; i++) {
0746: String msg = getLocalizedString(
0747: "JBIVerifyMissingComponentName",
0748: new Object[] { missingComponents[i] });
0749: displayMessage(msg, 4);
0750: }
0751: }
0752:
0753: if (compItemSet.contains("EndpointInfo")) {
0754: CompositeData[] endpointInfo = (CompositeData[]) compData
0755: .get("EndpointInfo");
0756:
0757: for (int i = 0; i < endpointInfo.length; i++) {
0758: displayOptionHeader(
0759: "JBIVerifyEndpointConfigHeader", 4);
0760: displayCompositeItem(endpointInfo[i],
0761: "EndpointName", "JBIVerifyEndpointName", 4);
0762: displayCompositeItem(endpointInfo[i],
0763: "ServiceUnitName",
0764: "JBIVerifyServiceUnitName", 4);
0765: displayCompositeItem(endpointInfo[i],
0766: "ComponentName", "JBIVerifyComponentName",
0767: 4);
0768: displayCompositeItem(endpointInfo[i], "Status",
0769: "JBIVerifyStatus", 4);
0770:
0771: String[] appVars = (String[]) getCompositeItem(
0772: endpointInfo[i],
0773: "MissingApplicationVariables");
0774: if (appVars != null && appVars.length > 0) {
0775: displayOptionHeader(
0776: "JBIVerifyMissingAppVarHeader", 8);
0777:
0778: for (int j = 0; j < appVars.length; j++) {
0779: displayMessage(appVars[j], 8);
0780: }
0781: }
0782:
0783: String[] appConfigs = (String[]) getCompositeItem(
0784: endpointInfo[i],
0785: "MissingApplicationConfigurations");
0786: if (appConfigs != null && appConfigs.length > 0) {
0787: displayOptionHeader(
0788: "JBIVerifyMissingAppConfigHeader", 8);
0789: for (int j = 0; j < appConfigs.length; j++) {
0790: displayMessage(appConfigs[j], 8);
0791: }
0792: }
0793: }
0794: }
0795:
0796: if (compItemSet.contains("JavaEEVerificationReport")) {
0797: CompositeData[] javaEEVerifierReports = (CompositeData[]) compData
0798: .get("JavaEEVerificationReport");
0799:
0800: if ((javaEEVerifierReports != null)
0801: && (javaEEVerifierReports.length > 0)) {
0802: displayOptionHeader(
0803: "JBIVerifyVerificationReportHeader", 4);
0804:
0805: for (int i = 0; i < javaEEVerifierReports.length; i++) {
0806: String suName = (String) getCompositeItem(
0807: javaEEVerifierReports[i],
0808: "ServiceUnitName");
0809: displayOptionHeader(
0810: "JBIVerifyVerificationSUHeader",
0811: suName, 8);
0812: TabularData reportTable = (TabularData) javaEEVerifierReports[i]
0813: .get("JavaEEVerifierReport");
0814: Set rows = reportTable.keySet();
0815: int blockCount = 0;
0816: for (Object row : rows) {
0817: if (blockCount > 0) {
0818: displayMessage(" ", 0);
0819: }
0820: blockCount++;
0821: Object[] key = ((java.util.List) row)
0822: .toArray();
0823: CompositeData suCompData = reportTable
0824: .get(key);
0825: printCompositeData(suCompData, 0, 8, 4);
0826: }
0827: }
0828: }
0829: }
0830: displayMessage(" ", 0);
0831: }
0832: }
0833:
0834: /**
0835: * Utility method that will determine the max width of the key field (col).
0836: * @param aSet The set containing the key value pairs that will be displayed.
0837: * @return the max length for the key field
0838: */
0839: protected int getMaxKeyLength(Set aSet) {
0840: Iterator itr = aSet.iterator();
0841: int maxSize = 0;
0842: while (itr.hasNext()) {
0843: String keyName = (String) itr.next();
0844: if (keyName.length() > maxSize) {
0845: maxSize = keyName.length();
0846: }
0847: }
0848: return maxSize;
0849: }
0850:
0851: /**
0852: * Utility method that will add the token seperator and the necessary
0853: * alignment spaces to the output string.
0854: * @param key The Key string (value displayed to the left of the seperator)
0855: * @param seperator The seperator to display between the key and the value
0856: * @param maxLength The length of the left column (where in string to place value str)
0857: * @return the formatted output string
0858: */
0859: private String addTokenSeperator(String key, String seperator,
0860: int maxLength) {
0861: int keyLength = key.length();
0862: int numSpaces = maxLength - keyLength;
0863: String keyString = key + createFillString(' ', numSpaces)
0864: + seperator;
0865: return keyString;
0866: }
0867:
0868: /**
0869: * Will parse and print the Report about the composite data.
0870: * @param compData The CompositeData
0871: * @param indention The amount to indent the string
0872: * @param tabsize The tabsize
0873: */
0874: protected void printCompositeData(TabularData statsReport,
0875: int indention, int tabsize) {
0876: Set names = statsReport.keySet();
0877: for (Object name : names) {
0878: Object[] key = ((java.util.List) name).toArray();
0879: CompositeData compData = statsReport.get(key);
0880: printCompositeData(compData, 1, indention, tabsize);
0881: }
0882: }
0883:
0884: /**
0885: * Will parse and print the Report about the composite data.
0886: * @param compData The CompositeData
0887: * @param recursiveLevel Level of recursion
0888: * @param indention The amount to indent the string
0889: * @param tabsize The tabsize (indention for each resursion level)
0890: */
0891: protected void printCompositeData(CompositeData compData,
0892: int recursiveLevel, int indention, int tabsize) {
0893:
0894: int indentAmount = indention + (tabsize * recursiveLevel);
0895: recursiveLevel++;
0896:
0897: CompositeType compType = compData.getCompositeType();
0898: Set compItemSet = compType.keySet();
0899: Iterator itr = compItemSet.iterator();
0900: int maxKeyLength = getMaxKeyLength(compItemSet);
0901:
0902: while (itr.hasNext()) {
0903: String keyName = (String) itr.next();
0904: OpenType openType = compType.getType(keyName);
0905: Object itemValue = compData.get(keyName);
0906: String className = null;
0907: if (itemValue != null) {
0908: className = itemValue.getClass().getName();
0909: }
0910:
0911: if (openType.isArray()) {
0912: if ((openType.getTypeName() != null)
0913: && (openType.getTypeName().compareTo(
0914: "[Ljava.lang.String;") == 0)) {
0915: String[] strArray = (String[]) compData
0916: .get(keyName);
0917: for (int i = 0; i < strArray.length; ++i) {
0918: String msg = keyName + "[" + i + "]: "
0919: + strArray[i];
0920: displayMessage(msg, indentAmount);
0921: }
0922: } else if ((openType.getTypeName() != null)
0923: && (openType
0924: .getTypeName()
0925: .compareTo(
0926: "[Ljavax.management.openmbean.CompositeData;") == 0)) {
0927: CompositeData[] compDataArray = (CompositeData[]) compData
0928: .get(keyName);
0929: for (int i = 0; i < compDataArray.length; ++i) {
0930: printCompositeData(compDataArray[i],
0931: recursiveLevel, indention, tabsize);
0932: }
0933: }
0934: }
0935:
0936: else {
0937: if (className != null
0938: && (className
0939: .equals("javax.management.openmbean.CompositeDataSupport") || className
0940: .equals("javax.management.openmbean.CompositeData"))) {
0941: printCompositeData((CompositeData) compData
0942: .get(keyName), recursiveLevel, indention,
0943: tabsize);
0944: } else if (className != null
0945: && (className
0946: .equals("javax.management.openmbean.TabularDataSupport") || className
0947: .equals("javax.management.openmbean.TabularData"))) {
0948: printCompositeData((TabularData) compData
0949: .get(keyName), indention, tabsize);
0950: } else {
0951: String msg = addTokenSeperator(keyName, ": ",
0952: maxKeyLength)
0953: + compData.get(keyName);
0954: displayMessage(msg, indentAmount);
0955:
0956: }
0957: }
0958: }
0959: }
0960:
0961: /**
0962: * Will extract the header using the given bundleKey and display it to the
0963: * screen.
0964: * @param bundleKey The property key value
0965: * @param indention The amount to indent the string
0966: */
0967: protected void displayOptionHeader(String bundleKey, int indention) {
0968: displayMessage(" ", 0);
0969: String msg = getLocalizedString(bundleKey);
0970: //String msg = _strMgr.getString(bundleKey);
0971: displayMessage(msg, indention);
0972: String underline = createFillString('-', msg.length());
0973: displayMessage(underline, indention);
0974: }
0975:
0976: /**
0977: * Will extract the header using the given bundleKey and display it using
0978: * the given value String.
0979: * @param bundleKey The property key value
0980: * @param valaueStr The string containing the values to use in the output string
0981: * @param indention The amount to indent the string
0982: */
0983: protected void displayOptionHeader(String bundleKey,
0984: String valueStr, int indention) {
0985: displayMessage(" ", 0);
0986: //String msg = _strMgr.getString(bundleKey, new Object[] {valueStr});
0987: String msg = getLocalizedString(bundleKey,
0988: new Object[] { valueStr });
0989: displayMessage(msg, indention);
0990: String underline = createFillString('-', msg.length());
0991: displayMessage(underline, indention);
0992: }
0993:
0994: /**
0995: * Will extract the object from the given CompositeData using itemKey. Then
0996: * it will display the object using it toString() method.
0997: * @param compData The composite data
0998: * @param itemKey The key to extract the object from the composite data
0999: * @param bundleKey The property key value
1000: * @param indention The amount to indent the string
1001: */
1002: protected void displayCompositeItem(CompositeData compData,
1003: String itemKey, String bundleKey, int indention) {
1004: CompositeType compType = compData.getCompositeType();
1005: Set compItemSet = compType.keySet();
1006: if (compItemSet.contains(itemKey)) {
1007: Object value = (Object) compData.get(itemKey);
1008: if (value != null) {
1009: String valueStr = value.toString();
1010: String msg = getLocalizedString(bundleKey,
1011: new Object[] { valueStr });
1012: displayMessage(msg, indention);
1013: }
1014: }
1015: }
1016:
1017: /**
1018: * Will extract the object from the given CompositeData using itemKey.
1019: * @param compData The composite data
1020: * @param itemKey The key to extract the object from the composite data
1021: * @return the object retrieved from the Composite Data.
1022: */
1023: protected Object getCompositeItem(CompositeData compData,
1024: String itemKey) {
1025: Object value = null;
1026: CompositeType compType = compData.getCompositeType();
1027: Set compItemSet = compType.keySet();
1028: if (compItemSet.contains(itemKey)) {
1029: value = (Object) compData.get(itemKey);
1030: }
1031: return value;
1032: }
1033:
1034: /**
1035: * Will extract the timestamp from the given CompositeData using itemKey. Then
1036: * it will display the time stamp using the bundleKey to retrieve the string
1037: * from the LocalString property file.
1038: * @param compData The composite data
1039: * @param itemKey The key to extract the object from the composite data
1040: * @param bundleKey The property key value
1041: * @param indention The amount to indent the string
1042: */
1043: protected void displayCompositeUpTime(CompositeData compData,
1044: String itemKey, String bundleKey, int indention) {
1045: CompositeType compType = compData.getCompositeType();
1046: Set compItemSet = compType.keySet();
1047: if (compItemSet.contains(itemKey)) {
1048: Long upTime = (Long) compData.get(itemKey);
1049: if (upTime != null) {
1050: JBITimeUtil elapsedTime = new JBITimeUtil(upTime
1051: .longValue());
1052: String msg = getLocalizedString(bundleKey,
1053: new Object[] { elapsedTime.getDays(),
1054: elapsedTime.getHours(),
1055: elapsedTime.getMinutes(),
1056: elapsedTime.getSeconds() });
1057: displayMessage(msg, indention);
1058: }
1059: }
1060: }
1061:
1062: /**
1063: * Will display the provided message to the screen.
1064: * @param msg The message to display
1065: * @param indentAmount The amount to indent the message by
1066: */
1067: protected void displayMessage(String msg, int indentAmount) {
1068: if (msg != null) {
1069: String outputString = createFillString(' ', indentAmount)
1070: + msg;
1071: CLILogger.getInstance().printMessage(outputString);
1072: }
1073: }
1074:
1075: /**
1076: * Will display the content of a Map sorted by the keys. The display
1077: * format will be key = value, one entry per line.
1078: * @param map The map to display
1079: */
1080: protected void displayMap(Map map, int indentAmount) {
1081: Set<String> keys = map.keySet();
1082: TreeSet<String> sortedKeys = new TreeSet<String>(keys);
1083: for (String key : sortedKeys) {
1084: String outputString = createFillString(' ', indentAmount)
1085: + key + " = " + map.get(key);
1086: CLILogger.getInstance().printMessage(outputString);
1087: }
1088: }
1089:
1090: /**
1091: * Will display the content of a Map sorted by the keys. The display
1092: * format will be key = value, one entry per line.
1093: * @param map The map to display
1094: */
1095: protected void displayProperties(Properties properties,
1096: int indentAmount) {
1097: Set keys = properties.keySet();
1098: TreeSet<String> sortedKeys = new TreeSet<String>(keys);
1099: for (String key : sortedKeys) {
1100: String outputString = createFillString(' ', indentAmount)
1101: + key + " = " + properties.get(key);
1102: CLILogger.getInstance().printMessage(outputString);
1103:
1104: }
1105: }
1106:
1107: /**
1108: * Will format the description text that is displayed in the show commands. The
1109: * formatting will consist of removing all new lines and extra white space, then
1110: * adding back in line breaks at the first avaliable location that is less then
1111: * or equal to the given max line length.
1112: * @param msgText the message string to format
1113: * @param maxLength the maximum line length size.
1114: * @param indentAmout the amount to indent row 2 - n
1115: */
1116: protected String multiLineFormat(String msgText, int maxLength,
1117: int indentAmount) {
1118: // Strip out the leading white spaces in each row, and remove any "\n"
1119: int endIndex = 0;
1120: int startIndex = 0;
1121: String finalString = "";
1122: String rowString = "";
1123: String space = "";
1124: endIndex = msgText.indexOf("\n", startIndex);
1125: while (endIndex != -1) {
1126: rowString = msgText.substring(startIndex, endIndex).trim();
1127: finalString += space + rowString;
1128: startIndex = endIndex + 1;
1129: endIndex = msgText.indexOf("\n", startIndex);
1130: space = " ";
1131: }
1132: rowString = msgText.substring(startIndex).trim();
1133: finalString += space + rowString;
1134:
1135: // Format the string by adding the line breaks in the correct location and adding
1136: // the indention amount at that beginning of each row.
1137: endIndex = 0;
1138: startIndex = 0;
1139: int spaceIndex = 0;
1140: int indentSize = 0;
1141: String newString = "";
1142: boolean done = false;
1143: int totalLength = finalString.length();
1144: while (!(done)) {
1145: endIndex = ((startIndex + maxLength) > totalLength) ? totalLength
1146: : (startIndex + maxLength);
1147: rowString = finalString.substring(startIndex, endIndex);
1148: spaceIndex = startIndex + rowString.lastIndexOf(" ");
1149: if (endIndex < totalLength) {
1150: spaceIndex = startIndex + rowString.lastIndexOf(" ");
1151: if (spaceIndex != -1) {
1152: endIndex = spaceIndex;
1153: }
1154: }
1155: rowString = finalString.substring(startIndex, endIndex)
1156: + "\n";
1157: startIndex = endIndex + 1;
1158: newString += createFillString(' ', indentSize) + rowString;
1159: indentSize = indentAmount;
1160: if (startIndex >= totalLength) {
1161: done = true;
1162: }
1163: }
1164: finalString = newString;
1165: return finalString;
1166: }
1167:
1168: /**
1169: * Will create a string of the size specified filled with the fillChar.
1170: * @param fillChar the character to create the string with
1171: * @param the size of the string
1172: */
1173: protected String createFillString(char fillChar, int size) {
1174: String fillString = "";
1175: for (int i = 0; i < size; i++) {
1176: fillString += fillChar;
1177: }
1178: return fillString;
1179: }
1180:
1181: /**
1182: * Will format and display the component (binding or engine) show results.
1183: * @param result the xml string containing the result information
1184: * @param aName the name of the component
1185: */
1186: protected void processJBIAdminShowComponentResult(String result,
1187: String aName) {
1188: List list = JBIComponentInfo.readFromXmlText(result);
1189: if (list.size() == 0) {
1190: CLILogger.getInstance().printMessage(
1191: getLocalizedString("JBINoComponentToShow",
1192: new Object[] { aName }));
1193: } else {
1194: CLILogger.getInstance().printMessage("");
1195: String header = getLocalizedString("JBIComponentShowHeader");
1196: CLILogger.getInstance().printMessage(header);
1197: CLILogger.getInstance().printMessage(
1198: createFillString('-', header.length()));
1199:
1200: Iterator it = list.iterator();
1201: mInfo = ((JBIComponentInfo) it.next());
1202: String componentName = mInfo.getName();
1203: String componentState = mInfo.getState();
1204: String componentDescription = mInfo.getDescription();
1205: String formattedDescription = multiLineFormat(
1206: componentDescription, 70, 14);
1207: formattedDescription = formattedDescription.trim();
1208: CLILogger.getInstance().printMessage(
1209: getLocalizedString("JBIComponentName",
1210: new Object[] { componentName }));
1211: CLILogger.getInstance().printMessage(
1212: getLocalizedString("JBIComponentState",
1213: new Object[] { componentState }));
1214: CLILogger.getInstance().printMessage(
1215: getLocalizedString("JBIComponentDescription",
1216: new Object[] { formattedDescription }));
1217: }
1218: }
1219:
1220: /**
1221: * Will format and display the Shared Library show results.
1222: * @param result the xml string containing the result information
1223: * @param aName the name of the shared library
1224: */
1225: protected void processJBIAdminShowLibraryResult(String result,
1226: String aName) {
1227: List list = JBIComponentInfo.readFromXmlText(result);
1228: if (list.size() == 0) {
1229: CLILogger.getInstance().printDetailMessage(
1230: getLocalizedString("JBINoLibraryToShow",
1231: new Object[] { aName }));
1232: } else {
1233: CLILogger.getInstance().printMessage("");
1234: String header = getLocalizedString("JBISharedLibraryShowHeader");
1235: CLILogger.getInstance().printMessage(header);
1236: CLILogger.getInstance().printMessage(
1237: createFillString('-', header.length()));
1238:
1239: Iterator it = list.iterator();
1240: JBIComponentInfo info = ((JBIComponentInfo) it.next());
1241: String libraryName = info.getName();
1242: String libraryDescription = info.getDescription();
1243: String formattedDescription = multiLineFormat(
1244: libraryDescription, 50, 14);
1245: CLILogger.getInstance().printMessage(
1246: getLocalizedString("JBISharedLibraryName",
1247: new Object[] { libraryName }));
1248: CLILogger.getInstance().printMessage(
1249: getLocalizedString("JBISharedLibraryDescription",
1250: new Object[] { formattedDescription }));
1251: }
1252: }
1253:
1254: /**
1255: * Will format and display the Service Assembly show results.
1256: * @param result the xml string containing the result information
1257: * @param aName the name of the service assembly
1258: */
1259: protected void processJBIAdminShowAssemblyResult(String result,
1260: String aName) {
1261: List list = ServiceAssemblyInfo
1262: .readFromXmlTextWithProlog(result);
1263:
1264: if (list.size() <= 0) {
1265: CLILogger.getInstance().printDetailMessage(
1266: getLocalizedString("JBINoServiceAssemblyToShow",
1267: new Object[] { aName }));
1268: } else {
1269: Iterator itr = list.iterator();
1270: ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) itr
1271: .next();
1272: List suInfoList = saInfo.getServiceUnitInfoList();
1273:
1274: String saName = saInfo.getName();
1275: String saState = saInfo.getState();
1276: String saDescription = saInfo.getDescription();
1277: String saSize = Integer.toString(suInfoList.size());
1278: String formattedSADescription = multiLineFormat(
1279: saDescription, 50, 16);
1280:
1281: CLILogger.getInstance().printMessage("");
1282: String SAHeader = getLocalizedString("JBIServiceAssemblyShowHeader");
1283: CLILogger.getInstance().printMessage(SAHeader);
1284: CLILogger.getInstance().printMessage(
1285: createFillString('-', SAHeader.length()));
1286: CLILogger.getInstance().printMessage(
1287: getLocalizedString("JBIServiceAssemblyName",
1288: new Object[] { saName }));
1289: CLILogger.getInstance().printMessage(
1290: getLocalizedString("JBIServiceAssemblyState",
1291: new Object[] { saState }));
1292: CLILogger.getInstance().printMessage(
1293: getLocalizedString(
1294: "JBIServiceAssemblyServiceUnits",
1295: new Object[] { saSize }));
1296: CLILogger.getInstance().printMessage(
1297: getLocalizedString("JBIServiceAssemblyDescription",
1298: new Object[] { formattedSADescription }));
1299:
1300: String indentString = " ";
1301: CLILogger.getInstance().printMessage("");
1302: String SUHeader = getLocalizedString("JBIServiceUnitShowHeader");
1303: CLILogger.getInstance().printMessage(
1304: indentString + SUHeader);
1305: CLILogger.getInstance().printMessage(
1306: indentString
1307: + createFillString('-', SUHeader.length()));
1308: boolean firstTime = true;
1309: for (Iterator suItr = suInfoList.iterator(); suItr
1310: .hasNext();) {
1311: ServiceUnitInfo suInfo = (ServiceUnitInfo) suItr.next();
1312: String suState = suInfo.getState();
1313: String suDepoyedOn = suInfo.getDeployedOn();
1314: String suName = suInfo.getName();
1315: String suDescription = suInfo.getDescription();
1316: String formattedSUDescription = multiLineFormat(
1317: suDescription, 50, 18);
1318: if (!(firstTime)) {
1319: CLILogger.getInstance().printMessage("");
1320: }
1321: CLILogger.getInstance().printMessage(
1322: indentString
1323: + getLocalizedString(
1324: "JBIServiceUnitName",
1325: new Object[] { suName }));
1326: CLILogger.getInstance().printMessage(
1327: indentString
1328: + getLocalizedString(
1329: "JBIServiceUnitState",
1330: new Object[] { suState }));
1331: CLILogger.getInstance().printMessage(
1332: indentString
1333: + getLocalizedString(
1334: "JBIServiceUnitDeployedOn",
1335: new Object[] { suDepoyedOn }));
1336: CLILogger
1337: .getInstance()
1338: .printMessage(
1339: indentString
1340: + getLocalizedString(
1341: "JBIServiceUnitDescription",
1342: new Object[] { formattedSUDescription }));
1343: firstTime = false;
1344: }
1345: }
1346: }
1347:
1348: /**
1349: * Will process the list results for the components (Service Engines,
1350: * Binding Components and Shared Libraries).
1351: * was specified, the default value will be returned.
1352: * @param result The result xml string
1353: */
1354: protected void processJBIAdminComponentListResult(String result) {
1355: List list = JBIComponentInfo.readFromXmlText(result);
1356: if (list.size() == 0) {
1357: CLILogger.getInstance().printDetailMessage(
1358: getLocalizedString("NoElementsToList",
1359: new Object[] { result }));
1360: } else {
1361: Iterator it = list.iterator();
1362: String listBreak = "";
1363: int count = 0;
1364: while (it.hasNext()) {
1365: JBIComponentInfo info = ((JBIComponentInfo) it.next());
1366: String componentName = info.getName();
1367: CLILogger.getInstance().printMessage(componentName);
1368:
1369: // TBD append global state info to end of name
1370: //String componentName = info.getName();
1371: //String state = info.getState();
1372: //String outputString = componentName + " : " + state;
1373: //CLILogger.getInstance().printDetailMessage (outputString);
1374: }
1375: }
1376: }
1377:
1378: /**
1379: * Will process the list results for the Service Assemblies
1380: * @param result The result xml string
1381: */
1382: protected void processJBIAdminAsseblyListResult(String result) {
1383: List list = ServiceAssemblyInfo
1384: .readFromXmlTextWithProlog(result);
1385: if (list.size() == 0) {
1386: CLILogger.getInstance().printDetailMessage(
1387: getLocalizedString("NoElementsToList",
1388: new Object[] { result }));
1389: } else {
1390: Iterator it = list.iterator();
1391: String listBreak = "";
1392: int count = 0;
1393: while (it.hasNext()) {
1394: ServiceAssemblyInfo info = ((ServiceAssemblyInfo) it
1395: .next());
1396: String assemblyName = info.getName();
1397: CLILogger.getInstance().printMessage(assemblyName);
1398:
1399: // TBD append global state info to end of name
1400: //String assemblyName = info.getName();
1401: //String state = info.getState();
1402: //String outputString = assemblyName + " : " + state;
1403: //CLILogger.getInstance().printDetailMessage (outputString);
1404: }
1405: }
1406: }
1407:
1408: /**
1409: * Will scan through the connection properties file and replace the ant property
1410: * keys with ones that are used by asadmin.
1411: * @param fileName the connection properties file
1412: * @throws IOException
1413: */
1414: protected void updateConectionPropertiesFile(String fileName)
1415: throws IOException {
1416: // Make sure the file specified is the absolute path.
1417: File inputFile = new File(fileName);
1418: String absolutePath = inputFile.getAbsolutePath();
1419:
1420: // Create a tempory file that will be renamed later
1421: String outputFileName = absolutePath + ".tmp";
1422:
1423: // Create FileReader Object
1424: FileReader inputFileReader = new FileReader(fileName);
1425: FileWriter outputFileReader = new FileWriter(outputFileName);
1426:
1427: // Create Buffered/PrintWriter Objects
1428: BufferedReader inputStream = new BufferedReader(inputFileReader);
1429: PrintWriter outputStream = new PrintWriter(outputFileReader);
1430:
1431: // Scan throuch the .properties and replace the ant properties keys
1432: // with asadmin properties keys.
1433: String inLine = null;
1434: Set keySet = mConnectionConversionTbl.keySet();
1435: while ((inLine = inputStream.readLine()) != null) {
1436: String output = inLine;
1437: Iterator it = keySet.iterator();
1438: while (it.hasNext()) {
1439: String patternStr = (String) it.next();
1440: String replacementStr = (String) mConnectionConversionTbl
1441: .get(patternStr);
1442: Pattern pattern = Pattern.compile(patternStr);
1443: Matcher matcher = pattern.matcher(inLine);
1444: if (matcher.find()) {
1445: output = matcher.replaceAll(replacementStr);
1446: break;
1447: }
1448: }
1449: outputStream.println(output);
1450: }
1451:
1452: // Close the files
1453: outputStream.close();
1454: inputStream.close();
1455:
1456: // Replace the old file with the new updated one.
1457: inputFile.delete();
1458: File newFile = new File(absolutePath);
1459: File outputFile = new File(outputFileName);
1460: outputFile.renameTo(newFile);
1461: }
1462:
1463: /**
1464: * Will convert the template file from an ant syntax style to a asadmin syntax style.
1465: * @param fileDir The directory containing the files to convert.
1466: * @throws CommandException
1467: */
1468: protected void convertTemplateFilesToAsadmin(String fileDir)
1469: throws CommandException {
1470: try {
1471:
1472: // First we need to convert the properties file to contain asadmin keys
1473: String propertiesFile = fileDir + "/"
1474: + CONFIG_PROPERTIES_FILENAME;
1475: updateConectionPropertiesFile(propertiesFile);
1476:
1477: // Parse the xml file and create a hash table containing command info
1478: String xmlConfigFile = fileDir + "/"
1479: + CONFIG_COMMAND_FILENAME_ANT;
1480: Hashtable commandHashTable = constructCommandHashtable(xmlConfigFile);
1481:
1482: // Create the asadmin configuration file
1483: String asadminConfigFile = fileDir + "/"
1484: + CONFIG_COMMAND_FILENAME_ASADMIN;
1485: createAsadminConfigFile(commandHashTable, propertiesFile,
1486: asadminConfigFile);
1487:
1488: // Delete the ant xml file
1489: File deleteFile = new File(xmlConfigFile);
1490: deleteFile.delete();
1491:
1492: // Delete the properties file
1493: File propFile = new File(propertiesFile);
1494: propFile.delete();
1495: }
1496:
1497: catch (Exception e) {
1498: throw new CommandException(getLocalizedString(
1499: "JBIErrorConfigFileConversion",
1500: new Object[] { fileDir }));
1501: }
1502: }
1503:
1504: /**
1505: * Utility method that will replace a pattern in a string.
1506: * @param originalStr The original input string
1507: * @param patternStr The pattern to replace in the string.
1508: * @param replacementStr The string to replace the patternStr with.
1509: */
1510: protected String replaceString(String originalStr,
1511: String patternStr, String replacementStr) {
1512: String outString = originalStr;
1513: Pattern pattern = Pattern.compile(patternStr);
1514: Matcher matcher = pattern.matcher(originalStr);
1515: if (matcher.find()) {
1516: String lString = matcher.quoteReplacement(replacementStr);
1517: outString = matcher.replaceAll(lString);
1518: }
1519: return outString;
1520: }
1521:
1522: /**
1523: * Using the provided commandHashTable, this method will create the asadmin
1524: * command file. This is the file that will contain the asadmin commands.
1525: * @param commandHashTable The hashtable the contains the commands.
1526: * @param propertyFile FilePath name of the property file containing the connection info.
1527: * @param asadminConfigFile Name of the asadmin config file to create.
1528: * @throws IOException
1529: */
1530: protected void createAsadminConfigFile(Hashtable commandHashTable,
1531: String propertyFile, String asadminConfigFile)
1532: throws IOException {
1533: // Create the Properties object
1534: File inputFile = new File(propertyFile);
1535: String absolutePath = inputFile.getAbsolutePath();
1536: Properties connectionProps = new Properties();
1537: FileInputStream in = new FileInputStream(absolutePath);
1538: connectionProps.load(in);
1539: in.close();
1540:
1541: // Create the file that will hold the asadmin commands
1542: String outputFileName = asadminConfigFile;
1543: FileWriter outputFileReader = new FileWriter(outputFileName);
1544: PrintWriter outputStream = new PrintWriter(outputFileReader);
1545:
1546: // For each item in the connection.properties, create an export statement in
1547: // the asadmin config file.
1548: outputStream
1549: .println(getLocalizedString("JBIConfigureFileTextLine1"));
1550: outputStream.println(getLocalizedString(
1551: "JBIConfigureFileTextLine2",
1552: new Object[] { asadminConfigFile }));
1553: outputStream
1554: .println(getLocalizedString("JBIConfigureFileCommentLine"));
1555: outputStream
1556: .println(getLocalizedString("JBIConfigureFileTextLine3"));
1557: outputStream
1558: .println(getLocalizedString("JBIConfigureFileCommentLine"));
1559: Enumeration connectionPropsEnum = connectionProps
1560: .propertyNames();
1561: while (connectionPropsEnum.hasMoreElements()) {
1562: String key = (String) connectionPropsEnum.nextElement();
1563: String value = connectionProps.getProperty(key);
1564: String exportStatement = "export " + key + "=" + value;
1565: outputStream.println(exportStatement);
1566: }
1567: outputStream
1568: .println(getLocalizedString("JBIConfigureFileCommentLine"));
1569: outputStream
1570: .println(getLocalizedString("JBIConfigureFileCommentLine"));
1571: outputStream
1572: .println(getLocalizedString("JBIConfigureFileTextLine4"));
1573: outputStream
1574: .println(getLocalizedString("JBIConfigureFileCommentLine"));
1575:
1576: // Loop through all the commands that are defined in the hashtable
1577: // Enumeration en = connectionProps.propertyNames ();
1578: Enumeration en = commandHashTable.keys();
1579: while (en.hasMoreElements()) {
1580: String antCommand = (String) en.nextElement();
1581: String adminCommand = (String) mCommandConversionTbl
1582: .get(antCommand);
1583: ArrayList list = (ArrayList) commandHashTable
1584: .get(antCommand);
1585: for (int j = 0; j < list.size(); j++) {
1586: Hashtable cmd = (Hashtable) list.get(j);
1587: Enumeration e = cmd.keys();
1588: while (e.hasMoreElements()) {
1589: String key = (String) e.nextElement();
1590: String value = (String) cmd.get(key);
1591: adminCommand = replaceString(adminCommand, key,
1592: value);
1593: }
1594: outputStream.println(adminCommand);
1595: }
1596: }
1597: outputStream.close();
1598: }
1599:
1600: /**
1601: * Using the ant file specified, this method will construct a hashtable that
1602: * will contain all the commands defined in the ant file.
1603: * @param filePath The file path to the ant command file.
1604: * @throws SAXException
1605: * @throws IOException
1606: * @throws ParserConfigurationException
1607: */
1608: protected Hashtable constructCommandHashtable(String filePath)
1609: throws SAXException, IOException,
1610: ParserConfigurationException {
1611: Hashtable commandsHashtable = new Hashtable();
1612:
1613: // Retrieve the set of commands to parse from the xml file
1614: Set commandSet = mCommandConversionTbl.keySet();
1615:
1616: // Create a hashtable entry for each command in the commandSet. Each
1617: // entry in the hashtable will hold a list of commands.
1618: Iterator it = commandSet.iterator();
1619: while (it.hasNext()) {
1620: ArrayList commandArray = new ArrayList();
1621: commandsHashtable.put(it.next(), commandArray);
1622: }
1623:
1624: DocumentBuilderFactory factory = DocumentBuilderFactory
1625: .newInstance();
1626: DocumentBuilder parser = factory.newDocumentBuilder();
1627: Document document = parser.parse(filePath);
1628:
1629: Node node = document.getDocumentElement();
1630: NodeList list = node.getChildNodes();
1631:
1632: ArrayList nodeListArray = new ArrayList();
1633: ArrayList nodeListIndexArray = new ArrayList();
1634: nodeListArray.add(list);
1635: nodeListIndexArray.add(new Integer(0));
1636: node = ((NodeList) nodeListArray.get(0)).item(0);
1637:
1638: int depth = 0;
1639: int i = 0;
1640: String commandName = "";
1641: String key = "";
1642: String value = "";
1643: Hashtable commandHash = null;
1644:
1645: while (depth >= 0) {
1646: while (node != null) {
1647: if (node.getNodeType() == node.ELEMENT_NODE) {
1648: if (node.getNodeName().equalsIgnoreCase("antcall")) {
1649: if (commandHash != null) {
1650: if (commandHash.size() > 0) {
1651: ArrayList cmdArray = (ArrayList) commandsHashtable
1652: .get(commandName);
1653: cmdArray.add(commandHash);
1654: }
1655: }
1656: commandHash = new Hashtable();
1657: }
1658:
1659: NamedNodeMap nodeMap = node.getAttributes();
1660: for (int j = 0; j < nodeMap.getLength(); j++) {
1661: Node elementNode = nodeMap.item(j);
1662: if (elementNode.getNodeName().equalsIgnoreCase(
1663: "target")) {
1664: commandName = elementNode.getNodeValue();
1665: } else if (elementNode.getNodeName()
1666: .equalsIgnoreCase("name")) {
1667: key = elementNode.getNodeValue();
1668: } else if (elementNode.getNodeName()
1669: .equalsIgnoreCase("value")) {
1670: value = elementNode.getNodeValue();
1671: commandHash.put(key, value);
1672: }
1673: }
1674:
1675: if (node.hasChildNodes()) {
1676: list = node.getChildNodes();
1677: nodeListArray.add(list);
1678: nodeListIndexArray.add(new Integer(0));
1679: depth++;
1680: }
1681: }
1682:
1683: i = ((Integer) (nodeListIndexArray.get(depth)))
1684: .intValue();
1685: i++;
1686: nodeListIndexArray.set(depth, i);
1687: node = ((NodeList) nodeListArray.get(depth)).item(i);
1688: }
1689: nodeListIndexArray.remove(depth);
1690: nodeListArray.remove(depth);
1691: depth--;
1692: if (depth >= 0) {
1693: i = ((Integer) (nodeListIndexArray.get(depth)))
1694: .intValue();
1695: i++;
1696: nodeListIndexArray.set(depth, i);
1697: node = ((NodeList) nodeListArray.get(depth)).item(i);
1698: }
1699: }
1700: if (commandHash != null) {
1701: if (commandHash.size() > 0) {
1702: ArrayList cmdArray = (ArrayList) commandsHashtable
1703: .get(commandName);
1704: cmdArray.add(commandHash);
1705: }
1706: }
1707: return commandsHashtable;
1708: }
1709:
1710: /**
1711: * Will first check the properties options for either a property file or
1712: * properties specified on the command line. If no properties option is
1713: * found, an empty properties object will be returned.
1714: * @return properties object, will be empty if not properties are found
1715: * @throws CommandException
1716: * @throws CommandValidationException
1717: */
1718: protected Properties getAnyProperties() throws CommandException,
1719: CommandValidationException {
1720: String compProperties = getOption(JBICommandConstants.PROPERTIES_OPTION);
1721: Properties properties = new Properties();
1722: if (compProperties != "") {
1723: try {
1724: properties.load(new FileInputStream(compProperties));
1725: } catch (IOException e) {
1726: properties = createPropertiesParam(compProperties);
1727: }
1728: }
1729: return properties;
1730: }
1731:
1732: }
|