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.openr66.context;
21  
22  import org.waarp.openr66.context.filesystem.R66File;
23  import org.waarp.openr66.database.data.DbTaskRunner;
24  import org.waarp.openr66.protocol.exception.OpenR66Exception;
25  
26  /**
27   * This class is the result for every operations in OpenR66.
28   */
29  public class R66Result {
30    /**
31     * The exception associated in case of error (if any exception)
32     */
33    private OpenR66Exception exception;
34    /**
35     * The file if any
36     */
37    private R66File file;
38    /**
39     * The runner if any
40     */
41    private DbTaskRunner runner;
42    /**
43     * Does this result already have been transfered to the remote server
44     */
45    private boolean isAnswered;
46    /**
47     * The code (error or not)
48     */
49    private ErrorCode code;
50    /**
51     * Any other object for special operations (test or shutdown for instance)
52     */
53    private Object other;
54  
55    /**
56     * @param exception
57     * @param session
58     * @param isAnswered
59     * @param code
60     * @param runner
61     */
62    public R66Result(final OpenR66Exception exception, final R66Session session,
63                     final boolean isAnswered, final ErrorCode code,
64                     final DbTaskRunner runner) {
65      setException(exception);
66      setRunner(runner);
67      if (session != null) {
68        setFile(session.getFile());
69        setRunner(session.getRunner());
70      }
71      setAnswered(isAnswered);
72      setCode(code);
73    }
74  
75    /**
76     * @param session
77     * @param isAnswered
78     * @param code
79     * @param runner
80     */
81    public R66Result(final R66Session session, final boolean isAnswered,
82                     final ErrorCode code, final DbTaskRunner runner) {
83      setRunner(runner);
84      if (session != null) {
85        setFile(session.getFile());
86        setRunner(session.getRunner());
87      }
88      setAnswered(isAnswered);
89      setCode(code);
90    }
91  
92    @Override
93    public final String toString() {
94      return (getException() != null? "Exception: " + getException() : "") +
95             (getFile() != null? getFile().toString() : " no file") + "     " +
96             (getRunner() != null? getRunner().toShortString() : " no runner") +
97             " isAnswered: " + isAnswered() + " Code: " + getCode().getMesg();
98    }
99  
100   /**
101    * @return the associated message with this Result
102    */
103   public final String getMessage() {
104     if (getException() != null) {
105       return getException().getMessage();
106     } else {
107       return getCode().getMesg();
108     }
109   }
110 
111   /**
112    * @return the exception
113    */
114   public final OpenR66Exception getException() {
115     return exception;
116   }
117 
118   /**
119    * @param exception the exception to set
120    */
121   public final void setException(final OpenR66Exception exception) {
122     this.exception = exception;
123   }
124 
125   /**
126    * @return the file
127    */
128   public final R66File getFile() {
129     return file;
130   }
131 
132   /**
133    * @param file the file to set
134    */
135   public final void setFile(final R66File file) {
136     this.file = file;
137   }
138 
139   /**
140    * @return the runner
141    */
142   public final DbTaskRunner getRunner() {
143     return runner;
144   }
145 
146   /**
147    * @param runner the runner to set
148    */
149   public final void setRunner(final DbTaskRunner runner) {
150     this.runner = runner;
151   }
152 
153   /**
154    * @return the isAnswered
155    */
156   public final boolean isAnswered() {
157     return isAnswered;
158   }
159 
160   /**
161    * @param isAnswered the isAnswered to set
162    */
163   public final void setAnswered(final boolean isAnswered) {
164     this.isAnswered = isAnswered;
165   }
166 
167   /**
168    * @return the code
169    */
170   public final ErrorCode getCode() {
171     return code;
172   }
173 
174   /**
175    * @param code the code to set
176    */
177   public final void setCode(final ErrorCode code) {
178     this.code = code;
179   }
180 
181   /**
182    * @return the other
183    */
184   public final Object getOther() {
185     return other;
186   }
187 
188   /**
189    * @param other the other to set
190    */
191   public final void setOther(final Object other) {
192     this.other = other;
193   }
194 }