Update ooo320-m1
[ooovba.git] / dbaccess / source / ui / dlg / DbAdminImpl.hxx
bloba8517c86ceeddef287097d3bafc4f04a0de13bc2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DbAdminImpl.hxx,v $
10 * $Revision: 1.10.68.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _DBAUI_DBADMINIMPL_HXX_
32 #define _DBAUI_DBADMINIMPL_HXX_
34 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #endif
37 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
41 #include <com/sun/star/uno/XNamingService.hpp>
42 #endif
43 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
47 #include <com/sun/star/beans/PropertyValue.hpp>
48 #endif
49 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
50 #include <com/sun/star/sdbc/XConnection.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_
53 #include <com/sun/star/sdbc/XDriver.hpp>
54 #endif
55 #ifndef _COMPHELPER_STLTYPES_HXX_
56 #include <comphelper/stl_types.hxx>
57 #endif
58 #ifndef _DBAUI_DSNTYPES_HXX_
59 #include "dsntypes.hxx"
60 #endif
61 #ifndef _SFXITEMSET_HXX
62 #include <svtools/itemset.hxx>
63 #endif
64 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
65 #include <com/sun/star/frame/XModel.hpp>
66 #endif
67 #include <svtools/poolitem.hxx>
69 class Window;
70 //.........................................................................
71 namespace dbaui
73 //.........................................................................
74 class DataSourceInfoConverter
76 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
77 public:
78 DataSourceInfoConverter(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory)
79 :m_xFactory(_xFactory)
82 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);
84 class IItemSetHelper;
85 //========================================================================
86 //= ODbDataSourceAdministrationHelper
87 //========================================================================
88 class ODbDataSourceAdministrationHelper
90 public:
91 DECLARE_STL_MAP(sal_Int32, ::rtl::OUString, ::std::less< sal_Int32 >, MapInt2String);
93 private:
94 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
95 m_xORB; /// service factory
96 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
97 m_xDatabaseContext; /// database context we're working in
98 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XNamingService >
99 m_xDynamicContext; /// just another interface of the context ...
100 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xDatasource;
101 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
103 ::com::sun::star::uno::Any m_aDataSourceOrName;
104 typedef ::std::set< ::rtl::OUString > StringSet;
105 typedef StringSet::const_iterator ConstStringSetIterator;
108 MapInt2String m_aDirectPropTranslator; /// translating property id's into names (direct properties of a data source)
109 MapInt2String m_aIndirectPropTranslator; /// translating property id's into names (indirect properties of a data source)
110 Window* m_pParent;
111 IItemSetHelper* m_pItemSetHelper;
112 public:
114 ODbDataSourceAdministrationHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB
115 ,Window* _pParent
116 ,IItemSetHelper* _pItemSetHelper);
118 /** translate the current dialog SfxItems into driver relevant PropertyValues
119 @see successfullyConnected
121 sal_Bool getCurrentSettings(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDriverParams);
123 /** to be called if the settings got from getCurrentSettings have been used for successfully connecting
124 @see getCurrentSettings
126 void successfullyConnected();
128 /// clear the password in the current data source's item set
129 void clearPassword();
131 inline ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getORB() const { return m_xORB; }
133 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getDatabaseContext() const { return m_xDatabaseContext; }
134 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XNamingService > getDynamicContext() const { return m_xDynamicContext; }
136 /** creates a new connection. The caller is responsible to dispose it !!!!
138 ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >,sal_Bool> createConnection();
140 /** return the corresponding driver for the selected URL
142 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver > getDriver();
144 /** returns the data source the dialog is currently working with
146 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getCurrentDataSource();
147 // returns the Url of a database document
148 String getDocumentUrl(SfxItemSet& _rDest);
150 void setDataSourceOrName( const ::com::sun::star::uno::Any& _rDataSourceOrName );
152 /** extracts the connection type from the given set<p/>
153 The connection type is determined by the value of the DSN item, analyzed by the TypeCollection item.
155 static ::rtl::OUString getDatasourceType( const SfxItemSet& _rSet );
157 /** returns the connection URL
158 @return
159 The connection URL
161 String getConnectionURL() const;
163 /// fill the nescessary information from the url line
164 void convertUrl(SfxItemSet& _rDest);
166 const MapInt2String& getIndirectProperties() const { return m_aIndirectPropTranslator; }
168 /** translates properties of an UNO data source into SfxItems
169 @param _rxSource
170 The data source
171 @param _rDest
172 The item set to fill.
174 void translateProperties(
175 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSource,
176 SfxItemSet& _rDest);
178 /** translate SfxItems into properties of an UNO data source
179 @param _rSource
180 The item set to read from.
181 @param _rxDest
182 The data source to fill.
184 void translateProperties(
185 const SfxItemSet& _rSource,
186 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDest);
188 sal_Bool saveChanges(const SfxItemSet& _rSource);
189 protected:
190 /** fill a data source info array with the settings from a given item set
192 void fillDatasourceInfo(const SfxItemSet& _rSource, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);
194 /// translate the given value into an SfxPoolItem, put this into the given set under the given id
195 void implTranslateProperty(SfxItemSet& _rSet, sal_Int32 _nId, const ::com::sun::star::uno::Any& _rValue);
197 /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>
198 ::com::sun::star::uno::Any implTranslateProperty(const SfxPoolItem* _pItem);
200 /// 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
201 void implTranslateProperty(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSet, const ::rtl::OUString& _rName, const SfxPoolItem* _pItem);
203 /** check if the data source described by the given set needs authentication<p/>
204 The return value depends on the data source type only.
206 sal_Bool hasAuthentication(const SfxItemSet& _rSet) const;
208 #ifdef DBG_UTIL
209 ::rtl::OString translatePropertyId( sal_Int32 _nId );
210 #endif
213 //.........................................................................
214 } // namespace dbaui
215 //.........................................................................
217 #endif // _DBAUI_DBADMINIMPL_HXX_