ListCommunityTemplatesCommand.java :  » Portal » Open-Portal » com » sun » portal » admin » cli » commands » communities » Java Open Source

Java Open Source » Portal » Open Portal 
Open Portal » com » sun » portal » admin » cli » commands » communities » ListCommunityTemplatesCommand.java
/**
 * Copyright 2004 Sun Microsystems, Inc. All
 * rights reserved. Use of this product is subject
 * to license terms. Federal Acquisitions:
 * Commercial Software -- Government Users
 * Subject to Standard License Terms and
 * Conditions.
 *
 * Sun, Sun Microsystems, the Sun logo, and Sun ONE
 * are trademarks or registered trademarks of Sun Microsystems,
 * Inc. in the United States and other countries.
 */
package com.sun.portal.admin.cli.commands.communities;

import java.io.*;
import java.lang.*;
import java.util.*;
import java.text.*;

// JMX
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.ReflectionException;
import javax.management.MalformedObjectNameException;

// PS Admin Common
import com.sun.portal.admin.common.util.AdminClientUtil;

// CLI framework
import com.sun.enterprise.cli.framework.*;

// Base Class
import com.sun.portal.admin.cli.commands.GenericCommand;

/**
 * This class implements the psadmin list-community-templates
 * subcommand. The list-community-templates subcommand calls
 * the CommunityManagerMBean and lists all community templates.
 */
public class ListCommunityTemplatesCommand extends GenericCommand {

    private String method = "getAvailableCommunityTemplates";
    
    /**
     *  An abstract method that executes the command
     *  @throws CommandException
     *  @throws CommandValidationException
     */
    public void runCommand() throws CommandException, CommandValidationException {
        validateOptions();
  validatePortalId();

  StringBuffer sb = new StringBuffer();

        try {
      LinkedList path = new LinkedList();
      path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
      path.addFirst(getPortalId());
      path.addFirst("CommunityManager");
            ObjectName on = AdminClientUtil.getResourceMBeanObjectName(AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);

            MBeanServerConnection mbsc = getMBeanServerConnection(getUserId(), getPassword(), getHost());

      Object[] params = {Locale.getDefault().toString()};
      String[] signatures = {"java.lang.String"};
      ArrayList data = (ArrayList)mbsc.invoke(on, method, params, signatures);
      sb.append("\n");
            for (int index = 0; index < data.size(); index++) {
    Properties p = (Properties)data.get(index);
    sb.append(getLocalizedString("communities.template.id", new Object[] {p.getProperty("id")}));
    sb.append(getLocalizedString("communities.template.name", new Object[] {p.getProperty("name")}));
    sb.append(getLocalizedString("communities.template.description", new Object[] {p.getProperty("description")}));
    sb.append("\n");
            }
        } catch (InstanceNotFoundException ie) {
            throw new CommandException(getLocalizedString(ERROR_MBEAN_INSTANCE_NOT_FOUND, new Object[] {method}), ie);
        } catch (MBeanException me) {
            throw new CommandException(getLocalizedString(ERROR_JMX_INVOKE, new Object[] {method}), me);
        } catch (ReflectionException re) {
            throw new CommandException(getLocalizedString(ERROR_MBEAN_REFLECTION_ERROR, new Object[] {method}), re);
        } catch (CommandException ce) {
            throw ce;
        } catch (Exception e) {
            throw new CommandException(getLocalizedString(COMMAND_FAILED), e);
        } finally {
            closeMBeanServerConnection();
        }        

  CLILogger.getInstance().printMessage(sb.toString());
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.