KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > syncinfo > BaserevInfo


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.syncinfo;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.team.internal.ccvs.core.*;
16 import org.eclipse.team.internal.ccvs.core.util.Util;
17
18 /**
19  * This class represents the information in the CVS/Baserev file
20  */

21 public class BaserevInfo {
22     private static final String JavaDoc BASEREV_PREFIX = "B"; //$NON-NLS-1$
23

24     private String JavaDoc name;
25     private String JavaDoc revision;
26     
27     public BaserevInfo(String JavaDoc entryLine) throws CVSException {
28         setEntryLine(entryLine);
29     }
30
31     public BaserevInfo(String JavaDoc name, String JavaDoc revision) {
32         this.name = name;
33         this.revision = revision;
34     }
35     /**
36      * Return the entry line as it appears in the CVS/Baserev file
37      * @return String
38      */

39     public String JavaDoc getEntryLine() {
40         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
41         result.append(BASEREV_PREFIX);
42         result.append(name);
43         result.append(ResourceSyncInfo.SEPARATOR);
44         result.append(revision);
45         result.append(ResourceSyncInfo.SEPARATOR);
46         return result.toString();
47     }
48     private void setEntryLine(String JavaDoc entryLine) throws CVSException {
49         if(entryLine.startsWith(BASEREV_PREFIX)) {
50             entryLine = entryLine.substring(1);
51         }
52         String JavaDoc[] strings = Util.parseIntoSubstrings(entryLine, ResourceSyncInfo.SEPARATOR);
53         // Accept either a length of 2 or 3. If the length is 3, we ignore the last
54
// string as per the CVS spec.
55
if(strings.length != 2 && strings.length != 3) {
56             IStatus status = new CVSStatus(IStatus.ERROR,NLS.bind(CVSMessages.BaseRevInfo_malformedEntryLine, new String JavaDoc[] { entryLine }));
57             throw new CVSException(status);
58         }
59
60         name = strings[0];
61
62         if(name.length()==0) {
63             IStatus status = new CVSStatus(IStatus.ERROR,NLS.bind(CVSMessages.BaseRevInfo_malformedEntryLine, new String JavaDoc[] { entryLine }));
64             throw new CVSException(status);
65         }
66
67         revision = strings[1];
68
69         if(revision.length()==0) {
70             IStatus status = new CVSStatus(IStatus.ERROR,NLS.bind(CVSMessages.BaseRevInfo_malformedEntryLine, new String JavaDoc[] { entryLine }));
71             throw new CVSException(status);
72         }
73     }
74     /**
75      * Returns the name.
76      * @return String
77      */

78     public String JavaDoc getName() {
79         return name;
80     }
81
82     /**
83      * Returns the revision.
84      * @return String
85      */

86     public String JavaDoc getRevision() {
87         return revision;
88     }
89
90 }
91
Popular Tags