1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sw; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import util.DBTools; 29cdf0e10cSrcweir import util.utils; 30cdf0e10cSrcweir import com.sun.star.beans.PropertyVetoException; 31cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException; 32cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 33cdf0e10cSrcweir import com.sun.star.container.NoSuchElementException; 34cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 35cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException; 36cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetException; 37cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 38cdf0e10cSrcweir import com.sun.star.sdb.CommandType; 39cdf0e10cSrcweir import com.sun.star.sdbc.*; 40cdf0e10cSrcweir import com.sun.star.sdbcx.XRowLocate; 41cdf0e10cSrcweir import com.sun.star.task.XJob; 42cdf0e10cSrcweir import com.sun.star.text.MailMergeType; 43cdf0e10cSrcweir import com.sun.star.uno.Exception; 44cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 45cdf0e10cSrcweir import com.sun.star.uno.XInterface; 46cdf0e10cSrcweir import java.io.PrintWriter; 47cdf0e10cSrcweir import lib.StatusException; 48cdf0e10cSrcweir import lib.TestCase; 49cdf0e10cSrcweir import lib.TestEnvironment; 50cdf0e10cSrcweir import lib.TestParameters; 51cdf0e10cSrcweir 52cdf0e10cSrcweir /** 53cdf0e10cSrcweir * Here <code>com.sun.star.text.MailMerge</code> service is tested.<p> 54cdf0e10cSrcweir * @see com.sun.star.text.MailMerge 55cdf0e10cSrcweir * @see com.sun.star.task.XJob 56cdf0e10cSrcweir * @see com.sun.star.text.XMailMergeBroadcaster 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir public class SwXMailMerge extends TestCase { 59cdf0e10cSrcweir 60cdf0e10cSrcweir public void initialize( TestParameters Param, PrintWriter log ) { 61cdf0e10cSrcweir if (! Param.containsKey("uniqueSuffix")){ 62cdf0e10cSrcweir Param.put("uniqueSuffix", new Integer(0)); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir /** 67cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. <p> 68cdf0e10cSrcweir * Creates <code>MailMerge</code> service * Object relations created : 69cdf0e10cSrcweir * <ul> 70cdf0e10cSrcweir * <li> <code>'executeArgs'</code> for 71cdf0e10cSrcweir * {@link ifc.text._XMailMergeBroadcaster} : NamedValue[]</li> 72cdf0e10cSrcweir * <li> <code>'Job'</code> for 73cdf0e10cSrcweir * {@link ifc.text._XMailMergeBroadcaster} : XJob</li> 74cdf0e10cSrcweir * <li> <code>'XJobArgs'</code> for 75cdf0e10cSrcweir * {@link ifc.task._XJob} : Object[]</li> 76cdf0e10cSrcweir * </ul> 77cdf0e10cSrcweir */ 78cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 79cdf0e10cSrcweir 80cdf0e10cSrcweir XInterface oObj = null; 81cdf0e10cSrcweir XInterface oRowSet = null; 82cdf0e10cSrcweir Object oConnection = null; 83cdf0e10cSrcweir XJob Job = null; 84cdf0e10cSrcweir 85cdf0e10cSrcweir log.println(" instantiate MailMerge service"); 86cdf0e10cSrcweir try { 87cdf0e10cSrcweir oObj = (XInterface) ( (XMultiServiceFactory) Param.getMSF()).createInstance 88cdf0e10cSrcweir ("com.sun.star.text.MailMerge"); 89cdf0e10cSrcweir } catch (Exception e) { 90cdf0e10cSrcweir throw new StatusException("Can't create object environment", e) ; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir // <set some variables> 94cdf0e10cSrcweir String cTestDoc = utils.getFullTestURL("MailMerge.sxw"); 95cdf0e10cSrcweir //cMailMerge_DocumentURL = cTestDoc 96cdf0e10cSrcweir String cOutputURL = utils.getOfficeTemp( (XMultiServiceFactory) Param.getMSF()); 97cdf0e10cSrcweir String cDataSourceName = "Bibliography"; 98cdf0e10cSrcweir String cDataCommand = "biblio"; 99cdf0e10cSrcweir Object[] sel = new Object[2]; 100cdf0e10cSrcweir sel[0] = new int[2]; 101cdf0e10cSrcweir sel[1] = new int[5]; 102cdf0e10cSrcweir Object[] myBookMarks = new Object[2]; 103cdf0e10cSrcweir // </set some variables> 104cdf0e10cSrcweir 105cdf0e10cSrcweir // <create XResultSet> 106cdf0e10cSrcweir log.println("create a XResultSet"); 107cdf0e10cSrcweir try { 108cdf0e10cSrcweir oRowSet = (XInterface) ( (XMultiServiceFactory) Param.getMSF()).createInstance 109cdf0e10cSrcweir ("com.sun.star.sdb.RowSet"); 110cdf0e10cSrcweir } catch (Exception e) { 111cdf0e10cSrcweir throw new StatusException("Can't create com.sun.star.sdb.RowSet", e); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir XPropertySet oRowSetProps = (XPropertySet) 114cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class, oRowSet); 115cdf0e10cSrcweir XRowSet xRowSet = (XRowSet) 116cdf0e10cSrcweir UnoRuntime.queryInterface(XRowSet.class, oRowSet); 117cdf0e10cSrcweir try { 118cdf0e10cSrcweir oRowSetProps.setPropertyValue("DataSourceName",cDataSourceName); 119cdf0e10cSrcweir oRowSetProps.setPropertyValue("Command",cDataCommand); 120cdf0e10cSrcweir oRowSetProps.setPropertyValue("CommandType", new Integer(CommandType.TABLE)); 121cdf0e10cSrcweir } catch (UnknownPropertyException e) { 122cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 123cdf0e10cSrcweir } catch (PropertyVetoException e) { 124cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 125cdf0e10cSrcweir } catch (IllegalArgumentException e) { 126cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 127cdf0e10cSrcweir } catch (WrappedTargetException e) { 128cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir try { 131cdf0e10cSrcweir xRowSet.execute(); 132cdf0e10cSrcweir } catch (SQLException e) { 133cdf0e10cSrcweir throw new StatusException("Can't execute oRowSet", e); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir XResultSet oResultSet = (XResultSet) 137cdf0e10cSrcweir UnoRuntime.queryInterface(XResultSet.class, oRowSet); 138cdf0e10cSrcweir 139cdf0e10cSrcweir 140cdf0e10cSrcweir 141cdf0e10cSrcweir 142cdf0e10cSrcweir // <create Bookmarks> 143cdf0e10cSrcweir log.println("create bookmarks"); 144cdf0e10cSrcweir try { 145cdf0e10cSrcweir XRowLocate oRowLocate = (XRowLocate) UnoRuntime.queryInterface( 146cdf0e10cSrcweir XRowLocate.class, oResultSet); 147cdf0e10cSrcweir oResultSet.first(); 148cdf0e10cSrcweir myBookMarks[0] = oRowLocate.getBookmark(); 149cdf0e10cSrcweir oResultSet.next(); 150cdf0e10cSrcweir myBookMarks[1] = oRowLocate.getBookmark(); 151cdf0e10cSrcweir } catch (SQLException e) { 152cdf0e10cSrcweir throw new StatusException("Cant get Bookmarks", e); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir // </create Bookmarks> 155cdf0e10cSrcweir 156cdf0e10cSrcweir // <fill object with values> 157cdf0e10cSrcweir 158cdf0e10cSrcweir log.println("fill MailMerge with default connection"); 159cdf0e10cSrcweir 160cdf0e10cSrcweir XPropertySet oObjProps = (XPropertySet) 161cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class, oObj); 162cdf0e10cSrcweir try { 163cdf0e10cSrcweir oObjProps.setPropertyValue("ActiveConnection", getLocalXConnection(Param)); 164cdf0e10cSrcweir oObjProps.setPropertyValue("DataSourceName", cDataSourceName); 165cdf0e10cSrcweir oObjProps.setPropertyValue("Command", cDataCommand); 166cdf0e10cSrcweir oObjProps.setPropertyValue("CommandType", new Integer(CommandType.TABLE)); 167cdf0e10cSrcweir oObjProps.setPropertyValue("OutputType", new Short(MailMergeType.FILE)); 168cdf0e10cSrcweir oObjProps.setPropertyValue("DocumentURL", cTestDoc); 169cdf0e10cSrcweir oObjProps.setPropertyValue("OutputURL", cOutputURL); 170cdf0e10cSrcweir oObjProps.setPropertyValue("FileNamePrefix", "Author"); 171cdf0e10cSrcweir oObjProps.setPropertyValue("FileNameFromColumn", new Boolean(false)); 172cdf0e10cSrcweir oObjProps.setPropertyValue("Selection", new Object[0]); 173cdf0e10cSrcweir 174cdf0e10cSrcweir } catch (UnknownPropertyException e) { 175cdf0e10cSrcweir throw new StatusException("Can't set properties on oObj", e); 176cdf0e10cSrcweir } catch (PropertyVetoException e) { 177cdf0e10cSrcweir throw new StatusException("Can't set properties on oObj", e); 178cdf0e10cSrcweir } catch (IllegalArgumentException e) { 179cdf0e10cSrcweir throw new StatusException("Can't set properties on oObj", e); 180cdf0e10cSrcweir } catch (WrappedTargetException e) { 181cdf0e10cSrcweir throw new StatusException("Can't set properties on oObj", e); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir // </fill object with values> 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir // <create object relations> 187cdf0e10cSrcweir Object[] vXJobArgs = new Object[4]; 188cdf0e10cSrcweir NamedValue[] vXJobArg0 = new NamedValue[8]; 189cdf0e10cSrcweir NamedValue[] vXJobArg1 = new NamedValue[7]; 190cdf0e10cSrcweir NamedValue[] vXJobArg2 = new NamedValue[10]; 191cdf0e10cSrcweir NamedValue[] vXJobArg3 = new NamedValue[0]; 192cdf0e10cSrcweir 193cdf0e10cSrcweir // first Arguments 194cdf0e10cSrcweir vXJobArg0[0] = new NamedValue("DataSourceName", cDataSourceName); 195cdf0e10cSrcweir vXJobArg0[1] = new NamedValue("Command", cDataCommand); 196cdf0e10cSrcweir vXJobArg0[2] = new NamedValue("CommandType",new Integer(CommandType.TABLE)); 197cdf0e10cSrcweir vXJobArg0[3] = new NamedValue("OutputType",new Short(MailMergeType.FILE)); 198cdf0e10cSrcweir vXJobArg0[4] = new NamedValue("DocumentURL", cTestDoc); 199cdf0e10cSrcweir vXJobArg0[5] = new NamedValue("OutputURL", cOutputURL); 200cdf0e10cSrcweir vXJobArg0[6] = new NamedValue("FileNamePrefix", "Identifier"); 201cdf0e10cSrcweir vXJobArg0[7] = new NamedValue("FileNameFromColumn", new Boolean(true)); 202cdf0e10cSrcweir 203cdf0e10cSrcweir //second Arguments 204cdf0e10cSrcweir vXJobArg1[0] = new NamedValue("DataSourceName", cDataSourceName); 205cdf0e10cSrcweir vXJobArg1[1] = new NamedValue("Command", cDataCommand); 206cdf0e10cSrcweir vXJobArg1[2] = new NamedValue("CommandType",new Integer(CommandType.TABLE)); 207cdf0e10cSrcweir vXJobArg1[3] = new NamedValue("OutputType", 208cdf0e10cSrcweir new Short(MailMergeType.PRINTER)); 209cdf0e10cSrcweir vXJobArg1[4] = new NamedValue("DocumentURL", cTestDoc); 210cdf0e10cSrcweir vXJobArg1[5] = new NamedValue("FileNamePrefix", "Author"); 211cdf0e10cSrcweir vXJobArg1[6] = new NamedValue("FileNameFromColumn", new Boolean(true)); 212cdf0e10cSrcweir 213cdf0e10cSrcweir // third Arguments 214cdf0e10cSrcweir vXJobArg2[0] = new NamedValue("ActiveConnection", getLocalXConnection(Param)); 215cdf0e10cSrcweir vXJobArg2[1] = new NamedValue("DataSourceName", cDataSourceName); 216cdf0e10cSrcweir vXJobArg2[2] = new NamedValue("Command", cDataCommand); 217cdf0e10cSrcweir vXJobArg2[3] = new NamedValue("CommandType",new Integer(CommandType.TABLE)); 218cdf0e10cSrcweir vXJobArg2[4] = new NamedValue("OutputType", 219cdf0e10cSrcweir new Short(MailMergeType.FILE)); 220cdf0e10cSrcweir vXJobArg2[5] = new NamedValue("ResultSet", oResultSet); 221cdf0e10cSrcweir vXJobArg2[6] = new NamedValue("OutputURL", cOutputURL); 222cdf0e10cSrcweir vXJobArg2[7] = new NamedValue("FileNamePrefix", "Identifier"); 223cdf0e10cSrcweir vXJobArg2[8] = new NamedValue("FileNameFromColumn", new Boolean(true)); 224cdf0e10cSrcweir vXJobArg2[9] = new NamedValue("Selection", myBookMarks); 225cdf0e10cSrcweir 226cdf0e10cSrcweir vXJobArgs[0] = vXJobArg0; 227cdf0e10cSrcweir vXJobArgs[1] = vXJobArg1; 228cdf0e10cSrcweir vXJobArgs[2] = vXJobArg2; 229cdf0e10cSrcweir vXJobArgs[3] = vXJobArg3; 230cdf0e10cSrcweir 231cdf0e10cSrcweir 232cdf0e10cSrcweir Job = (XJob) UnoRuntime.queryInterface(XJob.class, oObj); 233cdf0e10cSrcweir try{ 234cdf0e10cSrcweir Job.execute(vXJobArg2); 235cdf0e10cSrcweir } catch ( IllegalArgumentException e){ 236cdf0e10cSrcweir System.out.println(e.toString()); 237cdf0e10cSrcweir } catch ( Exception e){ 238cdf0e10cSrcweir System.out.println(e.toString()); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir 242cdf0e10cSrcweir // <create XResultSet> 243cdf0e10cSrcweir log.println("create XResultSet"); 244cdf0e10cSrcweir 245cdf0e10cSrcweir try { 246cdf0e10cSrcweir oRowSet = (XInterface) ( (XMultiServiceFactory) Param.getMSF()).createInstance 247cdf0e10cSrcweir ("com.sun.star.sdb.RowSet"); 248cdf0e10cSrcweir } catch (Exception e) { 249cdf0e10cSrcweir throw new StatusException("Can't create com.sun.star.sdb.RowSet", e); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir oRowSetProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRowSet); 252cdf0e10cSrcweir 253cdf0e10cSrcweir xRowSet = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, oRowSet); 254cdf0e10cSrcweir 255cdf0e10cSrcweir try { 256cdf0e10cSrcweir oRowSetProps.setPropertyValue("DataSourceName",cDataSourceName); 257cdf0e10cSrcweir oRowSetProps.setPropertyValue("Command",cDataCommand); 258cdf0e10cSrcweir oRowSetProps.setPropertyValue("CommandType", new Integer(CommandType.TABLE)); 259cdf0e10cSrcweir } catch (UnknownPropertyException e) { 260cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 261cdf0e10cSrcweir } catch (PropertyVetoException e) { 262cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 263cdf0e10cSrcweir } catch (IllegalArgumentException e) { 264cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 265cdf0e10cSrcweir } catch (WrappedTargetException e) { 266cdf0e10cSrcweir throw new StatusException("Can't set properties on oRowSet", e); 267cdf0e10cSrcweir } 268cdf0e10cSrcweir try { 269cdf0e10cSrcweir xRowSet.execute(); 270cdf0e10cSrcweir } catch (SQLException e) { 271cdf0e10cSrcweir throw new StatusException("Can't execute oRowSet", e); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir oResultSet = (XResultSet) 275cdf0e10cSrcweir UnoRuntime.queryInterface(XResultSet.class, oRowSet); 276cdf0e10cSrcweir 277cdf0e10cSrcweir XResultSet oMMXResultSet = null; 278cdf0e10cSrcweir try { 279cdf0e10cSrcweir oMMXResultSet = (XResultSet) 280cdf0e10cSrcweir UnoRuntime.queryInterface(XResultSet.class, 281cdf0e10cSrcweir ( (XInterface) 282cdf0e10cSrcweir ( (XMultiServiceFactory) 283cdf0e10cSrcweir Param.getMSF()).createInstance("com.sun.star.sdb.RowSet"))); 284cdf0e10cSrcweir 285cdf0e10cSrcweir } catch (Exception e) { 286cdf0e10cSrcweir throw new StatusException("Can't create com.sun.star.sdb.RowSet", e); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir // </create object relations> 289cdf0e10cSrcweir 290cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj) ; 291cdf0e10cSrcweir 292cdf0e10cSrcweir // <adding object relations> 293cdf0e10cSrcweir 294cdf0e10cSrcweir // com.sun.star.sdb.DataAccessDescriptor 295cdf0e10cSrcweir tEnv.addObjRelation("DataAccessDescriptor.XResultSet", oResultSet); 296cdf0e10cSrcweir tEnv.addObjRelation("DataAccessDescriptor.XConnection", getRemoteXConnection(Param)); 297cdf0e10cSrcweir 298cdf0e10cSrcweir // com.sun.star.text.MailMaerge 299cdf0e10cSrcweir tEnv.addObjRelation("MailMerge.XConnection", getRemoteXConnection(Param)); 300cdf0e10cSrcweir tEnv.addObjRelation("MailMerge.XResultSet", oMMXResultSet); 301cdf0e10cSrcweir 302cdf0e10cSrcweir // com.sun.star.text.XMailMergeBroadcaster 303cdf0e10cSrcweir tEnv.addObjRelation( "executeArgs", vXJobArg0); 304cdf0e10cSrcweir tEnv.addObjRelation( "Job", Job); 305cdf0e10cSrcweir 306cdf0e10cSrcweir // com.sun.star.task.XJob 307cdf0e10cSrcweir tEnv.addObjRelation("XJobArgs", vXJobArgs); 308cdf0e10cSrcweir 309cdf0e10cSrcweir // </adding object relations> 310cdf0e10cSrcweir 311cdf0e10cSrcweir return tEnv ; 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir private XConnection getRemoteXConnection(TestParameters Param){ 315cdf0e10cSrcweir 316cdf0e10cSrcweir log.println("create remote connection"); 317cdf0e10cSrcweir 318cdf0e10cSrcweir String databaseName = null ; 319cdf0e10cSrcweir XDataSource oXDataSource = null; 320cdf0e10cSrcweir Object oInterface = null; 321cdf0e10cSrcweir XMultiServiceFactory xMSF = null ; 322cdf0e10cSrcweir int uniqueSuffix = Param.getInt("uniqueSuffix"); 323cdf0e10cSrcweir 324cdf0e10cSrcweir try { 325cdf0e10cSrcweir xMSF = (XMultiServiceFactory)Param.getMSF(); 326cdf0e10cSrcweir oInterface = xMSF.createInstance( "com.sun.star.sdb.DatabaseContext" ); 327cdf0e10cSrcweir 328cdf0e10cSrcweir // retrieving temp directory for database 329cdf0e10cSrcweir String tmpDatabaseUrl = utils.getOfficeTempDir((XMultiServiceFactory)Param.getMSF()); 330cdf0e10cSrcweir 331cdf0e10cSrcweir databaseName = "NewDatabaseSource" + uniqueSuffix ; 332cdf0e10cSrcweir 333cdf0e10cSrcweir String tmpDatabaseFile = tmpDatabaseUrl + databaseName + ".odb"; 334cdf0e10cSrcweir System.out.println("try to delete '"+tmpDatabaseFile+"'"); 335cdf0e10cSrcweir utils.deleteFile(((XMultiServiceFactory) Param.getMSF()), tmpDatabaseFile); 336cdf0e10cSrcweir 337cdf0e10cSrcweir 338cdf0e10cSrcweir tmpDatabaseUrl = "sdbc:dbase:file:///" + tmpDatabaseUrl ; 339cdf0e10cSrcweir 340cdf0e10cSrcweir // Creating new DBase data source in the TEMP directory 341cdf0e10cSrcweir XInterface newSource = (XInterface) xMSF.createInstance 342cdf0e10cSrcweir ("com.sun.star.sdb.DataSource") ; 343cdf0e10cSrcweir 344cdf0e10cSrcweir XPropertySet xSrcProp = (XPropertySet) 345cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class, newSource); 346cdf0e10cSrcweir 347cdf0e10cSrcweir xSrcProp.setPropertyValue("URL", tmpDatabaseUrl) ; 348cdf0e10cSrcweir 349cdf0e10cSrcweir DBTools dbt = new DBTools( (XMultiServiceFactory)Param.getMSF(), log ); 350cdf0e10cSrcweir // registering source in DatabaseContext 351cdf0e10cSrcweir log.println("register database '"+tmpDatabaseUrl+"' as '"+databaseName+"'" ); 352cdf0e10cSrcweir dbt.reRegisterDB(databaseName, newSource) ; 353cdf0e10cSrcweir 354cdf0e10cSrcweir uniqueSuffix++; 355cdf0e10cSrcweir Param.put("uniqueSuffix", new Integer(uniqueSuffix)); 356cdf0e10cSrcweir 357cdf0e10cSrcweir return dbt.connectToSource(newSource); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir catch( Exception e ) { 360cdf0e10cSrcweir uniqueSuffix++; 361cdf0e10cSrcweir Param.put("uniqueSuffix", new Integer(uniqueSuffix)); 362cdf0e10cSrcweir log.println("could not register new database" ); 363cdf0e10cSrcweir e.printStackTrace(); 364cdf0e10cSrcweir throw new StatusException("could not register new database", e) ; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir private XConnection getLocalXConnection(TestParameters Param){ 369cdf0e10cSrcweir 370cdf0e10cSrcweir log.println("create local connection"); 371cdf0e10cSrcweir 372cdf0e10cSrcweir XInterface oDataCont = null; 373cdf0e10cSrcweir try { 374cdf0e10cSrcweir oDataCont = (XInterface)( (XMultiServiceFactory) Param.getMSF()).createInstance 375cdf0e10cSrcweir ("com.sun.star.sdb.DatabaseContext"); 376cdf0e10cSrcweir } catch(Exception e) { 377cdf0e10cSrcweir throw new StatusException("Couldn't create instance of 'com.sun.star.sdb.DatabaseContext'", e); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir XNameAccess xNADataCont = (XNameAccess) 380cdf0e10cSrcweir UnoRuntime.queryInterface(XNameAccess.class, oDataCont); 381cdf0e10cSrcweir 382cdf0e10cSrcweir String[] dataNames = xNADataCont.getElementNames(); 383cdf0e10cSrcweir 384cdf0e10cSrcweir String dataName=""; 385cdf0e10cSrcweir for (int i = 0; i < dataNames.length; i++){ 386cdf0e10cSrcweir if (dataNames[i].startsWith("Biblio")) dataName=dataNames[i]; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir try{ 390cdf0e10cSrcweir 391cdf0e10cSrcweir Object oDataBase = xNADataCont.getByName(dataName); 392cdf0e10cSrcweir XDataSource xDataSource = (XDataSource) 393cdf0e10cSrcweir UnoRuntime.queryInterface(XDataSource.class, oDataBase); 394cdf0e10cSrcweir 395cdf0e10cSrcweir return xDataSource.getConnection("",""); 396cdf0e10cSrcweir 397cdf0e10cSrcweir } catch ( NoSuchElementException e){ 398cdf0e10cSrcweir throw new StatusException("Couldn't get registered data base", e); 399cdf0e10cSrcweir } catch ( WrappedTargetException e){ 400cdf0e10cSrcweir throw new StatusException("Couldn't get registered data base", e); 401cdf0e10cSrcweir } catch ( SQLException e){ 402cdf0e10cSrcweir throw new StatusException("Couldn't get XConnection from registered data base", e); 403cdf0e10cSrcweir } 404cdf0e10cSrcweir 405cdf0e10cSrcweir } 406cdf0e10cSrcweir 407cdf0e10cSrcweir protected void cleanup(TestParameters Param, PrintWriter log) { 408cdf0e10cSrcweir log.println("closing connections..."); 409cdf0e10cSrcweir XMultiServiceFactory xMsf = (XMultiServiceFactory) Param.getMSF(); 410cdf0e10cSrcweir DBTools dbt = new DBTools( xMsf, log ); 411cdf0e10cSrcweir 412cdf0e10cSrcweir if (Param.containsKey("uniqueSuffix")){ 413cdf0e10cSrcweir int uniqueSuffix = Param.getInt("uniqueSuffix"); 414cdf0e10cSrcweir uniqueSuffix--; 415cdf0e10cSrcweir String databaseName = ""; 416cdf0e10cSrcweir while (uniqueSuffix >= 0){ 417cdf0e10cSrcweir 418cdf0e10cSrcweir databaseName = "NewDatabaseSource" + uniqueSuffix ; 419cdf0e10cSrcweir 420cdf0e10cSrcweir log.println("revoke '"+databaseName+"'"); 421cdf0e10cSrcweir 422cdf0e10cSrcweir try{ 423cdf0e10cSrcweir dbt.revokeDB(databaseName); 424cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e){ 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir uniqueSuffix--; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir 436