22#include <com/sun/star/lang/IllegalAccessException.hpp>
23#include <com/sun/star/lang/IllegalArgumentException.hpp>
24#include <com/sun/star/container/ElementExistException.hpp>
25#include <com/sun/star/container/NoSuchElementException.hpp>
26#include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
31#include <osl/diagnose.h>
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::RuntimeException;
42 using ::com::sun::star::uno::Any;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::XComponentContext;
45 using ::com::sun::star::container::NoSuchElementException;
46 using ::com::sun::star::lang::IllegalArgumentException;
47 using ::com::sun::star::lang::IllegalAccessException;
48 using ::com::sun::star::container::ElementExistException;
49 using ::com::sun::star::sdb::XDatabaseRegistrations;
50 using ::com::sun::star::sdb::XDatabaseRegistrationsListener;
51 using ::com::sun::star::sdb::DatabaseRegistrationEvent;
52 using ::com::sun::star::uno::XAggregation;
56 return "org.openoffice.Office.DataAccess/RegisteredNames";
82 virtual ~DatabaseRegistrations()
override;
85 virtual sal_Bool SAL_CALL hasRegisteredDatabase(
const OUString&
Name )
override;
86 virtual Sequence< OUString > SAL_CALL getRegistrationNames()
override;
87 virtual OUString SAL_CALL getDatabaseLocation(
const OUString&
Name )
override;
88 virtual void SAL_CALL registerDatabaseLocation(
const OUString&
Name,
const OUString& Location )
override;
89 virtual void SAL_CALL revokeDatabaseLocation(
const OUString&
Name )
override;
90 virtual void SAL_CALL changeDatabaseLocation(
const OUString&
Name,
const OUString& NewLocation )
override;
91 virtual sal_Bool SAL_CALL isDatabaseRegistrationReadOnly(
const OUString&
Name )
override;
92 virtual void SAL_CALL addDatabaseRegistrationsListener(
const Reference< XDatabaseRegistrationsListener >& Listener )
override;
93 virtual void SAL_CALL removeDatabaseRegistrationsListener(
const Reference< XDatabaseRegistrationsListener >& Listener )
override;
97 impl_checkValidName_common(std::u16string_view _rName);
99 impl_checkValidName_throw_must_exist(
const OUString& _rName);
101 impl_checkValidName_throw_must_not_exist(
const OUString& _rName);
103 void impl_checkValidLocation_throw( std::u16string_view _rLocation );
116 impl_getNodeForName_throw_must_exist(
const OUString& _rName);
130 impl_getNodeForName_throw_must_not_exist(
const OUString& _rName);
134 impl_getNodeForName_nothrow(std::u16string_view _rName);
145 DatabaseRegistrations::DatabaseRegistrations(
const Reference<XComponentContext> & _rxContext )
153 DatabaseRegistrations::~DatabaseRegistrations()
160 for (
auto const & nodeName : aNames )
166 if ( sTestName == _rName )
169 return ::utl::OConfigurationNode();
178 throw NoSuchElementException( _rName, *
this );
189 throw ElementExistException( _rName, *
this );
192 OUString sNewNodeName =
"org.openoffice." + _rName;
195 sNewNodeName =
"org.openoffice." + _rName +
" 2";
203 void DatabaseRegistrations::impl_checkValidName_common(std::u16string_view _rName)
208 if ( _rName.empty() )
209 throw IllegalArgumentException( OUString(), *
this, 1 );
214 impl_checkValidName_common(_rName);
215 return impl_getNodeForName_throw_must_exist(_rName);
220 impl_checkValidName_common(_rName);
221 return impl_getNodeForName_throw_must_not_exist(_rName);
224 void DatabaseRegistrations::impl_checkValidLocation_throw( std::u16string_view _rLocation )
226 if ( _rLocation.empty() )
227 throw IllegalArgumentException( OUString(), *
this, 2 );
230 if (
aURL.GetProtocol() == INetProtocol::NotValid )
231 throw IllegalArgumentException( OUString(), *
this, 2 );
234 sal_Bool SAL_CALL DatabaseRegistrations::hasRegisteredDatabase(
const OUString& Name )
236 ::osl::MutexGuard aGuard( m_aMutex );
241 Sequence< OUString > SAL_CALL DatabaseRegistrations::getRegistrationNames()
243 ::osl::MutexGuard aGuard( m_aMutex );
248 Sequence< OUString > aDisplayNames( aProgrammaticNames.getLength() );
249 OUString* pDisplayName = aDisplayNames.getArray();
251 for (
auto const & name : aProgrammaticNames )
258 return aDisplayNames;
261 OUString SAL_CALL DatabaseRegistrations::getDatabaseLocation(
const OUString& Name )
263 ::osl::MutexGuard aGuard( m_aMutex );
274 void SAL_CALL DatabaseRegistrations::registerDatabaseLocation(
const OUString& Name,
const OUString& Location )
276 ::osl::ClearableMutexGuard aGuard( m_aMutex );
279 impl_checkValidLocation_throw( Location );
287 DatabaseRegistrationEvent
aEvent( *
this, Name, OUString(), Location );
292 void SAL_CALL DatabaseRegistrations::revokeDatabaseLocation(
const OUString& Name )
294 ::osl::ClearableMutexGuard aGuard( m_aMutex );
307 throw IllegalAccessException( OUString(), *
this );
312 DatabaseRegistrationEvent
aEvent( *
this, Name, sLocation, OUString() );
317 void SAL_CALL DatabaseRegistrations::changeDatabaseLocation(
const OUString& Name,
const OUString& NewLocation )
319 ::osl::ClearableMutexGuard aGuard( m_aMutex );
322 impl_checkValidLocation_throw( NewLocation );
326 throw IllegalAccessException( OUString(), *
this );
329 OUString sOldLocation;
337 DatabaseRegistrationEvent
aEvent( *
this, Name, sOldLocation, NewLocation );
342 sal_Bool SAL_CALL DatabaseRegistrations::isDatabaseRegistrationReadOnly(
const OUString& Name )
344 ::osl::MutexGuard aGuard( m_aMutex );
349 void SAL_CALL DatabaseRegistrations::addDatabaseRegistrationsListener(
const Reference< XDatabaseRegistrationsListener >& Listener )
355 void SAL_CALL DatabaseRegistrations::removeDatabaseRegistrationsListener(
const Reference< XDatabaseRegistrationsListener >& Listener )
OUString SubstituteVariable(const OUString &rVar) const
css::uno::Sequence< OUString > getNodeNames() const noexcept
css::uno::Any getNodeValue(const OUString &_rPath) const noexcept
bool hasByName(const OUString &_rName) const noexcept
bool removeNode(const OUString &_rName) const noexcept
OUString getLocalName() const
bool setNodeValue(const OUString &_rPath, const css::uno::Any &_rValue) const noexcept
OConfigurationNode createNode(const OUString &_rName) const noexcept
OConfigurationNode openNode(const OUString &_rPath) const noexcept
static OConfigurationTreeRoot createWithComponentContext(const css::uno::Reference< css::uno::XComponentContext > &_rxContext, const OUString &_rPath, sal_Int32 _nDepth=-1, CREATION_MODE _eMode=CM_UPDATABLE)
bool commit() const noexcept
::comphelper::OInterfaceContainerHelper3< XDatabaseRegistrationsListener > m_aRegistrationListeners
::utl::OConfigurationTreeRoot m_aConfigurationRoot
Reference< XComponentContext > m_aContext
::cppu::WeakAggImplHelper1< XDatabaseRegistrations > DatabaseRegistrations_Base
Reference< XAggregation > createDataSourceRegistrations(const Reference< XComponentContext > &_rxContext)
static OUString getConfigurationRootPath()
static OUString getNameNodeName()
static OUString getLocationNodeName()
std::map< OUString, DatabaseRegistration > DatabaseRegistrations