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