01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12: package org.tmatesoft.svn.core.internal.wc;
13:
14: import org.tmatesoft.svn.core.SVNAuthenticationException;
15: import org.tmatesoft.svn.core.SVNCancelException;
16: import org.tmatesoft.svn.core.SVNErrorCode;
17: import org.tmatesoft.svn.core.SVNErrorMessage;
18: import org.tmatesoft.svn.core.SVNException;
19: import org.tmatesoft.svn.util.SVNDebugLog;
20:
21: /**
22: * @version 1.1.1
23: * @author TMate Software Ltd.
24: */
25: public class SVNErrorManager {
26:
27: public static void cancel(String message) throws SVNCancelException {
28: SVNDebugLog.getDefaultLog().info(message);
29: throw new SVNCancelException(SVNErrorMessage.create(
30: SVNErrorCode.CANCELLED, message));
31: }
32:
33: public static void authenticationFailed(String message,
34: Object messageObject) throws SVNAuthenticationException {
35: SVNErrorMessage err = SVNErrorMessage.create(
36: SVNErrorCode.RA_NOT_AUTHORIZED, message, messageObject);
37: SVNDebugLog.getDefaultLog().info(err.getMessage());
38: throw new SVNAuthenticationException(err);
39: }
40:
41: public static void error(SVNErrorMessage err) throws SVNException {
42: error(err, true);
43: }
44:
45: public static void error(SVNErrorMessage err, boolean log)
46: throws SVNException {
47: if (err == null) {
48: err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN);
49: }
50: if (log) {
51: SVNDebugLog.getDefaultLog().info(err.getFullMessage());
52: }
53: if (err.getErrorCode() == SVNErrorCode.CANCELLED) {
54: throw new SVNCancelException(err);
55: } else if (err.getErrorCode().isAuthentication()) {
56: throw new SVNAuthenticationException(err);
57: } else {
58: throw new SVNException(err);
59: }
60: }
61:
62: public static void error(SVNErrorMessage err, Throwable cause)
63: throws SVNException {
64: if (err == null) {
65: err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN);
66: }
67: SVNDebugLog.getDefaultLog().info(err.getMessage());
68: if (err.getErrorCode() == SVNErrorCode.CANCELLED) {
69: throw new SVNCancelException(err);
70: } else if (err.getErrorCode().isAuthentication()) {
71: throw new SVNAuthenticationException(err);
72: } else {
73: throw new SVNException(err, cause);
74: }
75: }
76:
77: public static void error(SVNErrorMessage err1, SVNErrorMessage err2)
78: throws SVNException {
79: if (err1 == null) {
80: error(err2);
81: } else if (err2 == null) {
82: error(err1);
83: }
84: err1.setChildErrorMessage(err2);
85: SVNDebugLog.getDefaultLog().info(err1.getMessage());
86: if (err1.getErrorCode() == SVNErrorCode.CANCELLED
87: || err2.getErrorCode() == SVNErrorCode.CANCELLED) {
88: throw new SVNCancelException(err1);
89: } else if (err1.getErrorCode().isAuthentication()
90: || err2.getErrorCode().isAuthentication()) {
91: throw new SVNAuthenticationException(err1);
92: }
93: throw new SVNException(err1);
94: }
95: }
|