KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > CVSStatus


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core;
12  
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.team.core.TeamStatus;
17 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
18 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
19 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
20     
21 public class CVSStatus extends TeamStatus {
22
23     /*** Status codes ***/
24     public static final int SERVER_ERROR = -10;
25     public static final int NO_SUCH_TAG = -11;
26     public static final int CONFLICT = -12;
27     public static final int ERROR_LINE = -14; // generic uninterpreted E line from the server
28
public static final int TAG_ALREADY_EXISTS = -15;
29     public static final int COMMITTING_SYNC_INFO_FAILED = -16;
30     public static final int DOES_NOT_EXIST = -17;
31     public static final int FOLDER_NEEDED_FOR_FILE_DELETIONS = -18;
32     public static final int CASE_VARIANT_EXISTS = -19;
33     public static final int UNSUPPORTED_SERVER_VERSION = -20;
34     public static final int SERVER_IS_CVSNT = -21;
35     public static final int SERVER_IS_UNKNOWN = -22;
36     public static final int PROTOCOL_ERROR = -23;
37     public static final int ERROR_LINE_PARSE_FAILURE = -24;
38     public static final int FAILED_TO_CACHE_SYNC_INFO = -25;
39     public static final int UNMEGERED_BINARY_CONFLICT = -26;
40     public static final int INVALID_LOCAL_RESOURCE_PATH = -27;
41     public static final int RESPONSE_HANDLING_FAILURE = -28;
42     public static final int COMMUNICATION_FAILURE = -29;
43     public static final int AUTHENTICATION_FAILURE = -30;
44     
45     // Path for resource related status
46
private ICVSFolder commandRoot;
47     // Server information
48
private ICVSRepositoryLocation cvsLocation;
49
50     public CVSStatus(int severity, int code, String JavaDoc message, Throwable JavaDoc t, ICVSRepositoryLocation cvsLocation) {
51         super(severity, CVSProviderPlugin.ID, code, message, t,null);
52         this.cvsLocation = cvsLocation;
53     }
54     
55     public CVSStatus(int severity, int code, String JavaDoc message,ICVSRepositoryLocation cvsLocation) {
56         this(severity, code, message, null, cvsLocation);
57     }
58     
59     public CVSStatus(int severity, int code, String JavaDoc message, Throwable JavaDoc t, IResource cvsResource) {
60         super(severity, CVSProviderPlugin.ID, code, message, t, cvsResource);
61     }
62     
63     public CVSStatus(int severity, int code, String JavaDoc message, IResource resource) {
64         this(severity, code, message, null, resource);
65     }
66     
67     public CVSStatus(int severity, int code, String JavaDoc message, Throwable JavaDoc t, ICVSFolder commandRoot) {
68         super(severity, CVSProviderPlugin.ID, code, message, t, null);
69         this.commandRoot = commandRoot;
70     }
71     
72     public CVSStatus(int severity, int code, String JavaDoc message, ICVSFolder commandRoot) {
73         this(severity, code, message, null, commandRoot);
74     }
75     
76     public CVSStatus(int severity, int code, String JavaDoc message, Throwable JavaDoc t) {
77         super(severity, CVSProviderPlugin.ID, code, message, t, null);
78     }
79     
80     public CVSStatus(int severity, String JavaDoc message, Throwable JavaDoc t) {
81         super(severity, CVSProviderPlugin.ID, CVSStatus.ERROR, message, t, null);
82     }
83     
84     public CVSStatus(int severity, String JavaDoc message) {
85         super(severity, CVSProviderPlugin.ID, CVSStatus.ERROR, message, null, null);
86     }
87     
88     /**
89      * @see IStatus#getMessage()
90      */

91     public String JavaDoc getMessage() {
92         String JavaDoc message = super.getMessage();
93         if (commandRoot != null) {
94             message = NLS.bind(CVSMessages.CVSStatus_messageWithRoot, new String JavaDoc[] { commandRoot.getName(), message });
95         }
96         return message;
97     }
98
99     /**
100      * Return whether this status is wrapping an internal error.
101      * An internal error is any error for which the wrapped exception
102      * is not a CVS exception. Check deeply to make sure there isn't
103      * an internal error buried deep down.
104      * @return whether this status is wrapping an internal error
105      */

106     public boolean isInternalError() {
107         Throwable JavaDoc ex = getException();
108         if (ex instanceof CVSException) {
109             CVSException cvsEx = (CVSException) ex;
110             IStatus status = cvsEx.getStatus();
111             return isInternalError(status);
112         }
113         return ex != null;
114     }
115
116     /**
117      * Return whether this status is wrapping an internal error.
118      * An internal error is any error for which the wrapped exception
119      * is not a CVS exception. Check deeply to make sure there isn't
120      * an internal error buried deep down.
121      * @return whether this status is wrapping an internal error
122      */

123     public static boolean isInternalError(IStatus status) {
124         if (status instanceof CVSStatus) {
125             return ((CVSStatus)status).isInternalError();
126         }
127         if (status.isMultiStatus()) {
128             IStatus[] children = status.getChildren();
129             for (int i = 0; i < children.length; i++) {
130                 IStatus child = children[i];
131                 if (isInternalError(child)) {
132                     return true;
133                 }
134             }
135             return false;
136         }
137         return true;
138     }
139
140     public ICVSRepositoryLocation getCvsLocation() {
141         if (cvsLocation==null){
142             try {
143             if (commandRoot!=null){
144                 FolderSyncInfo info = commandRoot.getFolderSyncInfo();
145                 if (info!=null){
146                     String JavaDoc repoString = info.getRoot();
147                     cvsLocation = KnownRepositories.getInstance().getRepository(repoString);
148                 }
149             } else if (getResource()!=null){
150                 ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor(getResource().getProject());
151                 FolderSyncInfo info = folder.getFolderSyncInfo();
152                 if (info!=null){
153                     String JavaDoc repoString = info.getRoot();
154                     cvsLocation = KnownRepositories.getInstance().getRepository(repoString);
155                 }
156             }
157             } catch (CVSException e){
158                 // do nothing as we are already creating a status for an exception
159
// we may need to trace it though
160
}
161         }
162         return cvsLocation;
163     }
164
165     public ICVSFolder getCommandRoot() {
166         return commandRoot;
167     }
168
169
170 }
171
Popular Tags