1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
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
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
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.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._cached;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.beans.Property;
27cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
28cdf0e10cSrcweir import com.sun.star.ucb.Command;
29cdf0e10cSrcweir import com.sun.star.ucb.NumberedSortingInfo;
30cdf0e10cSrcweir import com.sun.star.ucb.OpenCommandArgument2;
31cdf0e10cSrcweir import com.sun.star.ucb.OpenMode;
32cdf0e10cSrcweir import com.sun.star.ucb.XCommandProcessor;
33cdf0e10cSrcweir import com.sun.star.ucb.XContent;
34cdf0e10cSrcweir import com.sun.star.ucb.XContentIdentifier;
35cdf0e10cSrcweir import com.sun.star.ucb.XContentIdentifierFactory;
36cdf0e10cSrcweir import com.sun.star.ucb.XContentProvider;
37cdf0e10cSrcweir import com.sun.star.ucb.XDynamicResultSet;
38cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
39cdf0e10cSrcweir import com.sun.star.uno.XInterface;
40cdf0e10cSrcweir import com.sun.star.uno.Type;
41cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
42cdf0e10cSrcweir import java.io.PrintWriter;
43cdf0e10cSrcweir import lib.StatusException;
44cdf0e10cSrcweir import lib.TestCase;
45cdf0e10cSrcweir import lib.TestEnvironment;
46cdf0e10cSrcweir import lib.TestParameters;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /**
49cdf0e10cSrcweir * Test for object which is represented by service
50cdf0e10cSrcweir * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p>
51cdf0e10cSrcweir * Object implements the following interfaces :
52cdf0e10cSrcweir * <ul>
53cdf0e10cSrcweir *  <li> <code>com::sun::star::ucb::XCachedDynamicResultSetStubFactory</code></li>
54cdf0e10cSrcweir * </ul> <p>
55cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several
56cdf0e10cSrcweir * threads concurently.
57cdf0e10cSrcweir * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
58cdf0e10cSrcweir * @see com.sun.star.ucb.CachedDynamicResultSetStubFactory
59cdf0e10cSrcweir * @see ifc.ucb._XCachedDynamicResultSetStubFactory
60cdf0e10cSrcweir */
61cdf0e10cSrcweir public class CachedDynamicResultSetStubFactory extends TestCase {
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     /**
64*e6b649b5SPedro Giffuni     * Creating a TestEnvironment for the interfaces to be tested.
65cdf0e10cSrcweir     * Creates an instance of the service
66cdf0e10cSrcweir     * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p>
67cdf0e10cSrcweir     *     Object relations created :
68cdf0e10cSrcweir     * <ul>
69cdf0e10cSrcweir     *  <li> <code>'DynamicResultSet'</code> for
70*e6b649b5SPedro Giffuni     *      {@link ifc.ucb._XCachedDynamicResultSetStubFactory} : the destination
71cdf0e10cSrcweir     *   interface requires as its parameter an instance of
72cdf0e10cSrcweir     *   <code>DynamicResultSet</code> service. It is created
73*e6b649b5SPedro Giffuni     *   using <code>UniversalContentBroker</code> and querying it for
74cdf0e10cSrcweir     *   <code>PackageContent</code> which represents JAR file mentioned
75cdf0e10cSrcweir     *   above. Then the dynamic list of file contents (entries) is retrieved.
76cdf0e10cSrcweir     *  </li>
77cdf0e10cSrcweir     * </ul>
78cdf0e10cSrcweir     */
createTestEnvironment( TestParameters Param, PrintWriter log )79cdf0e10cSrcweir     public TestEnvironment createTestEnvironment( TestParameters Param,
80cdf0e10cSrcweir                                                   PrintWriter log )
81cdf0e10cSrcweir                                                     throws StatusException {
82cdf0e10cSrcweir         XInterface oObj = null;
83cdf0e10cSrcweir         Object oInterface = null;
84cdf0e10cSrcweir         XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
85cdf0e10cSrcweir         Object relationContainer = null ;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         try {
89cdf0e10cSrcweir             oInterface = xMSF.createInstance
90cdf0e10cSrcweir                 ( "com.sun.star.ucb.CachedDynamicResultSetStubFactory" );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir             // adding one child container
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir         catch( com.sun.star.uno.Exception e ) {
95cdf0e10cSrcweir             log.println("Can't create an object." );
96cdf0e10cSrcweir             throw new StatusException( "Can't create an object", e );
97cdf0e10cSrcweir         }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         oObj = (XInterface) oInterface;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         // creating relation for XCachedDynamicResultSetStubFactory
104cdf0e10cSrcweir         XDynamicResultSet dynResSet = null ;
105cdf0e10cSrcweir         try {
106cdf0e10cSrcweir             Object oUCB = xMSF.createInstanceWithArguments
107cdf0e10cSrcweir                 ("com.sun.star.ucb.UniversalContentBroker",
108cdf0e10cSrcweir                 new Object[] {"Local", "Office"}) ;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             XContentIdentifierFactory ciFac = (XContentIdentifierFactory)
111cdf0e10cSrcweir                 UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir             String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
114cdf0e10cSrcweir             String escUrl = "" ;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir             // In base URL of a JAR file in content URL all directory
117cdf0e10cSrcweir             // separators ('/') must be replaced with escape symbol '%2F'.
118cdf0e10cSrcweir             int idx = url.indexOf("/") ;
119cdf0e10cSrcweir             int lastIdx = -1 ;
120cdf0e10cSrcweir             while (idx >= 0) {
121cdf0e10cSrcweir                 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ;
122cdf0e10cSrcweir                 lastIdx = idx ;
123cdf0e10cSrcweir                 idx = url.indexOf("/", idx + 1) ;
124cdf0e10cSrcweir             }
125cdf0e10cSrcweir             escUrl += url.substring(lastIdx + 1) ;
126cdf0e10cSrcweir             String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir             XContentProvider cntProv = (XContentProvider)
131cdf0e10cSrcweir                 UnoRuntime.queryInterface(XContentProvider.class, oUCB) ;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir             XContent cnt = cntProv.queryContent(CI) ;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             XCommandProcessor cmdProc = (XCommandProcessor)
136cdf0e10cSrcweir                 UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             Property prop = new Property() ;
139cdf0e10cSrcweir             prop.Name = "Title" ;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             Command cmd = new Command("open", -1, new OpenCommandArgument2
142cdf0e10cSrcweir                 (OpenMode.ALL, 10000, null, new Property[] {prop},
143cdf0e10cSrcweir                  new NumberedSortingInfo[0])) ;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             dynResSet = null;
146cdf0e10cSrcweir             try {
147cdf0e10cSrcweir                 dynResSet = (XDynamicResultSet)
148cdf0e10cSrcweir                     AnyConverter.toObject(new Type(XDynamicResultSet.class),
149cdf0e10cSrcweir                                         cmdProc.execute(cmd, 0, null));
150cdf0e10cSrcweir             } catch (com.sun.star.lang.IllegalArgumentException iae) {
151cdf0e10cSrcweir                 throw new StatusException("Couldn't convert Any ",iae);
152cdf0e10cSrcweir             }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
155cdf0e10cSrcweir             log.println("Can't create relation." );
156cdf0e10cSrcweir             e.printStackTrace(log) ;
157cdf0e10cSrcweir             throw new StatusException( "Can't create relation", e );
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         tEnv.addObjRelation("DynamicResultSet", dynResSet) ;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         return tEnv;
163cdf0e10cSrcweir     } // finish method getTestEnvironment
164cdf0e10cSrcweir 
165cdf0e10cSrcweir }
166