KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > Artifact


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant;
8
9
10 import java.io.File JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.Date JavaDoc;
14 import java.util.List JavaDoc;
15
16
17 /**
18  * <p>
19  * This class is a single artifact produce by some project.
20  * </p>
21  *
22  * @author Brian Pontarelli
23  */

24 public class Artifact {
25
26     private String JavaDoc group;
27     private String JavaDoc project;
28     private String JavaDoc name;
29     private String JavaDoc version;
30     private String JavaDoc type;
31     private int expireMinutes;
32     private Date JavaDoc expireTime;
33     private List JavaDoc dependencies = new ArrayList JavaDoc();
34
35
36     public String JavaDoc getGroup() {
37         return group;
38     }
39
40     public void setGroup(String JavaDoc group) {
41         this.group = group;
42     }
43
44     public String JavaDoc getProjectname() {
45         return project;
46     }
47
48     public void setProjectname(String JavaDoc project) {
49         this.project = project;
50     }
51
52     public String JavaDoc getName() {
53         return name;
54     }
55
56     public void setName(String JavaDoc name) {
57         this.name = name;
58     }
59
60     public String JavaDoc getVersion() {
61         return version;
62     }
63
64     public void setVersion(String JavaDoc version) {
65         this.version = version;
66     }
67
68     public String JavaDoc getType() {
69         return type;
70     }
71
72     public void setType(String JavaDoc type) {
73         this.type = type;
74     }
75
76     public int getExpireminutes() {
77         return expireMinutes;
78     }
79
80     public void setExpireminutes(int expireMinutes) {
81         this.expireMinutes = expireMinutes;
82     }
83
84     public Date JavaDoc getExpiretime() {
85         return expireTime;
86     }
87
88     public void setExpiretime(Date JavaDoc expireTime) {
89         this.expireTime = expireTime;
90     }
91
92     /**
93      * Returns the list of dependencies that this single Artifact has. This List
94      * is immutable.
95      */

96     public List JavaDoc getDependencies() {
97         return Collections.unmodifiableList(dependencies);
98     }
99
100     /**
101      * Adds a new dependency Artifact for this Artifact.
102      */

103     public void addDependency(Artifact artifact) {
104         dependencies.add(artifact);
105     }
106
107     /**
108      * <p>
109      * Returns a directory where this artifact can be found or stored. This is
110      * composed of the group namd and the project name like this:
111      * </p>
112      *
113      * <p>
114      * group/project
115      * </p>
116      *
117      * @return The directory
118      */

119     public String JavaDoc getArtifactDir() {
120         return group + File.separator + project;
121     }
122
123     /**
124      * <p>
125      * Returns a file path (including the directory that is retrieve from {@link
126      * #getArtifactDir()}) where this artifact can be found or stored. This is
127      * composed of the group name, the project name, artifact name, version and
128      * type like this:
129      * </p>
130      *
131      * <p>
132      * group/project/artifact_name-version.type
133      * </p>
134      *
135      * @return The path
136      */

137     public String JavaDoc getArtifactFile() {
138         return getArtifactDir() + File.separator + name + "-" + version + "." +
139             type;
140     }
141
142     /**
143      * <p>
144      * Returns a file path (including the directory that is retrieve from {@link
145      * #getArtifactDir()}) where the dependency XML for this artifact can be
146      * found or stored. This is composed of the group name, the project name,
147      * artifact name, version and type like this:
148      * </p>
149      *
150      * <p>
151      * group/project/artifact_name-version.type.deps
152      * </p>
153      *
154      * @return The path
155      */

156     public String JavaDoc getArtifactDepsFile() {
157         return getArtifactFile() + ".deps";
158     }
159
160     /**
161      * Converts this artifact to a String.
162      *
163      * @return To String
164      */

165     public String JavaDoc toString() {
166         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
167         buf.append(group).append(", ").append(project).append(", ").append(name);
168         if (version != null) {
169             buf.append("-").append(version);
170         }
171         buf.append(".").append(type);
172
173         return buf.toString();
174     }
175
176     public boolean equals(Object JavaDoc o) {
177         if (this == o) {
178             return true;
179         }
180
181         if (!(o instanceof Artifact)) {
182             return false;
183         }
184
185         final Artifact artifact = (Artifact) o;
186
187         return (group == artifact.group || (group != null && group.equals(artifact.group))) &&
188             (name == artifact.name || (name != null && name.equals(artifact.name))) &&
189             (project == artifact.project || (project != null && project.equals(artifact.project))) &&
190             (type == artifact.type || (type != null && type.equals(artifact.type))) &&
191             (version == artifact.version || (version != null && version.equals(artifact.version)));
192     }
193
194     public int hashCode() {
195         int result;
196         result = (group != null ? group.hashCode() : 0);
197         result = 29 * result + (project != null ? project.hashCode() : 0);
198         result = 29 * result + (name != null ? name.hashCode() : 0);
199         result = 29 * result + (version != null ? version.hashCode() : 0);
200         result = 29 * result + (type != null ? type.hashCode() : 0);
201         return result;
202     }
203
204     /**
205      * Validates the attributes of the artifact.
206      *
207      * @throws SavantException If group, project, name or type is null
208      */

209     public void validate() throws SavantException {
210         if (group == null || project == null || name == null || type == null) {
211             throw new SavantException("A group, project, name and type are " +
212                 "required attributes for artifacts");
213         }
214     }
215 }
Popular Tags