1ef39d40dSAndrew Rist /**************************************************************
2*084e0718Smseidel  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*084e0718Smseidel  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*084e0718Smseidel  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19*084e0718Smseidel  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._dbaccess;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
27cdf0e10cSrcweir import java.io.PrintWriter;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import lib.Status;
30cdf0e10cSrcweir import lib.StatusException;
31cdf0e10cSrcweir import lib.TestCase;
32cdf0e10cSrcweir import lib.TestEnvironment;
33cdf0e10cSrcweir import lib.TestParameters;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
36cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
37cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
38cdf0e10cSrcweir import com.sun.star.uno.XInterface;
39cdf0e10cSrcweir import com.sun.star.uno.XNamingService;
40cdf0e10cSrcweir import com.sun.star.frame.XStorable;
41cdf0e10cSrcweir import com.sun.star.sdb.XDocumentDataSource;
42cdf0e10cSrcweir import util.utils;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /**
45cdf0e10cSrcweir * Test for object which is represented by service
46cdf0e10cSrcweir * <code>com.sun.star.sdb.DatabaseContext</code>. <p>
47cdf0e10cSrcweir *
48cdf0e10cSrcweir * Object implements the following interfaces :
49cdf0e10cSrcweir * <ul>
50cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
51cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XNameAccess</code></li>
52cdf0e10cSrcweir *  <li> <code>com::sun::star::container::XElementAccess</code></li>
53cdf0e10cSrcweir *  <li> <code>com::sun::star::uno::XNamingService</code></li>
54cdf0e10cSrcweir * </ul>
55cdf0e10cSrcweir *
56cdf0e10cSrcweir * @see com.sun.star.container.XNameAccess
57cdf0e10cSrcweir * @see com.sun.star.container.XEnumerationAccess
58cdf0e10cSrcweir * @see com.sun.star.container.XElementAccess
59cdf0e10cSrcweir * @see com.sun.star.uno.XNamingService
60cdf0e10cSrcweir * @see com.sun.star.sdb.DatabaseContext
61e6b649b5SPedro Giffuni * @see ifc.container._XNameAccess
62e6b649b5SPedro Giffuni * @see ifc.container._XEnumerationAccess
63e6b649b5SPedro Giffuni * @see ifc.container._XElementAccess
64e6b649b5SPedro Giffuni * @see ifc.uno._XNamingService
65cdf0e10cSrcweir */
66cdf0e10cSrcweir public class ODatabaseContext extends TestCase {
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /**
69cdf0e10cSrcweir     * Does nothing.
70cdf0e10cSrcweir     */
initialize( TestParameters Param, PrintWriter log)71cdf0e10cSrcweir     protected void initialize ( TestParameters Param, PrintWriter log) {
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     /**
76cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
77cdf0e10cSrcweir     * Creates service <code>com.sun.star.sdb.DatabaseContext</code>.
78cdf0e10cSrcweir     *     Needed object relations :
79cdf0e10cSrcweir     * <ul>
80cdf0e10cSrcweir     * <li> <code>'XNamingService.RegisterObject'</code> for
81e6b649b5SPedro Giffuni     *      {@link ifc.uno._XNamingService} as an
82cdf0e10cSrcweir     *      instance of <code>com.sun.star.sdb.DataSource</code>
83cdf0e10cSrcweir     *      service. </li>
84cdf0e10cSrcweir     * </ul>
85cdf0e10cSrcweir     */
createTestEnvironment(TestParameters Param, PrintWriter log)86cdf0e10cSrcweir     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
87cdf0e10cSrcweir         XInterface oObj = null;
88cdf0e10cSrcweir         Object oInterface = null;
89cdf0e10cSrcweir         XMultiServiceFactory xMSF = null ;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         try {
92cdf0e10cSrcweir             xMSF = (XMultiServiceFactory)Param.getMSF();
93cdf0e10cSrcweir             oInterface = xMSF.createInstance( "com.sun.star.sdb.DatabaseContext" );
94cdf0e10cSrcweir         }
95cdf0e10cSrcweir         catch( com.sun.star.uno.Exception e ) {
96cdf0e10cSrcweir             log.println("Service not available" );
97cdf0e10cSrcweir             throw new StatusException("Service not available", e) ;
98cdf0e10cSrcweir         }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         if (oInterface == null) {
101cdf0e10cSrcweir             log.println("Service wasn't created") ;
102cdf0e10cSrcweir             throw new StatusException(Status.failed("Service wasn't created")) ;
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         oObj = (XInterface) oInterface;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         log.println( "    creating a new environment for object" );
108cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         // adding obj relation for XNamingService
111cdf0e10cSrcweir         try {
112cdf0e10cSrcweir             xMSF = (XMultiServiceFactory)Param.getMSF();
113cdf0e10cSrcweir             oInterface = xMSF.createInstance( "com.sun.star.sdb.DataSource" );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir             XPropertySet xDSProps = (XPropertySet)
116cdf0e10cSrcweir                 UnoRuntime.queryInterface(XPropertySet.class, oInterface) ;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir             xDSProps.setPropertyValue("URL", "sdbc:dbase:file:///.") ;
119*084e0718Smseidel 
120cdf0e10cSrcweir             XDocumentDataSource xDDS = (XDocumentDataSource)
121cdf0e10cSrcweir             UnoRuntime.queryInterface(XDocumentDataSource.class, oInterface);
122cdf0e10cSrcweir             XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class,
123cdf0e10cSrcweir             xDDS.getDatabaseDocument ());
124cdf0e10cSrcweir             String aFile = utils.getOfficeTemp ((XMultiServiceFactory) Param.getMSF ())+"DatabaseContext.odb";
125cdf0e10cSrcweir             log.println("store to '" + aFile + "'");
126*084e0718Smseidel             store.storeAsURL(aFile,new PropertyValue[]{});
127*084e0718Smseidel 
128cdf0e10cSrcweir             tEnv.addObjRelation("XNamingService.RegisterObject", oInterface) ;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir             tEnv.addObjRelation("INSTANCE", oInterface);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             tEnv.addObjRelation("XContainer.Container",
133cdf0e10cSrcweir                 (XNamingService) UnoRuntime.queryInterface(
134cdf0e10cSrcweir                                     XNamingService.class, oObj));
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
137cdf0e10cSrcweir             throw new StatusException("Can't create object relation", e) ;
138cdf0e10cSrcweir         } catch (NullPointerException e) {
139cdf0e10cSrcweir             throw new StatusException("Can't create object relation", e) ;
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         return tEnv;
143cdf0e10cSrcweir     } // finish method getTestEnvironment
144cdf0e10cSrcweir 
145cdf0e10cSrcweir }
146*084e0718Smseidel 
147