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 set-search-database-attribute subcommand.
038: * The set-search-database-attribute subcommand calls the DatabaseMBean and
039: * changes a search database attribute.
040: */
041: public class SetDatabaseAttributeCommand 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: try {
054: LinkedList path = new LinkedList();
055: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
056: path.addFirst(getSearchServerId());
057: path.addFirst("database");
058: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
059: AdminClientUtil.SEARCH_DATABASE_MBEAN_TYPE, path);
060:
061: MBeanServerConnection msc = getMBeanServerConnection(
062: getUserId(), getPassword(), getHost());
063:
064: String database = getOption("database");
065:
066: Object[] params1 = { database };
067: String[] signatures1 = { "java.lang.String" };
068: Properties p = (Properties) msc.invoke(on, "getAttributes",
069: params1, signatures1);
070:
071: p.setProperty(getOption("attribute"), getOption("value"));
072:
073: Object[] params2 = { database, p };
074: String[] signatures2 = { "java.lang.String",
075: "java.util.Properties" };
076: msc.invoke(on, "setAttributes", params2, signatures2);
077: } catch (InstanceNotFoundException ie) {
078: throw new CommandException(getLocalizedString(
079: ERROR_MBEAN_INSTANCE_NOT_FOUND,
080: new Object[] { "setAttributes" }), ie);
081: } catch (MBeanException me) {
082: throw new CommandException(
083: getLocalizedString(ERROR_JMX_INVOKE,
084: new Object[] { "setAttributes" }), me);
085: } catch (ReflectionException re) {
086: throw new CommandException(getLocalizedString(
087: ERROR_MBEAN_REFLECTION_ERROR,
088: new Object[] { "setAttributes" }), re);
089:
090: } catch (CommandException ce) {
091: throw ce;
092: } catch (Exception e) {
093: throw new CommandException(
094: getLocalizedString(COMMAND_FAILED), e);
095: } finally {
096: closeMBeanServerConnection();
097: }
098: }
099:
100: }
|