1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSortedDynamicResultSetFactory.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import com
.sun
.star
.beans
.Property
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.sdbc
.XResultSet
;
36 import com
.sun
.star
.ucb
.Command
;
37 import com
.sun
.star
.ucb
.NumberedSortingInfo
;
38 import com
.sun
.star
.ucb
.OpenCommandArgument2
;
39 import com
.sun
.star
.ucb
.OpenMode
;
40 import com
.sun
.star
.ucb
.XCommandProcessor
;
41 import com
.sun
.star
.ucb
.XContent
;
42 import com
.sun
.star
.ucb
.XContentIdentifier
;
43 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
44 import com
.sun
.star
.ucb
.XContentProvider
;
45 import com
.sun
.star
.ucb
.XDynamicResultSet
;
46 import com
.sun
.star
.ucb
.XSortedDynamicResultSetFactory
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import lib
.MultiMethodTest
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
54 * Testing <code>com.sun.star.ucb.XSortedDynamicResultSetFactory</code>
57 * <li><code> createSortedDynamicResultSet()</code></li>
59 * The following predefined files needed to complete the test:
61 * <li> <code>solibrary.jar</code> : is used to retrieve
62 * content of its root directory.</li>
64 * Test is <b> NOT </b> multithread compilant. <p>
65 * @see com.sun.star.ucb.XSortedDynamicResultSetFactory
67 public class _XSortedDynamicResultSetFactory
extends MultiMethodTest
{
70 * Conatins the tested object.
72 public XSortedDynamicResultSetFactory oObj
;
75 * Creates sorted dynamic result set from result set. For this
76 * a dynamic result set is to be created. It is created by
77 * retrieving content list from JAR archive.
78 * Has <b>OK</b> status if numbers of rows are equal and they are
79 * greater then 0 (because JAR file contains at least one entry).
81 public void _createSortedDynamicResultSet() {
82 boolean result
= true ;
84 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
85 XDynamicResultSet dynResSet
= null ;
87 Object oUCB
= xMSF
.createInstanceWithArguments
88 ("com.sun.star.ucb.UniversalContentBroker",
89 new Object
[] {"Local", "Office"}) ;
91 XContentIdentifierFactory ciFac
= (XContentIdentifierFactory
)
92 UnoRuntime
.queryInterface
93 (XContentIdentifierFactory
.class,oUCB
) ;
95 String url
= util
.utils
.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
98 // In base URL of a JAR file in content URL all directory
99 // separators ('/') must be replaced with escape symbol '%2F'.
100 int idx
= url
.indexOf("/") ;
103 escUrl
+= url
.substring(lastIdx
+ 1, idx
) + "%2F" ;
105 idx
= url
.indexOf("/", idx
+ 1) ;
107 escUrl
+= url
.substring(lastIdx
+ 1) ;
108 String cntUrl
= "vnd.sun.star.pkg://" + escUrl
+ "/" ;
110 XContentIdentifier CI
= ciFac
.createContentIdentifier(cntUrl
) ;
112 XContentProvider cntProv
= (XContentProvider
)
113 UnoRuntime
.queryInterface(XContentProvider
.class, oUCB
) ;
115 XContent cnt
= cntProv
.queryContent(CI
) ;
117 XCommandProcessor cmdProc
= (XCommandProcessor
)
118 UnoRuntime
.queryInterface(XCommandProcessor
.class, cnt
) ;
120 Property prop
= new Property() ;
121 prop
.Name
= "Title" ;
123 Command cmd
= new Command("open", -1, new OpenCommandArgument2
124 (OpenMode
.ALL
, 10000, null, new Property
[] {prop
},
125 new NumberedSortingInfo
[0])) ;
127 dynResSet
= (XDynamicResultSet
) AnyConverter
.toObject(
128 new Type(XDynamicResultSet
.class),cmdProc
.execute(cmd
, 0, null));
129 } catch (com
.sun
.star
.uno
.Exception e
) {
130 e
.printStackTrace(log
);
133 XDynamicResultSet sortedSet
= oObj
.createSortedDynamicResultSet
134 (dynResSet
, new NumberedSortingInfo
[0], null) ;
137 if (sortedSet
!= null) {
138 XResultSet set
= null ;
140 set
= sortedSet
.getStaticResultSet() ;
141 } catch (com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
142 e
.printStackTrace(log
);
147 rowCount
= set
.getRow();
148 log
.println("Number of rows in result set: " + rowCount
);
149 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
150 log
.println("Exception occured while accessing "+
151 "sorted result set :");
152 e
.printStackTrace(log
);
155 log
.println("Null returned !!!");
159 result
&= rowCount
> 1 ;
161 tRes
.tested("createSortedDynamicResultSet()", result
) ;