1*a5b190bfSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a5b190bfSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a5b190bfSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a5b190bfSAndrew Rist  * distributed with this work for additional information
6*a5b190bfSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a5b190bfSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a5b190bfSAndrew Rist  * "License"); you may not use this file except in compliance
9*a5b190bfSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a5b190bfSAndrew Rist  *
11*a5b190bfSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a5b190bfSAndrew Rist  *
13*a5b190bfSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a5b190bfSAndrew Rist  * software distributed under the License is distributed on an
15*a5b190bfSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a5b190bfSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a5b190bfSAndrew Rist  * specific language governing permissions and limitations
18*a5b190bfSAndrew Rist  * under the License.
19*a5b190bfSAndrew Rist  *
20*a5b190bfSAndrew Rist  *************************************************************/
21*a5b190bfSAndrew Rist 
22*a5b190bfSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir package com.sun.star.comp.helper;
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /** The class provides a set of methods which create instances of the
33cdf0e10cSrcweir 	com.sun.star.lang.RegistryServiceManager service.
34cdf0e10cSrcweir 
35cdf0e10cSrcweir     @deprecated use class Bootstrap instead
36cdf0e10cSrcweir */
37cdf0e10cSrcweir public class RegistryServiceFactory {
38cdf0e10cSrcweir 	static {
39cdf0e10cSrcweir 		System.loadLibrary("juh");
40cdf0e10cSrcweir 	}
41cdf0e10cSrcweir 
createRegistryServiceFactory( String writeRegistryFile, String readRegistryFile, boolean readOnly, ClassLoader loader)42cdf0e10cSrcweir 	private static native Object createRegistryServiceFactory(
43cdf0e10cSrcweir 			String writeRegistryFile,
44cdf0e10cSrcweir 			String readRegistryFile,
45cdf0e10cSrcweir 			boolean readOnly,
46cdf0e10cSrcweir             ClassLoader loader);
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	/**
49cdf0e10cSrcweir  	 * This bootstraps an initial service factory working on a registry. If the first or both
50cdf0e10cSrcweir  	 * parameters contain a value then the service factory is initialized with a simple registry
51cdf0e10cSrcweir  	 * or a nested registry. Otherwise the service factory must be initialized later with a valid
52cdf0e10cSrcweir  	 * registry.
53cdf0e10cSrcweir  	 *<BR>
54cdf0e10cSrcweir  	 * @param writeRegistryFile	file name of the simple registry or the first registry file of
55cdf0e10cSrcweir  	 *								the nested registry which will be opened with read/write rights. This
56cdf0e10cSrcweir  	 *								file will be created if necessary.
57cdf0e10cSrcweir  	 * @param readRegistryFile		file name of the second registry file of the nested registry
58cdf0e10cSrcweir  	 *								which will be opened with readonly rights.
59cdf0e10cSrcweir 	 * @return a new RegistryServiceFactory.
60cdf0e10cSrcweir  	 */
create(String writeRegistryFile, String readRegistryFile)61cdf0e10cSrcweir 	public static XMultiServiceFactory create(String writeRegistryFile, String readRegistryFile)
62cdf0e10cSrcweir 		throws com.sun.star.uno.Exception
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		return create(writeRegistryFile, readRegistryFile, false);
65cdf0e10cSrcweir 	}
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	/**
68cdf0e10cSrcweir  	 * This bootstraps an initial service factory working on a registry. If the first or both
69cdf0e10cSrcweir  	 * parameters contain a value then the service factory is initialized with a simple registry
70cdf0e10cSrcweir  	 * or a nested registry. Otherwise the service factory must be initialized later with a valid
71cdf0e10cSrcweir  	 * registry.
72cdf0e10cSrcweir  	 *<BR>
73cdf0e10cSrcweir      * @param writeRegistryFile	    file name of the simple registry or the first registry file of
74cdf0e10cSrcweir      *								the nested registry which will be opened with read/write rights. This
75cdf0e10cSrcweir      *								file will be created if necessary.
76cdf0e10cSrcweir      * @param readRegistryFile		file name of the second registry file of the nested registry
77cdf0e10cSrcweir      *								which will be opened with readonly rights.
78cdf0e10cSrcweir      * @param readOnly				flag which specify that the first registry file will be opened with
79cdf0e10cSrcweir      *								readonly rights. Default is FALSE. If this flag is used the registry
80cdf0e10cSrcweir      *								will not be created if not exist.
81cdf0e10cSrcweir      *
82cdf0e10cSrcweir  	 * @return a new RegistryServiceFactory
83cdf0e10cSrcweir  	 */
create(String writeRegistryFile, String readRegistryFile, boolean readOnly)84cdf0e10cSrcweir 	public static XMultiServiceFactory create(String writeRegistryFile, String readRegistryFile, boolean readOnly)
85cdf0e10cSrcweir 		throws com.sun.star.uno.Exception
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		// Ensure that we are on a native threads vm
88cdf0e10cSrcweir 		// (binary UNO does use native threads).
89cdf0e10cSrcweir 		String vm_info = System.getProperty("java.vm.info");
90cdf0e10cSrcweir 		if(vm_info != null && vm_info.indexOf("green") != -1)
91cdf0e10cSrcweir 			throw new RuntimeException(RegistryServiceFactory.class.toString() + ".create - can't use binary UNO with green threads");
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         if (writeRegistryFile == null && readRegistryFile == null)
95cdf0e10cSrcweir             throw new com.sun.star.uno.Exception("No registry is specified!");
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //          if (writeRegistryFile != null) {
98cdf0e10cSrcweir //              java.io.File file = new java.io.File(writeRegistryFile);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir //              if (file.exists()) {
101cdf0e10cSrcweir //                  if (!file.isFile())
102cdf0e10cSrcweir //                      throw new com.sun.star.uno.Exception(writeRegistryFile + " is not a file!");
103cdf0e10cSrcweir //              } else
104cdf0e10cSrcweir //                  throw new com.sun.star.uno.Exception(writeRegistryFile + " doese not exist!");
105cdf0e10cSrcweir //          }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //          if (readRegistryFile != null) {
108cdf0e10cSrcweir //              java.io.File file = new java.io.File(readRegistryFile);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //              if (file.exists()) {
111cdf0e10cSrcweir //                  if (!file.isFile())
112cdf0e10cSrcweir //                      throw new com.sun.star.uno.Exception(readRegistryFile + " is not a file!");
113cdf0e10cSrcweir //              } else
114cdf0e10cSrcweir //                  throw new com.sun.star.uno.Exception(readRegistryFile + " doese not exist!");
115cdf0e10cSrcweir //          }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         Object obj = createRegistryServiceFactory(
118cdf0e10cSrcweir             writeRegistryFile, readRegistryFile, readOnly,
119cdf0e10cSrcweir             RegistryServiceFactory.class.getClassLoader() );
120cdf0e10cSrcweir 		return UnoRuntime.queryInterface(
121cdf0e10cSrcweir 			XMultiServiceFactory.class, obj );
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	/**
125cdf0e10cSrcweir 	 * This bootstraps an initial service factory working on a registry file.
126cdf0e10cSrcweir 	 *<BR>
127cdf0e10cSrcweir 	 * @param registryFile			file name of the registry to use/ create; if this is an empty
128cdf0e10cSrcweir 	 *								string, the default registry is used instead
129cdf0e10cSrcweir 	 *
130cdf0e10cSrcweir 	 * @return a new RegistryServiceFactory.
131cdf0e10cSrcweir 	 */
create(String registryFile)132cdf0e10cSrcweir 	public static XMultiServiceFactory create(String registryFile)
133cdf0e10cSrcweir 		throws com.sun.star.uno.Exception
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		return create(registryFile, null, false);
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	/**
139cdf0e10cSrcweir 	 * This bootstraps an initial service factory working on a registry file.
140cdf0e10cSrcweir 	 *<BR>
141cdf0e10cSrcweir      * @param registryFile			file name of the registry to use/ create; if this is an empty
142cdf0e10cSrcweir      *								string, the default registry is used instead
143cdf0e10cSrcweir      * @param readOnly				flag which specify that the registry file will be opened with
144cdf0e10cSrcweir      *								readonly rights. Default is FALSE. If this flag is used the registry
145cdf0e10cSrcweir      *								will not be created if not exist.
146cdf0e10cSrcweir 	 *
147cdf0e10cSrcweir 	 * @return a new RegistryServiceFactory.
148cdf0e10cSrcweir 	 */
create(String registryFile, boolean readOnly)149cdf0e10cSrcweir 	public static XMultiServiceFactory create(String registryFile, boolean readOnly)
150cdf0e10cSrcweir 		throws com.sun.star.uno.Exception
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		return create(registryFile, null, readOnly);
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	/**
156cdf0e10cSrcweir 	 * This bootstraps a service factory without initialize a registry.
157cdf0e10cSrcweir 	 *<BR>
158cdf0e10cSrcweir 	 * @return a new RegistryServiceFactory.
159cdf0e10cSrcweir 	 */
create()160cdf0e10cSrcweir 	public static XMultiServiceFactory create() throws com.sun.star.uno.Exception {
161cdf0e10cSrcweir 		return create( null, null, false );
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165