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 .
21 import com
.sun
.star
.beans
.Property
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.ucb
.Command
;
24 import com
.sun
.star
.ucb
.NumberedSortingInfo
;
25 import com
.sun
.star
.ucb
.OpenCommandArgument2
;
26 import com
.sun
.star
.ucb
.OpenMode
;
27 import com
.sun
.star
.ucb
.XCommandProcessor
;
28 import com
.sun
.star
.ucb
.XContent
;
29 import com
.sun
.star
.ucb
.XContentIdentifier
;
30 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
31 import com
.sun
.star
.ucb
.XContentProvider
;
32 import com
.sun
.star
.ucb
.XDynamicResultSet
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import java
.io
.PrintWriter
;
38 import lib
.StatusException
;
40 import lib
.TestEnvironment
;
41 import lib
.TestParameters
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p>
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::ucb::XCachedDynamicResultSetStubFactory</code></li>
50 * This object test <b> is NOT </b> designed to be run in several
51 * threads concurently.
52 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
53 * @see com.sun.star.ucb.CachedDynamicResultSetStubFactory
54 * @see ifc.ucb._XCachedDynamicResultSetStubFactory
56 public class CachedDynamicResultSetStubFactory
extends TestCase
{
59 * Creating a TestEnvironment for the interfaces to be tested.
60 * Creates an instance of the service
61 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p>
62 * Object relations created :
64 * <li> <code>'DynamicResultSet'</code> for
65 * {@link ifc.ucb._XCachedDynamicResultSetStubFactory} : the destination
66 * interface requires as its parameter an instance of
67 * <code>DynamicResultSet</code> service. It is created
68 * using <code>UniversalContentBroker</code> and querying it for
69 * <code>PackageContent</code> which represents JAR file mentioned
70 * above. Then the dynamic list of file contents (entries) is retrieved.
75 public TestEnvironment
createTestEnvironment( TestParameters Param
,
77 throws StatusException
{
78 XInterface oObj
= null;
79 Object oInterface
= null;
80 XMultiServiceFactory xMSF
= Param
.getMSF();
82 oInterface
= xMSF
.createInstance
83 ( "com.sun.star.ucb.CachedDynamicResultSetStubFactory" );
85 // adding one child container
87 catch( com
.sun
.star
.uno
.Exception e
) {
88 log
.println("Can't create an object." );
89 throw new StatusException( "Can't create an object", e
);
92 oObj
= (XInterface
) oInterface
;
94 TestEnvironment tEnv
= new TestEnvironment( oObj
);
96 // creating relation for XCachedDynamicResultSetStubFactory
97 XDynamicResultSet dynResSet
= null ;
99 Object oUCB
= xMSF
.createInstanceWithArguments
100 ("com.sun.star.ucb.UniversalContentBroker",
103 XContentIdentifierFactory ciFac
= UnoRuntime
.queryInterface(XContentIdentifierFactory
.class, oUCB
) ;
105 String url
= util
.utils
.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
108 // In base URL of a JAR file in content URL all directory
109 // separators ('/') must be replaced with escape symbol '%2F'.
110 int idx
= url
.indexOf("/") ;
113 escUrl
+= url
.substring(lastIdx
+ 1, idx
) + "%2F" ;
115 idx
= url
.indexOf("/", idx
+ 1) ;
117 escUrl
+= url
.substring(lastIdx
+ 1) ;
118 String cntUrl
= "vnd.sun.star.pkg://" + escUrl
+ "/" ;
120 XContentIdentifier CI
= ciFac
.createContentIdentifier(cntUrl
) ;
122 XContentProvider cntProv
= UnoRuntime
.queryInterface(XContentProvider
.class, oUCB
) ;
124 XContent cnt
= cntProv
.queryContent(CI
) ;
126 XCommandProcessor cmdProc
= UnoRuntime
.queryInterface(XCommandProcessor
.class, cnt
) ;
128 Property prop
= new Property() ;
129 prop
.Name
= "Title" ;
131 Command cmd
= new Command("open", -1, new OpenCommandArgument2
132 (OpenMode
.ALL
, 10000, null, new Property
[] {prop
},
133 new NumberedSortingInfo
[0])) ;
136 dynResSet
= (XDynamicResultSet
)
137 AnyConverter
.toObject(new Type(XDynamicResultSet
.class),
138 cmdProc
.execute(cmd
, 0, null));
139 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
140 throw new StatusException("Couldn't convert Any ",iae
);
143 } catch (com
.sun
.star
.uno
.Exception e
) {
144 log
.println("Can't create relation." );
145 e
.printStackTrace(log
) ;
146 throw new StatusException( "Can't create relation", e
);
149 tEnv
.addObjRelation("DynamicResultSet", dynResSet
) ;
152 } // finish method getTestEnvironment