1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "dsntypes.hxx"
#include "dbamiscres.hrc"
#include <unotools/confignode.hxx>
#include <tools/debug.hxx>
#include <osl/diagnose.h>
#include <tools/wldcrd.hxx>
#include <osl/file.hxx>
#include "dbastrings.hrc"
#include "core_resource.hxx"
#include "core_resource.hrc"
#include <comphelper/documentconstants.hxx>
#include <comphelper/string.hxx>
namespace dbaccess
{
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
namespace
{
void lcl_extractHostAndPort(const OUString& _sUrl,OUString& _sHostname,sal_Int32& _nPortNumber)
{
if ( comphelper::string::getTokenCount(_sUrl, ':') >= 2 )
{
_sHostname = _sUrl.getToken(0,':');
_nPortNumber = _sUrl.getToken(1,':').toInt32();
}
}
}
// ODsnTypeCollection
ODsnTypeCollection::ODsnTypeCollection(const css::uno::Reference< css::uno::XComponentContext >& _xContext)
:m_aDriverConfig(_xContext)
,m_xContext(_xContext)
#if OSL_DEBUG_LEVEL > 0
,m_nLivingIterators(0)
#endif
{
const uno::Sequence< OUString > aURLs = m_aDriverConfig.getURLs();
const OUString* pIter = aURLs.getConstArray();
const OUString* pEnd = pIter + aURLs.getLength();
for(;pIter != pEnd;++pIter )
{
m_aDsnPrefixes.push_back(*pIter);
m_aDsnTypesDisplayNames.push_back(m_aDriverConfig.getDriverTypeDisplayName(*pIter));
}
OSL_ENSURE(m_aDsnTypesDisplayNames.size() == m_aDsnPrefixes.size(),
"ODsnTypeCollection::ODsnTypeCollection : invalid resources !");
}
ODsnTypeCollection::~ODsnTypeCollection()
{
#if OSL_DEBUG_LEVEL > 0
OSL_ENSURE(0 == m_nLivingIterators, "ODsnTypeCollection::~ODsnTypeCollection : there are still living iterator objects!");
#endif
}
OUString ODsnTypeCollection::getTypeDisplayName(const OUString& _sURL) const
{
return m_aDriverConfig.getDriverTypeDisplayName(_sURL);
}
OUString ODsnTypeCollection::cutPrefix(const OUString& _sURL) const
{
OUString sRet;
OUString sOldPattern;
StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
for(;aIter != aEnd;++aIter)
{
WildCard aWildCard(*aIter);
if ( sOldPattern.getLength() < aIter->getLength() && aWildCard.Matches(_sURL) )
{
// This relies on the fact that all patterns are of the form
// foo*
// that is, the very concept of "prefix" applies.
OUString prefix(comphelper::string::stripEnd(*aIter, '*'));
OSL_ENSURE(prefix.getLength() <= _sURL.getLength(), "How can A match B when A shorter than B?");
sRet = _sURL.copy(prefix.getLength());
sOldPattern = *aIter;
}
}
return sRet;
}
OUString ODsnTypeCollection::getPrefix(const OUString& _sURL) const
{
OUString sRet;
OUString sOldPattern;
StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
for(;aIter != aEnd;++aIter)
{
WildCard aWildCard(*aIter);
if ( sOldPattern.getLength() < aIter->getLength() && aWildCard.Matches(_sURL) )
{
// This relies on the fact that all patterns are of the form
// foo*
// that is, the very concept of "prefix" applies.
sRet = comphelper::string::stripEnd(*aIter, '*');
OSL_ENSURE(sRet.getLength() <= _sURL.getLength(), "How can A match B when A shorter than B?");
sOldPattern = *aIter;
}
}
return sRet;
}
bool ODsnTypeCollection::hasDriver( const sal_Char* _pAsciiPattern ) const
{
OUString sPrefix( getPrefix( OUString::createFromAscii( _pAsciiPattern ) ) );
return ( sPrefix.getLength() > 0 );
}
bool ODsnTypeCollection::isConnectionUrlRequired(const OUString& _sURL) const
{
OUString sRet;
OUString sOldPattern;
StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
for(;aIter != aEnd;++aIter)
{
WildCard aWildCard(*aIter);
if ( sOldPattern.getLength() < aIter->getLength() && aWildCard.Matches(_sURL) )
{
sRet = *aIter;
sOldPattern = *aIter;
}
}
return sRet.getLength() > 0 && sRet[sRet.getLength()-1] == '*';
}
OUString ODsnTypeCollection::getMediaType(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
return aFeatures.getOrDefault("MediaType",OUString());
}
OUString ODsnTypeCollection::getDatasourcePrefixFromMediaType(const OUString& _sMediaType,const OUString& _sExtension)
{
OUString sURL, sFallbackURL;
const uno::Sequence< OUString > aURLs = m_aDriverConfig.getURLs();
const OUString* pIter = aURLs.getConstArray();
const OUString* pEnd = pIter + aURLs.getLength();
for(;pIter != pEnd;++pIter )
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(*pIter);
if ( aFeatures.getOrDefault("MediaType",OUString()) == _sMediaType )
{
const OUString sFileExtension = aFeatures.getOrDefault("Extension",OUString());
if ( _sExtension == sFileExtension )
{
sURL = *pIter;
break;
}
if ( sFileExtension.isEmpty() && !_sExtension.isEmpty() )
sFallbackURL = *pIter;
}
}
if ( !sURL.getLength() && sFallbackURL.getLength() )
sURL = sFallbackURL;
sURL = comphelper::string::stripEnd(sURL, '*');
return sURL;
}
bool ODsnTypeCollection::isShowPropertiesEnabled( const OUString& _sURL )
{
return !( _sURL.startsWithIgnoreAsciiCase("sdbc:embedded:hsqldb")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:embedded:firebird")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:outlook")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:outlookexp")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:mozilla:")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:kab")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:evolution:local")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:evolution:groupwise")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:evolution:ldap")
|| _sURL.startsWithIgnoreAsciiCase("sdbc:address:macab") );
}
void ODsnTypeCollection::extractHostNamePort(const OUString& _rDsn,OUString& _sDatabaseName,OUString& _rsHostname,sal_Int32& _nPortNumber) const
{
OUString sUrl = cutPrefix(_rDsn);
if ( _rDsn.startsWithIgnoreAsciiCase("jdbc:oracle:thin:") )
{
lcl_extractHostAndPort(sUrl,_rsHostname,_nPortNumber);
if ( !_rsHostname.getLength() && comphelper::string::getTokenCount(sUrl, ':') == 2 )
{
_nPortNumber = -1;
_rsHostname = sUrl.getToken(0,':');
}
if ( _rsHostname.getLength() )
_rsHostname = _rsHostname.getToken(comphelper::string::getTokenCount(_rsHostname, '@') - 1, '@');
_sDatabaseName = sUrl.getToken(comphelper::string::getTokenCount(sUrl, ':') - 1, ':');
}
else if ( _rDsn.startsWithIgnoreAsciiCase("sdbc:address:ldap:") )
{
lcl_extractHostAndPort(sUrl,_sDatabaseName,_nPortNumber);
}
else if ( _rDsn.startsWithIgnoreAsciiCase("sdbc:mysql:mysqlc:")
|| _rDsn.startsWithIgnoreAsciiCase("sdbc:mysql:jdbc:") )
{
lcl_extractHostAndPort(sUrl,_rsHostname,_nPortNumber);
if ( _nPortNumber == -1 && !_rsHostname.getLength() && comphelper::string::getTokenCount(sUrl, '/') == 2 )
_rsHostname = sUrl.getToken(0,'/');
_sDatabaseName = sUrl.getToken(comphelper::string::getTokenCount(sUrl, '/') - 1, '/');
}
else if ( _rDsn.startsWithIgnoreAsciiCase("sdbc:ado:access:Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=")
|| _rDsn.startsWithIgnoreAsciiCase("sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=") )
{
OUString sNewFileName;
if ( ::osl::FileBase::getFileURLFromSystemPath( sUrl, sNewFileName ) == ::osl::FileBase::E_None )
{
_sDatabaseName = sNewFileName;
}
}
}
OUString ODsnTypeCollection::getJavaDriverClass(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getProperties(_sURL);
return aFeatures.getOrDefault("JavaDriverClass",OUString());
}
bool ODsnTypeCollection::isFileSystemBased(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
return aFeatures.getOrDefault("FileSystemBased",false);
}
bool ODsnTypeCollection::supportsTableCreation(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
return aFeatures.getOrDefault("SupportsTableCreation",false);
}
bool ODsnTypeCollection::supportsColumnDescription(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
return aFeatures.getOrDefault("SupportsColumnDescription",false);
}
bool ODsnTypeCollection::supportsBrowsing(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
return aFeatures.getOrDefault("SupportsBrowsing",false);
}
bool ODsnTypeCollection::supportsDBCreation(const OUString& _sURL) const
{
const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
return aFeatures.getOrDefault("SupportsDBCreation",false);
}
Sequence<PropertyValue> ODsnTypeCollection::getDefaultDBSettings( const OUString& _sURL ) const
{
const ::comphelper::NamedValueCollection& aProperties = m_aDriverConfig.getProperties(_sURL);
return aProperties.getPropertyValues();
}
bool ODsnTypeCollection::isEmbeddedDatabase( const OUString& _sURL )
{
return _sURL.startsWith( "sdbc:embedded:" );
}
OUString ODsnTypeCollection::getEmbeddedDatabase() const
{
OUString sEmbeddedDatabaseURL;
static const char s_sNodeName[] = "org.openoffice.Office.DataAccess"; ///Installed
const ::utl::OConfigurationTreeRoot aInstalled = ::utl::OConfigurationTreeRoot::createWithComponentContext(m_xContext, s_sNodeName, -1, ::utl::OConfigurationTreeRoot::CM_READONLY);
if ( aInstalled.isValid() )
{
if ( aInstalled.hasByName("EmbeddedDatabases/DefaultEmbeddedDatabase/Value") )
{
static const char s_sValue[] = "EmbeddedDatabases/DefaultEmbeddedDatabase/Value";
aInstalled.getNodeValue(s_sValue) >>= sEmbeddedDatabaseURL;
if ( !sEmbeddedDatabaseURL.isEmpty() )
aInstalled.getNodeValue(OUStringLiteral(s_sValue) + "/" + sEmbeddedDatabaseURL + "/URL") >>= sEmbeddedDatabaseURL;
}
}
if ( sEmbeddedDatabaseURL.isEmpty() )
sEmbeddedDatabaseURL = "sdbc:embedded:hsqldb";
return sEmbeddedDatabaseURL;
}
DATASOURCE_TYPE ODsnTypeCollection::determineType(const OUString& _rDsn) const
{
OUString sDsn(comphelper::string::stripEnd(_rDsn, '*'));
sal_Int32 nSeparator = sDsn.indexOf(static_cast<sal_Unicode>(':'));
if (-1 == nSeparator)
{
if (!sDsn.isEmpty())
{
// there should be at least one such separator
OSL_FAIL("ODsnTypeCollection::implDetermineType : missing the colon !");
}
return DST_UNKNOWN;
}
// find first :
if (sDsn.startsWithIgnoreAsciiCase("jdbc:oracle:thin:"))
return DST_ORACLE_JDBC;
if (sDsn.startsWithIgnoreAsciiCase("jdbc:"))
return DST_JDBC;
if (sDsn.equalsIgnoreAsciiCase("sdbc:embedded:hsqldb"))
return DST_EMBEDDED_HSQLDB;
if (sDsn.equalsIgnoreAsciiCase("sdbc:embedded:firebird"))
return DST_EMBEDDED_FIREBIRD;
// find second :
nSeparator = sDsn.indexOf(static_cast<sal_Unicode>(':'), nSeparator + 1);
if (-1 == nSeparator)
{
// at the moment only jdbc is allowed to have just one separator
OSL_FAIL("ODsnTypeCollection::implDetermineType : missing the second colon !");
return DST_UNKNOWN;
}
if (sDsn.startsWithIgnoreAsciiCase("sdbc:ado:"))
{
if (sDsn.startsWithIgnoreAsciiCase("sdbc:ado:access:"))
{
if (sDsn.startsWithIgnoreAsciiCase("sdbc:ado:access:Provider=Microsoft.ACE.OLEDB.12.0;"))
return DST_MSACCESS_2007;
else
return DST_MSACCESS;
}
return DST_ADO;
}
struct KnownPrefix
{
const OUString sPrefix;
const DATASOURCE_TYPE eType;
const bool bMatchComplete;
KnownPrefix( const OUString &_s, const DATASOURCE_TYPE _t, const bool _m )
:sPrefix( _s )
,eType ( _t )
,bMatchComplete( _m )
{
}
bool match( const OUString &url) const
{
if(bMatchComplete)
{
return url.equalsIgnoreAsciiCase(sPrefix);
}
else
{
return url.startsWithIgnoreAsciiCase(sPrefix);
}
}
};
const KnownPrefix aKnowPrefixes[] =
{
KnownPrefix( "sdbc:calc:", DST_CALC, false ),
KnownPrefix( "sdbc:flat:", DST_FLAT, false ),
KnownPrefix( "sdbc:odbc:", DST_ODBC, false ),
KnownPrefix( "sdbc:dbase:", DST_DBASE, false ),
KnownPrefix( "sdbc:firebird:", DST_FIREBIRD, false ),
KnownPrefix( "sdbc:mysql:odbc:", DST_MYSQL_ODBC, false ),
KnownPrefix( "sdbc:mysql:jdbc:", DST_MYSQL_JDBC, false ),
KnownPrefix( "sdbc:mysql:mysqlc:", DST_MYSQL_NATIVE, false ),
KnownPrefix( "sdbc:mysqlc:", DST_MYSQL_NATIVE_DIRECT,false ),
KnownPrefix( "sdbc:postgresql:", DST_POSTGRES ,false ),
KnownPrefix( "sdbc:address:mozilla:", DST_MOZILLA, true ),
KnownPrefix( "sdbc:address:thunderbird:", DST_THUNDERBIRD, true ),
KnownPrefix( "sdbc:address:ldap:", DST_LDAP, true ),
KnownPrefix( "sdbc:address:outlook", DST_OUTLOOK, true ),
KnownPrefix( "sdbc:address:outlookexp", DST_OUTLOOKEXP, true ),
KnownPrefix( "sdbc:address:evolution:ldap", DST_EVOLUTION_LDAP, true ),
KnownPrefix( "sdbc:address:evolution:groupwise",DST_EVOLUTION_GROUPWISE,true ),
KnownPrefix( "sdbc:address:evolution:local", DST_EVOLUTION, true ),
KnownPrefix( "sdbc:address:kab", DST_KAB, true ),
KnownPrefix( "sdbc:address:macab", DST_MACAB, true )
};
for (const auto & aKnowPrefixe : aKnowPrefixes)
{
if( aKnowPrefixe.match(sDsn) )
{
return aKnowPrefixe.eType;
}
}
return DST_UNKNOWN;
}
void ODsnTypeCollection::fillPageIds(const OUString& _sURL,::std::vector<sal_Int16>& _rOutPathIds) const
{
DATASOURCE_TYPE eType = determineType(_sURL);
switch(eType)
{
case DST_ADO:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_ADO);
break;
case DST_DBASE:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_DBASE);
break;
case DST_FLAT:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_TEXT);
break;
case DST_CALC:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_SPREADSHEET);
break;
case DST_ODBC:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_ODBC);
break;
case DST_JDBC:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_JDBC);
break;
case DST_MYSQL_ODBC:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_INTRO);
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_ODBC);
break;
case DST_MYSQL_JDBC:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_INTRO);
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_JDBC);
break;
case DST_MYSQL_NATIVE:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_INTRO);
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_NATIVE);
break;
case DST_ORACLE_JDBC:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_ORACLE);
break;
case DST_LDAP:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_LDAP);
break;
case DST_MSACCESS:
case DST_MSACCESS_2007:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MSACCESS);
break;
case DST_OUTLOOKEXP:
case DST_OUTLOOK:
case DST_MOZILLA:
case DST_THUNDERBIRD:
case DST_EVOLUTION:
case DST_EVOLUTION_GROUPWISE:
case DST_EVOLUTION_LDAP:
case DST_KAB:
case DST_MACAB:
case DST_EMBEDDED_HSQLDB:
case DST_EMBEDDED_FIREBIRD:
break;
default:
_rOutPathIds.push_back(PAGE_DBSETUPWIZARD_USERDEFINED);
break;
}
}
OUString ODsnTypeCollection::getType(const OUString& _sURL) const
{
OUString sOldPattern;
StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
for(;aIter != aEnd;++aIter)
{
WildCard aWildCard(*aIter);
if ( sOldPattern.getLength() < aIter->getLength() && aWildCard.Matches(_sURL) )
{
sOldPattern = *aIter;
}
}
return sOldPattern;
}
sal_Int32 ODsnTypeCollection::getIndexOf(const OUString& _sURL) const
{
sal_Int32 nRet = -1;
OUString sOldPattern;
StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
for(sal_Int32 i = 0;aIter != aEnd;++aIter,++i)
{
WildCard aWildCard(*aIter);
if ( sOldPattern.getLength() < aIter->getLength() && aWildCard.Matches(_sURL) )
{
nRet = i;
sOldPattern = *aIter;
}
}
return nRet;
}
sal_Int32 ODsnTypeCollection::size() const
{
return m_aDsnPrefixes.size();
}
// ODsnTypeCollection::TypeIterator
ODsnTypeCollection::TypeIterator::TypeIterator(const ODsnTypeCollection* _pContainer, sal_Int32 _nInitialPos)
:m_pContainer(_pContainer)
,m_nPosition(_nInitialPos)
{
OSL_ENSURE(m_pContainer, "ODsnTypeCollection::TypeIterator::TypeIterator : invalid container!");
#if OSL_DEBUG_LEVEL > 0
++const_cast<ODsnTypeCollection*>(m_pContainer)->m_nLivingIterators;
#endif
}
ODsnTypeCollection::TypeIterator::TypeIterator(const TypeIterator& _rSource)
:m_pContainer(_rSource.m_pContainer)
,m_nPosition(_rSource.m_nPosition)
{
#if OSL_DEBUG_LEVEL > 0
++const_cast<ODsnTypeCollection*>(m_pContainer)->m_nLivingIterators;
#endif
}
ODsnTypeCollection::TypeIterator::~TypeIterator()
{
#if OSL_DEBUG_LEVEL > 0
--const_cast<ODsnTypeCollection*>(m_pContainer)->m_nLivingIterators;
#endif
}
OUString ODsnTypeCollection::TypeIterator::getDisplayName() const
{
OSL_ENSURE(m_nPosition < (sal_Int32)m_pContainer->m_aDsnTypesDisplayNames.size(), "ODsnTypeCollection::TypeIterator::getDisplayName : invalid position!");
return m_pContainer->m_aDsnTypesDisplayNames[m_nPosition];
}
OUString ODsnTypeCollection::TypeIterator::getURLPrefix() const
{
OSL_ENSURE(m_nPosition < (sal_Int32)m_pContainer->m_aDsnPrefixes.size(), "ODsnTypeCollection::TypeIterator::getDisplayName : invalid position!");
return m_pContainer->m_aDsnPrefixes[m_nPosition];
}
const ODsnTypeCollection::TypeIterator& ODsnTypeCollection::TypeIterator::operator++()
{
OSL_ENSURE(m_nPosition < (sal_Int32)m_pContainer->m_aDsnTypesDisplayNames.size(), "ODsnTypeCollection::TypeIterator::operator++ : invalid position!");
if (m_nPosition < (sal_Int32)m_pContainer->m_aDsnTypesDisplayNames.size())
++m_nPosition;
return *this;
}
bool operator==(const ODsnTypeCollection::TypeIterator& lhs, const ODsnTypeCollection::TypeIterator& rhs)
{
return (lhs.m_pContainer == rhs.m_pContainer) && (lhs.m_nPosition == rhs.m_nPosition);
}
} // namespace dbaccess
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|