xref: /AOO41X/main/qadevOOo/testdocs/backend/org/openoffice/JavaSystemBackend.java (revision ef39d40d3f5e66cf3f035b3e93783012b340500d)
1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package org.openoffice;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.comp.loader.FactoryHelper;
26cdf0e10cSrcweir import com.sun.star.configuration.backend.PropertyInfo;
27cdf0e10cSrcweir import com.sun.star.configuration.backend.XLayer;
28cdf0e10cSrcweir import com.sun.star.configuration.backend.XLayerContentDescriber;
29cdf0e10cSrcweir import com.sun.star.configuration.backend.XLayerHandler;
30cdf0e10cSrcweir import com.sun.star.configuration.backend.XSingleLayerStratum;
31cdf0e10cSrcweir import com.sun.star.lang.XComponent;
32cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
33cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
34cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
35cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
36cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
37cdf0e10cSrcweir import com.sun.star.uno.Type;
38cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
39cdf0e10cSrcweir import com.sun.star.uno.XInterface;
40cdf0e10cSrcweir import com.sun.star.util.XStringSubstitution;
41cdf0e10cSrcweir import com.sun.star.util.XTimeStamped;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /**
45cdf0e10cSrcweir  *
46cdf0e10cSrcweir  * @author  sw93809
47cdf0e10cSrcweir  */
48cdf0e10cSrcweir public class JavaSystemBackend implements XSingleLayerStratum, XTypeProvider,
49cdf0e10cSrcweir                                           XServiceInfo, XTimeStamped, XComponent {
50cdf0e10cSrcweir     public final static String __serviceName = "com.sun.star.configuration.backend.PlatformBackend";
51cdf0e10cSrcweir     public final static String __implName = "org.openoffice.JavaSystemBackend";
52cdf0e10cSrcweir     public final static String testComponent = "org.openoffice.Office.Common";
53cdf0e10cSrcweir     protected static XMultiServiceFactory msf = null;
54cdf0e10cSrcweir     protected XLayer aLayer = null;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     /**
57cdf0e10cSrcweir      * Get the implementation id.
58cdf0e10cSrcweir      * @return An empty implementation id.
59cdf0e10cSrcweir      * @see com.sun.star.lang.XTypeProvider
60cdf0e10cSrcweir      */
getImplementationId()61cdf0e10cSrcweir     public byte[] getImplementationId() {
62cdf0e10cSrcweir         return new byte[0];
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /**
66cdf0e10cSrcweir      * Function for reading the implementation name.
67cdf0e10cSrcweir      *
68cdf0e10cSrcweir      * @return the implementation name
69cdf0e10cSrcweir      * @see com.sun.star.lang.XServiceInfo
70cdf0e10cSrcweir      */
getImplementationName()71cdf0e10cSrcweir     public String getImplementationName() {
72cdf0e10cSrcweir         return __implName;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
getLayer(String str, String str1)75cdf0e10cSrcweir     public com.sun.star.configuration.backend.XLayer getLayer(String str,
76cdf0e10cSrcweir                                                               String str1)
77cdf0e10cSrcweir         throws com.sun.star.configuration.backend.BackendAccessException,
78cdf0e10cSrcweir                com.sun.star.lang.IllegalArgumentException {
79cdf0e10cSrcweir         if (aLayer == null) {
80cdf0e10cSrcweir             System.out.println("JavaSystemBackend::getLayer() called for " +
81cdf0e10cSrcweir                                str);
82cdf0e10cSrcweir             aLayer = new CommonLayer();
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         return aLayer;
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     /**
89cdf0e10cSrcweir      * Function for reading all supported services
90cdf0e10cSrcweir      *
91cdf0e10cSrcweir      * @return An aaray with all supported service names
92cdf0e10cSrcweir      * @see com.sun.star.lang.XServiceInfo
93cdf0e10cSrcweir      */
getSupportedServiceNames()94cdf0e10cSrcweir     public String[] getSupportedServiceNames() {
95cdf0e10cSrcweir         String[] supServiceNames = { __serviceName };
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         return supServiceNames;
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
getTimestamp()100cdf0e10cSrcweir     public String getTimestamp() {
101cdf0e10cSrcweir         //not really implemented
102cdf0e10cSrcweir         return "2004-03-31";
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     /**
106cdf0e10cSrcweir      * Get all implemented types of this class.
107cdf0e10cSrcweir      * @return An array of implemented interface types.
108cdf0e10cSrcweir      * @see com.sun.star.lang.XTypeProvider
109cdf0e10cSrcweir      */
getTypes()110cdf0e10cSrcweir     public Type[] getTypes() {
111cdf0e10cSrcweir         Type[] type = new Type[5];
112cdf0e10cSrcweir         type[0] = new Type(XInterface.class);
113cdf0e10cSrcweir         type[1] = new Type(XTypeProvider.class);
114cdf0e10cSrcweir         type[2] = new Type(XSingleLayerStratum.class);
115cdf0e10cSrcweir         type[3] = new Type(XServiceInfo.class);
116cdf0e10cSrcweir         type[4] = new Type(XTimeStamped.class);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         return type;
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
getUpdatableLayer(String str)121cdf0e10cSrcweir     public com.sun.star.configuration.backend.XUpdatableLayer getUpdatableLayer(String str)
122cdf0e10cSrcweir         throws com.sun.star.configuration.backend.BackendAccessException,
123cdf0e10cSrcweir                com.sun.star.lang.NoSupportException,
124cdf0e10cSrcweir                com.sun.star.lang.IllegalArgumentException {
125cdf0e10cSrcweir         throw new com.sun.star.lang.NoSupportException(
126cdf0e10cSrcweir                 "Cannot write to test backend", this);
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     /**
130cdf0e10cSrcweir      * Does the implementation support this service?
131cdf0e10cSrcweir      *
132cdf0e10cSrcweir      * @param serviceName The name of the service in question
133cdf0e10cSrcweir      * @return true, if service is supported, false otherwise
134cdf0e10cSrcweir      * @see com.sun.star.lang.XServiceInfo
135cdf0e10cSrcweir      */
supportsService(String serviceName)136cdf0e10cSrcweir     public boolean supportsService(String serviceName) {
137cdf0e10cSrcweir         if (serviceName.equals(__serviceName)) {
138cdf0e10cSrcweir             return true;
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         return false;
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     /**
145cdf0e10cSrcweir     *
146cdf0e10cSrcweir     * Gives a factory for creating the service.
147cdf0e10cSrcweir     * This method is called by the <code>JavaLoader</code>
148cdf0e10cSrcweir     * <p>
149cdf0e10cSrcweir     * @return  returns a <code>XSingleServiceFactory</code> for creating the component
150cdf0e10cSrcweir     * @param   implName     the name of the implementation for which a service is desired
151cdf0e10cSrcweir     * @param   multiFactory the service manager to be used if needed
152cdf0e10cSrcweir     * @param   regKey       the registryKey
153cdf0e10cSrcweir     * @see                  com.sun.star.comp.loader.JavaLoader
154cdf0e10cSrcweir     */
__getServiceFactory(String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey)155cdf0e10cSrcweir     public static XSingleServiceFactory __getServiceFactory(String implName,
156cdf0e10cSrcweir                                                             XMultiServiceFactory multiFactory,
157cdf0e10cSrcweir                                                             XRegistryKey regKey) {
158cdf0e10cSrcweir         XSingleServiceFactory xSingleServiceFactory = null;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         msf = multiFactory;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         if (implName.equals(JavaSystemBackend.class.getName())) {
163cdf0e10cSrcweir             xSingleServiceFactory = FactoryHelper.getServiceFactory(
164cdf0e10cSrcweir                                             JavaSystemBackend.class,
165cdf0e10cSrcweir                                             __serviceName, multiFactory,
166cdf0e10cSrcweir                                             regKey);
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         return xSingleServiceFactory;
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     /**
173cdf0e10cSrcweir      * Writes the service information into the given registry key.
174cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
175cdf0e10cSrcweir      * <p>
176cdf0e10cSrcweir      * @return  returns true if the operation succeeded
177cdf0e10cSrcweir      * @param   regKey       the registryKey
178cdf0e10cSrcweir      * @see                  com.sun.star.comp.loader.JavaLoader
179cdf0e10cSrcweir      */
__writeRegistryServiceInfo(XRegistryKey regKey)180cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
181cdf0e10cSrcweir         boolean success = FactoryHelper.writeRegistryServiceInfo(__implName,
182cdf0e10cSrcweir                                                                  __serviceName,
183cdf0e10cSrcweir                                                                  regKey);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         if (success) {
186cdf0e10cSrcweir             try {
187cdf0e10cSrcweir                 String keyName = "/" + __implName +
188cdf0e10cSrcweir                                  "/DATA/SupportedComponents";
189cdf0e10cSrcweir                 XRegistryKey newKey = regKey.createKey(keyName);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir                 String[] supportedComponents = { testComponent };
192cdf0e10cSrcweir                 newKey.setAsciiListValue(supportedComponents);
193cdf0e10cSrcweir             } catch (Exception ex) {
194cdf0e10cSrcweir                 success = false; // prevent startup loop
195cdf0e10cSrcweir                 System.out.println("can't register component");
196cdf0e10cSrcweir             }
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         return success;
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir 
addEventListener(com.sun.star.lang.XEventListener xEventListener)202cdf0e10cSrcweir     public void addEventListener(com.sun.star.lang.XEventListener xEventListener) {
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
dispose()205cdf0e10cSrcweir     public void dispose() {
206cdf0e10cSrcweir         System.out.println("JavaSystemBackend::dispose() called");
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir 
removeEventListener(com.sun.star.lang.XEventListener xEventListener)209cdf0e10cSrcweir     public void removeEventListener(com.sun.star.lang.XEventListener xEventListener) {
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     protected class CommonLayer implements XLayer, XTimeStamped {
readData(XLayerHandler xLayerHandler)213cdf0e10cSrcweir         public void readData(XLayerHandler xLayerHandler)
214cdf0e10cSrcweir                       throws com.sun.star.lang.NullPointerException,
215cdf0e10cSrcweir                              com.sun.star.lang.WrappedTargetException,
216cdf0e10cSrcweir                              com.sun.star.configuration.backend.MalformedDataException {
217cdf0e10cSrcweir             System.out.println("CommonLayer is read");
218cdf0e10cSrcweir 
219cdf0e10cSrcweir             if (xLayerHandler == null) {
220cdf0e10cSrcweir                 throw new com.sun.star.lang.NullPointerException(
221cdf0e10cSrcweir                         "null is not a legal LayerHandler");
222cdf0e10cSrcweir             }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir             XLayerContentDescriber xLayerContentDescriber = null;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir             try {
227cdf0e10cSrcweir                 xLayerContentDescriber = (XLayerContentDescriber) UnoRuntime.queryInterface(
228cdf0e10cSrcweir                                                  XLayerContentDescriber.class,
229cdf0e10cSrcweir                                                  msf.createInstance(
230cdf0e10cSrcweir                                                          "com.sun.star.comp.configuration.backend.LayerDescriber"));
231cdf0e10cSrcweir             } catch (com.sun.star.uno.Exception e) {
232cdf0e10cSrcweir                 throw new com.sun.star.lang.NullPointerException(
233cdf0e10cSrcweir                         "exception while creating LayerDesccriber");
234cdf0e10cSrcweir             }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir             if (xLayerContentDescriber == null) {
237cdf0e10cSrcweir                 throw new com.sun.star.lang.NullPointerException(
238cdf0e10cSrcweir                         "created LayerDescriber isn't valid");
239cdf0e10cSrcweir             }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir             PropertyInfo[] pInfo = new PropertyInfo[1];
242cdf0e10cSrcweir             pInfo[0] = new PropertyInfo();
243cdf0e10cSrcweir             pInfo[0].Name = "org.openoffice.Office.Common/Undo/Steps";
244cdf0e10cSrcweir             pInfo[0].Value = new Integer(12);
245cdf0e10cSrcweir             pInfo[0].Type = "int";
246cdf0e10cSrcweir             pInfo[0].Protected = false;
247cdf0e10cSrcweir             xLayerContentDescriber.describeLayer(xLayerHandler, pInfo);
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir 
getTimestamp()250cdf0e10cSrcweir         public String getTimestamp() {
251cdf0e10cSrcweir             //not really implemented
252cdf0e10cSrcweir             return "2004-03-31";
253cdf0e10cSrcweir         }
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir }