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