KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > server > engine > Sync4jOperationStatusError


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.server.engine;
20
21 import sync4j.framework.core.ModificationCommand;
22 import sync4j.framework.core.StatusCode;
23 import sync4j.framework.engine.SyncOperation;
24 import sync4j.framework.engine.SyncException;
25 import sync4j.framework.engine.source.SyncSource;
26 import sync4j.framework.server.error.ServerException;
27
28 import org.apache.commons.lang.builder.ToStringBuilder;
29
30
31 /**
32  * This class represents the status of the execution of a <i>SyncOperation</i>
33  * that has failed.
34  *
35  * @author Stefano Fornari @ Funambol
36  * @version $Id: Sync4jOperationStatusError.java,v 1.6 2005/03/02 20:57:39 harrie Exp $
37  
38  * @see sync4j.framework.engine.SyncOperation
39  *
40  */

41 public class Sync4jOperationStatusError extends Sync4jOperationStatus{
42     
43     // -------------------------------------------------------------- Properties
44

45     /**
46      * The error condition if caused by an exception
47      */

48     private Throwable JavaDoc error = null;
49     
50     /** Getter for property error.
51      * @return Value of property error.
52      *
53      */

54     public Throwable JavaDoc getError() {
55         return error;
56     }
57         
58     // ------------------------------------------------------------- Contructors
59

60     /**
61      * Creates a new instance of SyncOperationStatusError
62      *
63      * @param operation the operation - NOT NULL
64      * @param syncSource the source the operation was performed on - NOT NULL
65      * @param cmd the command this status relates to - NULL
66      * @param error the error condition - NULL
67      *
68      * @throws IllegalArgumentException in case operation is null
69      */

70     public Sync4jOperationStatusError(SyncOperation operation ,
71                                       SyncSource syncSource,
72                                       ModificationCommand cmd ,
73                                       Throwable JavaDoc error ) {
74         super(operation, syncSource, cmd);
75         
76         this.error = error;
77     }
78        
79     // ---------------------------------------------------------- Public methods
80

81     public String JavaDoc toString() {
82         ToStringBuilder builder = new ToStringBuilder(this);
83         
84         builder.append("operation" , getOperation().toString() );
85         builder.append("syncSource", getSyncSource().toString());
86         if (error != null) {
87             builder.append("error", error.getMessage());
88         } else {
89             builder.append("error", (String JavaDoc)null);
90         }
91         
92         return builder.toString();
93     }
94     
95     /** Which SyncML status code this condition corresponds to?
96      *
97      */

98     public int getStatusCode() {
99         Throwable JavaDoc cause = error.getCause();
100         
101         if (cause == null) {
102             cause = error;
103         }
104         
105         if (cause instanceof ServerException) {
106             return ((ServerException)cause).getStatusCode();
107         } else if (cause instanceof SyncException) {
108             return ((SyncException)cause).getStatusCode();
109         }
110         
111         return StatusCode.COMMAND_FAILED;
112     }
113     
114 }
Popular Tags