KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > Version


1 package JSci;
2
3 import java.io.*;
4 import java.net.*;
5 import java.util.ResourceBundle JavaDoc;
6
7 /**
8 * The Version class contains information about the current and latest release.
9 * @version 1.3
10 * @author Mark Hale
11 */

12 public final class Version extends Object JavaDoc implements Serializable {
13         /**
14         * Major version number.
15         */

16         public final int major;
17         /**
18         * Minor version number.
19         */

20         public final int minor;
21         /**
22         * Java platform required.
23         */

24         public final String JavaDoc platform;
25         /**
26         * The URL for the home of this version.
27         */

28         public final String JavaDoc home;
29         /**
30         * Gets the current version.
31         */

32         public static Version getCurrent() {
33                 ResourceBundle JavaDoc bundle = ResourceBundle.getBundle("JSci.Bundle");
34                 int major = Integer.parseInt(bundle.getString("version.major"));
35                 int minor = Integer.parseInt(bundle.getString("version.minor"));
36                 String JavaDoc platform = bundle.getString("version.platform");
37                 String JavaDoc home = bundle.getString("version.home");
38                 return new Version(major, minor, home, platform);
39         }
40         /**
41         * Retrieves the latest version from the home URL.
42         */

43         public static Version getLatest() throws IOException {
44                 Version latest = null;
45                 try {
46                         URL serurl = new URL(getCurrent().home+"version.ser");
47                         ObjectInputStream in = new ObjectInputStream(serurl.openStream());
48                         latest = (Version) in.readObject();
49                         in.close();
50                 } catch(MalformedURLException murle) {
51                 } catch(ClassNotFoundException JavaDoc cnfe) {}
52                 return latest;
53         }
54         /**
55         * Constructs a version object.
56         */

57         private Version(int major, int minor, String JavaDoc home, String JavaDoc platform) {
58                 this.major = major;
59                 this.minor = minor;
60                 this.home = home;
61                 this.platform = platform;
62         }
63         /**
64         * Compares two versions for equality.
65         */

66         public boolean equals(Object JavaDoc o) {
67                 if(!(o instanceof Version))
68                         return false;
69                 Version ver = (Version) o;
70                 return (major == ver.major) && (minor == ver.minor) && platform.equals(ver.platform);
71         }
72     public int hashCode() {
73         return 37*(37*(37*17+major)+minor)+platform.hashCode();
74     }
75         /**
76         * Returns the version number as a string.
77         */

78         public String JavaDoc toString() {
79                 return new StringBuffer JavaDoc().append(major).append('.').append(minor).toString();
80         }
81         /**
82         * Returns true if this is later than another version.
83         */

84         public boolean isLater(Version ver) {
85                 return (major>ver.major) ||
86                         (major == ver.major && minor>ver.minor);
87         }
88 }
89
90
Popular Tags