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