1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _DBAUI_DBADMINIMPL_HXX_
30 #define _DBAUI_DBADMINIMPL_HXX_
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/uno/XNamingService.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/sdbc/XConnection.hpp>
38 #include <com/sun/star/sdbc/XDriver.hpp>
39 #include <comphelper/stl_types.hxx>
40 #include "dsntypes.hxx"
41 #include <svl/itemset.hxx>
42 #include <com/sun/star/frame/XModel.hpp>
43 #include <svl/poolitem.hxx>
46 //.........................................................................
49 //.........................................................................
50 class DataSourceInfoConverter
52 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> m_xFactory
;
54 DataSourceInfoConverter(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xFactory
)
55 :m_xFactory(_xFactory
)
58 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
);
61 //========================================================================
62 //= ODbDataSourceAdministrationHelper
63 //========================================================================
64 class ODbDataSourceAdministrationHelper
67 DECLARE_STL_MAP(sal_Int32
, ::rtl::OUString
, ::std::less
< sal_Int32
>, MapInt2String
);
70 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>
71 m_xORB
; /// service factory
72 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>
73 m_xDatabaseContext
; /// database context we're working in
74 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XNamingService
>
75 m_xDynamicContext
; /// just another interface of the context ...
76 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xDatasource
;
77 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> m_xModel
;
79 ::com::sun::star::uno::Any m_aDataSourceOrName
;
80 typedef ::std::set
< ::rtl::OUString
> StringSet
;
81 typedef StringSet::const_iterator ConstStringSetIterator
;
84 MapInt2String m_aDirectPropTranslator
; /// translating property id's into names (direct properties of a data source)
85 MapInt2String m_aIndirectPropTranslator
; /// translating property id's into names (indirect properties of a data source)
87 IItemSetHelper
* m_pItemSetHelper
;
90 ODbDataSourceAdministrationHelper(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xORB
92 ,IItemSetHelper
* _pItemSetHelper
);
94 /** translate the current dialog SfxItems into driver relevant PropertyValues
95 @see successfullyConnected
97 sal_Bool
getCurrentSettings(::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _rDriverParams
);
99 /** to be called if the settings got from getCurrentSettings have been used for successfully connecting
100 @see getCurrentSettings
102 void successfullyConnected();
104 /// clear the password in the current data source's item set
105 void clearPassword();
107 inline ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> getORB() const { return m_xORB
; }
109 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> getDatabaseContext() const { return m_xDatabaseContext
; }
110 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XNamingService
> getDynamicContext() const { return m_xDynamicContext
; }
112 /** creates a new connection. The caller is responsible to dispose it !!!!
114 ::std::pair
< ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>,sal_Bool
> createConnection();
116 /** return the corresponding driver for the selected URL
118 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
> getDriver();
119 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDriver
> getDriver(const ::rtl::OUString
& _sURL
);
121 /** returns the data source the dialog is currently working with
123 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getCurrentDataSource();
124 // returns the Url of a database document
125 String
getDocumentUrl(SfxItemSet
& _rDest
);
127 void setDataSourceOrName( const ::com::sun::star::uno::Any
& _rDataSourceOrName
);
129 /** extracts the connection type from the given set<p/>
130 The connection type is determined by the value of the DSN item, analyzed by the TypeCollection item.
132 static ::rtl::OUString
getDatasourceType( const SfxItemSet
& _rSet
);
134 /** returns the connection URL
138 String
getConnectionURL() const;
140 /// fill the necessary information from the url line
141 void convertUrl(SfxItemSet
& _rDest
);
143 const MapInt2String
& getIndirectProperties() const { return m_aIndirectPropTranslator
; }
145 /** translates properties of an UNO data source into SfxItems
149 The item set to fill.
151 void translateProperties(
152 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxSource
,
155 /** translate SfxItems into properties of an UNO data source
157 The item set to read from.
159 The data source to fill.
161 void translateProperties(
162 const SfxItemSet
& _rSource
,
163 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxDest
);
165 sal_Bool
saveChanges(const SfxItemSet
& _rSource
);
167 /** fill a data source info array with the settings from a given item set
169 void fillDatasourceInfo(const SfxItemSet
& _rSource
, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _rInfo
);
171 /// translate the given value into an SfxPoolItem, put this into the given set under the given id
172 void implTranslateProperty(SfxItemSet
& _rSet
, sal_Int32 _nId
, const ::com::sun::star::uno::Any
& _rValue
);
174 /// translate the given SfxPoolItem into an <type scope="com.sun.star.Any">uno</type>
175 ::com::sun::star::uno::Any
implTranslateProperty(const SfxPoolItem
* _pItem
);
177 /// 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
178 void implTranslateProperty(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxSet
, const ::rtl::OUString
& _rName
, const SfxPoolItem
* _pItem
);
180 /** check if the data source described by the given set needs authentication<p/>
181 The return value depends on the data source type only.
183 sal_Bool
hasAuthentication(const SfxItemSet
& _rSet
) const;
185 #if OSL_DEBUG_LEVEL > 0
186 ::rtl::OString
translatePropertyId( sal_Int32 _nId
);
190 //.........................................................................
192 //.........................................................................
194 #endif // _DBAUI_DBADMINIMPL_HXX_
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */