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