View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.waarp.commandexec.utils;
21  
22  /**
23   * Message Result for an Execution
24   */
25  public class LocalExecResult {
26    private int status;
27    private boolean isSuccess;
28    private Exception exception;
29    private String result;
30  
31    /**
32     * @param status
33     * @param exception
34     * @param result
35     */
36    public LocalExecResult(final boolean isSuccess, final int status,
37                           final Exception exception, final String result) {
38      setSuccess(isSuccess);
39      setStatus(status);
40      setException(exception);
41      setResult(result);
42    }
43  
44    /**
45     * Constructor from a pre-existing LocalExecResult
46     *
47     * @param localExecResult
48     */
49    public LocalExecResult(final LocalExecResult localExecResult) {
50      setSuccess(localExecResult.isSuccess());
51      setStatus(localExecResult.getStatus());
52      setException(localExecResult.getException());
53      setResult(localExecResult.getResult());
54    }
55  
56    /**
57     * Set the values from a LocalExecResult (pointer copy)
58     *
59     * @param localExecResult
60     */
61    public final void set(final LocalExecResult localExecResult) {
62      setSuccess(localExecResult.isSuccess());
63      setStatus(localExecResult.getStatus());
64      setException(localExecResult.getException());
65      setResult(localExecResult.getResult());
66    }
67  
68    @Override
69    public String toString() {
70      return "Status: " + getStatus() + " Output: " + getResult() +
71             (getException() != null? "\nError: " + getException().getMessage() :
72                 "");
73    }
74  
75    /**
76     * @return the status
77     */
78    public final int getStatus() {
79      return status;
80    }
81  
82    /**
83     * @param status the status to set
84     */
85    public final void setStatus(final int status) {
86      this.status = status;
87    }
88  
89    /**
90     * @return the isSuccess
91     */
92    public final boolean isSuccess() {
93      return isSuccess;
94    }
95  
96    /**
97     * @param isSuccess the isSuccess to set
98     */
99    public final void setSuccess(final boolean isSuccess) {
100     this.isSuccess = isSuccess;
101   }
102 
103   /**
104    * @return the exception
105    */
106   public final Exception getException() {
107     return exception;
108   }
109 
110   /**
111    * @param exception the exception to set
112    */
113   public final void setException(final Exception exception) {
114     this.exception = exception;
115   }
116 
117   /**
118    * @return the result
119    */
120   public final String getResult() {
121     return result;
122   }
123 
124   /**
125    * @param result the result to set
126    */
127   public final void setResult(final String result) {
128     this.result = result;
129   }
130 
131 }