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: myucp_datasupplier.cxx,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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
34 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
42 #include "ucbhelper/contentidentifier.hxx"
43 #include "ucbhelper/providerhelper.hxx"
45 #include "myucp_datasupplier.hxx"
46 #include "myucp_content.hxx"
48 using namespace com::sun::star
;
50 // @@@ Adjust namespace name.
54 //=========================================================================
56 // struct ResultListEntry.
58 //=========================================================================
60 struct ResultListEntry
63 uno::Reference
< ucb::XContentIdentifier
> xId
;
64 uno::Reference
< ucb::XContent
> xContent
;
65 uno::Reference
< sdbc::XRow
> xRow
;
66 const ContentProperties
& rData
;
68 ResultListEntry( const ContentProperties
& rEntry
) : rData( rEntry
) {}
71 //=========================================================================
75 //=========================================================================
77 typedef std::vector
< ResultListEntry
* > ResultList
;
79 //=========================================================================
81 // struct DataSupplier_Impl.
83 //=========================================================================
85 struct DataSupplier_Impl
88 ResultList m_aResults
;
89 rtl::Reference
< Content
> m_xContent
;
90 uno::Reference
< lang::XMultiServiceFactory
> m_xSMgr
;
91 // @@@ The data source and an iterator for it
93 // Entry::iterator m_aIterator;
94 sal_Int32 m_nOpenMode
;
95 sal_Bool m_bCountFinal
;
97 DataSupplier_Impl( const uno::Reference
< lang::XMultiServiceFactory
>& rxSMgr
,
98 const rtl::Reference
< Content
>& rContent
,
100 : m_xContent( rContent
), m_xSMgr( rxSMgr
),
101 // m_aFolder( rxSMgr, rContent->getIdentifier()->getContentIdentifier() ),
102 m_nOpenMode( nOpenMode
), m_bCountFinal( sal_False
) {}
103 ~DataSupplier_Impl();
106 //=========================================================================
107 DataSupplier_Impl::~DataSupplier_Impl()
109 ResultList::const_iterator it
= m_aResults
.begin();
110 ResultList::const_iterator end
= m_aResults
.end();
119 //=========================================================================
120 //=========================================================================
122 // DataSupplier Implementation.
124 //=========================================================================
125 //=========================================================================
127 DataSupplier::DataSupplier( const uno::Reference
< lang::XMultiServiceFactory
>& rxSMgr
,
128 const rtl::Reference
< Content
>& rContent
,
129 sal_Int32 nOpenMode
)
130 : m_pImpl( new DataSupplier_Impl( rxSMgr
, rContent
, nOpenMode
) )
134 //=========================================================================
136 DataSupplier::~DataSupplier()
141 //=========================================================================
143 rtl::OUString
DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex
)
145 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
147 if ( nIndex
< m_pImpl
->m_aResults
.size() )
149 rtl::OUString aId
= m_pImpl
->m_aResults
[ nIndex
]->aId
;
150 if ( aId
.getLength() )
157 if ( getResult( nIndex
) )
160 = m_pImpl
->m_xContent
->getIdentifier()->getContentIdentifier();
162 aId
+= m_pImpl
->m_aResults
[ nIndex
]->rData
.aTitle
;
164 m_pImpl
->m_aResults
[ nIndex
]->aId
= aId
;
167 return rtl::OUString();
170 //=========================================================================
172 uno::Reference
< ucb::XContentIdentifier
>
173 DataSupplier::queryContentIdentifier( sal_uInt32 nIndex
)
175 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
177 if ( nIndex
< m_pImpl
->m_aResults
.size() )
179 uno::Reference
< ucb::XContentIdentifier
> xId
180 = m_pImpl
->m_aResults
[ nIndex
]->xId
;
188 rtl::OUString aId
= queryContentIdentifierString( nIndex
);
189 if ( aId
.getLength() )
191 uno::Reference
< ucb::XContentIdentifier
> xId
192 = new ::ucbhelper::ContentIdentifier( aId
);
193 m_pImpl
->m_aResults
[ nIndex
]->xId
= xId
;
196 return uno::Reference
< ucb::XContentIdentifier
>();
199 //=========================================================================
201 uno::Reference
< ucb::XContent
>
202 DataSupplier::queryContent( sal_uInt32 nIndex
)
204 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
206 if ( nIndex
< m_pImpl
->m_aResults
.size() )
208 uno::Reference
< ucb::XContent
> xContent
209 = m_pImpl
->m_aResults
[ nIndex
]->xContent
;
217 uno::Reference
< ucb::XContentIdentifier
> xId
218 = queryContentIdentifier( nIndex
);
223 uno::Reference
< ucb::XContent
> xContent
224 = m_pImpl
->m_xContent
->getProvider()->queryContent( xId
);
225 m_pImpl
->m_aResults
[ nIndex
]->xContent
= xContent
;
229 catch ( ucb::IllegalIdentifierException
& )
233 return uno::Reference
< ucb::XContent
>();
236 //=========================================================================
238 sal_Bool
DataSupplier::getResult( sal_uInt32 nIndex
)
240 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
242 if ( m_pImpl
->m_aResults
.size() > nIndex
)
244 // Result already present.
248 // Result not (yet) present.
250 if ( m_pImpl
->m_bCountFinal
)
253 // Try to obtain result...
255 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
256 sal_Bool bFound
= sal_False
;
258 // @@@ Obtain data and put it into result list...
260 sal_uInt32 nPos = nOldCount;
261 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
263 m_pImpl->m_aResults.push_back(
264 new ResultListEntry( *m_pImpl->m_aIterator ) );
266 if ( nPos == nIndex )
278 m_pImpl
->m_bCountFinal
= sal_True
;
280 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet().get();
281 if ( xResultSet
.is() )
286 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
287 xResultSet
->rowCountChanged(
288 nOldCount
, m_pImpl
->m_aResults
.size() );
290 if ( m_pImpl
->m_bCountFinal
)
291 xResultSet
->rowCountFinal();
297 //=========================================================================
299 sal_uInt32
DataSupplier::totalCount()
301 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
303 if ( m_pImpl
->m_bCountFinal
)
304 return m_pImpl
->m_aResults
.size();
306 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
308 // @@@ Obtain data and put it into result list...
310 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
311 m_pImpl->m_aResults.push_back(
312 new ResultListEntry( *m_pImpl->m_aIterator ) );
314 m_pImpl
->m_bCountFinal
= sal_True
;
316 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet().get();
317 if ( xResultSet
.is() )
322 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
323 xResultSet
->rowCountChanged(
324 nOldCount
, m_pImpl
->m_aResults
.size() );
326 xResultSet
->rowCountFinal();
329 return m_pImpl
->m_aResults
.size();
332 //=========================================================================
334 sal_uInt32
DataSupplier::currentCount()
336 return m_pImpl
->m_aResults
.size();
339 //=========================================================================
341 sal_Bool
DataSupplier::isCountFinal()
343 return m_pImpl
->m_bCountFinal
;
346 //=========================================================================
348 uno::Reference
< sdbc::XRow
>
349 DataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
351 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
353 if ( nIndex
< m_pImpl
->m_aResults
.size() )
355 uno::Reference
< sdbc::XRow
> xRow
= m_pImpl
->m_aResults
[ nIndex
]->xRow
;
363 if ( getResult( nIndex
) )
365 uno::Reference
< sdbc::XRow
> xRow
= Content::getPropertyValues(
367 getResultSet()->getProperties(),
368 m_pImpl
->m_aResults
[ nIndex
]->rData
,
369 m_pImpl
->m_xContent
->getProvider().get(),
370 queryContentIdentifierString( nIndex
) );
371 m_pImpl
->m_aResults
[ nIndex
]->xRow
= xRow
;
375 return uno::Reference
< sdbc::XRow
>();
378 //=========================================================================
380 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
382 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
384 if ( nIndex
< m_pImpl
->m_aResults
.size() )
385 m_pImpl
->m_aResults
[ nIndex
]->xRow
= uno::Reference
< sdbc::XRow
>();
388 //=========================================================================
390 void DataSupplier::close()
394 //=========================================================================
396 void DataSupplier::validate()
397 throw( ucb::ResultSetException
)