1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegistryServiceFactory.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 package com
.sun
.star
.comp
.helper
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.RuntimeException
;
39 /** The class provides a set of methods which create instances of the
40 com.sun.star.lang.RegistryServiceManager service.
42 @deprecated use class Bootstrap instead
44 public class RegistryServiceFactory
{
46 System
.loadLibrary("juh");
49 private static native Object
createRegistryServiceFactory(
50 String writeRegistryFile
,
51 String readRegistryFile
,
56 * This bootstraps an initial service factory working on a registry. If the first or both
57 * parameters contain a value then the service factory is initialized with a simple registry
58 * or a nested registry. Otherwise the service factory must be initialized later with a valid
61 * @param writeRegistryFile file name of the simple registry or the first registry file of
62 * the nested registry which will be opened with read/write rights. This
63 * file will be created if necessary.
64 * @param readRegistryFile file name of the second registry file of the nested registry
65 * which will be opened with readonly rights.
66 * @return a new RegistryServiceFactory.
68 public static XMultiServiceFactory
create(String writeRegistryFile
, String readRegistryFile
)
69 throws com
.sun
.star
.uno
.Exception
71 return create(writeRegistryFile
, readRegistryFile
, false);
75 * This bootstraps an initial service factory working on a registry. If the first or both
76 * parameters contain a value then the service factory is initialized with a simple registry
77 * or a nested registry. Otherwise the service factory must be initialized later with a valid
80 * @param writeRegistryFile file name of the simple registry or the first registry file of
81 * the nested registry which will be opened with read/write rights. This
82 * file will be created if necessary.
83 * @param readRegistryFile file name of the second registry file of the nested registry
84 * which will be opened with readonly rights.
85 * @param readOnly flag which specify that the first registry file will be opened with
86 * readonly rights. Default is FALSE. If this flag is used the registry
87 * will not be created if not exist.
89 * @return a new RegistryServiceFactory
91 public static XMultiServiceFactory
create(String writeRegistryFile
, String readRegistryFile
, boolean readOnly
)
92 throws com
.sun
.star
.uno
.Exception
94 // Ensure that we are on a native threads vm
95 // (binary UNO does use native threads).
96 String vm_info
= System
.getProperty("java.vm.info");
97 if(vm_info
!= null && vm_info
.indexOf("green") != -1)
98 throw new RuntimeException(RegistryServiceFactory
.class.toString() + ".create - can't use binary UNO with green threads");
101 if (writeRegistryFile
== null && readRegistryFile
== null)
102 throw new com
.sun
.star
.uno
.Exception("No registry is specified!");
104 // if (writeRegistryFile != null) {
105 // java.io.File file = new java.io.File(writeRegistryFile);
107 // if (file.exists()) {
108 // if (!file.isFile())
109 // throw new com.sun.star.uno.Exception(writeRegistryFile + " is not a file!");
111 // throw new com.sun.star.uno.Exception(writeRegistryFile + " doese not exist!");
114 // if (readRegistryFile != null) {
115 // java.io.File file = new java.io.File(readRegistryFile);
117 // if (file.exists()) {
118 // if (!file.isFile())
119 // throw new com.sun.star.uno.Exception(readRegistryFile + " is not a file!");
121 // throw new com.sun.star.uno.Exception(readRegistryFile + " doese not exist!");
124 Object obj
= createRegistryServiceFactory(
125 writeRegistryFile
, readRegistryFile
, readOnly
,
126 RegistryServiceFactory
.class.getClassLoader() );
127 return UnoRuntime
.queryInterface(
128 XMultiServiceFactory
.class, obj
);
132 * This bootstraps an initial service factory working on a registry file.
134 * @param registryFile file name of the registry to use/ create; if this is an empty
135 * string, the default registry is used instead
137 * @return a new RegistryServiceFactory.
139 public static XMultiServiceFactory
create(String registryFile
)
140 throws com
.sun
.star
.uno
.Exception
142 return create(registryFile
, null, false);
146 * This bootstraps an initial service factory working on a registry file.
148 * @param registryFile file name of the registry to use/ create; if this is an empty
149 * string, the default registry is used instead
150 * @param readOnly flag which specify that the registry file will be opened with
151 * readonly rights. Default is FALSE. If this flag is used the registry
152 * will not be created if not exist.
154 * @return a new RegistryServiceFactory.
156 public static XMultiServiceFactory
create(String registryFile
, boolean readOnly
)
157 throws com
.sun
.star
.uno
.Exception
159 return create(registryFile
, null, readOnly
);
163 * This bootstraps a service factory without initialize a registry.
165 * @return a new RegistryServiceFactory.
167 public static XMultiServiceFactory
create() throws com
.sun
.star
.uno
.Exception
{
168 return create( null, null, false );