1 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 41 public class Sync4jOperationStatusError extends Sync4jOperationStatus{ 42 43 45 48 private Throwable error = null; 49 50 54 public Throwable getError() { 55 return error; 56 } 57 58 60 70 public Sync4jOperationStatusError(SyncOperation operation , 71 SyncSource syncSource, 72 ModificationCommand cmd , 73 Throwable error ) { 74 super(operation, syncSource, cmd); 75 76 this.error = error; 77 } 78 79 81 public String 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 )null); 90 } 91 92 return builder.toString(); 93 } 94 95 98 public int getStatusCode() { 99 Throwable 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 |