View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, 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 GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.context;
22  
23  import openr66.context.filesystem.R66File;
24  import openr66.database.data.DbTaskRunner;
25  import openr66.protocol.exception.OpenR66Exception;
26  
27  /**
28   * This class is the result for every operations in OpenR66.
29   *
30   * @author Frederic Bregier
31   *
32   */
33  public class R66Result {
34      /**
35       * The exception associated in case of error (if any exception)
36       */
37      public OpenR66Exception exception = null;
38      /**
39       * The file if any
40       */
41      public R66File file = null;
42      /**
43       * The runner if any
44       */
45      public DbTaskRunner runner = null;
46      /**
47       * Does this result already have been transfered to the remote server
48       */
49      public boolean isAnswered = false;
50      /**
51       * The code (error or not)
52       */
53      public ErrorCode code;
54      /**
55       * Any other object for special operations (test or shutdown for instance)
56       */
57      public Object other = null;
58  
59      /**
60       * @param exception
61       * @param session
62       * @param isAnswered
63       * @param code
64       * @param runner
65       */
66      public R66Result(OpenR66Exception exception, R66Session session,
67              boolean isAnswered, ErrorCode code, DbTaskRunner runner) {
68          this.exception = exception;
69          this.runner = runner;
70          if (session != null) {
71              file = session.getFile();
72              this.runner = session.getRunner();
73          }
74          this.isAnswered = isAnswered;
75          this.code = code;
76      }
77  
78      /**
79       * @param session
80       * @param isAnswered
81       * @param code
82       * @param runner
83       */
84      public R66Result(R66Session session, boolean isAnswered, ErrorCode code,
85              DbTaskRunner runner) {
86          this.runner = runner;
87          if (session != null) {
88              file = session.getFile();
89              this.runner = session.getRunner();
90          }
91          this.isAnswered = isAnswered;
92          this.code = code;
93      }
94  
95      @Override
96      public String toString() {
97          return (exception != null? "Exception: " + exception.toString() : "") +
98                  (file != null? file.toString() : " no file") + "\n    "+
99                  (runner != null? runner.toShortString() : " no runner") +
100                 " isAnswered: " + isAnswered + " Code: " + code.mesg;
101     }
102     /**
103      * 
104      * @return the associated message with this Result
105      */
106     public String getMessage() {
107     	if (exception != null) {
108     		return exception.getMessage();
109     	} else {
110     		return code.mesg;
111     	}
112     }
113 }