1*2e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2e2212a7SAndrew Rist  * distributed with this work for additional information
6*2e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
9*2e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2e2212a7SAndrew Rist  *
11*2e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2e2212a7SAndrew Rist  *
13*2e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2e2212a7SAndrew Rist  * software distributed under the License is distributed on an
15*2e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2e2212a7SAndrew Rist  * specific language governing permissions and limitations
18*2e2212a7SAndrew Rist  * under the License.
19*2e2212a7SAndrew Rist  *
20*2e2212a7SAndrew Rist  *************************************************************/
21*2e2212a7SAndrew Rist 
22*2e2212a7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_
25cdf0e10cSrcweir #define _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "ModelImpl.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /** === begin UNO includes === **/
30cdf0e10cSrcweir #include <com/sun/star/container/ElementExistException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sdb/XDatabaseEnvironment.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
41cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
42cdf0e10cSrcweir #include <com/sun/star/uno/XAggregation.hpp>
43cdf0e10cSrcweir /** === end UNO includes === **/
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <basic/basicmanagerrepository.hxx>
46cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
47cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
48cdf0e10cSrcweir #include <cppuhelper/compbase8.hxx>
49cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // needed for registration
54cdf0e10cSrcweir namespace com { namespace sun { namespace star {
55cdf0e10cSrcweir 	namespace lang
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		class XMultiServiceFactory;
58cdf0e10cSrcweir 		class IllegalArgumentException;
59cdf0e10cSrcweir 	}
60cdf0e10cSrcweir } } }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //........................................................................
63cdf0e10cSrcweir namespace dbaccess
64cdf0e10cSrcweir {
65cdf0e10cSrcweir //........................................................................
66cdf0e10cSrcweir class DatabaseDocumentLoader;
67cdf0e10cSrcweir //============================================================
68cdf0e10cSrcweir //= ODatabaseContext
69cdf0e10cSrcweir //============================================================
70cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
71cdf0e10cSrcweir 	ODatabaseContext_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper8	<	::com::sun::star::lang::XServiceInfo
74cdf0e10cSrcweir 											,	::com::sun::star::container::XEnumerationAccess
75cdf0e10cSrcweir 											,	::com::sun::star::container::XNameAccess
76cdf0e10cSrcweir 											,	::com::sun::star::uno::XNamingService
77cdf0e10cSrcweir 											,	::com::sun::star::container::XContainer
78cdf0e10cSrcweir 											,	::com::sun::star::lang::XSingleServiceFactory
79cdf0e10cSrcweir 											,	::com::sun::star::lang::XUnoTunnel
80cdf0e10cSrcweir 											,	::com::sun::star::sdb::XDatabaseRegistrations
81cdf0e10cSrcweir 											>	DatabaseAccessContext_Base;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir class ODatabaseContext  :public DatabaseAccessContext_Base
84cdf0e10cSrcweir                         ,public ::basic::BasicManagerCreationListener
85cdf0e10cSrcweir {
86cdf0e10cSrcweir private:
87cdf0e10cSrcweir     /** loads the given object from the given URL
88cdf0e10cSrcweir     @throws WrappedTargetException
89cdf0e10cSrcweir         if an error occurs accessing the URL via the UCB
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     */
92cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > loadObjectFromURL(const ::rtl::OUString& _rName,const ::rtl::OUString& _sURL);
93cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getObject( const ::rtl::OUString& _rURL );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     /** sets all properties which were transient at the data source. e.g. password
96cdf0e10cSrcweir         @param  _sURL       The file URL of the data source
97cdf0e10cSrcweir         @param  _xObject    The data source itself.
98cdf0e10cSrcweir     */
99cdf0e10cSrcweir     void setTransientProperties(const ::rtl::OUString& _sURL, ODatabaseModelImpl& _rDataSourceModel );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     /** creates a new data source
102cdf0e10cSrcweir     */
103cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
104cdf0e10cSrcweir             impl_createNewDataSource();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir protected:
107cdf0e10cSrcweir 	::osl::Mutex	                m_aMutex;
108cdf0e10cSrcweir     ::comphelper::ComponentContext  m_aContext;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation >
111cdf0e10cSrcweir                                     m_xDBRegistrationAggregate;
112cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrations >
113cdf0e10cSrcweir                                     m_xDatabaseRegistrations;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	DECLARE_STL_USTRINGACCESS_MAP( ODatabaseModelImpl*, ObjectCache );
116cdf0e10cSrcweir 	ObjectCache		m_aDatabaseObjects;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >, PropertyCache );
119cdf0e10cSrcweir 	PropertyCache	m_aDatasourceProperties;
120cdf0e10cSrcweir 		// as we hold our data sources weak, we have to cache all properties on the data sources which are
121cdf0e10cSrcweir 		// transient but stored as long as the session lasts. The database context is the session (as it lives
122cdf0e10cSrcweir 		// as long as the session does), but the data sources may die before the session does, and then be
123cdf0e10cSrcweir 		// recreated afterwards. So it's our (the context's) responsibility to store the session-persistent
124cdf0e10cSrcweir 		// properties.
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	::cppu::OInterfaceContainerHelper		m_aContainerListeners;
127cdf0e10cSrcweir     DatabaseDocumentLoader*                 m_pDatabaseDocumentLoader;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir public:
130cdf0e10cSrcweir 	ODatabaseContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& );
131cdf0e10cSrcweir 	virtual ~ODatabaseContext();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     // OComponentHelper
135cdf0e10cSrcweir 	virtual void SAL_CALL disposing(void);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     // XSingleServiceFactory
138cdf0e10cSrcweir     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);
139cdf0e10cSrcweir     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);
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     // XServiceInfo
142cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
143cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
144cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // XServiceInfo - static methods
147cdf0e10cSrcweir 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException );
148cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException );
149cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
150cdf0e10cSrcweir 		SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // XElementAccess
153cdf0e10cSrcweir     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw(::com::sun::star::uno::RuntimeException);
154cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements(  ) throw(::com::sun::star::uno::RuntimeException);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     // XEnumerationAccess
157cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  ) throw(::com::sun::star::uno::RuntimeException);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     // XNameAccess
160cdf0e10cSrcweir 	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);
161cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw(::com::sun::star::uno::RuntimeException);
162cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     // XNamingService
165cdf0e10cSrcweir 	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);
166cdf0e10cSrcweir     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);
167cdf0e10cSrcweir     virtual void SAL_CALL revokeObject( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     // XDatabaseRegistrations
170cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL hasRegisteredDatabase( const ::rtl::OUString& Name ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
171cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRegistrationNames() throw (::com::sun::star::uno::RuntimeException);
172cdf0e10cSrcweir     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);
173cdf0e10cSrcweir     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);
174cdf0e10cSrcweir     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);
175cdf0e10cSrcweir     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);
176cdf0e10cSrcweir     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);
177cdf0e10cSrcweir     virtual void SAL_CALL addDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrationsListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
178cdf0e10cSrcweir     virtual void SAL_CALL removeDatabaseRegistrationsListener( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XDatabaseRegistrationsListener >& Listener ) throw (::com::sun::star::uno::RuntimeException);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     // XContainer
181cdf0e10cSrcweir     virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
182cdf0e10cSrcweir     virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	// com::sun::star::lang::XUnoTunnel
185cdf0e10cSrcweir     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
186cdf0e10cSrcweir 	static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	void registerDatabaseDocument( ODatabaseModelImpl& _rModelImpl);
189cdf0e10cSrcweir 	void revokeDatabaseDocument( const ODatabaseModelImpl& _rModelImpl);
190cdf0e10cSrcweir 	void databaseDocumentURLChange(const ::rtl::OUString& _sOldName, const ::rtl::OUString& _sNewName);
191cdf0e10cSrcweir     void storeTransientProperties( ODatabaseModelImpl& _rModelImpl);
192cdf0e10cSrcweir     void appendAtTerminateListener(const ODatabaseModelImpl& _rDataSourceModel);
193cdf0e10cSrcweir     void removeFromTerminateListener(const ODatabaseModelImpl& _rDataSourceModel);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir private:
196cdf0e10cSrcweir     // BasicManagerCreationListener
197cdf0e10cSrcweir     virtual void onBasicManagerCreated(
198cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxForDocument,
199cdf0e10cSrcweir         BasicManager& _rBasicManager
200cdf0e10cSrcweir     );
201cdf0e10cSrcweir };
202cdf0e10cSrcweir 
203cdf0e10cSrcweir //........................................................................
204cdf0e10cSrcweir }	// namespace dbaccess
205cdf0e10cSrcweir //........................................................................
206cdf0e10cSrcweir 
207cdf0e10cSrcweir #endif // _DBA_COREDATAACCESS_DATABASECONTEXT_HXX_
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210