Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgCallbackTargetException.java @ 275:6d1804fe0ed7
Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Thu, 25 Aug 2011 21:35:03 +0200 | 
| parents | c251bbc979cf | 
| children | 678e326fd27c | 
   comparison
  equal
  deleted
  inserted
  replaced
| 274:9fb50c04f03c | 275:6d1804fe0ed7 | 
|---|---|
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License | 
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com | 
| 16 */ | 16 */ | 
| 17 package org.tmatesoft.hg.core; | 17 package org.tmatesoft.hg.core; | 
| 18 | 18 | 
| 19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; | 19 import org.tmatesoft.hg.util.Path; | 
| 20 | 20 | 
| 21 import org.tmatesoft.hg.repo.HgRepository; | 21 | 
| 22 import org.tmatesoft.hg.util.Path; | |
| 23 | 22 | 
| 24 /** | 23 /** | 
| 25 * Checked exception that indicates errors in client code and tries to supply extra information about the context it occured in. | 24 * Checked exception that indicates errors in client code and tries to supply extra information about the context it occured in. | 
| 26 * | 25 * | 
| 27 * @author Artem Tikhomirov | 26 * @author Artem Tikhomirov | 
| 28 * @author TMate Software Ltd. | 27 * @author TMate Software Ltd. | 
| 29 */ | 28 */ | 
| 30 @SuppressWarnings("serial") | 29 @SuppressWarnings("serial") | 
| 31 public class HgCallbackTargetException extends HgException { | 30 public class HgCallbackTargetException extends HgException { | 
| 32 private int revNumber = BAD_REVISION; | |
| 33 private Nodeid revision; | |
| 34 private Path filename; | |
| 35 | |
| 36 /** | 31 /** | 
| 37 * @param cause can't be <code>null</code> | 32 * @param cause can't be <code>null</code> | 
| 38 */ | 33 */ | 
| 39 public HgCallbackTargetException(Throwable cause) { | 34 public HgCallbackTargetException(Throwable cause) { | 
| 40 super((String) null); | 35 super((String) null); | 
| 47 } else { | 42 } else { | 
| 48 initCause(cause); | 43 initCause(cause); | 
| 49 } | 44 } | 
| 50 } | 45 } | 
| 51 | 46 | 
| 52 /** | |
| 53 * @return not {@link HgRepository#BAD_REVISION} only when local revision number was supplied at the construction time | |
| 54 */ | |
| 55 public int getRevisionNumber() { | |
| 56 return revNumber; | |
| 57 } | |
| 58 | |
| 59 public HgCallbackTargetException setRevisionNumber(int rev) { | |
| 60 revNumber = rev; | |
| 61 return this; | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * @return non-null only when revision was supplied at construction time | |
| 66 */ | |
| 67 public Nodeid getRevision() { | |
| 68 return revision; | |
| 69 } | |
| 70 | |
| 71 public HgCallbackTargetException setRevision(Nodeid r) { | |
| 72 revision = r; | |
| 73 return this; | |
| 74 } | |
| 75 | |
| 76 /** | |
| 77 * @return non-null only if file name was set at construction time | |
| 78 */ | |
| 79 public Path getFileName() { | |
| 80 return filename; | |
| 81 } | |
| 82 | |
| 83 public HgCallbackTargetException setFileName(Path name) { | |
| 84 filename = name; | |
| 85 return this; | |
| 86 } | |
| 87 | |
| 88 @SuppressWarnings("unchecked") | 47 @SuppressWarnings("unchecked") | 
| 89 public <T extends Exception> T getTargetException() { | 48 public <T extends Exception> T getTargetException() { | 
| 90 return (T) getCause(); | 49 return (T) getCause(); | 
| 91 } | 50 } | 
| 92 | 51 | 
| 95 * valuable debugging information about what led to the error. | 54 * valuable debugging information about what led to the error. | 
| 96 */ | 55 */ | 
| 97 @Override | 56 @Override | 
| 98 public String getMessage() { | 57 public String getMessage() { | 
| 99 StringBuilder sb = new StringBuilder(); | 58 StringBuilder sb = new StringBuilder(); | 
| 100 if (filename != null) { | 59 appendDetails(sb); | 
| 101 sb.append(filename); | |
| 102 sb.append(':'); | |
| 103 sb.append(' '); | |
| 104 } | |
| 105 if (revNumber != BAD_REVISION) { | |
| 106 sb.append(revNumber); | |
| 107 if (revision != null) { | |
| 108 sb.append(':'); | |
| 109 } | |
| 110 } | |
| 111 if (revision != null) { | |
| 112 sb.append(revision.shortNotation()); | |
| 113 } | |
| 114 return sb.toString(); | 60 return sb.toString(); | 
| 61 } | |
| 62 | |
| 63 @Override | |
| 64 public HgCallbackTargetException setRevision(Nodeid r) { | |
| 65 return (HgCallbackTargetException) super.setRevision(r); | |
| 66 } | |
| 67 @Override | |
| 68 public HgCallbackTargetException setRevisionNumber(int rev) { | |
| 69 return (HgCallbackTargetException) super.setRevisionNumber(rev); | |
| 70 } | |
| 71 @Override | |
| 72 public HgCallbackTargetException setFileName(Path name) { | |
| 73 return (HgCallbackTargetException) super.setFileName(name); | |
| 115 } | 74 } | 
| 116 | 75 | 
| 117 /** | 76 /** | 
| 118 * Given the approach high-level handlers throw RuntimeExceptions to indicate errors, and | 77 * Given the approach high-level handlers throw RuntimeExceptions to indicate errors, and | 
| 119 * a need to throw reasonable checked exception from client code, clients may utilize this class | 78 * a need to throw reasonable checked exception from client code, clients may utilize this class | 
