1 /***
2 * Copyright (C) 2008 Jeremy Thomerson (jthomerson@users.sourceforge.net)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.vcaperture.model;
18
19 import java.util.Collection;
20
21 import org.apache.commons.lang.builder.EqualsBuilder;
22 import org.apache.commons.lang.builder.HashCodeBuilder;
23 import org.apache.log4j.Logger;
24
25 /***
26 * Abstract repository. Implements all common functionality of of a repository,
27 * leaving the rest for VC-specific implementations.
28 *
29 * @author Jeremy Thomerson (jthomerson@users.sourceforge.net)
30 */
31 public abstract class AbstractRepository {
32
33 protected static final Logger LOGGER = Logger.getLogger(AbstractRepository.class);
34
35
36 private String mName;
37
38 private String mURL;
39
40
41 public String getName() {
42 return mName;
43 }
44
45 public void setName(String name) {
46 mName = name;
47 }
48
49 public String getURL() {
50 return mURL;
51 }
52
53 public void setURL(String url) {
54 mURL = url;
55 }
56
57 /***
58 * @see java.lang.Object#equals(Object)
59 */
60 public boolean equals(Object object) {
61 if (!(object instanceof AbstractRepository)) {
62 return false;
63 }
64 AbstractRepository rhs = (AbstractRepository) object;
65 return new EqualsBuilder().appendSuper(super.equals(object)).append(this.mName, rhs.mName).append(this.mURL, rhs.mURL).isEquals();
66 }
67
68 /***
69 * @see java.lang.Object#hashCode()
70 */
71 public int hashCode() {
72 return new HashCodeBuilder(-730539281, 1450742465).appendSuper(super.hashCode()).append(this.mName).append(this.mURL).toHashCode();
73 }
74
75 protected static void copy(AbstractRepository from, ProcessedRepository to) {
76 to.setName(from.getName());
77 to.setURL(from.getURL());
78 }
79
80 public RepoFile getRootDirectory() {
81 RepoFile rf = new RepoFile();
82 rf.setDirectory(true);
83 rf.setRelativePath("/");
84 return rf;
85 }
86
87 public abstract Collection<Revision> getRevisions(String startingRevision, int maxRevisions);
88
89 public String getNullRevisionDefault() {
90 return "0";
91 }
92
93 public abstract String getLatestRevision();
94
95 /***
96 * Is revision <tt>name</tt> newer than <tt>startingRevision</tt>?
97 * @param name
98 * @param startingRevision
99 * @return true if revision <tt>name</tt> is newer than <tt>startingRevision</tt>
100 */
101 public abstract boolean isRevisionNewer(String name, String startingRevision);
102
103 public abstract RepoFile getFile(String relativePath);
104
105 }