Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / testdocs / backend / org / openoffice / JavaSystemBackend.java
blob98aee0e1e326d31b618239e1cb04c8dbe0884e52
1 /*
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 static final String __serviceName = "com.sun.star.configuration.backend.PlatformBackend";
40 public static final String __implName = "org.openoffice.JavaSystemBackend";
41 public static final String testComponent = "org.openoffice.Office.Common";
42 protected static XMultiServiceFactory msf = null;
43 protected XLayer aLayer = null;
45 /**
46 * Get the implementation id.
47 * @return An empty implementation id.
48 * @see com.sun.star.lang.XTypeProvider
50 public byte[] getImplementationId() {
51 return new byte[0];
54 /**
55 * Function for reading the implementation name.
57 * @return the implementation name
58 * @see com.sun.star.lang.XServiceInfo
60 public String getImplementationName() {
61 return __implName;
64 public com.sun.star.configuration.backend.XLayer getLayer(String str,
65 String str1)
66 throws com.sun.star.configuration.backend.BackendAccessException,
67 com.sun.star.lang.IllegalArgumentException {
68 if (aLayer == null) {
69 System.out.println("JavaSystemBackend::getLayer() called for " +
70 str);
71 aLayer = new CommonLayer();
74 return aLayer;
77 /**
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
91 return "2004-03-31";
94 /**
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);
107 return type;
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 return serviceName.equals(__serviceName);
131 * Gives a factory for creating the service.
132 * This method is called by the <code>JavaLoader</code>
133 * <p>
134 * @return returns a <code>XSingleServiceFactory</code> for creating the component
135 * @param implName the name of the implementation for which a service is desired
136 * @param multiFactory the service manager to be used if needed
137 * @param regKey the registryKey
138 * @see com.sun.star.comp.loader.JavaLoader
140 public static XSingleServiceFactory __getServiceFactory(String implName,
141 XMultiServiceFactory multiFactory,
142 XRegistryKey regKey) {
143 XSingleServiceFactory xSingleServiceFactory = null;
145 msf = multiFactory;
147 if (implName.equals(JavaSystemBackend.class.getName())) {
148 xSingleServiceFactory = FactoryHelper.getServiceFactory(
149 JavaSystemBackend.class,
150 __serviceName, multiFactory,
151 regKey);
154 return xSingleServiceFactory;
158 * Writes the service information into the given registry key.
159 * This method is called by the <code>JavaLoader</code>
160 * <p>
161 * @return returns true if the operation succeeded
162 * @param regKey the registryKey
163 * @see com.sun.star.comp.loader.JavaLoader
165 public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
166 boolean success = FactoryHelper.writeRegistryServiceInfo(__implName,
167 __serviceName,
168 regKey);
170 if (success) {
171 try {
172 String keyName = "/" + __implName +
173 "/DATA/SupportedComponents";
174 XRegistryKey newKey = regKey.createKey(keyName);
176 String[] supportedComponents = { testComponent };
177 newKey.setAsciiListValue(supportedComponents);
178 } catch (Exception ex) {
179 success = false; // prevent startup loop
180 System.out.println("can't register component");
184 return success;
187 public void addEventListener(com.sun.star.lang.XEventListener xEventListener) {
190 public void dispose() {
191 System.out.println("JavaSystemBackend::dispose() called");
194 public void removeEventListener(com.sun.star.lang.XEventListener xEventListener) {
197 private class CommonLayer implements XLayer, XTimeStamped {
198 public void readData(XLayerHandler xLayerHandler)
199 throws com.sun.star.lang.NullPointerException,
200 com.sun.star.lang.WrappedTargetException,
201 com.sun.star.configuration.backend.MalformedDataException {
202 System.out.println("CommonLayer is read");
204 if (xLayerHandler == null) {
205 throw new com.sun.star.lang.NullPointerException(
206 "null is not a legal LayerHandler");
209 XLayerContentDescriber xLayerContentDescriber = null;
211 try {
212 xLayerContentDescriber = UnoRuntime.queryInterface(
213 XLayerContentDescriber.class,
214 msf.createInstance(
215 "com.sun.star.comp.configuration.backend.LayerDescriber"));
216 } catch (com.sun.star.uno.Exception e) {
217 throw new com.sun.star.lang.NullPointerException(e,
218 "exception while creating LayerDesccriber");
221 if (xLayerContentDescriber == null) {
222 throw new com.sun.star.lang.NullPointerException(
223 "created LayerDescriber isn't valid");
226 PropertyInfo[] pInfo = new PropertyInfo[1];
227 pInfo[0] = new PropertyInfo();
228 pInfo[0].Name = "org.openoffice.Office.Common/Undo/Steps";
229 pInfo[0].Value = Integer.valueOf(12);
230 pInfo[0].Type = "int";
231 pInfo[0].Protected = false;
232 xLayerContentDescriber.describeLayer(xLayerHandler, pInfo);
235 public String getTimestamp() {
236 //not really implemented
237 return "2004-03-31";