1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10*96de5490SAndrew Rist * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*96de5490SAndrew Rist * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19*96de5490SAndrew Rist * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/sdb/XDatabaseRegistrations.hpp> 29cdf0e10cSrcweir /** === end UNO includes === **/ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 32cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 33cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 34cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 35cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 36cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 37cdf0e10cSrcweir #include <tools/urlobj.hxx> 38cdf0e10cSrcweir #include <unotools/confignode.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir //........................................................................ 41cdf0e10cSrcweir namespace dbaccess 42cdf0e10cSrcweir { 43cdf0e10cSrcweir //........................................................................ 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** === begin UNO using === **/ 46cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 47cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 48cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 49cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 50cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 51cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 52cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 53cdf0e10cSrcweir using ::com::sun::star::uno::Any; 54cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 55cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 56cdf0e10cSrcweir using ::com::sun::star::uno::Type; 57cdf0e10cSrcweir using ::com::sun::star::container::NoSuchElementException; 58cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException; 59cdf0e10cSrcweir using ::com::sun::star::lang::IllegalAccessException; 60cdf0e10cSrcweir using ::com::sun::star::container::ElementExistException; 61cdf0e10cSrcweir using ::com::sun::star::sdb::XDatabaseRegistrations; 62cdf0e10cSrcweir using ::com::sun::star::sdb::XDatabaseRegistrationsListener; 63cdf0e10cSrcweir using ::com::sun::star::sdb::DatabaseRegistrationEvent; 64cdf0e10cSrcweir using ::com::sun::star::uno::XAggregation; 65cdf0e10cSrcweir /** === end UNO using === **/ 66cdf0e10cSrcweir 67cdf0e10cSrcweir //-------------------------------------------------------------------- getConfigurationRootPath()68cdf0e10cSrcweir static const ::rtl::OUString& getConfigurationRootPath() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii("org.openoffice.Office.DataAccess/RegisteredNames"); 71cdf0e10cSrcweir return s_sNodeName; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir //-------------------------------------------------------------------- getLocationNodeName()75cdf0e10cSrcweir const ::rtl::OUString& getLocationNodeName() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii( "Location" ); 78cdf0e10cSrcweir return s_sNodeName; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir //-------------------------------------------------------------------- getNameNodeName()82cdf0e10cSrcweir const ::rtl::OUString& getNameNodeName() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir static ::rtl::OUString s_sNodeName = ::rtl::OUString::createFromAscii( "Name" ); 85cdf0e10cSrcweir return s_sNodeName; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir //==================================================================== 89cdf0e10cSrcweir //= DatabaseRegistrations - declaration 90cdf0e10cSrcweir //==================================================================== 91cdf0e10cSrcweir typedef ::cppu::WeakAggImplHelper1 < XDatabaseRegistrations 92cdf0e10cSrcweir > DatabaseRegistrations_Base; 93cdf0e10cSrcweir class DatabaseRegistrations :public ::cppu::BaseMutex 94cdf0e10cSrcweir ,public DatabaseRegistrations_Base 95cdf0e10cSrcweir { 96cdf0e10cSrcweir public: 97cdf0e10cSrcweir DatabaseRegistrations( const ::comphelper::ComponentContext& _rxContext ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir protected: 100cdf0e10cSrcweir ~DatabaseRegistrations(); 101cdf0e10cSrcweir 102cdf0e10cSrcweir public: 103cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasRegisteredDatabase( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, RuntimeException); 104cdf0e10cSrcweir virtual Sequence< ::rtl::OUString > SAL_CALL getRegistrationNames() throw (RuntimeException); 105cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException); 106cdf0e10cSrcweir virtual void SAL_CALL registerDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _Location ) throw (IllegalArgumentException, ElementExistException, RuntimeException); 107cdf0e10cSrcweir virtual void SAL_CALL revokeDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException); 108cdf0e10cSrcweir virtual void SAL_CALL changeDatabaseLocation( const ::rtl::OUString& Name, const ::rtl::OUString& NewLocation ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException); 109cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL isDatabaseRegistrationReadOnly( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException); 110cdf0e10cSrcweir virtual void SAL_CALL addDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener ) throw (RuntimeException); 111cdf0e10cSrcweir virtual void SAL_CALL removeDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& Listener ) throw (RuntimeException); 112cdf0e10cSrcweir 113cdf0e10cSrcweir private: 114cdf0e10cSrcweir ::utl::OConfigurationNode 115cdf0e10cSrcweir impl_checkValidName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir void impl_checkValidLocation_throw( const ::rtl::OUString& _rLocation ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir /** retrieves the configuration node whose "Name" sub node has the given value 120cdf0e10cSrcweir 121cdf0e10cSrcweir Since we separated the name of the registration node from the "Name" value of the registration, we cannot 122cdf0e10cSrcweir simply do a "getByName" (equivalent) when we want to retrieve the node for a given registration name. 123cdf0e10cSrcweir Instead, we must search all nodes. 124cdf0e10cSrcweir 125cdf0e10cSrcweir If _bMustExist is <TRUE/>, and a node with the given display name does not exist, then a NoSuchElementException 126cdf0e10cSrcweir is thrown. 127cdf0e10cSrcweir 128cdf0e10cSrcweir If _bMustExist is <FALSE/>, and a node with the given name already exists, then a ElementExistException is 129cdf0e10cSrcweir thrown. 130cdf0e10cSrcweir 131cdf0e10cSrcweir In either case, if no exception is thrown, then a valid node is returned: If the node existed and was allowed 132cdf0e10cSrcweir to exist, it is returned, if the node did not yet exist, and was required to not exist, a new node is created. 133cdf0e10cSrcweir However, in this case the root node is not yet committed. 134cdf0e10cSrcweir */ 135cdf0e10cSrcweir ::utl::OConfigurationNode 136cdf0e10cSrcweir impl_getNodeForName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir ::utl::OConfigurationNode 139cdf0e10cSrcweir impl_getNodeForName_nothrow( const ::rtl::OUString& _rName ); 140cdf0e10cSrcweir 141cdf0e10cSrcweir private: 142cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 143cdf0e10cSrcweir ::utl::OConfigurationTreeRoot m_aConfigurationRoot; 144cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aRegistrationListeners; 145cdf0e10cSrcweir }; 146cdf0e10cSrcweir 147cdf0e10cSrcweir //==================================================================== 148cdf0e10cSrcweir //= DatabaseRegistrations - implementation 149cdf0e10cSrcweir //==================================================================== 150cdf0e10cSrcweir //-------------------------------------------------------------------- DatabaseRegistrations(const::comphelper::ComponentContext & _rxContext)151cdf0e10cSrcweir DatabaseRegistrations::DatabaseRegistrations( const ::comphelper::ComponentContext& _rxContext ) 152cdf0e10cSrcweir :m_aContext( _rxContext ) 153cdf0e10cSrcweir ,m_aConfigurationRoot() 154cdf0e10cSrcweir ,m_aRegistrationListeners( m_aMutex ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir m_aConfigurationRoot = ::utl::OConfigurationTreeRoot::createWithServiceFactory( 157cdf0e10cSrcweir m_aContext.getLegacyServiceFactory(), getConfigurationRootPath(), -1, ::utl::OConfigurationTreeRoot::CM_UPDATABLE ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir //-------------------------------------------------------------------- ~DatabaseRegistrations()161cdf0e10cSrcweir DatabaseRegistrations::~DatabaseRegistrations() 162cdf0e10cSrcweir { 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir //-------------------------------------------------------------------- impl_getNodeForName_nothrow(const::rtl::OUString & _rName)166cdf0e10cSrcweir ::utl::OConfigurationNode DatabaseRegistrations::impl_getNodeForName_nothrow( const ::rtl::OUString& _rName ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( m_aConfigurationRoot.getNodeNames() ); 169cdf0e10cSrcweir for ( const ::rtl::OUString* pName = aNames.getConstArray(); 170cdf0e10cSrcweir pName != aNames.getConstArray() + aNames.getLength(); 171cdf0e10cSrcweir ++pName 172cdf0e10cSrcweir ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir ::utl::OConfigurationNode aNodeForName = m_aConfigurationRoot.openNode( *pName ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir ::rtl::OUString sTestName; 177cdf0e10cSrcweir OSL_VERIFY( aNodeForName.getNodeValue( getNameNodeName() ) >>= sTestName ); 178cdf0e10cSrcweir if ( sTestName == _rName ) 179cdf0e10cSrcweir return aNodeForName; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir return ::utl::OConfigurationNode(); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir //-------------------------------------------------------------------- impl_getNodeForName_throw(const::rtl::OUString & _rName,const bool _bMustExist)185cdf0e10cSrcweir ::utl::OConfigurationNode DatabaseRegistrations::impl_getNodeForName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir ::utl::OConfigurationNode aNodeForName( impl_getNodeForName_nothrow( _rName ) ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir if ( aNodeForName.isValid() ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir if ( !_bMustExist ) 192cdf0e10cSrcweir throw ElementExistException( _rName, *this ); 193cdf0e10cSrcweir 194cdf0e10cSrcweir return aNodeForName; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir if ( _bMustExist ) 198cdf0e10cSrcweir throw NoSuchElementException( _rName, *this ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir ::rtl::OUString sNewNodeName; 201cdf0e10cSrcweir { 202cdf0e10cSrcweir ::rtl::OUStringBuffer aNewNodeName; 203cdf0e10cSrcweir aNewNodeName.appendAscii( "org.openoffice." ); 204cdf0e10cSrcweir aNewNodeName.append( _rName ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir // make unique 207cdf0e10cSrcweir ::rtl::OUStringBuffer aReset( aNewNodeName ); 208cdf0e10cSrcweir sNewNodeName = aNewNodeName.makeStringAndClear(); 209cdf0e10cSrcweir sal_Int32 i=2; 210cdf0e10cSrcweir while ( m_aConfigurationRoot.hasByName( sNewNodeName ) ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir aNewNodeName = aReset; 213cdf0e10cSrcweir aNewNodeName.appendAscii( " " ); 214cdf0e10cSrcweir aNewNodeName.append( i ); 215cdf0e10cSrcweir sNewNodeName = aNewNodeName.makeStringAndClear(); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir ::utl::OConfigurationNode aNewNode( m_aConfigurationRoot.createNode( sNewNodeName ) ); 220cdf0e10cSrcweir aNewNode.setNodeValue( getNameNodeName(), makeAny( _rName ) ); 221cdf0e10cSrcweir return aNewNode; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir //-------------------------------------------------------------------- impl_checkValidName_throw(const::rtl::OUString & _rName,const bool _bMustExist)225cdf0e10cSrcweir ::utl::OConfigurationNode DatabaseRegistrations::impl_checkValidName_throw( const ::rtl::OUString& _rName, const bool _bMustExist ) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir if ( !m_aConfigurationRoot.isValid() ) 228cdf0e10cSrcweir throw RuntimeException( ::rtl::OUString(), *this ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir if ( !_rName.getLength() ) 231cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 1 ); 232cdf0e10cSrcweir 233cdf0e10cSrcweir return impl_getNodeForName_throw( _rName, _bMustExist ); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir //-------------------------------------------------------------------- impl_checkValidLocation_throw(const::rtl::OUString & _rLocation)237cdf0e10cSrcweir void DatabaseRegistrations::impl_checkValidLocation_throw( const ::rtl::OUString& _rLocation ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir if ( !_rLocation.getLength() ) 240cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 2 ); 241cdf0e10cSrcweir 242cdf0e10cSrcweir INetURLObject aURL( _rLocation ); 243cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_NOT_VALID ) 244cdf0e10cSrcweir throw IllegalArgumentException( ::rtl::OUString(), *this, 2 ); 245cdf0e10cSrcweir } 246cdf0e10cSrcweir 247cdf0e10cSrcweir //-------------------------------------------------------------------- hasRegisteredDatabase(const::rtl::OUString & _Name)248cdf0e10cSrcweir ::sal_Bool SAL_CALL DatabaseRegistrations::hasRegisteredDatabase( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, RuntimeException) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 251cdf0e10cSrcweir ::utl::OConfigurationNode aNodeForName = impl_getNodeForName_nothrow( _Name ); 252cdf0e10cSrcweir return aNodeForName.isValid(); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir //------------------------------------------------------------------------------ getRegistrationNames()256cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL DatabaseRegistrations::getRegistrationNames() throw (RuntimeException) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 259cdf0e10cSrcweir if ( !m_aConfigurationRoot.isValid() ) 260cdf0e10cSrcweir throw RuntimeException( ::rtl::OUString(), *this ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir Sequence< ::rtl::OUString > aProgrammaticNames( m_aConfigurationRoot.getNodeNames() ); 263cdf0e10cSrcweir Sequence< ::rtl::OUString > aDisplayNames( aProgrammaticNames.getLength() ); 264cdf0e10cSrcweir ::rtl::OUString* pDisplayName = aDisplayNames.getArray(); 265cdf0e10cSrcweir 266cdf0e10cSrcweir for ( const ::rtl::OUString* pName = aProgrammaticNames.getConstArray(); 267cdf0e10cSrcweir pName != aProgrammaticNames.getConstArray() + aProgrammaticNames.getLength(); 268cdf0e10cSrcweir ++pName, ++pDisplayName 269cdf0e10cSrcweir ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir ::utl::OConfigurationNode aRegistrationNode = m_aConfigurationRoot.openNode( *pName ); 272cdf0e10cSrcweir OSL_VERIFY( aRegistrationNode.getNodeValue( getNameNodeName() ) >>= *pDisplayName ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir return aDisplayNames; 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir //-------------------------------------------------------------------- getDatabaseLocation(const::rtl::OUString & _Name)280cdf0e10cSrcweir ::rtl::OUString SAL_CALL DatabaseRegistrations::getDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 283cdf0e10cSrcweir 284cdf0e10cSrcweir ::utl::OConfigurationNode aNodeForName = impl_checkValidName_throw( _Name, true ); 285cdf0e10cSrcweir 286cdf0e10cSrcweir ::rtl::OUString sLocation; 287cdf0e10cSrcweir OSL_VERIFY( aNodeForName.getNodeValue( getLocationNodeName() ) >>= sLocation ); 288cdf0e10cSrcweir sLocation = SvtPathOptions().SubstituteVariable( sLocation ); 289cdf0e10cSrcweir 290cdf0e10cSrcweir return sLocation; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir //-------------------------------------------------------------------- registerDatabaseLocation(const::rtl::OUString & _Name,const::rtl::OUString & _Location)294cdf0e10cSrcweir void SAL_CALL DatabaseRegistrations::registerDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _Location ) throw (IllegalArgumentException, ElementExistException, RuntimeException) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex ); 297cdf0e10cSrcweir 298cdf0e10cSrcweir // check 299cdf0e10cSrcweir impl_checkValidLocation_throw( _Location ); 300cdf0e10cSrcweir ::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw( _Name, false ); 301cdf0e10cSrcweir 302cdf0e10cSrcweir // register 303cdf0e10cSrcweir aDataSourceRegistration.setNodeValue( getLocationNodeName(), makeAny( _Location ) ); 304cdf0e10cSrcweir m_aConfigurationRoot.commit(); 305cdf0e10cSrcweir 306cdf0e10cSrcweir // notify 307cdf0e10cSrcweir DatabaseRegistrationEvent aEvent( *this, _Name, ::rtl::OUString(), _Location ); 308cdf0e10cSrcweir aGuard.clear(); 309cdf0e10cSrcweir m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::registeredDatabaseLocation, aEvent ); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir //-------------------------------------------------------------------- revokeDatabaseLocation(const::rtl::OUString & _Name)313cdf0e10cSrcweir void SAL_CALL DatabaseRegistrations::revokeDatabaseLocation( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex ); 316cdf0e10cSrcweir 317cdf0e10cSrcweir // check 318cdf0e10cSrcweir ::utl::OConfigurationNode aNodeForName = impl_checkValidName_throw( _Name, true ); 319cdf0e10cSrcweir 320cdf0e10cSrcweir // obtain properties for notification 321cdf0e10cSrcweir ::rtl::OUString sLocation; 322cdf0e10cSrcweir OSL_VERIFY( aNodeForName.getNodeValue( getLocationNodeName() ) >>= sLocation ); 323cdf0e10cSrcweir 324cdf0e10cSrcweir // revoke 325cdf0e10cSrcweir if ( aNodeForName.isReadonly() 326cdf0e10cSrcweir || !m_aConfigurationRoot.removeNode( aNodeForName.getLocalName() ) 327cdf0e10cSrcweir ) 328cdf0e10cSrcweir throw IllegalAccessException( ::rtl::OUString(), *this ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir m_aConfigurationRoot.commit(); 331cdf0e10cSrcweir 332cdf0e10cSrcweir // notify 333cdf0e10cSrcweir DatabaseRegistrationEvent aEvent( *this, _Name, sLocation, ::rtl::OUString() ); 334cdf0e10cSrcweir aGuard.clear(); 335cdf0e10cSrcweir m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::revokedDatabaseLocation, aEvent ); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338cdf0e10cSrcweir //-------------------------------------------------------------------- changeDatabaseLocation(const::rtl::OUString & _Name,const::rtl::OUString & _NewLocation)339cdf0e10cSrcweir void SAL_CALL DatabaseRegistrations::changeDatabaseLocation( const ::rtl::OUString& _Name, const ::rtl::OUString& _NewLocation ) throw (IllegalArgumentException, NoSuchElementException, IllegalAccessException, RuntimeException) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir // check 344cdf0e10cSrcweir impl_checkValidLocation_throw( _NewLocation ); 345cdf0e10cSrcweir ::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw( _Name, true ); 346cdf0e10cSrcweir 347cdf0e10cSrcweir if ( aDataSourceRegistration.isReadonly() ) 348cdf0e10cSrcweir throw IllegalAccessException( ::rtl::OUString(), *this ); 349cdf0e10cSrcweir 350cdf0e10cSrcweir // obtain properties for notification 351cdf0e10cSrcweir ::rtl::OUString sOldLocation; 352cdf0e10cSrcweir OSL_VERIFY( aDataSourceRegistration.getNodeValue( getLocationNodeName() ) >>= sOldLocation ); 353cdf0e10cSrcweir 354cdf0e10cSrcweir // change 355cdf0e10cSrcweir aDataSourceRegistration.setNodeValue( getLocationNodeName(), makeAny( _NewLocation ) ); 356cdf0e10cSrcweir m_aConfigurationRoot.commit(); 357cdf0e10cSrcweir 358cdf0e10cSrcweir // notify 359cdf0e10cSrcweir DatabaseRegistrationEvent aEvent( *this, _Name, sOldLocation, _NewLocation ); 360cdf0e10cSrcweir aGuard.clear(); 361cdf0e10cSrcweir m_aRegistrationListeners.notifyEach( &XDatabaseRegistrationsListener::changedDatabaseLocation, aEvent ); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir //-------------------------------------------------------------------- isDatabaseRegistrationReadOnly(const::rtl::OUString & _Name)365cdf0e10cSrcweir ::sal_Bool SAL_CALL DatabaseRegistrations::isDatabaseRegistrationReadOnly( const ::rtl::OUString& _Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 368cdf0e10cSrcweir ::utl::OConfigurationNode aDataSourceRegistration = impl_checkValidName_throw( _Name, true ); 369cdf0e10cSrcweir return aDataSourceRegistration.isReadonly(); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir //-------------------------------------------------------------------- addDatabaseRegistrationsListener(const Reference<XDatabaseRegistrationsListener> & _Listener)373cdf0e10cSrcweir void SAL_CALL DatabaseRegistrations::addDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& _Listener ) throw (RuntimeException) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir if ( _Listener.is() ) 376cdf0e10cSrcweir m_aRegistrationListeners.addInterface( _Listener ); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir //-------------------------------------------------------------------- removeDatabaseRegistrationsListener(const Reference<XDatabaseRegistrationsListener> & _Listener)380cdf0e10cSrcweir void SAL_CALL DatabaseRegistrations::removeDatabaseRegistrationsListener( const Reference< XDatabaseRegistrationsListener >& _Listener ) throw (RuntimeException) 381cdf0e10cSrcweir { 382cdf0e10cSrcweir if ( _Listener.is() ) 383cdf0e10cSrcweir m_aRegistrationListeners.removeInterface( _Listener ); 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir //==================================================================== 387cdf0e10cSrcweir //= DatabaseRegistrations - factory 388cdf0e10cSrcweir //==================================================================== createDataSourceRegistrations(const::comphelper::ComponentContext & _rxContext)389cdf0e10cSrcweir Reference< XAggregation > createDataSourceRegistrations( const ::comphelper::ComponentContext& _rxContext ) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir return new DatabaseRegistrations( _rxContext ); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir //........................................................................ 395cdf0e10cSrcweir } // namespace dbaccess 396cdf0e10cSrcweir //........................................................................ 397