xref: /trunk/main/javaunohelper/com/sun/star/comp/helper/RegistryServiceFactory.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 package com.sun.star.comp.helper;
30 
31 
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.RuntimeException;
35 
36 /** The class provides a set of methods which create instances of the
37     com.sun.star.lang.RegistryServiceManager service.
38 
39     @deprecated use class Bootstrap instead
40 */
41 public class RegistryServiceFactory {
42     static {
43         System.loadLibrary("juh");
44     }
45 
46     private static native Object createRegistryServiceFactory(
47             String writeRegistryFile,
48             String readRegistryFile,
49             boolean readOnly,
50             ClassLoader loader);
51 
52     /**
53      * This bootstraps an initial service factory working on a registry. If the first or both
54      * parameters contain a value then the service factory is initialized with a simple registry
55      * or a nested registry. Otherwise the service factory must be initialized later with a valid
56      * registry.
57      *<BR>
58      * @param writeRegistryFile file name of the simple registry or the first registry file of
59      *                              the nested registry which will be opened with read/write rights. This
60      *                              file will be created if necessary.
61      * @param readRegistryFile      file name of the second registry file of the nested registry
62      *                              which will be opened with readonly rights.
63      * @return a new RegistryServiceFactory.
64      */
65     public static XMultiServiceFactory create(String writeRegistryFile, String readRegistryFile)
66         throws com.sun.star.uno.Exception
67     {
68         return create(writeRegistryFile, readRegistryFile, false);
69     }
70 
71     /**
72      * This bootstraps an initial service factory working on a registry. If the first or both
73      * parameters contain a value then the service factory is initialized with a simple registry
74      * or a nested registry. Otherwise the service factory must be initialized later with a valid
75      * registry.
76      *<BR>
77      * @param writeRegistryFile     file name of the simple registry or the first registry file of
78      *                              the nested registry which will be opened with read/write rights. This
79      *                              file will be created if necessary.
80      * @param readRegistryFile      file name of the second registry file of the nested registry
81      *                              which will be opened with readonly rights.
82      * @param readOnly              flag which specify that the first registry file will be opened with
83      *                              readonly rights. Default is FALSE. If this flag is used the registry
84      *                              will not be created if not exist.
85      *
86      * @return a new RegistryServiceFactory
87      */
88     public static XMultiServiceFactory create(String writeRegistryFile, String readRegistryFile, boolean readOnly)
89         throws com.sun.star.uno.Exception
90     {
91         // Ensure that we are on a native threads vm
92         // (binary UNO does use native threads).
93         String vm_info = System.getProperty("java.vm.info");
94         if(vm_info != null && vm_info.indexOf("green") != -1)
95             throw new RuntimeException(RegistryServiceFactory.class.toString() + ".create - can't use binary UNO with green threads");
96 
97 
98         if (writeRegistryFile == null && readRegistryFile == null)
99             throw new com.sun.star.uno.Exception("No registry is specified!");
100 
101 //          if (writeRegistryFile != null) {
102 //              java.io.File file = new java.io.File(writeRegistryFile);
103 
104 //              if (file.exists()) {
105 //                  if (!file.isFile())
106 //                      throw new com.sun.star.uno.Exception(writeRegistryFile + " is not a file!");
107 //              } else
108 //                  throw new com.sun.star.uno.Exception(writeRegistryFile + " doese not exist!");
109 //          }
110 
111 //          if (readRegistryFile != null) {
112 //              java.io.File file = new java.io.File(readRegistryFile);
113 
114 //              if (file.exists()) {
115 //                  if (!file.isFile())
116 //                      throw new com.sun.star.uno.Exception(readRegistryFile + " is not a file!");
117 //              } else
118 //                  throw new com.sun.star.uno.Exception(readRegistryFile + " doese not exist!");
119 //          }
120 
121         Object obj = createRegistryServiceFactory(
122             writeRegistryFile, readRegistryFile, readOnly,
123             RegistryServiceFactory.class.getClassLoader() );
124         return UnoRuntime.queryInterface(
125             XMultiServiceFactory.class, obj );
126     }
127 
128     /**
129      * This bootstraps an initial service factory working on a registry file.
130      *<BR>
131      * @param registryFile          file name of the registry to use/ create; if this is an empty
132      *                              string, the default registry is used instead
133      *
134      * @return a new RegistryServiceFactory.
135      */
136     public static XMultiServiceFactory create(String registryFile)
137         throws com.sun.star.uno.Exception
138     {
139         return create(registryFile, null, false);
140     }
141 
142     /**
143      * This bootstraps an initial service factory working on a registry file.
144      *<BR>
145      * @param registryFile          file name of the registry to use/ create; if this is an empty
146      *                              string, the default registry is used instead
147      * @param readOnly              flag which specify that the registry file will be opened with
148      *                              readonly rights. Default is FALSE. If this flag is used the registry
149      *                              will not be created if not exist.
150      *
151      * @return a new RegistryServiceFactory.
152      */
153     public static XMultiServiceFactory create(String registryFile, boolean readOnly)
154         throws com.sun.star.uno.Exception
155     {
156         return create(registryFile, null, readOnly);
157     }
158 
159     /**
160      * This bootstraps a service factory without initialize a registry.
161      *<BR>
162      * @return a new RegistryServiceFactory.
163      */
164     public static XMultiServiceFactory create() throws com.sun.star.uno.Exception {
165         return create( null, null, false );
166     }
167 }
168 
169