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 package mod._dbaccess; 29 30 import com.sun.star.beans.PropertyValue; 31 import java.io.PrintWriter; 32 33 import lib.Status; 34 import lib.StatusException; 35 import lib.TestCase; 36 import lib.TestEnvironment; 37 import lib.TestParameters; 38 39 import com.sun.star.beans.XPropertySet; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.uno.UnoRuntime; 42 import com.sun.star.uno.XInterface; 43 import com.sun.star.uno.XNamingService; 44 import com.sun.star.frame.XStorable; 45 import com.sun.star.sdb.XDocumentDataSource; 46 import util.utils; 47 48 /** 49 * Test for object which is represented by service 50 * <code>com.sun.star.sdb.DatabaseContext</code>. <p> 51 * 52 * Object implements the following interfaces : 53 * <ul> 54 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 55 * <li> <code>com::sun::star::container::XNameAccess</code></li> 56 * <li> <code>com::sun::star::container::XElementAccess</code></li> 57 * <li> <code>com::sun::star::uno::XNamingService</code></li> 58 * </ul> 59 * 60 * @see com.sun.star.container.XNameAccess 61 * @see com.sun.star.container.XEnumerationAccess 62 * @see com.sun.star.container.XElementAccess 63 * @see com.sun.star.uno.XNamingService 64 * @see com.sun.star.sdb.DatabaseContext 65 * @see ifc.container.XNameAccess 66 * @see ifc.container.XEnumerationAccess 67 * @see ifc.container.XElementAccess 68 * @see ifc.uno.XNamingService 69 */ 70 public class ODatabaseContext extends TestCase { 71 72 /** 73 * Does nothing. 74 */ 75 protected void initialize ( TestParameters Param, PrintWriter log) { 76 77 } 78 79 /** 80 * Creating a Testenvironment for the interfaces to be tested. 81 * Creates service <code>com.sun.star.sdb.DatabaseContext</code>. 82 * Needed object relations : 83 * <ul> 84 * <li> <code>'XNamingService.RegisterObject'</code> for 85 * {@link ifc.namingservice.XNamingService} as an 86 * instance of <code>com.sun.star.sdb.DataSource</code> 87 * service. </li> 88 * </ul> 89 */ 90 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 91 XInterface oObj = null; 92 Object oInterface = null; 93 XMultiServiceFactory xMSF = null ; 94 95 try { 96 xMSF = (XMultiServiceFactory)Param.getMSF(); 97 oInterface = xMSF.createInstance( "com.sun.star.sdb.DatabaseContext" ); 98 } 99 catch( com.sun.star.uno.Exception e ) { 100 log.println("Service not available" ); 101 throw new StatusException("Service not available", e) ; 102 } 103 104 if (oInterface == null) { 105 log.println("Service wasn't created") ; 106 throw new StatusException(Status.failed("Service wasn't created")) ; 107 } 108 109 oObj = (XInterface) oInterface; 110 111 log.println( " creating a new environment for object" ); 112 TestEnvironment tEnv = new TestEnvironment( oObj ); 113 114 // adding obj relation for XNamingService 115 try { 116 xMSF = (XMultiServiceFactory)Param.getMSF(); 117 oInterface = xMSF.createInstance( "com.sun.star.sdb.DataSource" ); 118 119 XPropertySet xDSProps = (XPropertySet) 120 UnoRuntime.queryInterface(XPropertySet.class, oInterface) ; 121 122 xDSProps.setPropertyValue("URL", "sdbc:dbase:file:///.") ; 123 124 XDocumentDataSource xDDS = (XDocumentDataSource) 125 UnoRuntime.queryInterface(XDocumentDataSource.class, oInterface); 126 XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, 127 xDDS.getDatabaseDocument ()); 128 String aFile = utils.getOfficeTemp ((XMultiServiceFactory) Param.getMSF ())+"DatabaseContext.odb"; 129 log.println("store to '" + aFile + "'"); 130 store.storeAsURL(aFile,new PropertyValue[]{}); 131 132 tEnv.addObjRelation("XNamingService.RegisterObject", oInterface) ; 133 134 tEnv.addObjRelation("INSTANCE", oInterface); 135 136 tEnv.addObjRelation("XContainer.Container", 137 (XNamingService) UnoRuntime.queryInterface( 138 XNamingService.class, oObj)); 139 140 } catch (com.sun.star.uno.Exception e) { 141 throw new StatusException("Can't create object relation", e) ; 142 } catch (NullPointerException e) { 143 throw new StatusException("Can't create object relation", e) ; 144 } 145 146 return tEnv; 147 } // finish method getTestEnvironment 148 149 } 150