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