xref: /AOO41X/main/dbaccess/source/ui/dlg/DbAdminImpl.hxx (revision 2e2212a7c22e96cf6f6fab0dd042c34a45a64bd6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _DBAUI_DBADMINIMPL_HXX_
25 #define _DBAUI_DBADMINIMPL_HXX_
26 
27 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #endif
30 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
31 #include <com/sun/star/container/XNameAccess.hpp>
32 #endif
33 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
34 #include <com/sun/star/uno/XNamingService.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
43 #include <com/sun/star/sdbc/XConnection.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_
46 #include <com/sun/star/sdbc/XDriver.hpp>
47 #endif
48 #ifndef _COMPHELPER_STLTYPES_HXX_
49 #include <comphelper/stl_types.hxx>
50 #endif
51 #ifndef _DBAUI_DSNTYPES_HXX_
52 #include "dsntypes.hxx"
53 #endif
54 #ifndef _SFXITEMSET_HXX
55 #include <svl/itemset.hxx>
56 #endif
57 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
58 #include <com/sun/star/frame/XModel.hpp>
59 #endif
60 #include <svl/poolitem.hxx>
61 
62 class Window;
63 //.........................................................................
64 namespace dbaui
65 {
66 //.........................................................................
67     class DataSourceInfoConverter
68     {
69         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
70     public:
DataSourceInfoConverter(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _xFactory)71         DataSourceInfoConverter(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory)
72             :m_xFactory(_xFactory)
73         {
74         }
75         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);
76     };
77     class IItemSetHelper;
78     //========================================================================
79     //= ODbDataSourceAdministrationHelper
80     //========================================================================
81     class ODbDataSourceAdministrationHelper
82     {
83     public:
84         DECLARE_STL_MAP(sal_Int32, ::rtl::OUString, ::std::less< sal_Int32 >, MapInt2String);
85 
86     private:
87         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
88                             m_xORB;                 /// service factory
89         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
90                                 m_xDatabaseContext;     /// database context we're working in
91         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XNamingService >
92                                 m_xDynamicContext;      /// just another interface of the context ...
93         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >   m_xDatasource;
94         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >         m_xModel;
95 
96         ::com::sun::star::uno::Any              m_aDataSourceOrName;
97         typedef ::std::set< ::rtl::OUString >   StringSet;
98         typedef StringSet::const_iterator       ConstStringSetIterator;
99 
100 
101         MapInt2String           m_aDirectPropTranslator;    /// translating property id's into names (direct properties of a data source)
102         MapInt2String           m_aIndirectPropTranslator;  /// translating property id's into names (indirect properties of a data source)
103         Window*                 m_pParent;
104         IItemSetHelper*         m_pItemSetHelper;
105     public:
106 
107         ODbDataSourceAdministrationHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB
108                                         ,Window* _pParent
109                                         ,IItemSetHelper* _pItemSetHelper);
110 
111         /** translate the current dialog SfxItems into driver relevant PropertyValues
112             @see successfullyConnected
113         */
114         sal_Bool    getCurrentSettings(::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rDriverParams);
115 
116         /** to be called if the settings got from getCurrentSettings have been used for successfully connecting
117             @see getCurrentSettings
118         */
119         void        successfullyConnected();
120 
121         /// clear the password in the current data source's item set
122         void        clearPassword();
123 
getORB() const124         inline ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getORB() const { return m_xORB; }
125 
getDatabaseContext() const126         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getDatabaseContext() const { return m_xDatabaseContext; }
getDynamicContext() const127         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XNamingService > getDynamicContext() const { return m_xDynamicContext; }
128 
129         /** creates a new connection. The caller is responsible to dispose it !!!!
130         */
131         ::std::pair< ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >,sal_Bool>      createConnection();
132 
133         /** return the corresponding driver for the selected URL
134         */
135         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >         getDriver();
136         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDriver >         getDriver(const ::rtl::OUString& _sURL);
137 
138         /** returns the data source the dialog is currently working with
139         */
140         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >   getCurrentDataSource();
141         // returns the Url of a database document
142         String              getDocumentUrl(SfxItemSet& _rDest);
143 
144         void setDataSourceOrName( const ::com::sun::star::uno::Any& _rDataSourceOrName );
145 
146         /** extracts the connection type from the given set<p/>
147             The connection type is determined by the value of the DSN item, analyzed by the TypeCollection item.
148         */
149         static ::rtl::OUString getDatasourceType( const SfxItemSet& _rSet );
150 
151         /** returns the connection URL
152             @return
153                 The connection URL
154         */
155         String getConnectionURL() const;
156 
157         /// fill the nescessary information from the url line
158         void convertUrl(SfxItemSet& _rDest);
159 
getIndirectProperties() const160         const MapInt2String& getIndirectProperties() const { return m_aIndirectPropTranslator; }
161 
162         /** translates properties of an UNO data source into SfxItems
163             @param  _rxSource
164                 The data source
165             @param  _rDest
166                 The item set to fill.
167         */
168         void translateProperties(
169                 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSource,
170                 SfxItemSet& _rDest);
171 
172         /** translate SfxItems into properties of an UNO data source
173             @param  _rSource
174                 The item set to read from.
175             @param  _rxDest
176                 The data source to fill.
177         */
178         void translateProperties(
179                 const SfxItemSet& _rSource,
180                 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDest);
181 
182         sal_Bool saveChanges(const SfxItemSet& _rSource);
183     protected:
184         /** fill a data source info array with the settings from a given item set
185         */
186         void fillDatasourceInfo(const SfxItemSet& _rSource, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);
187 
188         /// translate the given value into an SfxPoolItem, put this into the given set under the given id
189         void        implTranslateProperty(SfxItemSet& _rSet, sal_Int32  _nId, const ::com::sun::star::uno::Any& _rValue);
190 
191         /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>
192         ::com::sun::star::uno::Any implTranslateProperty(const SfxPoolItem* _pItem);
193 
194         /// 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
195         void        implTranslateProperty(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxSet, const ::rtl::OUString& _rName, const SfxPoolItem* _pItem);
196 
197         /** check if the data source described by the given set needs authentication<p/>
198             The return value depends on the data source type only.
199         */
200         sal_Bool            hasAuthentication(const SfxItemSet& _rSet) const;
201 
202 #ifdef DBG_UTIL
203         ::rtl::OString translatePropertyId( sal_Int32 _nId );
204 #endif
205     };
206 
207 //.........................................................................
208 }   // namespace dbaui
209 //.........................................................................
210 
211 #endif // _DBAUI_DBADMINIMPL_HXX_
212 
213