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 _DBAUI_DBADMINIMPL_HXX_
25cdf0e10cSrcweir #define _DBAUI_DBADMINIMPL_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
34cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
40cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
43cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_
46cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriver.hpp>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _COMPHELPER_STLTYPES_HXX_
49cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef _DBAUI_DSNTYPES_HXX_
52cdf0e10cSrcweir #include "dsntypes.hxx"
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #ifndef _SFXITEMSET_HXX
55cdf0e10cSrcweir #include <svl/itemset.hxx>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
58cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir #include <svl/poolitem.hxx>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir class Window;
63cdf0e10cSrcweir //.........................................................................
64cdf0e10cSrcweir namespace dbaui
65cdf0e10cSrcweir {
66cdf0e10cSrcweir //.........................................................................
67cdf0e10cSrcweir     class DataSourceInfoConverter
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
70cdf0e10cSrcweir     public:
DataSourceInfoConverter(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _xFactory)71cdf0e10cSrcweir         DataSourceInfoConverter(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory)
72cdf0e10cSrcweir             :m_xFactory(_xFactory)
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir         void convert(const ::dbaccess::ODsnTypeCollection* _pCollection,const ::rtl::OUString& _sOldURLPrefix,const ::rtl::OUString& _sNewURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource);
76cdf0e10cSrcweir     };
77cdf0e10cSrcweir 	class IItemSetHelper;
78cdf0e10cSrcweir 	//========================================================================
79cdf0e10cSrcweir 	//= ODbDataSourceAdministrationHelper
80cdf0e10cSrcweir 	//========================================================================
81cdf0e10cSrcweir 	class ODbDataSourceAdministrationHelper
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 	public:
84cdf0e10cSrcweir 		DECLARE_STL_MAP(sal_Int32, ::rtl::OUString, ::std::less< sal_Int32 >, MapInt2String);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	private:
87cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
88cdf0e10cSrcweir 							m_xORB;					/// service factory
89cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
90cdf0e10cSrcweir 								m_xDatabaseContext;		/// database context we're working in
91cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XNamingService >
92cdf0e10cSrcweir 								m_xDynamicContext;		/// just another interface of the context ...
93cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >   m_xDatasource;
94cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >         m_xModel;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		::com::sun::star::uno::Any				m_aDataSourceOrName;
97cdf0e10cSrcweir 		typedef	::std::set< ::rtl::OUString >	StringSet;
98cdf0e10cSrcweir 		typedef	StringSet::const_iterator		ConstStringSetIterator;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 		MapInt2String			m_aDirectPropTranslator;	/// translating property id's into names (direct properties of a data source)
102cdf0e10cSrcweir 		MapInt2String			m_aIndirectPropTranslator;	/// translating property id's into names (indirect properties of a data source)
103cdf0e10cSrcweir 		Window*					m_pParent;
104cdf0e10cSrcweir 		IItemSetHelper*			m_pItemSetHelper;
105cdf0e10cSrcweir 	public:
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		ODbDataSourceAdministrationHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB
108cdf0e10cSrcweir 										,Window* _pParent
109cdf0e10cSrcweir 										,IItemSetHelper* _pItemSetHelper);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		/** translate the current dialog SfxItems into driver relevant PropertyValues
112cdf0e10cSrcweir 			@see successfullyConnected
113cdf0e10cSrcweir 		*/
114cdf0e10cSrcweir 		sal_Bool	getCurrentSettings(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDriverParams);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		/** to be called if the settings got from getCurrentSettings have been used for successfully connecting
117cdf0e10cSrcweir 			@see getCurrentSettings
118cdf0e10cSrcweir 		*/
119cdf0e10cSrcweir 		void		successfullyConnected();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 		/// clear the password in the current data source's item set
122cdf0e10cSrcweir 		void		clearPassword();
123cdf0e10cSrcweir 
getORB() const124cdf0e10cSrcweir 		inline ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getORB() const { return m_xORB; }
125cdf0e10cSrcweir 
getDatabaseContext() const126cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getDatabaseContext() const { return m_xDatabaseContext; }
getDynamicContext() const127cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::uno::XNamingService > getDynamicContext() const { return m_xDynamicContext; }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		/** creates a new connection. The caller is responsible to dispose it !!!!
130cdf0e10cSrcweir 		*/
131cdf0e10cSrcweir 		::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >,sal_Bool>		createConnection();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		/** return the corresponding driver for the selected URL
134cdf0e10cSrcweir 		*/
135cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >			getDriver();
136cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >			getDriver(const ::rtl::OUString& _sURL);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 		/** returns the data source the dialog is currently working with
139cdf0e10cSrcweir 		*/
140cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >	getCurrentDataSource();
141cdf0e10cSrcweir         // returns the Url of a database document
142cdf0e10cSrcweir         String              getDocumentUrl(SfxItemSet& _rDest);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 		void setDataSourceOrName( const ::com::sun::star::uno::Any& _rDataSourceOrName );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		/** extracts the connection type from the given set<p/>
147cdf0e10cSrcweir 			The connection type is determined by the value of the DSN item, analyzed by the TypeCollection item.
148cdf0e10cSrcweir 		*/
149cdf0e10cSrcweir 		static ::rtl::OUString getDatasourceType( const SfxItemSet& _rSet );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 		/** returns the connection URL
152cdf0e10cSrcweir 			@return
153cdf0e10cSrcweir 				The connection URL
154cdf0e10cSrcweir 		*/
155cdf0e10cSrcweir 		String getConnectionURL() const;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		/// fill the nescessary information from the url line
158cdf0e10cSrcweir 		void convertUrl(SfxItemSet& _rDest);
159cdf0e10cSrcweir 
getIndirectProperties() const160cdf0e10cSrcweir 		const MapInt2String& getIndirectProperties() const { return m_aIndirectPropTranslator; }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		/** translates properties of an UNO data source into SfxItems
163cdf0e10cSrcweir 			@param	_rxSource
164cdf0e10cSrcweir 				The data source
165cdf0e10cSrcweir 			@param	_rDest
166cdf0e10cSrcweir 				The item set to fill.
167cdf0e10cSrcweir 		*/
168cdf0e10cSrcweir 		void translateProperties(
169cdf0e10cSrcweir 				const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSource,
170cdf0e10cSrcweir 				SfxItemSet& _rDest);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 		/** translate SfxItems into properties of an UNO data source
173cdf0e10cSrcweir 			@param	_rSource
174cdf0e10cSrcweir 				The item set to read from.
175cdf0e10cSrcweir 			@param	_rxDest
176cdf0e10cSrcweir 				The data source to fill.
177cdf0e10cSrcweir 		*/
178cdf0e10cSrcweir 		void translateProperties(
179cdf0e10cSrcweir 				const SfxItemSet& _rSource,
180cdf0e10cSrcweir 				const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDest);
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		sal_Bool saveChanges(const SfxItemSet& _rSource);
183cdf0e10cSrcweir 	protected:
184cdf0e10cSrcweir 		/** fill a data source info array with the settings from a given item set
185cdf0e10cSrcweir 		*/
186cdf0e10cSrcweir 		void fillDatasourceInfo(const SfxItemSet& _rSource, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 		/// translate the given value into an SfxPoolItem, put this into the given set under the given id
189cdf0e10cSrcweir 		void		implTranslateProperty(SfxItemSet& _rSet, sal_Int32  _nId, const ::com::sun::star::uno::Any& _rValue);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 		/// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>
192cdf0e10cSrcweir 		::com::sun::star::uno::Any implTranslateProperty(const SfxPoolItem* _pItem);
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 		/// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>, set it (under the given name) on the given property set
195cdf0e10cSrcweir 		void		implTranslateProperty(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSet, const ::rtl::OUString& _rName, const SfxPoolItem* _pItem);
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 		/** check if the data source described by the given set needs authentication<p/>
198cdf0e10cSrcweir 			The return value depends on the data source type only.
199cdf0e10cSrcweir 		*/
200cdf0e10cSrcweir 		sal_Bool			hasAuthentication(const SfxItemSet& _rSet) const;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir #ifdef DBG_UTIL
203cdf0e10cSrcweir 		::rtl::OString translatePropertyId( sal_Int32 _nId );
204cdf0e10cSrcweir #endif
205cdf0e10cSrcweir 	};
206cdf0e10cSrcweir 
207cdf0e10cSrcweir //.........................................................................
208cdf0e10cSrcweir }	// namespace dbaui
209cdf0e10cSrcweir //.........................................................................
210cdf0e10cSrcweir 
211cdf0e10cSrcweir #endif // _DBAUI_DBADMINIMPL_HXX_
212cdf0e10cSrcweir 
213