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: import javax.management.RuntimeOperationsException;
027:
028: // PS Admin Common
029: import com.sun.portal.admin.common.util.AdminClientUtil;
030:
031: // CLI framework
032: import com.sun.enterprise.cli.framework.*;
033:
034: // Base Class
035: import com.sun.portal.admin.cli.commands.GenericCommand;
036:
037: /**
038: * This class implements the psadmin modify-search-rd subcommand. The
039: * modify-search-rd subcommand calls the SearchServerMBean and modifies a
040: * search resource description.
041: */
042: public class ModifyResourceDescriptionCommand extends GenericCommand {
043:
044: /**
045: * An abstract method that executes the command
046: * @throws CommandException
047: * @throws CommandValidationException
048: */
049: public void runCommand() throws CommandException,
050: CommandValidationException {
051: validateOptions();
052: validateSearchServerID();
053:
054: try {
055: LinkedList path = new LinkedList();
056: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
057: path.addFirst(getSearchServerId());
058: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
059: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
060:
061: Object[] params = { readFile("file"), getOption("database") };
062: String[] signatures = { "java.lang.String",
063: "java.lang.String" };
064:
065: MBeanServerConnection msc = getMBeanServerConnection(
066: getUserId(), getPassword(), getHost());
067: msc.invoke(on, "editResourceDescriptions", params,
068: signatures);
069: } catch (InstanceNotFoundException ie) {
070: throw new CommandException(getLocalizedString(
071: ERROR_MBEAN_INSTANCE_NOT_FOUND,
072: new Object[] { "editResourceDescriptions" }), ie);
073: } catch (MBeanException me) {
074: throw new CommandException(getLocalizedString(
075: ERROR_JMX_INVOKE,
076: new Object[] { "editResourceDescriptions" }), me);
077: } catch (ReflectionException re) {
078: throw new CommandException(getLocalizedString(
079: ERROR_MBEAN_REFLECTION_ERROR,
080: new Object[] { "editResourceDescriptions" }), re);
081:
082: } catch (CommandException ce) {
083: throw ce;
084: } catch (Exception e) {
085: throw new CommandException(
086: getLocalizedString(COMMAND_FAILED), e);
087: } finally {
088: closeMBeanServerConnection();
089: }
090: }
091:
092: private String readFile(String optionName) throws Exception {
093: StringBuffer sb = new StringBuffer();
094:
095: BufferedReader br = new BufferedReader(new InputStreamReader(
096: new FileInputStream(getOption(optionName)), "UTF-8"));
097: String line;
098: while ((line = br.readLine()) != null) {
099: sb.append(line + "\n");
100: }
101:
102: return sb.toString();
103: }
104:
105: }
|