com.clustercontrol.jobmanagement.bean.JobCommandInfo.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.jobmanagement.bean.JobCommandInfo.java

Source

/*
    
Copyright (C) 2006 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more details.
    
 */

package com.clustercontrol.jobmanagement.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.xml.bind.annotation.XmlType;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * ??????
 *
 * @version 2.0.0
 * @since 1.0.0
 */
@XmlType(namespace = "http://jobmanagement.ws.clustercontrol.com")
public class JobCommandInfo implements Serializable {
    /** ???UID */
    private static final long serialVersionUID = 333607610499761260L;

    private static Log m_log = LogFactory.getLog(JobCommandInfo.class);

    /** ID */
    private String m_facilityID;

    /**  */
    private String m_scope;

    /** ? */
    private Integer m_processingMethod = 0;

    /** ??? */
    private Boolean m_managerDistribution = false;

    /** ?? */
    private String m_scriptName;

    /**  */
    private String m_scriptEncoding;

    /**  */
    private String m_scriptContent;

    /**  */
    private String m_startCommand;

    /** ?? */
    private Integer m_stopType;

    /** ? */
    private String m_stopCommand;

    /**  */
    private Boolean m_specifyUser = false;

    /**  */
    private String m_user;

    /**  */
    private Integer m_messageRetry;

    /**  */
    private Boolean m_messageRetryEndFlg = false;

    /**  */
    private Integer m_messageRetryEndValue = 0;

    /** ??? */
    private Boolean m_commandRetryFlg = false;

    /** ??? */
    private Integer m_commandRetry;

    /**  */
    private ArrayList<JobCommandParam> m_jobCommandParamList;
    /**  */
    private List<JobEnvVariableInfo> m_envVariable;

    /**
     * ?<BR>
     * @return 
     */
    public Boolean getMessageRetryEndFlg() {
        return m_messageRetryEndFlg;
    }

    /**
     * ?<BR>
     * @param messageRetryEndFlg 
     */
    public void setMessageRetryEndFlg(Boolean messageRetryEndFlg) {
        this.m_messageRetryEndFlg = messageRetryEndFlg;
    }

    /**
     * ?<BR>
     * @return 
     */
    public Integer getMessageRetryEndValue() {
        return m_messageRetryEndValue;
    }

    /**
     * ?<BR>
     * @param messageRetryEndValue 
     */
    public void setMessageRetryEndValue(Integer messageRetryEndValue) {
        this.m_messageRetryEndValue = messageRetryEndValue;
    }

    /**
     * ?<BR>
     * @return 
     */
    public String getScope() {
        return m_scope;
    }

    /**
     * ?<BR>
     * @param scope 
     */
    public void setScope(String scope) {
        this.m_scope = scope;
    }

    /**
     * ??????????<BR>
     * @return ?????????
     */
    public Boolean getManagerDistribution() {
        return m_managerDistribution;
    }

    /**
     * ??????????<BR>
     * @param managerDistribution ?????????
     */
    public void setManagerDistribution(Boolean managerDistribution) {
        this.m_managerDistribution = managerDistribution;
    }

    /**
     * ???<BR>
     * @return ??
     */
    public String getScriptName() {
        return m_scriptName;
    }

    /**
     * ???<BR>
     * @param scriptName ??
     */
    public void setScriptName(String scriptName) {
        this.m_scriptName = scriptName;
    }

    /**
     * ?<BR>
     * @return 
     */
    public String getScriptEncoding() {
        return m_scriptEncoding;
    }

    /**
     * ?<BR>
     * @param scriptEncoding 
     */
    public void setScriptEncoding(String scriptEncoding) {
        this.m_scriptEncoding = scriptEncoding;
    }

    /**
     * ?<BR>
     * @return 
     */
    public String getScriptContent() {
        return m_scriptContent;
    }

    /**
     * ?<BR>
     * @param scriptContent 
     */
    public void setScriptContent(String scriptContent) {
        this.m_scriptContent = scriptContent;
    }

