1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_ 29*cdf0e10cSrcweir #define _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "ModelImpl.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir /** === begin UNO includes === **/ 34*cdf0e10cSrcweir #include <com/sun/star/container/ElementExistException.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/sdb/XDatabaseEnvironment.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/sdb/XDatabaseRegistrations.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/uno/XAggregation.hpp> 47*cdf0e10cSrcweir /** === end UNO includes === **/ 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include <basic/basicmanagerrepository.hxx> 50*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 51*cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 52*cdf0e10cSrcweir #include <cppuhelper/compbase8.hxx> 53*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // needed for registration 58*cdf0e10cSrcweir namespace com { namespace sun { namespace star { 59*cdf0e10cSrcweir namespace lang 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir class XMultiServiceFactory; 62*cdf0e10cSrcweir class IllegalArgumentException; 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir } } } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //........................................................................ 67*cdf0e10cSrcweir namespace dbaccess 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir //........................................................................ 70*cdf0e10cSrcweir class DatabaseDocumentLoader; 71*cdf0e10cSrcweir //============================================================ 72*cdf0e10cSrcweir //= ODatabaseContext 73*cdf0e10cSrcweir //============================================================ 74*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 75*cdf0e10cSrcweir ODatabaseContext_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper8 < ::com::sun::star::lang::XServiceInfo 78*cdf0e10cSrcweir , ::com::sun::star::container::XEnumerationAccess 79*cdf0e10cSrcweir , ::com::sun::star::container::XNameAccess 80*cdf0e10cSrcweir , ::com::sun::star::uno::XNamingService 81*cdf0e10cSrcweir , ::com::sun::star::container::XContainer 82*cdf0e10cSrcweir , ::com::sun::star::lang::XSingleServiceFactory 83*cdf0e10cSrcweir , ::com::sun::star::lang::XUnoTunnel 84*cdf0e10cSrcweir , ::com::sun::star::sdb::XDatabaseRegistrations 85*cdf0e10cSrcweir > DatabaseAccessContext_Base; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir class ODatabaseContext :public DatabaseAccessContext_Base 88*cdf0e10cSrcweir ,public ::basic::BasicManagerCreationListener 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir private: 91*cdf0e10cSrcweir /** loads the given object from the given URL 92*cdf0e10cSrcweir @throws WrappedTargetException 93*cdf0e10cSrcweir if an error occurs accessing the URL via the UCB 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir */ 96*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > loadObjectFromURL(const ::rtl::OUString& _rName,const ::rtl::OUString& _sURL); 97*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getObject( const ::rtl::OUString& _rURL ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir /** sets all properties which were transient at the data source. e.g. password 100*cdf0e10cSrcweir @param _sURL The file URL of the data source 101*cdf0e10cSrcweir @param _xObject The data source itself. 102*cdf0e10cSrcweir */ 103*cdf0e10cSrcweir void setTransientProperties(const ::rtl::OUString& _sURL, ODatabaseModelImpl& _rDataSourceModel ); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir /** creates a new data source 106*cdf0e10cSrcweir */ 107*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 108*cdf0e10cSrcweir impl_createNewDataSource(); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir protected: 111*cdf0e10cSrcweir ::osl::Mutex m_aMutex; 112*cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > 115*cdf0e10cSrcweir m_xDBRegistrationAggregate; 116*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrations > 117*cdf0e10cSrcweir m_xDatabaseRegistrations; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir DECLARE_STL_USTRINGACCESS_MAP( ODatabaseModelImpl*, ObjectCache ); 120*cdf0e10cSrcweir ObjectCache m_aDatabaseObjects; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >, PropertyCache ); 123*cdf0e10cSrcweir PropertyCache m_aDatasourceProperties; 124*cdf0e10cSrcweir // as we hold our data sources weak, we have to cache all properties on the data sources which are 125*cdf0e10cSrcweir // transient but stored as long as the session lasts. The database context is the session (as it lives 126*cdf0e10cSrcweir // as long as the session does), but the data sources may die before the session does, and then be 127*cdf0e10cSrcweir // recreated afterwards. So it's our (the context's) responsibility to store the session-persistent 128*cdf0e10cSrcweir // properties. 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aContainerListeners; 131*cdf0e10cSrcweir DatabaseDocumentLoader* m_pDatabaseDocumentLoader; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir public: 134*cdf0e10cSrcweir ODatabaseContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& ); 135*cdf0e10cSrcweir virtual ~ODatabaseContext(); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // OComponentHelper 139*cdf0e10cSrcweir virtual void SAL_CALL disposing(void); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // XSingleServiceFactory 142*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 143*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // XServiceInfo 146*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 147*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 148*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir // XServiceInfo - static methods 151*cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException ); 152*cdf0e10cSrcweir static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException ); 153*cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 154*cdf0e10cSrcweir SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // XElementAccess 157*cdf0e10cSrcweir virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException); 158*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // XEnumerationAccess 161*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration( ) throw(::com::sun::star::uno::RuntimeException); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // XNameAccess 164*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 165*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException); 166*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // XNamingService 169*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getRegisteredObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 170*cdf0e10cSrcweir virtual void SAL_CALL registerObject( const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Object ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 171*cdf0e10cSrcweir virtual void SAL_CALL revokeObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir // XDatabaseRegistrations 174*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasRegisteredDatabase( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 175*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRegistrationNames() throw (::com::sun::star::uno::RuntimeException); 176*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getDatabaseLocation( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); 177*cdf0e10cSrcweir virtual void SAL_CALL registerDatabaseLocation( const ::rtl::OUString& Name, const ::rtl::OUString& Location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 178*cdf0e10cSrcweir virtual void SAL_CALL revokeDatabaseLocation( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 179*cdf0e10cSrcweir virtual void SAL_CALL changeDatabaseLocation( const ::rtl::OUString& Name, const ::rtl::OUString& NewLocation ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException); 180*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL isDatabaseRegistrationReadOnly( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); 181*cdf0e10cSrcweir virtual void SAL_CALL addDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrationsListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 182*cdf0e10cSrcweir virtual void SAL_CALL removeDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrationsListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // XContainer 185*cdf0e10cSrcweir virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); 186*cdf0e10cSrcweir virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel 189*cdf0e10cSrcweir virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); 190*cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir void registerDatabaseDocument( ODatabaseModelImpl& _rModelImpl); 193*cdf0e10cSrcweir void revokeDatabaseDocument( const ODatabaseModelImpl& _rModelImpl); 194*cdf0e10cSrcweir void databaseDocumentURLChange(const ::rtl::OUString& _sOldName, const ::rtl::OUString& _sNewName); 195*cdf0e10cSrcweir void storeTransientProperties( ODatabaseModelImpl& _rModelImpl); 196*cdf0e10cSrcweir void appendAtTerminateListener(const ODatabaseModelImpl& _rDataSourceModel); 197*cdf0e10cSrcweir void removeFromTerminateListener(const ODatabaseModelImpl& _rDataSourceModel); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir private: 200*cdf0e10cSrcweir // BasicManagerCreationListener 201*cdf0e10cSrcweir virtual void onBasicManagerCreated( 202*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxForDocument, 203*cdf0e10cSrcweir BasicManager& _rBasicManager 204*cdf0e10cSrcweir ); 205*cdf0e10cSrcweir }; 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir //........................................................................ 208*cdf0e10cSrcweir } // namespace dbaccess 209*cdf0e10cSrcweir //........................................................................ 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir #endif // _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_ 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir 214