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 #if defined(OS2)
80 	,
81         Rel_OS2
82 #endif
83     };
84 
85     //contains major,minor,micro,update
86     int m_arVersionParts[4];
87     // The update can be followed by a char, e.g. 1.4.1_01a
88     char m_nUpdateSpecial;
89 
90     PreRelease m_preRelease;
91 public:
92     SunVersion(const char * szVer);
93     SunVersion(const rtl::OUString& usVer);
94     ~SunVersion();
95 
96     /**
97        Pre-release versions are taken into account.
98        1.5.0-beta > 1.5.0-ea > 1.4.2
99      */
100     bool operator > (const SunVersion& ver) const;
101     bool operator < (const SunVersion& ver) const;
102     bool operator == (const SunVersion& ver) const;
103 
104     /** Test if the version is compatible tu SUN's versioning scheme
105      */
106     operator bool ();
107 
108     /** Will always contain a value if the object has been constructed with
109         a version string.
110      */
111     rtl::OUString usVersion;
112 
113 protected:
114     bool init(const char * szVer);
115 
116     bool m_bValid;
117 
118     /* Determines if a string constitutes a pre release. For example, if
119        "ea" is passed then Rel_EA is returned. If the string is no pre release
120        then Rel_NONE is returned.
121     */
122     PreRelease getPreRelease(const char *szRel);
123 };
124 
125 }
126 
127 #endif // INCLUDED_JVMACCESS_SUNVERSION_HXX
128