    /**
     * ?<BR>
     * @return 
     */
    public String getStartCommand() {
        return m_startCommand;
    }

    /**
     * ?<BR>
     * @param startCommand 
     */
    public void setStartCommand(String startCommand) {
        this.m_startCommand = startCommand;
    }

    /**
     * ID?<BR>
     * @return ID
     */
    public String getFacilityID() {
        return m_facilityID;
    }

    /**
     * ID?<BR>
     * @param facilityID ID
     */
    public void setFacilityID(String facilityID) {
        this.m_facilityID = facilityID;
    }

    /**
     * ??<BR>
     * @return ?
     */
    public Integer getStopType() {
        return m_stopType;
    }

    /**
     * ??<BR>
     * @param stopType ?
     */
    public void setStopType(Integer stopType) {
        this.m_stopType = stopType;
    }

    /**
     * ??<BR>
     * @return ?
     */
    public String getStopCommand() {
        return m_stopCommand;
    }

    /**
     * ??<BR>
     * @param stopCommand ?
     */
    public void setStopCommand(String stopCommand) {
        this.m_stopCommand = stopCommand;
    }

    /**
     * ??<BR>
     * @return ?
     * @see com.clustercontrol.bean.ProcessingMethodConstant
     */
    public Integer getProcessingMethod() {
        return m_processingMethod;
    }

    /**
     * ??<BR>
     * @param processingMethod ?
     * @see com.clustercontrol.bean.ProcessingMethodConstant
     */
    public void setProcessingMethod(Integer processingMethod) {
        this.m_processingMethod = processingMethod;
    }

    /**
     * ?<BR>
     * @return 
     */
    public Boolean getSpecifyUser() {
        return m_specifyUser;
    }

    /**
     * ?<BR>
     * @param specifyUser 
     */
    public void setSpecifyUser(Boolean specifyUser) {
        this.m_specifyUser = specifyUser;
    }

    /**
     * ?<BR>
     * @return 
     */
    public String getUser() {
        return m_user;
    }

    /**
     * ?<BR>
     * @param user 
     */
    public void setUser(String user) {
        this.m_user = user;
    }

    /**
     * ?<BR>
     * @return 
     */
    public Integer getMessageRetry() {
        return m_messageRetry;
    }

    /**
     * ?<BR>
     * @param messageRetry 
     */
    public void setMessageRetry(Integer messageRetry) {
        this.m_messageRetry = messageRetry;
    }

    /**
     * ????<BR>
     * @return ???
     */
    public Boolean getCommandRetryFlg() {
        return m_commandRetryFlg;
    }

    /**
     * ????<BR>
     * @param errorRetryFlg ???
     */
    public void setCommandRetryFlg(Boolean commandRetryFlg) {
        this.m_commandRetryFlg = commandRetryFlg;
    }

    /**
     * ????<BR>
     * @return ???
     */
    public Integer getCommandRetry() {
        return m_commandRetry;
    }

    /**
     * ????<BR>
     * @param commandRetry ???
     */
    public void setCommandRetry(Integer commandRetry) {
        this.m_commandRetry = commandRetry;
    }

    /**
     * ??<BR>
     * @return ?
     */
    public List<JobEnvVariableInfo> getEnvVariableInfo() {
        return m_envVariable;
    }

