1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="registry_XImplementationRegistration" script:language="StarBasic"> 4cdf0e10cSrcweir 5cdf0e10cSrcweir 6cdf0e10cSrcweir'************************************************************************* 7cdf0e10cSrcweir' 8*3e6afcd2SAndrew Rist' Licensed to the Apache Software Foundation (ASF) under one 9*3e6afcd2SAndrew Rist' or more contributor license agreements. See the NOTICE file 10*3e6afcd2SAndrew Rist' distributed with this work for additional information 11*3e6afcd2SAndrew Rist' regarding copyright ownership. The ASF licenses this file 12*3e6afcd2SAndrew Rist' to you under the Apache License, Version 2.0 (the 13*3e6afcd2SAndrew Rist' "License"); you may not use this file except in compliance 14*3e6afcd2SAndrew Rist' with the License. You may obtain a copy of the License at 15*3e6afcd2SAndrew Rist' 16*3e6afcd2SAndrew Rist' http://www.apache.org/licenses/LICENSE-2.0 17*3e6afcd2SAndrew Rist' 18*3e6afcd2SAndrew Rist' Unless required by applicable law or agreed to in writing, 19*3e6afcd2SAndrew Rist' software distributed under the License is distributed on an 20*3e6afcd2SAndrew Rist' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21*3e6afcd2SAndrew Rist' KIND, either express or implied. See the License for the 22*3e6afcd2SAndrew Rist' specific language governing permissions and limitations 23*3e6afcd2SAndrew Rist' under the License. 24cdf0e10cSrcweir' 25cdf0e10cSrcweir'************************************************************************* 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29*3e6afcd2SAndrew Rist 30*3e6afcd2SAndrew Rist 31cdf0e10cSrcweir' Be sure that all variables are dimensioned: 32cdf0e10cSrcweiroption explicit 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweirSub RunTest() 37cdf0e10cSrcweir 38cdf0e10cSrcweir'************************************************************************* 39cdf0e10cSrcweir' INTERFACE: 40cdf0e10cSrcweir' com.sun.star.registry.XImplementationRegistration 41cdf0e10cSrcweir'************************************************************************* 42cdf0e10cSrcweirOn Error Goto ErrHndl 43cdf0e10cSrcweir Dim bOK As Boolean 44cdf0e10cSrcweir Dim aImplementationLoader As String 45cdf0e10cSrcweir Dim aImplementations As Variant 46cdf0e10cSrcweir Dim aMissingServices As Variant 47cdf0e10cSrcweir Dim aLocation As String 48cdf0e10cSrcweir Dim i As Integer 49cdf0e10cSrcweir Dim k As Integer 50cdf0e10cSrcweir Dim xReg As Object 51cdf0e10cSrcweir Dim regKey As Object 52cdf0e10cSrcweir Dim keyNames As Variant 53cdf0e10cSrcweir Dim bNeedTest As Boolean 54cdf0e10cSrcweir 55cdf0e10cSrcweir xReg = createUNOService("com.sun.star.registry.SimpleRegistry") 56cdf0e10cSrcweir xReg.Open(utils.Path2URL(cTestDocsDir & "XImpReg.reg"), false, true) 57cdf0e10cSrcweir aImplementationLoader = "com.sun.star.loader.Java2" 58cdf0e10cSrcweir aLocation = utils.Path2URL(cTestDocsDir & "qadevlibs/MyPersistObjectImpl.jar") 59cdf0e10cSrcweir 60cdf0e10cSrcweir Test.StartMethod("getImplementations()") 61cdf0e10cSrcweir bOK = true 62cdf0e10cSrcweir aImplementations = oObj.getImplementations(aImplementationLoader, aLocation) 63cdf0e10cSrcweir bOK = bOK AND i >= 0 64cdf0e10cSrcweir for i = 0 to ubound(aImplementations) 65cdf0e10cSrcweir Out.Log "" & i + 1 & ") " & aImplementations(i) 66cdf0e10cSrcweir next i 67cdf0e10cSrcweir Test.MethodTested("getImplementations()", bOK) 68cdf0e10cSrcweir 69cdf0e10cSrcweir Test.StartMethod("registerImplementation()") 70cdf0e10cSrcweir Out.Log("Registering implementation from " & aLocation) 71cdf0e10cSrcweir bOK = true 72cdf0e10cSrcweir oObj.registerImplementation(aImplementationLoader, aLocation, xReg) 73cdf0e10cSrcweir 74cdf0e10cSrcweir bOK = bOK AND xReg.isValid() 75cdf0e10cSrcweir 76cdf0e10cSrcweir regKey = xReg.getRootKey.openKey("IMPLEMENTATIONS") 77cdf0e10cSrcweir keyNames = regKey.getKeyNames() 78cdf0e10cSrcweir Out.Log("In registry found " & ubound(keyNames) + 1 & " implementations.") 79cdf0e10cSrcweir Dim aFlags(ubound(aImplementations())) As Boolean 80cdf0e10cSrcweir for i = 0 to ubound(aFlags()) 81cdf0e10cSrcweir aFlags(i) = false 82cdf0e10cSrcweir next i 83cdf0e10cSrcweir 84cdf0e10cSrcweir for i = 0 to ubound(keyNames()) 85cdf0e10cSrcweir Out.Log("Found key: " & keyNames(i)) 86cdf0e10cSrcweir for k = 0 to ubound(aImplementations) 87cdf0e10cSrcweir if (inStr(1, keyNames(i), aImplementations(k)) > 0 ) then 88cdf0e10cSrcweir aFlags(k) = true 89cdf0e10cSrcweir end if 90cdf0e10cSrcweir next k 91cdf0e10cSrcweir next i 92cdf0e10cSrcweir 93cdf0e10cSrcweir for i = 0 to ubound(aFlags()) 94cdf0e10cSrcweir if (NOT aFlags(i)) then 95cdf0e10cSrcweir Out.Log("Can't find information about " & aImplementations(i) & " in regestry") 96cdf0e10cSrcweir bOK = false 97cdf0e10cSrcweir end if 98cdf0e10cSrcweir next i 99cdf0e10cSrcweir 100cdf0e10cSrcweir Test.MethodTested("registerImplementation()", bOK) 101cdf0e10cSrcweir 102cdf0e10cSrcweir Test.StartMethod("checkInstantiation()") 103cdf0e10cSrcweir bOK = true 104cdf0e10cSrcweir Out.Log("Looking for missing services to create " & aImplementations(0)) 105cdf0e10cSrcweir aMissingServices = oObj.checkInstantiation(aImplementations(0)) 106cdf0e10cSrcweir Out.Log("" & ubound(aMissingServices) + 1 & " missing services were found") 107cdf0e10cSrcweir for i = 0 to ubound(aMissingServices) 108cdf0e10cSrcweir Out.Log "" & i & ") " & aMissingServices(i) 109cdf0e10cSrcweir next i 110cdf0e10cSrcweir Test.MethodTested("checkInstantiation()", bOK) 111cdf0e10cSrcweir 112cdf0e10cSrcweir Test.StartMethod("revokeImplementation()") 113cdf0e10cSrcweir bOK = true 114cdf0e10cSrcweir bNeedTest = false 115cdf0e10cSrcweir 116cdf0e10cSrcweir oObj.revokeImplementation(aLocation, xReg) 117cdf0e10cSrcweir 118cdf0e10cSrcweir bOK = bOK AND xReg.isValid() 119cdf0e10cSrcweir regKey = xReg.getRootKey 120cdf0e10cSrcweir keyNames = regKey.getKeyNames() 121cdf0e10cSrcweir for i = 0 to ubound(keyNames()) 122cdf0e10cSrcweir if (inStr(1, keyNames(i), "IMPLEMENTATIONS") > 0) then 123cdf0e10cSrcweir bNeedTest = true 124cdf0e10cSrcweir end if 125cdf0e10cSrcweir next i 126cdf0e10cSrcweir if (NOT bNeedTest) then 127cdf0e10cSrcweir Out.Log("No implementation was found.") 128cdf0e10cSrcweir end if 129cdf0e10cSrcweir 130cdf0e10cSrcweir if (bOK AND bNeedTest) then 131cdf0e10cSrcweir regKey = xReg.getRootKey.openKey("IMPLEMENTATIONS") 132cdf0e10cSrcweir Out.Log("In registry found " & ubound(keyNames) + 1 & " implementations.") 133cdf0e10cSrcweir 134cdf0e10cSrcweir for i = 0 to ubound(aFlags()) 135cdf0e10cSrcweir aFlags(i) = false 136cdf0e10cSrcweir next i 137cdf0e10cSrcweir 138cdf0e10cSrcweir for i = 0 to ubound(keyNames()) 139cdf0e10cSrcweir Out.Log("Found key: " & keyNames(i)) 140cdf0e10cSrcweir for k = 0 to ubound(aImplementations) 141cdf0e10cSrcweir if (inStr(1, keyNames(i), aImplementations(k)) > 0 ) then 142cdf0e10cSrcweir aFlags(k) = true 143cdf0e10cSrcweir end if 144cdf0e10cSrcweir next k 145cdf0e10cSrcweir next i 146cdf0e10cSrcweir 147cdf0e10cSrcweir for i = 0 to ubound(aFlags()) 148cdf0e10cSrcweir if (aFlags(i)) then 149cdf0e10cSrcweir Out.Log("Information about " & aImplementations(i) & " is still in regestry") 150cdf0e10cSrcweir bOK = false 151cdf0e10cSrcweir end if 152cdf0e10cSrcweir next i 153cdf0e10cSrcweir end if 154cdf0e10cSrcweir Test.MethodTested("revokeImplementation()", bOK) 155cdf0e10cSrcweir 156cdf0e10cSrcweir xReg.Close() 157cdf0e10cSrcweirExit Sub 158cdf0e10cSrcweirErrHndl: 159cdf0e10cSrcweir Test.Exception() 160cdf0e10cSrcweir bOK = false 161cdf0e10cSrcweir resume next 162cdf0e10cSrcweirEnd Sub 163cdf0e10cSrcweir</script:module> 164