~ubuntu-branches/ubuntu/feisty/postgis/feisty

« back to all changes in this revision

Viewing changes to jdbc2/src/org/postgis/Version.java

  • Committer: Bazaar Package Importer
  • Author(s): Alex Bodnaru
  • Date: 2005-05-05 10:02:45 UTC
  • Revision ID: james.westby@ubuntu.com-20050505100245-3005l6jn1jwvpsrw
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Version.java
 
3
 * 
 
4
 * PostGIS extension for PostgreSQL JDBC driver - current version identification
 
5
 * 
 
6
 * (C) 2005 Markus Schaber, markus@schabi.de
 
7
 * 
 
8
 * This library is free software; you can redistribute it and/or modify it under
 
9
 * the terms of the GNU Lesser General Public License as published by the Free
 
10
 * Software Foundation, either version 2.1 of the License.
 
11
 * 
 
12
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 
15
 * details.
 
16
 * 
 
17
 * You should have received a copy of the GNU Lesser General Public License
 
18
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 
19
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit the web at
 
20
 * http://www.gnu.org.
 
21
 * 
 
22
 * $Id: Version.java,v 1.6 2005/03/30 15:24:40 mschaber Exp $
 
23
 */
 
24
 
 
25
package org.postgis;
 
26
 
 
27
import java.io.BufferedReader;
 
28
import java.io.IOException;
 
29
import java.io.InputStreamReader;
 
30
import java.net.URL;
 
31
 
 
32
/** Corresponds to the appropriate PostGIS that carried this source */
 
33
public class Version {
 
34
    /** We read our version information from this ressource... */
 
35
    private static final String RESSOURCENAME = "org/postgis/version.properties";
 
36
    
 
37
    /** The major version */
 
38
    public static final int MAJOR;
 
39
 
 
40
    /** The minor version */
 
41
    public static final int MINOR;
 
42
 
 
43
    /**
 
44
     * The micro version, usually a number including possibly textual suffixes
 
45
     * like RC3.
 
46
     */
 
47
    public static final String MICRO;
 
48
 
 
49
    static {
 
50
        int major = -1;
 
51
        int minor = -1;
 
52
        String micro = "INVALID";
 
53
        try {
 
54
            ClassLoader loader = Version.class.getClassLoader();
 
55
            URL ver = loader.getResource(RESSOURCENAME);
 
56
            if (ver == null) {
 
57
                throw new ExceptionInInitializerError(
 
58
                        "Error initializing PostGIS JDBC version! Cause: Ressource "+RESSOURCENAME+" not found!");
 
59
            }
 
60
            BufferedReader rd = new BufferedReader(new InputStreamReader(ver.openStream()));
 
61
 
 
62
            String line;
 
63
            while ((line = rd.readLine()) != null) {
 
64
                line = line.trim();
 
65
                if (line.startsWith("JDBC_MAJOR_VERSION")) {
 
66
                    major = Integer.parseInt(line.substring(19));
 
67
                } else if (line.startsWith("JDBC_MINOR_VERSION")) {
 
68
                    minor = Integer.parseInt(line.substring(19));
 
69
                } else if (line.startsWith("JDBC_MICRO_VERSION")) {
 
70
                    micro = line.substring(19);
 
71
                } else {
 
72
                    // ignore line
 
73
                }
 
74
            }
 
75
            if (major == -1 || minor == -1 || micro.equals("INVALID")) {
 
76
                throw new ExceptionInInitializerError("Error initializing PostGIS JDBC version! Cause: Ressource "+RESSOURCENAME+" incomplete!");
 
77
            }
 
78
        } catch (IOException e) {
 
79
            throw new ExceptionInInitializerError("Error initializing PostGIS JDBC version! Cause: " + e.getMessage());
 
80
        } finally {
 
81
            MAJOR = major;
 
82
            MINOR = minor;
 
83
            MICRO = micro;
 
84
        }
 
85
    }
 
86
 
 
87
    /** Full version for human reading - code should use the constants above */
 
88
    public static final String FULL = "PostGIS JDBC V" + MAJOR + "." + MINOR + "." + MICRO;
 
89
 
 
90
    public static void main(String[] args) {
 
91
        System.out.println(FULL);
 
92
    }
 
93
 
 
94
    public static String getFullVersion() {
 
95
        return FULL;
 
96
    }
 
97
}