    /**
     * ??<BR>
     * @param ?
     */
    public void setEnvVariableInfo(List<JobEnvVariableInfo> envVariable) {
        this.m_envVariable = envVariable;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((m_commandRetry == null) ? 0 : m_commandRetry.hashCode());
        result = prime * result + ((m_commandRetryFlg == null) ? 0 : m_commandRetryFlg.hashCode());
        result = prime * result + ((m_facilityID == null) ? 0 : m_facilityID.hashCode());
        result = prime * result + ((m_messageRetry == null) ? 0 : m_messageRetry.hashCode());
        result = prime * result + ((m_messageRetryEndFlg == null) ? 0 : m_messageRetryEndFlg.hashCode());
        result = prime * result + ((m_messageRetryEndValue == null) ? 0 : m_messageRetryEndValue.hashCode());
        result = prime * result + ((m_processingMethod == null) ? 0 : m_processingMethod.hashCode());
        result = prime * result + ((m_scope == null) ? 0 : m_scope.hashCode());
        result = prime * result + ((m_specifyUser == null) ? 0 : m_specifyUser.hashCode());
        result = prime * result + ((m_startCommand == null) ? 0 : m_startCommand.hashCode());
        result = prime * result + ((m_stopCommand == null) ? 0 : m_stopCommand.hashCode());
        result = prime * result + ((m_stopType == null) ? 0 : m_stopType.hashCode());
        result = prime * result + ((m_user == null) ? 0 : m_user.hashCode());
        result = prime * result + ((m_managerDistribution == null) ? 0 : m_managerDistribution.hashCode());
        result = prime * result + ((m_scriptName == null) ? 0 : m_scriptName.hashCode());
        result = prime * result + ((m_scriptEncoding == null) ? 0 : m_scriptEncoding.hashCode());
        result = prime * result + ((m_scriptContent == null) ? 0 : m_scriptContent.hashCode());
        result = prime * result + ((m_envVariable == null) ? 0 : m_envVariable.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof JobCommandInfo)) {
            return false;
        }
        JobCommandInfo o1 = this;
        JobCommandInfo o2 = (JobCommandInfo) o;

