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 10cdf0e10cSrcweir * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package mod._forms; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.io.PrintWriter; 26cdf0e10cSrcweir import java.util.Vector; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.Status; 29cdf0e10cSrcweir import lib.StatusException; 30cdf0e10cSrcweir import lib.TestCase; 31cdf0e10cSrcweir import lib.TestEnvironment; 32cdf0e10cSrcweir import lib.TestParameters; 33cdf0e10cSrcweir import util.DBTools; 34cdf0e10cSrcweir import util.DrawTools; 35cdf0e10cSrcweir import util.FormTools; 36cdf0e10cSrcweir import util.WriterTools; 37cdf0e10cSrcweir import util.utils; 38cdf0e10cSrcweir 39cdf0e10cSrcweir import com.sun.star.awt.XControl; 40cdf0e10cSrcweir import com.sun.star.awt.XControlModel; 41cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 42cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 43cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 44cdf0e10cSrcweir import com.sun.star.container.XNameContainer; 45cdf0e10cSrcweir import com.sun.star.container.XNamed; 46cdf0e10cSrcweir import com.sun.star.drawing.XControlShape; 47cdf0e10cSrcweir import com.sun.star.drawing.XShape; 48cdf0e10cSrcweir import com.sun.star.drawing.XShapes; 49cdf0e10cSrcweir import com.sun.star.form.DatabaseParameterEvent; 50cdf0e10cSrcweir import com.sun.star.form.XForm; 51cdf0e10cSrcweir import com.sun.star.form.XLoadable; 52cdf0e10cSrcweir import com.sun.star.lang.EventObject; 53cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 54cdf0e10cSrcweir import com.sun.star.sdb.CommandType; 55cdf0e10cSrcweir import com.sun.star.sdb.ParametersRequest; 56cdf0e10cSrcweir import com.sun.star.sdb.RowChangeEvent; 57cdf0e10cSrcweir import com.sun.star.sdbc.SQLException; 58cdf0e10cSrcweir import com.sun.star.sdbc.XConnection; 59cdf0e10cSrcweir import com.sun.star.sdbc.XResultSet; 60cdf0e10cSrcweir import com.sun.star.sdbc.XResultSetUpdate; 61cdf0e10cSrcweir import com.sun.star.sdbc.XRow; 62cdf0e10cSrcweir import com.sun.star.sdbc.XRowSet; 63cdf0e10cSrcweir import com.sun.star.sdbc.XRowUpdate; 64cdf0e10cSrcweir import com.sun.star.task.XInteractionRequest; 65cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 66cdf0e10cSrcweir import com.sun.star.uno.Any; 67cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 68cdf0e10cSrcweir import com.sun.star.uno.Type; 69cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 70cdf0e10cSrcweir import com.sun.star.uno.XInterface; 71cdf0e10cSrcweir import com.sun.star.util.Date; 72cdf0e10cSrcweir import com.sun.star.util.DateTime; 73cdf0e10cSrcweir import com.sun.star.util.Time; 74cdf0e10cSrcweir import com.sun.star.util.XCloseable; 75cdf0e10cSrcweir import com.sun.star.view.XControlAccess; 76cdf0e10cSrcweir import ifc.form._XDatabaseParameterBroadcaster; 77cdf0e10cSrcweir import ifc.sdb._XCompletedExecution; 78cdf0e10cSrcweir 79cdf0e10cSrcweir 80cdf0e10cSrcweir /** 81cdf0e10cSrcweir * Test for object which is represented by service 82cdf0e10cSrcweir * <code>com.sun.star.form.component.DatabaseForm</code>. <p> 83cdf0e10cSrcweir * 84cdf0e10cSrcweir * Object implements the following interfaces : 85cdf0e10cSrcweir * <ul> 86cdf0e10cSrcweir * <li> <code>com::sun::star::script::XEventAttacherManager</code></li> 87cdf0e10cSrcweir * <li> <code>com::sun::star::container::XElementAccess</code></li> 88cdf0e10cSrcweir * <li> <code>com::sun::star::sdbcx::ResultSet</code></li> 89cdf0e10cSrcweir * <li> <code>com::sun::star::container::XChild</code></li> 90cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li> 91cdf0e10cSrcweir * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li> 92cdf0e10cSrcweir * <li> <code>com::sun::star::form::FormComponent</code></li> 93cdf0e10cSrcweir * <li> <code>com::sun::star::form::component::DataForm</code></li> 94cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li> 95cdf0e10cSrcweir * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 96cdf0e10cSrcweir * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li> 97cdf0e10cSrcweir * <li> <code>com::sun::star::sdb::RowSet</code></li> 98cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 99cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XRowSet</code></li> 100cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li> 101cdf0e10cSrcweir * <li> <code>com::sun::star::form::XLoadable</code></li> 102cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNamed</code></li> 103cdf0e10cSrcweir * <li> <code>com::sun::star::container::XIndexReplace</code></li> 104cdf0e10cSrcweir * <li> <code>com::sun::star::io::XPersistObject</code></li> 105cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNameReplace</code></li> 106cdf0e10cSrcweir * <li> <code>com::sun::star::container::XIndexContainer</code></li> 107cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNameAccess</code></li> 108cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XParameters</code></li> 109cdf0e10cSrcweir * <li> <code>com::sun::star::util::XCancellable</code></li> 110cdf0e10cSrcweir * <li> <code>com::sun::star::form::XReset</code></li> 111cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XCloseable</code></li> 112cdf0e10cSrcweir * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li> 113cdf0e10cSrcweir * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li> 114cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::ResultSet</code></li> 115cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XResultSet</code></li> 116cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XRow</code></li> 117cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li> 118cdf0e10cSrcweir * <li> <code>com::sun::star::awt::XTabControllerModel</code></li> 119cdf0e10cSrcweir * <li> <code>com::sun::star::container::XIndexAccess</code></li> 120cdf0e10cSrcweir * <li> <code>com::sun::star::form::XSubmit</code></li> 121cdf0e10cSrcweir * <li> <code>com::sun::star::form::component::HTMLForm</code></li> 122cdf0e10cSrcweir * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li> 123cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li> 124cdf0e10cSrcweir * <li> <code>com::sun::star::container::XNameContainer</code></li> 125cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 126cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 127cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 128cdf0e10cSrcweir * <li> <code>com::sun::star::sdbc::RowSet</code></li> 129cdf0e10cSrcweir * </ul> <p> 130cdf0e10cSrcweir * 131cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 132cdf0e10cSrcweir * threads concurently. 133cdf0e10cSrcweir * The following parameters in ini-file used by this test: 134cdf0e10cSrcweir * <ul> 135cdf0e10cSrcweir * <li><code>test.db.url</code> - URL to MySQL database. 136cdf0e10cSrcweir * For example: <code>mysql://mercury:3306/api_current</code></li> 137cdf0e10cSrcweir * <li><code>test.db.user</code> - user for MySQL database</li> 138cdf0e10cSrcweir * <li><code>test.db.password</code> - password for MySQL database</li> 139cdf0e10cSrcweir * </ul><p> 140cdf0e10cSrcweir * 141cdf0e10cSrcweir * @see com.sun.star.script.XEventAttacherManager 142cdf0e10cSrcweir * @see com.sun.star.container.XElementAccess 143cdf0e10cSrcweir * @see com.sun.star.sdbcx.ResultSet 144cdf0e10cSrcweir * @see com.sun.star.container.XChild 145cdf0e10cSrcweir * @see com.sun.star.sdbc.XResultSetUpdate 146cdf0e10cSrcweir * @see com.sun.star.sdb.XResultSetAccess 147cdf0e10cSrcweir * @see com.sun.star.form.FormComponent 148cdf0e10cSrcweir * @see com.sun.star.form.component.DataForm 149cdf0e10cSrcweir * @see com.sun.star.sdbc.XResultSetMetaDataSupplier 150cdf0e10cSrcweir * @see com.sun.star.container.XEnumerationAccess 151cdf0e10cSrcweir * @see com.sun.star.sdbcx.XDeleteRows 152cdf0e10cSrcweir * @see com.sun.star.sdb.RowSet 153cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 154cdf0e10cSrcweir * @see com.sun.star.sdbc.XRowSet 155cdf0e10cSrcweir * @see com.sun.star.sdbc.XRowUpdate 156cdf0e10cSrcweir * @see com.sun.star.form.XLoadable 157cdf0e10cSrcweir * @see com.sun.star.container.XNamed 158cdf0e10cSrcweir * @see com.sun.star.container.XIndexReplace 159cdf0e10cSrcweir * @see com.sun.star.io.XPersistObject 160cdf0e10cSrcweir * @see com.sun.star.container.XNameReplace 161cdf0e10cSrcweir * @see com.sun.star.container.XIndexContainer 162cdf0e10cSrcweir * @see com.sun.star.container.XNameAccess 163cdf0e10cSrcweir * @see com.sun.star.sdbc.XParameters 164cdf0e10cSrcweir * @see com.sun.star.util.XCancellable 165cdf0e10cSrcweir * @see com.sun.star.form.XReset 166cdf0e10cSrcweir * @see com.sun.star.sdbc.XCloseable 167cdf0e10cSrcweir * @see com.sun.star.sdbcx.XColumnsSupplier 168cdf0e10cSrcweir * @see com.sun.star.sdb.XRowSetApproveBroadcaster 169cdf0e10cSrcweir * @see com.sun.star.sdbc.ResultSet 170cdf0e10cSrcweir * @see com.sun.star.sdbc.XResultSet 171cdf0e10cSrcweir * @see com.sun.star.sdbc.XRow 172cdf0e10cSrcweir * @see com.sun.star.sdbc.XColumnLocate 173cdf0e10cSrcweir * @see com.sun.star.awt.XTabControllerModel 174cdf0e10cSrcweir * @see com.sun.star.container.XIndexAccess 175cdf0e10cSrcweir * @see com.sun.star.form.XSubmit 176cdf0e10cSrcweir * @see com.sun.star.form.component.HTMLForm 177cdf0e10cSrcweir * @see com.sun.star.sdbcx.XRowLocate 178cdf0e10cSrcweir * @see com.sun.star.sdbc.XWarningsSupplier 179cdf0e10cSrcweir * @see com.sun.star.container.XNameContainer 180cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 181cdf0e10cSrcweir * @see com.sun.star.sdbc.RowSet 182cdf0e10cSrcweir * @see ifc.script._XEventAttacherManager 183cdf0e10cSrcweir * @see ifc.container._XElementAccess 184cdf0e10cSrcweir * @see ifc.sdbcx._ResultSet 185cdf0e10cSrcweir * @see ifc.container._XChild 186cdf0e10cSrcweir * @see ifc.sdbc._XResultSetUpdate 187cdf0e10cSrcweir * @see ifc.sdb._XResultSetAccess 188cdf0e10cSrcweir * @see ifc.form._FormComponent 189cdf0e10cSrcweir * @see ifc.form.component._DataForm 190cdf0e10cSrcweir * @see ifc.sdbc._XResultSetMetaDataSupplier 191cdf0e10cSrcweir * @see ifc.container._XEnumerationAccess 192cdf0e10cSrcweir * @see ifc.sdbcx._XDeleteRows 193cdf0e10cSrcweir * @see ifc.sdb._RowSet 194cdf0e10cSrcweir * @see ifc.lang._XComponent 195cdf0e10cSrcweir * @see ifc.sdbc._XRowSet 196cdf0e10cSrcweir * @see ifc.sdbc._XRowUpdate 197cdf0e10cSrcweir * @see ifc.form._XLoadable 198cdf0e10cSrcweir * @see ifc.container._XNamed 199cdf0e10cSrcweir * @see ifc.container._XIndexReplace 200cdf0e10cSrcweir * @see ifc.io._XPersistObject 201cdf0e10cSrcweir * @see ifc.container._XNameReplace 202cdf0e10cSrcweir * @see ifc.container._XIndexContainer 203cdf0e10cSrcweir * @see ifc.container._XNameAccess 204cdf0e10cSrcweir * @see ifc.sdbc._XParameters 205cdf0e10cSrcweir * @see ifc.util._XCancellable 206cdf0e10cSrcweir * @see ifc.form._XReset 207cdf0e10cSrcweir * @see ifc.sdbc._XCloseable 208cdf0e10cSrcweir * @see ifc.sdbcx._XColumnsSupplier 209cdf0e10cSrcweir * @see ifc.sdb._XRowSetApproveBroadcaster 210cdf0e10cSrcweir * @see ifc.sdbc._ResultSet 211cdf0e10cSrcweir * @see ifc.sdbc._XResultSet 212cdf0e10cSrcweir * @see ifc.sdbc._XRow 213cdf0e10cSrcweir * @see ifc.sdbc._XColumnLocate 214cdf0e10cSrcweir * @see ifc.awt._XTabControllerModel 215cdf0e10cSrcweir * @see ifc.container._XIndexAccess 216cdf0e10cSrcweir * @see ifc.form._XSubmit 217cdf0e10cSrcweir * @see ifc.form.component._HTMLForm 218cdf0e10cSrcweir * @see ifc.sdbcx._XRowLocate 219cdf0e10cSrcweir * @see ifc.sdbc._XWarningsSupplier 220cdf0e10cSrcweir * @see ifc.container._XNameContainer 221cdf0e10cSrcweir * @see ifc.beans._XPropertyAccess 222cdf0e10cSrcweir * @see ifc.beans._XPropertyContainer 223cdf0e10cSrcweir * @see ifc.beans._XPropertySet 224cdf0e10cSrcweir * @see ifc.sdbc._RowSet 225cdf0e10cSrcweir */ 226cdf0e10cSrcweir public class ODatabaseForm extends TestCase { 227cdf0e10cSrcweir protected final static String dbSourceName = "ODatabaseFormDataSource"; 228cdf0e10cSrcweir private static int uniqueSuffix = 0; 229cdf0e10cSrcweir private static String origDB = null; 230cdf0e10cSrcweir private static String tmpDir = null; 231cdf0e10cSrcweir protected XTextDocument xTextDoc = null; 232cdf0e10cSrcweir private DBTools dbTools = null; 233cdf0e10cSrcweir String tableName = null; 234cdf0e10cSrcweir DBTools.DataSourceInfo srcInf = null; 235cdf0e10cSrcweir boolean isMySQLDB = false; 236cdf0e10cSrcweir protected XConnection conn = null; 237cdf0e10cSrcweir private Object dbSrc = null; 238cdf0e10cSrcweir initialize(TestParameters tParam, PrintWriter log)239cdf0e10cSrcweir protected void initialize(TestParameters tParam, PrintWriter log) { 240cdf0e10cSrcweir //log.println( "creating a draw document" ); 241cdf0e10cSrcweir //xTextDoc = WriterTools.createTextDoc(t((XMultiServiceFactory) Param.getMSF)); 242cdf0e10cSrcweir tmpDir = utils.getOfficeTemp(((XMultiServiceFactory) tParam.getMSF())); 243cdf0e10cSrcweir 244cdf0e10cSrcweir origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf"); 245cdf0e10cSrcweir 246cdf0e10cSrcweir dbTools = new DBTools( (XMultiServiceFactory)tParam.getMSF(), log ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir // creating DataSource and registering it in DatabaseContext 249cdf0e10cSrcweir String dbURL = (String) tParam.get("test.db.url"); 250cdf0e10cSrcweir String dbUser = (String) tParam.get("test.db.user"); 251cdf0e10cSrcweir String dbPassword = (String) tParam.get("test.db.password"); 252cdf0e10cSrcweir 253cdf0e10cSrcweir log.println("Creating and registering DataSource ..."); 254cdf0e10cSrcweir srcInf = dbTools.newDataSourceInfo(); 255cdf0e10cSrcweir 256cdf0e10cSrcweir if ((dbURL != null) && (dbUser != null) && (dbPassword != null)) { 257cdf0e10cSrcweir isMySQLDB = true; 258cdf0e10cSrcweir log.println("dbURL = " + dbURL); 259cdf0e10cSrcweir log.println("dbUSER = " + dbUser); 260cdf0e10cSrcweir log.println("dbPASSWORD = " + dbPassword); 261cdf0e10cSrcweir 262cdf0e10cSrcweir //DataSource for mysql db 263cdf0e10cSrcweir try { 264cdf0e10cSrcweir tableName = "soffice_test_table"; 265cdf0e10cSrcweir srcInf.URL = "jdbc:" + dbURL; 266cdf0e10cSrcweir srcInf.IsPasswordRequired = new Boolean(true); 267cdf0e10cSrcweir srcInf.Password = dbPassword; 268cdf0e10cSrcweir srcInf.User = dbUser; 269cdf0e10cSrcweir 270cdf0e10cSrcweir PropertyValue[] propInfo = new PropertyValue[1]; 271cdf0e10cSrcweir propInfo[0] = new PropertyValue(); 272cdf0e10cSrcweir propInfo[0].Name = "JavaDriverClass"; 273cdf0e10cSrcweir // propInfo[0].Value = "org.gjt.mm.mysql.Driver"; 274cdf0e10cSrcweir propInfo[0].Value = "util.dddriver.Driver"; 275cdf0e10cSrcweir srcInf.Info = propInfo; 276cdf0e10cSrcweir 277cdf0e10cSrcweir dbSrc = srcInf.getDataSourceService(); 278cdf0e10cSrcweir dbTools.reRegisterDB(dbSourceName, dbSrc); 279cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 280cdf0e10cSrcweir log.println("Error while object test initialization :"); 281cdf0e10cSrcweir e.printStackTrace(log); 282cdf0e10cSrcweir throw new StatusException("Error while object test" + 283cdf0e10cSrcweir " initialization", e); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir } else { 286cdf0e10cSrcweir //DataSource for sdbc db 287cdf0e10cSrcweir try { 288cdf0e10cSrcweir String myDbUrl = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir); 289cdf0e10cSrcweir srcInf.URL = myDbUrl; 290cdf0e10cSrcweir 291cdf0e10cSrcweir log.println("try to register '"+myDbUrl+"' as '"+dbSourceName+"'"); 292cdf0e10cSrcweir 293cdf0e10cSrcweir dbSrc = srcInf.getDataSourceService(); 294cdf0e10cSrcweir dbTools.reRegisterDB(dbSourceName, dbSrc); 295cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 296cdf0e10cSrcweir log.println("Error while object test initialization :"); 297cdf0e10cSrcweir e.printStackTrace(log); 298cdf0e10cSrcweir throw new StatusException( 299cdf0e10cSrcweir "Error while object test initialization", e); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir String oldF = null; 303cdf0e10cSrcweir String newF = null; 304cdf0e10cSrcweir 305cdf0e10cSrcweir do { 306cdf0e10cSrcweir tableName = "ODatabaseForm_tmp" + uniqueSuffix; 307cdf0e10cSrcweir oldF = utils.getFullURL(origDB); 308cdf0e10cSrcweir newF = utils.getOfficeTemp((XMultiServiceFactory) tParam.getMSF()) + tableName + 309cdf0e10cSrcweir ".dbf"; 310cdf0e10cSrcweir } while (!utils.tryOverwriteFile(((XMultiServiceFactory) tParam.getMSF()), oldF, newF) && 311cdf0e10cSrcweir (uniqueSuffix++ < 50)); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir /** 316cdf0e10cSrcweir * * creating a Testenvironment for the interfaces to be tested 317cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)318cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 319cdf0e10cSrcweir PrintWriter log) { 320cdf0e10cSrcweir if (xTextDoc != null) { 321cdf0e10cSrcweir try { 322cdf0e10cSrcweir XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 323cdf0e10cSrcweir XCloseable.class, xTextDoc); 324cdf0e10cSrcweir closer.close(true); 325cdf0e10cSrcweir } catch (com.sun.star.util.CloseVetoException e) { 326cdf0e10cSrcweir log.println("couldn't close document"); 327cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 328cdf0e10cSrcweir log.println("couldn't close document"); 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir log.println("Existing document disposed"); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir 334cdf0e10cSrcweir log.println("creating a text document"); 335cdf0e10cSrcweir xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) Param.getMSF())); 336cdf0e10cSrcweir 337cdf0e10cSrcweir //initialize test table 338cdf0e10cSrcweir if (isMySQLDB) { 339cdf0e10cSrcweir try { 340cdf0e10cSrcweir dbTools.initTestTableUsingJDBC(tableName, srcInf); 341cdf0e10cSrcweir } catch (java.sql.SQLException e) { 342cdf0e10cSrcweir e.printStackTrace(log); 343cdf0e10cSrcweir throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException...")); 344cdf0e10cSrcweir } catch (java.lang.ClassNotFoundException e) { 345cdf0e10cSrcweir throw new StatusException(Status.failed("Couldn't " + "register mysql driver")); 346cdf0e10cSrcweir } 347cdf0e10cSrcweir } 348cdf0e10cSrcweir 349cdf0e10cSrcweir XInterface oObj = null; 350cdf0e10cSrcweir XShapes oShapes = null; 351cdf0e10cSrcweir XInterface oInstance = null; 352cdf0e10cSrcweir XConnection connection = null; 353cdf0e10cSrcweir 354cdf0e10cSrcweir 355cdf0e10cSrcweir // creation of testobject here 356cdf0e10cSrcweir // first we write what we are intend to do to log file 357cdf0e10cSrcweir log.println("creating a test environment"); 358cdf0e10cSrcweir 359cdf0e10cSrcweir XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage( 360cdf0e10cSrcweir xTextDoc)); 361cdf0e10cSrcweir 362cdf0e10cSrcweir try { 363cdf0e10cSrcweir String[] formNames = forms.getElementNames(); 364cdf0e10cSrcweir 365cdf0e10cSrcweir for (int i = 0; i < formNames.length; i++) { 366cdf0e10cSrcweir log.println("Removing form '" + formNames[i] + "' ..."); 367cdf0e10cSrcweir forms.removeByName(formNames[i]); 368cdf0e10cSrcweir } 369cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 370cdf0e10cSrcweir e.printStackTrace(log); 371cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 372cdf0e10cSrcweir e.printStackTrace(log); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir String[] formNames = forms.getElementNames(); 376cdf0e10cSrcweir FormTools.insertForm(xTextDoc, forms, "MyForm"); 377cdf0e10cSrcweir formNames = forms.getElementNames(); 378cdf0e10cSrcweir 379cdf0e10cSrcweir XLoadable formLoader = null; 380cdf0e10cSrcweir 381cdf0e10cSrcweir try { 382cdf0e10cSrcweir formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName, 383cdf0e10cSrcweir tableName); 384cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 385cdf0e10cSrcweir log.println("Cann't bind the form to source '" + dbSourceName + 386cdf0e10cSrcweir "', table '" + tableName + "' :"); 387cdf0e10cSrcweir e.printStackTrace(log); 388cdf0e10cSrcweir throw new StatusException("Cann't bind a form", e); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir 392cdf0e10cSrcweir // DEBUG 393cdf0e10cSrcweir log.println("Forms before adding controls : "); 394cdf0e10cSrcweir formNames = forms.getElementNames(); 395cdf0e10cSrcweir 396cdf0e10cSrcweir for (int i = 0; i < formNames.length; i++) { 397cdf0e10cSrcweir log.println(" '" + formNames[i] + "'"); 398cdf0e10cSrcweir } 399cdf0e10cSrcweir 400cdf0e10cSrcweir XControlShape shape1 = null; 401cdf0e10cSrcweir XControlShape shape2 = null; 402cdf0e10cSrcweir 403cdf0e10cSrcweir try { 404cdf0e10cSrcweir 405cdf0e10cSrcweir log.println("Elements in the 'MyForm' :"); 406cdf0e10cSrcweir 407cdf0e10cSrcweir XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface( 408cdf0e10cSrcweir XIndexAccess.class, 409cdf0e10cSrcweir forms.getByName("MyForm")); 410cdf0e10cSrcweir 411cdf0e10cSrcweir for (int i = 0; i < formElements1.getCount(); i++) { 412cdf0e10cSrcweir XNamed elemName = (XNamed) UnoRuntime.queryInterface( 413cdf0e10cSrcweir XNamed.class, 414cdf0e10cSrcweir formElements1.getByIndex(i)); 415cdf0e10cSrcweir log.println(" '" + elemName.getName() + "'"); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir 418cdf0e10cSrcweir 419cdf0e10cSrcweir // END DEBUG 420cdf0e10cSrcweir //put something on the drawpage 421cdf0e10cSrcweir log.println("inserting some ControlShapes"); 422cdf0e10cSrcweir oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc)); 423cdf0e10cSrcweir shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 424cdf0e10cSrcweir 1000, "CommandButton"); 425cdf0e10cSrcweir shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500, 426cdf0e10cSrcweir 5000, "TextField"); 427cdf0e10cSrcweir 428cdf0e10cSrcweir XControlShape shape3 = FormTools.createControlShape(xTextDoc, 2000, 429cdf0e10cSrcweir 1500, 1000, 430cdf0e10cSrcweir 1000, 431cdf0e10cSrcweir "CheckBox"); 432cdf0e10cSrcweir oShapes.add((XShape) shape1); 433cdf0e10cSrcweir oShapes.add((XShape) shape2); 434cdf0e10cSrcweir oShapes.add(shape3); 435cdf0e10cSrcweir } catch (Exception e) { 436cdf0e10cSrcweir e.printStackTrace(log); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir log.println("Forms after adding controls : "); 440cdf0e10cSrcweir formNames = forms.getElementNames(); 441cdf0e10cSrcweir 442cdf0e10cSrcweir for (int i = 0; i < formNames.length; i++) { 443cdf0e10cSrcweir log.println(" '" + formNames[i] + "'"); 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir try { 447cdf0e10cSrcweir log.println("Elements in the 'MyForm' :"); 448cdf0e10cSrcweir 449cdf0e10cSrcweir XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface( 450cdf0e10cSrcweir XIndexAccess.class, 451cdf0e10cSrcweir forms.getByName("MyForm")); 452cdf0e10cSrcweir 453cdf0e10cSrcweir for (int i = 0; i < formElements1.getCount(); i++) { 454cdf0e10cSrcweir XNamed elemName = (XNamed) UnoRuntime.queryInterface( 455cdf0e10cSrcweir XNamed.class, 456cdf0e10cSrcweir formElements1.getByIndex(i)); 457cdf0e10cSrcweir log.println(" '" + elemName.getName() + "'"); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir } catch (Exception e) { 460cdf0e10cSrcweir e.printStackTrace(log); 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir formLoader.load(); 464cdf0e10cSrcweir 465cdf0e10cSrcweir try { 466cdf0e10cSrcweir oObj = (XForm) AnyConverter.toObject(new Type(XForm.class), 467cdf0e10cSrcweir (FormTools.getForms( 468cdf0e10cSrcweir WriterTools.getDrawPage( 469cdf0e10cSrcweir xTextDoc))) 470cdf0e10cSrcweir .getByName("MyForm")); 471cdf0e10cSrcweir 472cdf0e10cSrcweir XPropertySet xSetProp = (XPropertySet) UnoRuntime.queryInterface( 473cdf0e10cSrcweir XPropertySet.class, oObj); 474cdf0e10cSrcweir connection = (XConnection) AnyConverter.toObject( 475cdf0e10cSrcweir new Type(XConnection.class), 476cdf0e10cSrcweir xSetProp.getPropertyValue("ActiveConnection")); 477cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 478cdf0e10cSrcweir log.println("Couldn't get Form"); 479cdf0e10cSrcweir e.printStackTrace(log); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir 483cdf0e10cSrcweir // get a control 484cdf0e10cSrcweir oInstance = FormTools.createControl(xTextDoc, "TextField"); 485cdf0e10cSrcweir 486cdf0e10cSrcweir log.println("creating a new environment for drawpage object"); 487cdf0e10cSrcweir 488cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 489cdf0e10cSrcweir 490cdf0e10cSrcweir 491cdf0e10cSrcweir // adding relation for closing connection while environment disposing. 492cdf0e10cSrcweir this.conn = connection; 493cdf0e10cSrcweir 494cdf0e10cSrcweir // adding relation for XSubmit 495cdf0e10cSrcweir XControlModel the_Model = shape2.getControl(); 496cdf0e10cSrcweir XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 497cdf0e10cSrcweir XControlAccess.class, 498cdf0e10cSrcweir xTextDoc.getCurrentController()); 499cdf0e10cSrcweir XControl cntrl = null; 500cdf0e10cSrcweir 501cdf0e10cSrcweir //now get the OEditControl 502cdf0e10cSrcweir try { 503cdf0e10cSrcweir cntrl = the_access.getControl(the_Model); 504cdf0e10cSrcweir log.println(cntrl.getClass().getName()); 505cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 506cdf0e10cSrcweir log.println("Couldn't get OEditControl"); 507cdf0e10cSrcweir e.printStackTrace(log); 508cdf0e10cSrcweir throw new StatusException("Couldn't get OEditControl", e); 509cdf0e10cSrcweir } 510cdf0e10cSrcweir 511cdf0e10cSrcweir XResultSet the_set = (XResultSet) UnoRuntime.queryInterface( 512cdf0e10cSrcweir XResultSet.class, oObj); 513cdf0e10cSrcweir 514cdf0e10cSrcweir try { 515cdf0e10cSrcweir the_set.first(); 516cdf0e10cSrcweir } catch (SQLException e) { 517cdf0e10cSrcweir log.println("Cann't move cursor to the first row."); 518cdf0e10cSrcweir e.printStackTrace(); 519cdf0e10cSrcweir throw new StatusException("Can't move cursor to the first row.", e); 520cdf0e10cSrcweir } 521cdf0e10cSrcweir 522cdf0e10cSrcweir tEnv.addObjRelation("Model1", shape1.getControl()); 523cdf0e10cSrcweir tEnv.addObjRelation("Model2", shape2.getControl()); 524cdf0e10cSrcweir 525cdf0e10cSrcweir 526cdf0e10cSrcweir // adding an object for XNameReplace testing 527cdf0e10cSrcweir log.println("adding oInstace as obj relation to environment"); 528cdf0e10cSrcweir tEnv.addObjRelation("INSTANCE", oInstance); 529cdf0e10cSrcweir 530cdf0e10cSrcweir 531cdf0e10cSrcweir // INDEX : _XNameContainer 532cdf0e10cSrcweir log.println("adding INDEX as obj relation to environment"); 533cdf0e10cSrcweir tEnv.addObjRelation("INDEX", "0"); 534cdf0e10cSrcweir 535cdf0e10cSrcweir 536cdf0e10cSrcweir // INDEX : _XNameReplace 537cdf0e10cSrcweir log.println("adding NameReplaceIndex as obj relation to environment"); 538cdf0e10cSrcweir tEnv.addObjRelation("XNameReplaceINDEX", "2"); 539cdf0e10cSrcweir 540cdf0e10cSrcweir 541cdf0e10cSrcweir // INSTANCEn : _XNameContainer; _XNameReplace 542cdf0e10cSrcweir log.println("adding INSTANCEn as obj relation to environment"); 543cdf0e10cSrcweir 544cdf0e10cSrcweir //XComponent xComp = (XComponent) 545cdf0e10cSrcweir // UnoRuntime.queryInterface(XComponent.class, xDrawDoc); 546cdf0e10cSrcweir String tc = (String) Param.get("THRCNT"); 547cdf0e10cSrcweir int THRCNT = 1; 548cdf0e10cSrcweir 549cdf0e10cSrcweir if (tc != null) { 550cdf0e10cSrcweir THRCNT = Integer.parseInt(tc); 551cdf0e10cSrcweir } 552cdf0e10cSrcweir 553cdf0e10cSrcweir for (int n = 1; n < (2 * (THRCNT + 1)); n++) { 554cdf0e10cSrcweir log.println("adding INSTANCE" + n + 555cdf0e10cSrcweir " as obj relation to environment"); 556cdf0e10cSrcweir tEnv.addObjRelation("INSTANCE" + n, 557cdf0e10cSrcweir FormTools.createControl(xTextDoc, "CheckBox")); 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir 561cdf0e10cSrcweir // adding relation for XNameContainer 562cdf0e10cSrcweir tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object()); 563cdf0e10cSrcweir 564cdf0e10cSrcweir 565cdf0e10cSrcweir // adding relation for XPersistObject 566cdf0e10cSrcweir tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form"); 567cdf0e10cSrcweir 568cdf0e10cSrcweir if (the_set != null) { 569cdf0e10cSrcweir log.println("The Form has a not empty ResultSet"); 570cdf0e10cSrcweir } 571cdf0e10cSrcweir 572cdf0e10cSrcweir // Adding obj relation for XRowSetApproveBroadcaster test 573cdf0e10cSrcweir final XResultSet xResSet = (XResultSet) UnoRuntime.queryInterface( 574cdf0e10cSrcweir XResultSet.class, oObj); 575cdf0e10cSrcweir final XResultSetUpdate xResSetUpdate = (XResultSetUpdate) UnoRuntime.queryInterface( 576cdf0e10cSrcweir XResultSetUpdate.class, 577cdf0e10cSrcweir oObj); 578cdf0e10cSrcweir final XRowSet xRowSet = (XRowSet) UnoRuntime.queryInterface( 579cdf0e10cSrcweir XRowSet.class, oObj); 580cdf0e10cSrcweir final PrintWriter logF = log; 581cdf0e10cSrcweir tEnv.addObjRelation("XRowSetApproveBroadcaster.ApproveChecker", 582cdf0e10cSrcweir new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() { 583cdf0e10cSrcweir public void moveCursor() { 584cdf0e10cSrcweir try { 585cdf0e10cSrcweir xResSet.beforeFirst(); 586cdf0e10cSrcweir xResSet.afterLast(); 587cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e) { 588cdf0e10cSrcweir logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :"); 589cdf0e10cSrcweir e.printStackTrace(logF); 590cdf0e10cSrcweir } 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir public RowChangeEvent changeRow() { 594cdf0e10cSrcweir try { 595cdf0e10cSrcweir xResSet.first(); 596cdf0e10cSrcweir 597cdf0e10cSrcweir XRowUpdate row = (XRowUpdate) UnoRuntime.queryInterface( 598cdf0e10cSrcweir XRowUpdate.class, xResSet); 599cdf0e10cSrcweir row.updateString(1, "1"); 600cdf0e10cSrcweir xResSetUpdate.updateRow(); 601cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e) { 602cdf0e10cSrcweir logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :"); 603cdf0e10cSrcweir e.printStackTrace(logF); 604cdf0e10cSrcweir } 605cdf0e10cSrcweir 606cdf0e10cSrcweir RowChangeEvent ev = new RowChangeEvent(); 607cdf0e10cSrcweir ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE; 608cdf0e10cSrcweir ev.Rows = 1; 609cdf0e10cSrcweir 610cdf0e10cSrcweir return ev; 611cdf0e10cSrcweir } 612cdf0e10cSrcweir 613cdf0e10cSrcweir public void changeRowSet() { 614cdf0e10cSrcweir try { 615cdf0e10cSrcweir xRowSet.execute(); 616cdf0e10cSrcweir } catch (com.sun.star.sdbc.SQLException e) { 617cdf0e10cSrcweir logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :"); 618cdf0e10cSrcweir e.printStackTrace(logF); 619cdf0e10cSrcweir } 620cdf0e10cSrcweir } 621cdf0e10cSrcweir }); 622cdf0e10cSrcweir 623cdf0e10cSrcweir 624cdf0e10cSrcweir // Adding relation for XColumnLocate test 625cdf0e10cSrcweir tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F); 626cdf0e10cSrcweir 627cdf0e10cSrcweir // Adding relation for XParameters ifc test 628cdf0e10cSrcweir Vector params = new Vector(); 629cdf0e10cSrcweir 630cdf0e10cSrcweir 631cdf0e10cSrcweir /***** statement parameter types and their initial 632cdf0e10cSrcweir values must be added here as relation. */ 633cdf0e10cSrcweir params.add(new String("SAU99")) ; 634cdf0e10cSrcweir params.add(new Boolean(false)) ; 635cdf0e10cSrcweir params.add(new Byte((byte) 123)) ; 636cdf0e10cSrcweir params.add(new Short((short) 234)) ; 637cdf0e10cSrcweir params.add(new Integer(12345)) ; 638cdf0e10cSrcweir params.add(new Long(23456)) ; 639cdf0e10cSrcweir params.add(new Float(1.234)) ; 640cdf0e10cSrcweir params.add(new Double(2.345)) ; 641cdf0e10cSrcweir params.add(new byte[] {1, 2, 3}) ; 642cdf0e10cSrcweir Date d = new Date(); 643cdf0e10cSrcweir d.Day = 26; d.Month = 1; d.Year = 2001; 644cdf0e10cSrcweir params.add(d) ; 645cdf0e10cSrcweir Time t = new Time(); 646cdf0e10cSrcweir t.Hours = 1; t.HundredthSeconds = 12; t.Minutes = 25; t.Seconds = 14; 647cdf0e10cSrcweir params.add(t) ; 648cdf0e10cSrcweir DateTime dt = new DateTime(); 649cdf0e10cSrcweir dt.Day = 26; dt.Month = 1; dt.Year = 2001; dt.Hours = 1; 650cdf0e10cSrcweir dt.HundredthSeconds = 12; dt.Minutes = 25; dt.Seconds = 14; 651cdf0e10cSrcweir params.add(dt) ; 652cdf0e10cSrcweir tEnv.addObjRelation("XParameters.ParamValues", params); 653cdf0e10cSrcweir 654cdf0e10cSrcweir // Adding relation for XCompletedExecution 655cdf0e10cSrcweir tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl()); 656cdf0e10cSrcweir 657cdf0e10cSrcweir // Adding for XWarningSupplier 658cdf0e10cSrcweir tEnv.addObjRelation("CheckWarningsSupplier", new Boolean(isMySQLDB)); 659cdf0e10cSrcweir 660cdf0e10cSrcweir // Adding relation for XDatabaseParameterBroadcaster 661cdf0e10cSrcweir tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl()); 662cdf0e10cSrcweir XPropertySet xSetProp = (XPropertySet) UnoRuntime.queryInterface 663cdf0e10cSrcweir (XPropertySet.class, oObj) ; 664cdf0e10cSrcweir try { 665cdf0e10cSrcweir xSetProp.setPropertyValue("DataSourceName", dbSourceName) ; 666cdf0e10cSrcweir if(isMySQLDB) { 667cdf0e10cSrcweir xSetProp.setPropertyValue("Command", "SELECT Column0 FROM soffice_test_table WHERE ( ( Column0 = :param1 ) )"); 668cdf0e10cSrcweir } 669cdf0e10cSrcweir else { 670cdf0e10cSrcweir xSetProp.setPropertyValue("Command", "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )"); 671cdf0e10cSrcweir } 672cdf0e10cSrcweir 673cdf0e10cSrcweir xSetProp.setPropertyValue("CommandType", 674cdf0e10cSrcweir new Integer(CommandType.COMMAND)) ; 675cdf0e10cSrcweir } 676cdf0e10cSrcweir catch(Exception e) { 677cdf0e10cSrcweir } 678cdf0e10cSrcweir 679cdf0e10cSrcweir // Adding relation for XResultSetUpdate 680cdf0e10cSrcweir final XRowUpdate xRowUpdate = (XRowUpdate) UnoRuntime.queryInterface( 681cdf0e10cSrcweir XRowUpdate.class, oObj); 682cdf0e10cSrcweir final XRow xRow = (XRow) UnoRuntime.queryInterface(XRow.class, oObj); 683cdf0e10cSrcweir 684cdf0e10cSrcweir tEnv.addObjRelation("XResultSetUpdate.UpdateTester", 685cdf0e10cSrcweir new ifc.sdbc._XResultSetUpdate.UpdateTester() { 686cdf0e10cSrcweir String lastUpdate = null; 687cdf0e10cSrcweir 688cdf0e10cSrcweir public int rowCount() throws SQLException { 689cdf0e10cSrcweir int prevPos = xResSet.getRow(); 690cdf0e10cSrcweir xResSet.last(); 691cdf0e10cSrcweir 692cdf0e10cSrcweir int count = xResSet.getRow(); 693cdf0e10cSrcweir xResSet.absolute(prevPos); 694cdf0e10cSrcweir 695cdf0e10cSrcweir return count; 696cdf0e10cSrcweir } 697cdf0e10cSrcweir 698cdf0e10cSrcweir public void update() throws SQLException { 699cdf0e10cSrcweir lastUpdate = xRow.getString(1); 700cdf0e10cSrcweir lastUpdate += "_"; 701cdf0e10cSrcweir xRowUpdate.updateString(1, lastUpdate); 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir public boolean wasUpdated() throws SQLException { 705cdf0e10cSrcweir String getStr = xRow.getString(1); 706cdf0e10cSrcweir 707cdf0e10cSrcweir return lastUpdate.equals(getStr); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir 710cdf0e10cSrcweir public int currentRow() throws SQLException { 711cdf0e10cSrcweir return xResSet.getRow(); 712cdf0e10cSrcweir } 713cdf0e10cSrcweir }); 714cdf0e10cSrcweir 715cdf0e10cSrcweir // Adding relations for XRow as a Vector with all data 716cdf0e10cSrcweir // of current row of RowSet. 717cdf0e10cSrcweir 718cdf0e10cSrcweir Vector rowData = new Vector(); 719cdf0e10cSrcweir 720cdf0e10cSrcweir for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) { 721cdf0e10cSrcweir rowData.add(DBTools.TST_TABLE_VALUES[0][i]); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir tEnv.addObjRelation("CurrentRowData", rowData); 725cdf0e10cSrcweir 726cdf0e10cSrcweir // Adding relation for XRowUpdate 727cdf0e10cSrcweir XRow row = (XRow) UnoRuntime.queryInterface(XRow.class, oObj); 728cdf0e10cSrcweir tEnv.addObjRelation("XRowUpdate.XRow", row); 729cdf0e10cSrcweir 730cdf0e10cSrcweir 731cdf0e10cSrcweir tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle"); 732cdf0e10cSrcweir 733cdf0e10cSrcweir PropertyValue propVal = new PropertyValue(); 734cdf0e10cSrcweir propVal.Name = "Name"; 735cdf0e10cSrcweir propVal.Value = "Text since XPropertyAccess"; 736cdf0e10cSrcweir 737cdf0e10cSrcweir tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal); 738cdf0e10cSrcweir 739cdf0e10cSrcweir return tEnv; 740cdf0e10cSrcweir } // finish method getTestEnvironment 741cdf0e10cSrcweir 742cdf0e10cSrcweir /** 743cdf0e10cSrcweir * Closes connection of <code>RowSet</code> instance created. 744cdf0e10cSrcweir */ cleanup(TestParameters Param, PrintWriter log)745cdf0e10cSrcweir protected void cleanup(TestParameters Param, PrintWriter log) { 746cdf0e10cSrcweir log.println("closing connection..."); 747cdf0e10cSrcweir try { 748cdf0e10cSrcweir conn.close(); 749cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 750cdf0e10cSrcweir log.println("Can't close the connection"); 751cdf0e10cSrcweir e.printStackTrace(log); 752cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 753cdf0e10cSrcweir log.println("Connection was already closed. It's OK."); 754cdf0e10cSrcweir } 755cdf0e10cSrcweir 756cdf0e10cSrcweir 757cdf0e10cSrcweir log.println("closing data source..."); 758cdf0e10cSrcweir try { 759cdf0e10cSrcweir XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 760cdf0e10cSrcweir XCloseable.class, dbSrc); 761cdf0e10cSrcweir closer.close(true); 762cdf0e10cSrcweir } catch (com.sun.star.util.CloseVetoException e) { 763cdf0e10cSrcweir log.println("couldn't close data source"); 764cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 765cdf0e10cSrcweir log.println("couldn't close data source"); 766cdf0e10cSrcweir } 767cdf0e10cSrcweir 768cdf0e10cSrcweir 769cdf0e10cSrcweir log.println("closing document..."); 770cdf0e10cSrcweir 771cdf0e10cSrcweir try { 772cdf0e10cSrcweir XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 773cdf0e10cSrcweir XCloseable.class, xTextDoc); 774cdf0e10cSrcweir closer.close(true); 775cdf0e10cSrcweir } catch (com.sun.star.util.CloseVetoException e) { 776cdf0e10cSrcweir log.println("couldn't close document"); 777cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException e) { 778cdf0e10cSrcweir log.println("couldn't close document"); 779cdf0e10cSrcweir } 780cdf0e10cSrcweir 781cdf0e10cSrcweir log.println("revoking data source..."); 782cdf0e10cSrcweir try { 783cdf0e10cSrcweir dbTools.revokeDB(dbSourceName); 784cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e){ 785cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 786cdf0e10cSrcweir log.println("Error while object test cleaning up :"); 787cdf0e10cSrcweir e.printStackTrace(log); 788cdf0e10cSrcweir throw new StatusException("Error while object test cleaning up", e); 789cdf0e10cSrcweir } 790cdf0e10cSrcweir } 791cdf0e10cSrcweir 792cdf0e10cSrcweir /** 793cdf0e10cSrcweir * Implementation of interface _XDatabaseParameterBroadcaster.CheckParameterListener 794cdf0e10cSrcweir * for the XDatabaseParameterBroadcaster test 795cdf0e10cSrcweir * @see ifc.form._XDatabaseParameterBroadcaster 796cdf0e10cSrcweir */ 797cdf0e10cSrcweir public class ParameterListenerImpl implements _XDatabaseParameterBroadcaster.CheckParameterListener { 798cdf0e10cSrcweir boolean listenerWasCalled = false; 799cdf0e10cSrcweir PrintWriter log = new PrintWriter(System.out); 800cdf0e10cSrcweir 801cdf0e10cSrcweir /** 802cdf0e10cSrcweir * Return true, if the listener was called, false otherwise. 803cdf0e10cSrcweir * @return True, if any other method of the listener was called. 804cdf0e10cSrcweir */ checkListener()805cdf0e10cSrcweir public boolean checkListener() { 806cdf0e10cSrcweir return listenerWasCalled; 807cdf0e10cSrcweir } 808cdf0e10cSrcweir 809cdf0e10cSrcweir /** 810cdf0e10cSrcweir * Take the DataBaseParameterEvent and fill it with a meaningful value. 811cdf0e10cSrcweir * @param e The database parameter that will be filled with a value. 812cdf0e10cSrcweir * @return True, if the value could be filled. 813cdf0e10cSrcweir */ approveParameter(DatabaseParameterEvent e)814cdf0e10cSrcweir public boolean approveParameter(DatabaseParameterEvent e) { 815cdf0e10cSrcweir log.println("### ParameterListenerImpl: approve called."); 816cdf0e10cSrcweir XIndexAccess params = e.Parameters; 817cdf0e10cSrcweir int count = params.getCount(); 818cdf0e10cSrcweir try { 819cdf0e10cSrcweir for(int i=0; i<count; i++) { 820cdf0e10cSrcweir log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter "+i+": "+params.getByIndex(i)); 821cdf0e10cSrcweir XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i)); 822cdf0e10cSrcweir log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'"); 823cdf0e10cSrcweir xProp.setPropertyValue("Value", new Integer(1)); 824cdf0e10cSrcweir listenerWasCalled = true; 825cdf0e10cSrcweir } 826cdf0e10cSrcweir } 827cdf0e10cSrcweir catch(Exception eI) { 828cdf0e10cSrcweir log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Exception!"); 829cdf0e10cSrcweir eI.printStackTrace(log); 830cdf0e10cSrcweir return false; 831cdf0e10cSrcweir } 832cdf0e10cSrcweir return true; 833cdf0e10cSrcweir } 834cdf0e10cSrcweir 835cdf0e10cSrcweir /** 836cdf0e10cSrcweir * Dummy implemetnation. Do nothing, just log 837cdf0e10cSrcweir * @param o Ignore. 838cdf0e10cSrcweir */ disposing(EventObject o)839cdf0e10cSrcweir public void disposing(EventObject o) { 840cdf0e10cSrcweir log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: disposing"); 841cdf0e10cSrcweir } 842cdf0e10cSrcweir 843cdf0e10cSrcweir /** 844cdf0e10cSrcweir * Set a log writer, so messages go to log instead of Standard.out 845cdf0e10cSrcweir * @param log The log messages get printed to. 846cdf0e10cSrcweir */ setLog(PrintWriter log)847cdf0e10cSrcweir public void setLog(PrintWriter log) { 848cdf0e10cSrcweir this.log = log; 849cdf0e10cSrcweir } 850cdf0e10cSrcweir 851cdf0e10cSrcweir } 852cdf0e10cSrcweir 853cdf0e10cSrcweir 854cdf0e10cSrcweir /** 855cdf0e10cSrcweir * Implementation of interface _XCompletedExecution.CheckInteractionHandler 856cdf0e10cSrcweir * for the XCompletedExecution test 857cdf0e10cSrcweir * @see ifc.sdb._XCompletedExecution 858cdf0e10cSrcweir */ 859cdf0e10cSrcweir public class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler { 860cdf0e10cSrcweir private boolean handlerWasUsed = false; 861cdf0e10cSrcweir private PrintWriter log = new PrintWriter(System.out); 862cdf0e10cSrcweir checkInteractionHandler()863cdf0e10cSrcweir public boolean checkInteractionHandler() { 864cdf0e10cSrcweir return handlerWasUsed; 865cdf0e10cSrcweir } 866cdf0e10cSrcweir handle(XInteractionRequest xInteractionRequest)867cdf0e10cSrcweir public void handle(XInteractionRequest xInteractionRequest) { 868cdf0e10cSrcweir log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called."); 869cdf0e10cSrcweir handlerWasUsed = true; 870cdf0e10cSrcweir 871cdf0e10cSrcweir Object o = xInteractionRequest.getRequest(); 872cdf0e10cSrcweir ParametersRequest req = (ParametersRequest)o; 873cdf0e10cSrcweir XIndexAccess params = req.Parameters; 874cdf0e10cSrcweir int count = params.getCount(); 875cdf0e10cSrcweir try { 876cdf0e10cSrcweir for(int i=0; i<count; i++) { 877cdf0e10cSrcweir Object aObject = params.getByIndex(i); 878cdf0e10cSrcweir Any any = (Any)aObject; 879cdf0e10cSrcweir log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter "+i+": "+params.getByIndex(i)); 880cdf0e10cSrcweir XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i)); 881cdf0e10cSrcweir log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'"); 882cdf0e10cSrcweir xProp.setPropertyValue("Value", new Integer(1)); 883cdf0e10cSrcweir handlerWasUsed = true; 884cdf0e10cSrcweir } 885cdf0e10cSrcweir } 886cdf0e10cSrcweir catch(Exception eI) { 887cdf0e10cSrcweir log.println("### _XCompletedExecution.InteractionHandlerImpl: Exception!"); 888cdf0e10cSrcweir eI.printStackTrace(log); 889cdf0e10cSrcweir } 890cdf0e10cSrcweir } 891cdf0e10cSrcweir setLog(PrintWriter log)892cdf0e10cSrcweir public void setLog(PrintWriter log) { 893cdf0e10cSrcweir this.log = log; 894cdf0e10cSrcweir } 895cdf0e10cSrcweir 896cdf0e10cSrcweir } 897cdf0e10cSrcweir } // finish class ODatabaseForm 898