xref: /AOO41X/main/extensions/source/abpilot/datasourcehandling.hxx (revision 46dbaceef8c12a09e4905feda473ecab36e10d03)
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 EXTENSIONS_ABP_DATASOURCEHANDLING_HXX
25 #define EXTENSIONS_ABP_DATASOURCEHANDLING_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include "abptypes.hxx"
29 
30 //========================================================================
31 namespace com { namespace sun { namespace star {
32     namespace lang {
33         class XMultiServiceFactory;
34     }
35     namespace beans {
36         class XPropertySet;
37     }
38 } } }
39 
40 class Window;
41 
42 
43 //.........................................................................
44 namespace abp
45 {
46 //.........................................................................
47 
48     //=====================================================================
49     //= ODataSourceContext
50     //=====================================================================
51     struct ODataSourceContextImpl;
52     class ODataSource;
53     /// a non-UNO wrapper for the data source context
54     class ODataSourceContext
55     {
56     private:
57         ODataSourceContextImpl*     m_pImpl;
58 
59     public:
60         ODataSourceContext(
61             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
62         );
63 
64         /// retrieves the names of all data sources
65         void    getDataSourceNames( StringBag& _rNames ) const SAL_THROW (( ));
66 
67         /// disambiguates the given name by appending auccessive numbers
68         ::rtl::OUString& disambiguate(::rtl::OUString& _rDataSourceName);
69 
70         /// creates a new MORK data source
71         ODataSource createNewMORK( const ::rtl::OUString& _rName ) SAL_THROW (( ));
72 
73         /// creates a new Thunderbird data source
74         ODataSource createNewThunderbird( const ::rtl::OUString& _rName ) SAL_THROW (( ));
75 
76         /// creates a new Evolution local data source
77         ODataSource createNewEvolution( const ::rtl::OUString& _rName ) SAL_THROW (( ));
78 
79         /// creates a new Evolution LDAP data source
80         ODataSource createNewEvolutionLdap( const ::rtl::OUString& _rName ) SAL_THROW (( ));
81 
82         /// creates a new Evolution GROUPWISE data source
83         ODataSource createNewEvolutionGroupwise( const ::rtl::OUString& _rName ) SAL_THROW (( ));
84 
85         /// creates a new KDE address book data source
86         ODataSource createNewKab( const ::rtl::OUString& _rName ) SAL_THROW (( ));
87 
88         /// creates a new Mac OS X address book data source
89         ODataSource createNewMacab( const ::rtl::OUString& _rName ) SAL_THROW (( ));
90 
91         /// creates a new LDAP data source
92         ODataSource createNewLDAP( const ::rtl::OUString& _rName ) SAL_THROW (( ));
93 
94         /// creates a new Outlook data source
95         ODataSource createNewOutlook( const ::rtl::OUString& _rName ) SAL_THROW (( ));
96 
97         /// creates a new Outlook express data source
98         ODataSource createNewOE( const ::rtl::OUString& _rName ) SAL_THROW (( ));
99 
100         /// creates a new dBase data source
101         ODataSource createNewDBase( const ::rtl::OUString& _rName ) SAL_THROW (( ));
102     };
103 
104     //=====================================================================
105     //= ODataSource
106     //=====================================================================
107     struct ODataSourceImpl;
108     struct PackageAccessControl;
109     /** a non-UNO wrapper for a data source
110         <p>This class allows to access data sources without the need to compile the respective file with
111         exception handling enabled (hopefully :).</p>
112         <p>In addition to wrapping an UNO data source, an instance of this class can handle at most
113         one valid connection, as obtained from the data source.</p>
114     */
115     class ODataSource
116     {
117     private:
118         ODataSourceImpl*    m_pImpl;
119 
120     public:
121         // ----------------------------------------------------------------
122         // - ctor/dtor/assignment
123         // ----------------------------------------------------------------
124         /// constructs an object which is initially invalid
125         ODataSource(
126             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
127         );
128 
129         /// copy ctor
130         ODataSource( const ODataSource& _rSource );
131 
132         /// dtor
133         ~ODataSource( );
134 
135         /// assignment
136         ODataSource& operator=( const ODataSource& _rSource );
137 
138         // ----------------------------------------------------------------
139         /// checks whether or not the object represents a valid data source
140         sal_Bool    isValid() const SAL_THROW (( ));
141 
142         // ----------------------------------------------------------------
143         /// removes the data source represented by the object from the data source context
144         void        remove() SAL_THROW (( ));
145             // TODO: put this into the context class
146 
147         /// returns the name of the data source
148         ::rtl::OUString
149                     getName() const SAL_THROW (( ));
150 
151         /// renames the data source
152         sal_Bool    rename( const ::rtl::OUString& _rName ) SAL_THROW (( ));
153             // TODO: put this into the context class
154 
155         // ----------------------------------------------------------------
156         // - connection handling
157         // ----------------------------------------------------------------
158         /** connects to the data source represented by this object
159             @param _pMessageParent
160                 the window to use as parent for any error messages. If this is <NULL/>, no messages are displayed
161                 at all.
162             @see isConnected
163         */
164         sal_Bool    connect( Window* _pMessageParent ) SAL_THROW (( ));
165 
166         /// returns <TRUE/> if the object has a valid connection, obtained from it's data source
167         sal_Bool    isConnected( ) const SAL_THROW (( ));
168 
169         /// disconnects from the data source (i.e. disposes the UNO connection hold internally)
170         void        disconnect( ) SAL_THROW (( ));
171 
172         /// stores the database file
173         void        store() SAL_THROW (( ));
174 
175         /// register the data source under the given name in the configuration
176         void        registerDataSource( const ::rtl::OUString& _sRegisteredDataSourceName )  SAL_THROW (( ));
177 
178         // ----------------------------------------------------------------
179         /** retrieves the tables names from the connection
180             <p>to be called when <method>isConnection</method> returns <TRUE/> only</p>
181         */
182         const StringBag&    getTableNames() const SAL_THROW (( ));
183 
184         /** determines whether a given table exists
185         */
186         bool    hasTable( const ::rtl::OUString& _rTableName ) const;
187 
188         /// return the intern data source object
189         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getDataSource() const SAL_THROW (( ));
190 
191 
192         // ----------------------------------------------------------------
193         /** set a new data source.
194             <p>Available to selected clients only</p>
195         */
196         void        setDataSource(
197             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxDS
198             ,const ::rtl::OUString& _sName
199             ,PackageAccessControl
200         );
201 
202     private:
203         ODataSource( ); // never implemented
204     };
205 
206 //.........................................................................
207 }   // namespace abp
208 //.........................................................................
209 
210 #endif // EXTENSIONS_ABP_DATASOURCEHANDLING_HXX
211 
212