        boolean ret = false;
        ret = equalsSub(o1.getMessageRetryEndFlg(), o2.getMessageRetryEndFlg())
                && equalsSub(o1.getMessageRetryEndValue(), o2.getMessageRetryEndValue())
                && equalsSub(o1.getFacilityID(), o2.getFacilityID())
                && equalsSub(o1.getMessageRetry(), o2.getMessageRetry())
                && equalsSub(o1.getCommandRetryFlg(), o2.getCommandRetryFlg())
                && equalsSub(o1.getCommandRetry(), o2.getCommandRetry())
                && equalsSub(o1.getProcessingMethod(), o2.getProcessingMethod())
                && equalsSub(o1.getSpecifyUser(), o2.getSpecifyUser())
                && equalsSub(o1.getStartCommand(), o2.getStartCommand())
                && equalsSub(o1.getStopCommand(), o2.getStopCommand())
                && equalsSub(o1.getStopType(), o2.getStopType()) && equalsSub(o1.getUser(), o2.getUser())
                && equalsArray(o1.getJobCommandParamList(), o2.getJobCommandParamList())
                && equalsSub(o1.getUser(), o2.getUser()) && equalsSub(o1.getScope(), o2.getScope())
                && equalsSub(o1.getManagerDistribution(), o2.getManagerDistribution())
                && equalsSub(o1.getScriptName(), o2.getScriptName())
                && equalsSub(o1.getScriptEncoding(), o2.getScriptEncoding())
                && equalsSub(o1.getScriptContent(), o2.getScriptContent())
                && equalsSub(o1.getEnvVariableInfo(), o2.getEnvVariableInfo());
        return ret;
    }

    private boolean equalsSub(Object o1, Object o2) {
        if (o1 == o2)
            return true;

        if (o1 == null)
            return false;

        boolean ret = o1.equals(o2);
        if (!ret) {
            if (m_log.isTraceEnabled()) {
                m_log.trace("equalsSub : " + o1 + "!=" + o2);
            }
        }
        return ret;
    }

    private boolean equalsArray(ArrayList<?> list1, ArrayList<?> list2) {
        if (list1 != null && !list1.isEmpty()) {
            if (list2 != null && list1.size() == list2.size()) {
                Object[] ary1 = list1.toArray();
                Object[] ary2 = list2.toArray();
                Arrays.sort(ary1);
                Arrays.sort(ary2);

                for (int i = 0; i < ary1.length; i++) {
                    if (!ary1[i].equals(ary2[i])) {
                        if (m_log.isTraceEnabled()) {
                            m_log.trace("equalsArray : " + ary1[i] + "!=" + ary2[i]);
                        }
                        return false;
                    }
                }
                return true;
            }
        } else if (list2 == null || list2.isEmpty()) {
            return true;
        }
        return false;
    }

    /**
     * ?
     * @param args
     */
    public static void main(String args[]) {
        testEquals();
    }

    /**
     * ?
     */
    public static void testEquals() {
        System.out.println("*** ALL ***");
        JobCommandInfo info1 = createSampleInfo();
        JobCommandInfo info2 = createSampleInfo();
        judge(true, info1.equals(info2));

        String[] str = { "", "",
                "ID", "", "?", "",
                "", "", "?", "??",
                "", "???", "??",
                "", "", "" };
        /**
         * ????
         * 1?????
         */
        for (int i = 0; i < 16; i++) {
            info2 = createSampleInfo();
            switch (i) {
            case 0:
                info2.setMessageRetryEndFlg(true);
                break;
            case 1:
                info2.setMessageRetryEndValue(1);
                break;
            case 2:
                info2.setFacilityID("facility_ID");
                break;
            case 3:
                info2.setMessageRetry(1);
                break;
            case 4:
                info2.setProcessingMethod(1);
                break;
            case 5:
                info2.setScope("Stope");
                break;
            case 6:
                info2.setSpecifyUser(true);
                break;
            case 7:
                info2.setStartCommand("echo");
                break;
            case 8:
                info2.setStopCommand("echo 1");
                break;
            case 9:
                info2.setStopType(1);
                break;
            case 10:
                info2.setUser("admin");
                break;
            case 11:
                info2.setManagerDistribution(true);
                break;
            case 12:
                info2.setScriptName("test2.sh");
                break;
            case 13:
                info2.setScriptEncoding("MS932");
                break;
            case 14:
                info2.setScriptContent("echo test2");
                break;
            case 15:
                info2.setEnvVariableInfo(createEnvVariableList("bbb"));
                break;
            default:
                break;
            }
            System.out.println("*** " + str[i] + "? ????***");
            judge(false, info1.equals(info2));
        }
    }

    /**
     * ?
     * ?????????????
     * @return
     */
    public static JobCommandInfo createSampleInfo() {
        JobCommandInfo info = new JobCommandInfo();
        info.setMessageRetryEndFlg(false);
        info.setMessageRetryEndValue(0);
        info.setFacilityID("facilityID");
        info.setMessageRetry(0);
        info.setProcessingMethod(0);
        info.setScope("Scope");
        info.setSpecifyUser(false);
        info.setStartCommand("ls");
        info.setStopCommand("ls -l");
        info.setStopType(0);
        info.setUser("root");
        info.setManagerDistribution(false);
        info.setScriptName("test.sh");
        info.setScriptEncoding("UTF-8");
        info.setScriptContent("echo test");
        info.setEnvVariableInfo(createEnvVariableList("aaa"));
        return info;
    }

    private static List<JobEnvVariableInfo> createEnvVariableList(String s) {
        JobEnvVariableInfo info = new JobEnvVariableInfo();
        info.setEnvVariableId(s);
        info.setValue(s);
        info.setDescription(s);
        List<JobEnvVariableInfo> l = new ArrayList<JobEnvVariableInfo>();
        l.add(info);
        return l;
    }

    /**
     * ?????????
     * @param judge
     * @param result
     */
    private static void judge(boolean judge, boolean result) {

        System.out.println("expect : " + judge);
        System.out.print("result : " + result);
        String ret = "NG";
        if (judge == result) {
            ret = "OK";
        }
        System.out.println("    is ...  " + ret);
    }

    public ArrayList<JobCommandParam> getJobCommandParamList() {
        return m_jobCommandParamList;
    }

    public void setJobCommandParamList(ArrayList<JobCommandParam> jobCommandParamList) {
        this.m_jobCommandParamList = jobCommandParamList;
    }
}