KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > ResolvedURL


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy;
7
8 import java.io.IOException JavaDoc;
9 import java.net.HttpURLConnection JavaDoc;
10 import java.net.URL JavaDoc;
11 import java.net.URLConnection JavaDoc;
12
13 import fr.jayasoft.ivy.util.Message;
14
15 public class ResolvedURL implements ArtifactInfo {
16     URL JavaDoc url;
17     String JavaDoc revision;
18     private Long JavaDoc _lastModified;
19     
20     public ResolvedURL(URL JavaDoc url, String JavaDoc revision) {
21         this.url = url;
22         this.revision = revision;
23     }
24     
25     public String JavaDoc toString() {
26         return url + "(" + revision + ")";
27     }
28
29     public String JavaDoc getRevision() {
30         return revision;
31     }
32
33     public long getLastModified() {
34         if (_lastModified == null) {
35             URLConnection JavaDoc con = null;
36             try {
37                 con = url.openConnection();
38                 _lastModified = new Long JavaDoc(con.getLastModified());
39             } catch (IOException JavaDoc e) {
40                 Message.warn("impossible to open connection to "+url+": "+e.getMessage());
41                 _lastModified = new Long JavaDoc(0);
42             } finally {
43                 if (con instanceof HttpURLConnection JavaDoc) {
44                     ((HttpURLConnection JavaDoc)con).disconnect();
45                 }
46             }
47         }
48         return _lastModified.longValue();
49     }
50
51     public URL JavaDoc getURL() {
52         return url;
53     }
54 }
55
Popular Tags