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