1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #if !defined INCLUDED_JVMACCESS_SUNVERSION_HXX
25 #define INCLUDED_JVMACCESS_SUNVERSION_HXX
26 
27 #include "rtl/ustring.hxx"
28 
29 namespace jfw_plugin {
30 // Define OSL_DEBUG_LEVEL >= 2 to run a test when this lib is loaded
31 
32 /* SunVersion is used to compare java versions based on a string, as taken
33    from the registry. The strings look like "1.3", "1.3.1", "1.3.1_02" etc.
34    Versions such as "1.4.1_01a" are allowed although this is not specified.
35    1.4.1_01 < 1.4.1_01a < 1.4.1_01b < 1.4.1_02
36    Pre - release versions, such as 1.4.1-ea, 1.4.1-beta, 1.4.1-rc are recognized,
37    but are treated as minor to release versions:
38    1.4.0 > 1.4.2-beta
39    Pre releases relate this way
40    1.4.1-ea < 1.4.1-beta < 1.4.1-rc1
41 
42    This class supports also a FreeBSD Java. This is currently necessary because
43    it also has the vendor string "Sun Microsystems Inc.".
44 
45    An object acts as holder for the version string. That string may be present
46    even if the version could not be parsed. Then the version may not be compatible
47    to a SUN Java version.
48 
49    An invalid object, that is, operator bool returns false, will always be
50    the lower version in a comparison. If two invalid objects are compared
51    then they are considered equal.
52 
53    To test if the version is ok, that is this object can be compared to others,
54    use the bool conversion operator.
55  */
56 class SunVersion
57 {
58 protected:
59 
60     enum PreRelease
61     {
62         Rel_NONE,
63         Rel_EA,
64         Rel_EA1,
65         Rel_EA2,
66         Rel_EA3,
67         Rel_BETA,
68         Rel_BETA1,
69         Rel_BETA2,
70         Rel_BETA3,
71         Rel_RC,
72         Rel_RC1,
73         Rel_RC2,
74         Rel_RC3
75 #if defined(FREEBSD)
76 	,
77         Rel_FreeBSD
78 #endif
79     };
80 
81     //contains major,minor,micro,update
82     int m_arVersionParts[4];
83     // The update can be followed by a char, e.g. 1.4.1_01a
84     char m_nUpdateSpecial;
85 
86     PreRelease m_preRelease;
87 public:
88     SunVersion(const char * szVer);
89     SunVersion(const rtl::OUString& usVer);
90     ~SunVersion();
91 
92     /**
93        Pre-release versions are taken into account.
94        1.5.0-beta > 1.5.0-ea > 1.4.2
95      */
96     bool operator > (const SunVersion& ver) const;
97     bool operator < (const SunVersion& ver) const;
98     bool operator == (const SunVersion& ver) const;
99 
100     /** Test if the version is compatible tu SUN's versioning scheme
101      */
102     operator bool ();
103 
104     /** Will always contain a value if the object has been constructed with
105         a version string.
106      */
107     rtl::OUString usVersion;
108 
109 protected:
110     bool init(const char * szVer);
111 
112     bool m_bValid;
113 
114     /* Determines if a string constitutes a pre release. For example, if
115        "ea" is passed then Rel_EA is returned. If the string is no pre release
116        then Rel_NONE is returned.
117     */
118     PreRelease getPreRelease(const char *szRel);
119 };
120 
121 }
122 
123 #endif // INCLUDED_JVMACCESS_SUNVERSION_HXX
124