2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package org
.openoffice
;
20 import com
.sun
.star
.comp
.loader
.FactoryHelper
;
21 import com
.sun
.star
.configuration
.backend
.PropertyInfo
;
22 import com
.sun
.star
.configuration
.backend
.XLayer
;
23 import com
.sun
.star
.configuration
.backend
.XLayerContentDescriber
;
24 import com
.sun
.star
.configuration
.backend
.XLayerHandler
;
25 import com
.sun
.star
.configuration
.backend
.XSingleLayerStratum
;
26 import com
.sun
.star
.lang
.XComponent
;
27 import com
.sun
.star
.lang
.XMultiServiceFactory
;
28 import com
.sun
.star
.lang
.XServiceInfo
;
29 import com
.sun
.star
.lang
.XSingleServiceFactory
;
30 import com
.sun
.star
.lang
.XTypeProvider
;
31 import com
.sun
.star
.registry
.XRegistryKey
;
32 import com
.sun
.star
.uno
.Type
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
35 import com
.sun
.star
.util
.XTimeStamped
;
37 public class JavaSystemBackend
implements XSingleLayerStratum
, XTypeProvider
,
38 XServiceInfo
, XTimeStamped
, XComponent
{
39 public final static String __serviceName
= "com.sun.star.configuration.backend.PlatformBackend";
40 public final static String __implName
= "org.openoffice.JavaSystemBackend";
41 public final static String testComponent
= "org.openoffice.Office.Common";
42 protected static XMultiServiceFactory msf
= null;
43 protected XLayer aLayer
= null;
46 * Get the implementation id.
47 * @return An empty implementation id.
48 * @see com.sun.star.lang.XTypeProvider
50 public byte[] getImplementationId() {
55 * Function for reading the implementation name.
57 * @return the implementation name
58 * @see com.sun.star.lang.XServiceInfo
60 public String
getImplementationName() {
64 public com
.sun
.star
.configuration
.backend
.XLayer
getLayer(String str
,
66 throws com
.sun
.star
.configuration
.backend
.BackendAccessException
,
67 com
.sun
.star
.lang
.IllegalArgumentException
{
69 System
.out
.println("JavaSystemBackend::getLayer() called for " +
71 aLayer
= new CommonLayer();
78 * Function for reading all supported services
80 * @return An aaray with all supported service names
81 * @see com.sun.star.lang.XServiceInfo
83 public String
[] getSupportedServiceNames() {
84 String
[] supServiceNames
= { __serviceName
};
86 return supServiceNames
;
89 public String
getTimestamp() {
90 //not really implemented
95 * Get all implemented types of this class.
96 * @return An array of implemented interface types.
97 * @see com.sun.star.lang.XTypeProvider
99 public Type
[] getTypes() {
100 Type
[] type
= new Type
[5];
101 type
[0] = new Type(XInterface
.class);
102 type
[1] = new Type(XTypeProvider
.class);
103 type
[2] = new Type(XSingleLayerStratum
.class);
104 type
[3] = new Type(XServiceInfo
.class);
105 type
[4] = new Type(XTimeStamped
.class);
110 public com
.sun
.star
.configuration
.backend
.XUpdatableLayer
getUpdatableLayer(String str
)
111 throws com
.sun
.star
.configuration
.backend
.BackendAccessException
,
112 com
.sun
.star
.lang
.NoSupportException
,
113 com
.sun
.star
.lang
.IllegalArgumentException
{
114 throw new com
.sun
.star
.lang
.NoSupportException(
115 "Cannot write to test backend", this);
119 * Does the implementation support this service?
121 * @param serviceName The name of the service in question
122 * @return true, if service is supported, false otherwise
123 * @see com.sun.star.lang.XServiceInfo
125 public boolean supportsService(String serviceName
) {
126 if (serviceName
.equals(__serviceName
)) {
135 * Gives a factory for creating the service.
136 * This method is called by the <code>JavaLoader</code>
138 * @return returns a <code>XSingleServiceFactory</code> for creating the component
139 * @param implName the name of the implementation for which a service is desired
140 * @param multiFactory the service manager to be used if needed
141 * @param regKey the registryKey
142 * @see com.sun.star.comp.loader.JavaLoader
144 public static XSingleServiceFactory
__getServiceFactory(String implName
,
145 XMultiServiceFactory multiFactory
,
146 XRegistryKey regKey
) {
147 XSingleServiceFactory xSingleServiceFactory
= null;
151 if (implName
.equals(JavaSystemBackend
.class.getName())) {
152 xSingleServiceFactory
= FactoryHelper
.getServiceFactory(
153 JavaSystemBackend
.class,
154 __serviceName
, multiFactory
,
158 return xSingleServiceFactory
;
162 * Writes the service information into the given registry key.
163 * This method is called by the <code>JavaLoader</code>
165 * @return returns true if the operation succeeded
166 * @param regKey the registryKey
167 * @see com.sun.star.comp.loader.JavaLoader
169 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey
) {
170 boolean success
= FactoryHelper
.writeRegistryServiceInfo(__implName
,
176 String keyName
= "/" + __implName
+
177 "/DATA/SupportedComponents";
178 XRegistryKey newKey
= regKey
.createKey(keyName
);
180 String
[] supportedComponents
= { testComponent
};
181 newKey
.setAsciiListValue(supportedComponents
);
182 } catch (Exception ex
) {
183 success
= false; // prevent startup loop
184 System
.out
.println("can't register component");
191 public void addEventListener(com
.sun
.star
.lang
.XEventListener xEventListener
) {
194 public void dispose() {
195 System
.out
.println("JavaSystemBackend::dispose() called");
198 public void removeEventListener(com
.sun
.star
.lang
.XEventListener xEventListener
) {
201 protected class CommonLayer
implements XLayer
, XTimeStamped
{
202 public void readData(XLayerHandler xLayerHandler
)
203 throws com
.sun
.star
.lang
.NullPointerException
,
204 com
.sun
.star
.lang
.WrappedTargetException
,
205 com
.sun
.star
.configuration
.backend
.MalformedDataException
{
206 System
.out
.println("CommonLayer is read");
208 if (xLayerHandler
== null) {
209 throw new com
.sun
.star
.lang
.NullPointerException(
210 "null is not a legal LayerHandler");
213 XLayerContentDescriber xLayerContentDescriber
= null;
216 xLayerContentDescriber
= UnoRuntime
.queryInterface(
217 XLayerContentDescriber
.class,
219 "com.sun.star.comp.configuration.backend.LayerDescriber"));
220 } catch (com
.sun
.star
.uno
.Exception e
) {
221 throw new com
.sun
.star
.lang
.NullPointerException(
222 "exception while creating LayerDesccriber");
225 if (xLayerContentDescriber
== null) {
226 throw new com
.sun
.star
.lang
.NullPointerException(
227 "created LayerDescriber isn't valid");
230 PropertyInfo
[] pInfo
= new PropertyInfo
[1];
231 pInfo
[0] = new PropertyInfo();
232 pInfo
[0].Name
= "org.openoffice.Office.Common/Undo/Steps";
233 pInfo
[0].Value
= new Integer(12);
234 pInfo
[0].Type
= "int";
235 pInfo
[0].Protected
= false;
236 xLayerContentDescriber
.describeLayer(xLayerHandler
, pInfo
);
239 public String
getTimestamp() {
240 //not really implemented