tikhomirov@148: /* tikhomirov@394: * Copyright (c) 2011-2012 TMate Software Ltd tikhomirov@148: * tikhomirov@148: * This program is free software; you can redistribute it and/or modify tikhomirov@148: * it under the terms of the GNU General Public License as published by tikhomirov@148: * the Free Software Foundation; version 2 of the License. tikhomirov@148: * tikhomirov@148: * This program is distributed in the hope that it will be useful, tikhomirov@148: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@148: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@148: * GNU General Public License for more details. tikhomirov@148: * tikhomirov@148: * For information on how to redistribute this software under tikhomirov@148: * the terms of a license other than GNU General Public License tikhomirov@148: * contact TMate Software at support@hg4j.com tikhomirov@148: */ tikhomirov@148: package org.tmatesoft.hg.core; tikhomirov@148: tikhomirov@275: import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; tikhomirov@275: tikhomirov@275: import org.tmatesoft.hg.repo.HgRepository; tikhomirov@275: import org.tmatesoft.hg.util.Path; tikhomirov@275: tikhomirov@148: /** tikhomirov@148: * Root class for all hg4j exceptions. tikhomirov@148: * tikhomirov@148: * @author Artem Tikhomirov tikhomirov@148: * @author TMate Software Ltd. tikhomirov@148: */ tikhomirov@148: @SuppressWarnings("serial") tikhomirov@148: public class HgException extends Exception { tikhomirov@148: tikhomirov@275: protected int revNumber = BAD_REVISION; tikhomirov@275: protected Nodeid revision; tikhomirov@275: protected Path filename; tikhomirov@275: tikhomirov@148: public HgException(String reason) { tikhomirov@148: super(reason); tikhomirov@148: } tikhomirov@148: tikhomirov@148: public HgException(String reason, Throwable cause) { tikhomirov@148: super(reason, cause); tikhomirov@148: } tikhomirov@148: tikhomirov@148: public HgException(Throwable cause) { tikhomirov@148: super(cause); tikhomirov@148: } tikhomirov@148: tikhomirov@275: /** tikhomirov@368: * @return not {@link HgRepository#BAD_REVISION} only when revision index was supplied at the construction time tikhomirov@275: */ tikhomirov@367: public int getRevisionIndex() { tikhomirov@275: return revNumber; tikhomirov@275: } tikhomirov@275: tikhomirov@367: /** tikhomirov@367: * @deprecated use {@link #getRevisionIndex()} tikhomirov@367: */ tikhomirov@367: @Deprecated tikhomirov@367: public int getRevisionNumber() { tikhomirov@367: return getRevisionIndex(); tikhomirov@367: } tikhomirov@367: tikhomirov@367: tikhomirov@367: public HgException setRevisionIndex(int rev) { tikhomirov@275: revNumber = rev; tikhomirov@275: return this; tikhomirov@275: } tikhomirov@367: tikhomirov@367: /** tikhomirov@367: * @deprecated use {@link #setRevisionIndex(int)} tikhomirov@367: */ tikhomirov@367: @Deprecated tikhomirov@367: public final HgException setRevisionNumber(int rev) { tikhomirov@367: return setRevisionIndex(rev); tikhomirov@367: } tikhomirov@275: tikhomirov@275: /** tikhomirov@275: * @return non-null only when revision was supplied at construction time tikhomirov@275: */ tikhomirov@275: public Nodeid getRevision() { tikhomirov@275: return revision; tikhomirov@275: } tikhomirov@275: tikhomirov@275: public HgException setRevision(Nodeid r) { tikhomirov@275: revision = r; tikhomirov@275: return this; tikhomirov@275: } tikhomirov@275: tikhomirov@275: /** tikhomirov@275: * @return non-null only if file name was set at construction time tikhomirov@275: */ tikhomirov@275: public Path getFileName() { tikhomirov@275: return filename; tikhomirov@275: } tikhomirov@275: tikhomirov@275: public HgException setFileName(Path name) { tikhomirov@275: filename = name; tikhomirov@275: return this; tikhomirov@275: } tikhomirov@275: tikhomirov@275: protected void appendDetails(StringBuilder sb) { tikhomirov@275: if (filename != null) { tikhomirov@394: sb.append("path:'"); tikhomirov@275: sb.append(filename); tikhomirov@320: sb.append('\''); tikhomirov@320: sb.append(';'); tikhomirov@275: sb.append(' '); tikhomirov@275: } tikhomirov@320: sb.append("rev:"); tikhomirov@275: if (revNumber != BAD_REVISION) { tikhomirov@275: sb.append(revNumber); tikhomirov@275: if (revision != null) { tikhomirov@275: sb.append(':'); tikhomirov@275: } tikhomirov@275: } tikhomirov@275: if (revision != null) { tikhomirov@275: sb.append(revision.shortNotation()); tikhomirov@275: } tikhomirov@275: } tikhomirov@275: tikhomirov@320: @Override tikhomirov@320: public String toString() { tikhomirov@320: StringBuilder sb = new StringBuilder(super.toString()); tikhomirov@320: sb.append(' '); tikhomirov@320: sb.append('('); tikhomirov@320: appendDetails(sb); tikhomirov@320: sb.append(')'); tikhomirov@320: return sb.toString(); tikhomirov@320: } tikhomirov@148: // /* XXX CONSIDER capability to pass extra information about errors */ tikhomirov@148: // public static class Status { tikhomirov@148: // public Status(String message, Throwable cause, int errorCode, Object extraData) { tikhomirov@148: // } tikhomirov@148: // } tikhomirov@148: }