001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.cli.commands.search;
013:
014: import java.io.*;
015: import java.lang.*;
016: import java.util.*;
017: import java.text.*;
018:
019: // JMX
020: import javax.management.MBeanServerConnection;
021: import javax.management.ObjectName;
022: import javax.management.InstanceNotFoundException;
023: import javax.management.MBeanException;
024: import javax.management.ReflectionException;
025: import javax.management.MalformedObjectNameException;
026:
027: // PS Admin Common
028: import com.sun.portal.admin.common.util.AdminClientUtil;
029:
030: // CLI framework
031: import com.sun.enterprise.cli.framework.*;
032:
033: // Base Class
034: import com.sun.portal.admin.cli.commands.GenericCommand;
035:
036: /**
037: * This class implements the psadmin list-search-database-attributes subcommand.
038: * The list-search-database-attributes subcommand calls the DatabaseMBean and
039: * list search database attributes.
040: */
041: public class ListDatabaseAttributesCommand extends GenericCommand {
042:
043: /**
044: * An abstract method that executes the command
045: * @throws CommandException
046: * @throws CommandValidationException
047: */
048: public void runCommand() throws CommandException,
049: CommandValidationException {
050: validateOptions();
051: validateSearchServerID();
052:
053: StringBuffer sb = new StringBuffer();
054: String method = "";
055:
056: try {
057: LinkedList path = new LinkedList();
058: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
059: path.addFirst(getSearchServerId());
060: path.addFirst("database");
061: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
062: AdminClientUtil.SEARCH_DATABASE_MBEAN_TYPE, path);
063:
064: MBeanServerConnection msc = getMBeanServerConnection(
065: getUserId(), getPassword(), getHost());
066:
067: Object[] params = { getOption("database") };
068: String[] signatures = { "java.lang.String" };
069: method = "getAttributes";
070:
071: Properties attributes = (Properties) msc.invoke(on,
072: "getAttributes", params, signatures);
073:
074: Enumeration e = attributes.propertyNames();
075: while (e.hasMoreElements()) {
076: sb.append((String) e.nextElement() + "\n");
077: }
078: } catch (InstanceNotFoundException ie) {
079: throw new CommandException(getLocalizedString(
080: ERROR_MBEAN_INSTANCE_NOT_FOUND,
081: new Object[] { method }), ie);
082: } catch (MBeanException me) {
083: throw new CommandException(getLocalizedString(
084: ERROR_JMX_INVOKE, new Object[] { method }), me);
085: } catch (ReflectionException re) {
086: throw new CommandException(getLocalizedString(
087: ERROR_MBEAN_REFLECTION_ERROR,
088: new Object[] { method }), re);
089: } catch (CommandException ce) {
090: throw ce;
091: } catch (Exception e) {
092: throw new CommandException(
093: getLocalizedString(COMMAND_FAILED), e);
094: } finally {
095: closeMBeanServerConnection();
096: }
097:
098: CLILogger.getInstance().printMessage(sb.toString());
099: }
100:
101: }
|