2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod
._dbaccess
;
20 import com
.sun
.star
.sdbc
.XConnection
;
21 import com
.sun
.star
.uno
.Exception
;
22 import java
.io
.PrintWriter
;
25 import lib
.StatusException
;
27 import lib
.TestEnvironment
;
28 import lib
.TestParameters
;
29 import util
.DesktopTools
;
31 import com
.sun
.star
.beans
.PropertyValue
;
32 import com
.sun
.star
.container
.XNameAccess
;
33 import com
.sun
.star
.frame
.XController
;
34 import com
.sun
.star
.frame
.XDesktop
;
35 import com
.sun
.star
.frame
.XDispatch
;
36 import com
.sun
.star
.frame
.XDispatchProvider
;
37 import com
.sun
.star
.frame
.XFrame
;
38 import com
.sun
.star
.frame
.XModel
;
39 import com
.sun
.star
.lang
.XInitialization
;
40 import com
.sun
.star
.lang
.XMultiServiceFactory
;
41 import com
.sun
.star
.text
.XTextDocument
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
44 import com
.sun
.star
.util
.URL
;
45 import util
.SOfficeFactory
;
46 import com
.sun
.star
.sdb
.XDocumentDataSource
;
47 import com
.sun
.star
.sdbc
.XDataSource
;
49 public class OQueryDesign
extends TestCase
{
51 private static XDesktop xDesk
;
52 private static XFrame xFrame
;
53 private static final String sDataSourceName
= "Bibliography";
54 private static XConnection xConn
;
55 private static XTextDocument xTextDoc
;
59 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
62 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
63 xDesk
= DesktopTools
.createDesktop(Param
.getMSF());
67 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
69 log
.println( "creating a test environment" );
71 XDispatchProvider aProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class,xDesk
);
72 XMultiServiceFactory xMSF
= Param
.getMSF();
74 // we use the first datasource
75 XNameAccess xNameAccess
= UnoRuntime
.queryInterface(
77 xMSF
.createInstance("com.sun.star.sdb.DatabaseContext"));
78 XDataSource xDS
= UnoRuntime
.queryInterface(
79 XDataSource
.class, xNameAccess
.getByName( "Bibliography" ));
81 log
.println("check XMultiServiceFactory");
83 xConn
= xDS
.getConnection("", "");
85 log
.println( "opening QueryDesign" );
86 URL the_url
= new URL();
87 the_url
.Complete
= ".component:DB/QueryDesign";
88 XDispatch getting
= aProv
.queryDispatch(the_url
,"Query",12);
89 PropertyValue
[] Args
= new PropertyValue
[2];
90 PropertyValue param1
= new PropertyValue();
91 param1
.Name
= "DataSourceName";
92 param1
.Value
= "Bibliography";
94 PropertyValue param2
= new PropertyValue();
95 param2
.Name
= "QueryDesignView";
96 param2
.Value
= Boolean
.FALSE
;
98 param1
.Name
= "ActiveConnection";
101 getting
.dispatch(the_url
,Args
);
103 util
.utils
.waitForEventIdle(Param
.getMSF());
105 Object oDBC
= xMSF
.createInstance( "com.sun.star.sdb.DatabaseContext" );
107 Object oDataSource
= null;
108 XNameAccess xNA
= UnoRuntime
.queryInterface(XNameAccess
.class, oDBC
);
109 oDataSource
= xNA
.getByName(sDataSourceName
);
110 UnoRuntime
.queryInterface(XDocumentDataSource
.class, oDataSource
);
112 xFrame
= DesktopTools
.getCurrentFrame(xMSF
);
114 SOfficeFactory SOF
= null;
116 SOF
= SOfficeFactory
.getFactory( xMSF
);
117 log
.println( "creating a textdocument" );
118 xTextDoc
= SOF
.createTextDoc( null );
120 XModel xDocMod
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
122 XFrame xTextFrame
= xDocMod
.getCurrentController().getFrame();
124 Object
[] params
= new Object
[3];
125 param1
= new PropertyValue();
126 param1
.Name
= "DataSourceName";
127 param1
.Value
= "Bibliography";
129 param2
= new PropertyValue();
130 param2
.Name
= "Frame";
131 param2
.Value
= xTextFrame
;
133 PropertyValue param3
= new PropertyValue();
134 param3
.Name
= "QueryDesignView";
135 param3
.Value
= Boolean
.TRUE
;
139 XInterface oObj
= xFrame
.getController();
141 TestEnvironment tEnv
= new TestEnvironment(oObj
);
143 //Adding ObjRelations for XInitialization
144 tEnv
.addObjRelation("XInitialization.args", params
);
146 Object
[] ExceptionParams
= new Object
[3];
147 PropertyValue ExceptionParam1
= new PropertyValue();
148 ExceptionParam1
.Name
= "DataSourceName";
149 ExceptionParam1
.Value
= "Bibliography2";
150 ExceptionParams
[0] = ExceptionParam1
;
151 PropertyValue ExceptionParam2
= new PropertyValue();
152 ExceptionParam2
.Name
= "Frame";
153 ExceptionParam2
.Value
= null;
154 ExceptionParams
[1] = ExceptionParam2
;
155 PropertyValue ExceptionParam3
= new PropertyValue();
156 ExceptionParam3
.Name
= "QueryDesignView";
157 ExceptionParam3
.Value
= Integer
.valueOf(17);//Boolean.TRUE;
158 ExceptionParams
[2] = ExceptionParam3
;
160 tEnv
.addObjRelation("XInitialization.ExceptionArgs", ExceptionParams
);
162 tEnv
.addObjRelation("Frame", xFrame
);
164 tEnv
.addObjRelation("XInitialization.xIni", getUninitializedObj(Param
));
166 log
.println("ImplementationName: "+util
.utils
.getImplName(oObj
));
170 } // finish method getTestEnvironment
172 private XInitialization
getUninitializedObj(TestParameters Param
) throws Exception
{
173 // creating an object which ist not initialized
175 // get a model of a DataSource
177 XMultiServiceFactory xMSF
;
179 xMSF
= Param
.getMSF();
180 oDBC
= xMSF
.createInstance( "com.sun.star.sdb.DatabaseContext" );
182 Object oDataSource
= null;
183 XNameAccess xNA
= UnoRuntime
.queryInterface(XNameAccess
.class, oDBC
);
184 oDataSource
= xNA
.getByName(sDataSourceName
);
186 XDocumentDataSource xDDS
= UnoRuntime
.queryInterface(XDocumentDataSource
.class, oDataSource
);
187 XModel xMod
= UnoRuntime
.queryInterface(XModel
.class, xDDS
.getDatabaseDocument ());
189 // get an instance of QueryDesign
190 Object oQueryDesign
= xMSF
.createInstance("com.sun.star.sdb.QueryDesign");
192 XController xCont
= UnoRuntime
.queryInterface(XController
.class, oQueryDesign
);
195 boolean bSuccess
= xCont
.attachModel(xMod
);
198 throw new StatusException (Status
.failed (
199 "Couldn't attach model"));
202 xMod
.connectController(xCont
);
203 xMod
.setCurrentController(xCont
);
205 return UnoRuntime
.queryInterface(XInitialization
.class, oQueryDesign
);
209 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
212 DesktopTools
.closeDoc(xFrame
);
213 DesktopTools
.closeDoc(xTextDoc
);
214 } catch (com
.sun
.star
.uno
.Exception e
) {
215 log
.println("Can't close the connection") ;
216 e
.printStackTrace(log
) ;
217 } catch (com
.sun
.star
.lang
.DisposedException e
) {
218 log
.println("Connection was already closed. It's OK.") ;
223 } // finish class oDatasourceBrowser