xref: /trunk/main/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.hxx (revision 22994af5c7b170ab8a0cd369962243bf8b0a8831)
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_JFW_PLUGIN_VENDORBASE_HXX
25 #define INCLUDED_JFW_PLUGIN_VENDORBASE_HXX
26 
27 #include "rtl/ustring.hxx"
28 #include "rtl/ref.hxx"
29 #include "osl/endian.h"
30 #include "salhelper/simplereferenceobject.hxx"
31 #include <vector>
32 
33 namespace jfw_plugin
34 {
35 
36 
37 //Used by subclasses of VendorBase to build paths to Java runtime
38 #if defined(__sparcv9)
39 #define JFW_PLUGIN_ARCH "sparcv9"
40 #elif defined SPARC
41 #define JFW_PLUGIN_ARCH "sparc"
42 #elif defined X86_64
43 #define JFW_PLUGIN_ARCH "amd64"
44 #elif defined INTEL
45 #define JFW_PLUGIN_ARCH "i386"
46 #elif defined POWERPC64
47 #ifdef OSL_BIGENDIAN
48 #define JFW_PLUGIN_ARCH "ppc64"
49 #else
50 #define JFW_PLUGIN_ARCH "ppc64le"
51 #endif
52 #elif defined POWERPC
53 #define JFW_PLUGIN_ARCH "ppc"
54 #elif defined MIPS
55 #ifdef OSL_BIGENDIAN
56 #  define JFW_PLUGIN_ARCH "mips"
57 #else
58 #  define JFW_PLUGIN_ARCH "mips32"
59 #endif
60 #elif defined S390X
61 #define JFW_PLUGIN_ARCH "s390x"
62 #elif defined S390
63 #define JFW_PLUGIN_ARCH "s390"
64 #elif defined AARCH64
65 #define JFW_PLUGIN_ARCH "aarch64"
66 #elif defined ARM
67 #define JFW_PLUGIN_ARCH "arm"
68 #elif defined IA64
69 #define JFW_PLUGIN_ARCH "ia64"
70 #elif defined M68K
71 #define JFW_PLUGIN_ARCH "m68k"
72 #elif defined HPPA
73 #define JFW_PLUGIN_ARCH "parisc"
74 #elif defined AXP
75 #define JFW_PLUGIN_ARCH "alpha"
76 #else // SPARC, INTEL, POWERPC, MIPS, ARM, IA64, M68K, HPPA, ALPHA
77 #error unknown platform
78 #endif // SPARC, INTEL, POWERPC, MIPS, ARM, IA64, M68K, HPPA, ALPHA
79 
80 
81 class MalformedVersionException
82 {
83 public:
84     MalformedVersionException();
85 
86     MalformedVersionException(const MalformedVersionException &);
87 
88     virtual ~MalformedVersionException();
89 
90     MalformedVersionException & operator =(const MalformedVersionException &);
91 };
92 
93 class VendorBase: public salhelper::SimpleReferenceObject
94 {
95 public:
96     VendorBase();
97     /* returns relativ paths to the java executable as
98        file URLs.
99 
100        For example "bin/java.exe". You need
101        to implement this function in a derived class, if
102        the paths differ. This implementation provides for
103        Windows "bin/java.exe" and for Unix "bin/java".
104        The paths are relative file URLs. That is, they always
105        contain '/' even on windows. The paths are relative
106        to the installation directory of a JRE.
107 
108 
109        The signature of this function must correspond to
110        getJavaExePaths_func.
111      */
112     static char const* const *  getJavaExePaths(int* size);
113 
114     /* creates an instance of this class. MUST be overridden
115        in a derived class.
116        ####################################################
117        OVERRIDE in derived class
118        ###################################################
119        @param
120        Key - value pairs of the system properties of the JRE.
121      */
122     static rtl::Reference<VendorBase> createInstance();
123 
124     /* called automatically on the instance created by createInstance.
125 
126        @return
127        true - the object could completely initialize.
128        false - the object could not completely initialize. In this case
129        it will be discarded by the caller.
130     */
131     virtual bool initialize(
132         std::vector<std::pair<rtl::OUString, rtl::OUString> > props);
133 
134     /* returns relative file URLs to the runtime library.
135        For example         "/bin/client/jvm.dll"
136     */
137     virtual char const* const* getRuntimePaths(int* size);
138 
139     virtual char const* const* getLibraryPaths(int* size);
140 
141     virtual const rtl::OUString & getVendor() const;
142     virtual const rtl::OUString & getVersion() const;
143     virtual const rtl::OUString & getHome() const;
144     virtual const rtl::OUString & getRuntimeLibrary() const;
145     virtual const rtl::OUString & getLibraryPaths() const;
146     virtual bool supportsAccessibility() const;
147     /* determines if prior to running java something has to be done,
148        like setting the LD_LIBRARY_PATH. This implementation checks
149        if an LD_LIBRARY_PATH (getLD_LIBRARY_PATH) needs to be set and
150        if so, needsRestart returns true.
151      */
152     virtual bool needsRestart() const;
153 
154     /* compares versions of this vendor. MUST be overridden
155        in a derived class.
156        ####################################################
157        OVERRIDE in derived class
158        ###################################################
159       @return
160       0 this.version == sSecond
161       1 this.version > sSecond
162       -1 this.version < sSEcond
163 
164       @throw
165       MalformedVersionException if the version string was not recognized.
166      */
167     virtual int compareVersions(const rtl::OUString& sSecond) const;
168 
169 protected:
170 
171     rtl::OUString m_sVendor;
172     rtl::OUString m_sVersion;
173     rtl::OUString m_sHome;
174     rtl::OUString m_sRuntimeLibrary;
175     rtl::OUString m_sLD_LIBRARY_PATH;
176     bool m_bAccessibility;
177 
178 
179     typedef rtl::Reference<VendorBase> (* createInstance_func) ();
180     friend rtl::Reference<VendorBase> createInstance(
181         createInstance_func pFunc,
182         std::vector<std::pair<rtl::OUString, rtl::OUString> > properties);
183 };
184 
185 }
186 
187 #endif
188