1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
5 *
6 * OpenOffice.org - a multi-platform office productivity suite
7 *
8 * This file is part of OpenOffice.org.
9 *
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
13 *
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org.  If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
24 ************************************************************************/
25 
26 #ifndef SUBCOMPONENTRECOVERY_HXX
27 #define SUBCOMPONENTRECOVERY_HXX
28 
29 #include "subcomponents.hxx"
30 
31 /** === begin UNO includes === **/
32 #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
33 #include <com/sun/star/embed/XStorage.hpp>
34 /** === end UNO includes === **/
35 
36 #include <comphelper/componentcontext.hxx>
37 
38 //........................................................................
39 namespace dbaccess
40 {
41 //........................................................................
42 
43 	//====================================================================
44 	//= SubComponentRecovery
45 	//====================================================================
46     class DBACCESS_DLLPRIVATE SubComponentRecovery
47     {
48     public:
49         SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rController,
50                 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& i_rComponent )
51             :m_rContext( i_rContext )
52             ,m_xDocumentUI( i_rController, ::com::sun::star::uno::UNO_SET_THROW )
53             ,m_xComponent( i_rComponent )
54             ,m_eType( UNKNOWN )
55             ,m_aCompDesc()
56         {
57             impl_identifyComponent_throw();
58         }
59 
60         SubComponentRecovery( const ::comphelper::ComponentContext& i_rContext, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >& i_rController,
61                 const SubComponentType i_eType )
62             :m_rContext( i_rContext )
63             ,m_xDocumentUI( i_rController, ::com::sun::star::uno::UNO_SET_THROW )
64             ,m_xComponent()
65             ,m_eType( i_eType )
66             ,m_aCompDesc()
67         {
68         }
69 
70         // only to be used after being constructed with a component
71         void    saveToRecoveryStorage(
72                     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage,
73                     MapCompTypeToCompDescs& io_mapCompDescs
74                 );
75 
76         // only to be used after being constructed with a type
77         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
78                 recoverFromStorage(
79                     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage,
80                     const ::rtl::OUString& i_rComponentName,
81                     const bool i_bForEditing
82                 );
83 
84         static const ::rtl::OUString getComponentsStorageName( const SubComponentType i_eType );
85 
86     private:
87         void    impl_saveSubDocument_throw(
88                     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rObjectStorage
89                 );
90 
91         void    impl_saveQueryDesign_throw(
92                     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rObjectStorage
93                 );
94 
95         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
96                 impl_recoverSubDocument_throw(
97                     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage,
98                     const ::rtl::OUString& i_rComponentName,
99                     const bool i_bForEditing
100                 );
101 
102         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
103                 impl_recoverQueryDesign_throw(
104                     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& i_rRecoveryStorage,
105                     const ::rtl::OUString& i_rComponentName,
106                     const bool i_bForEditing
107                 );
108 
109         void    impl_identifyComponent_throw();
110 
111     private:
112         const ::comphelper::ComponentContext&   m_rContext;
113         ::com::sun::star::uno::Reference< ::com::sun::star::sdb::application::XDatabaseDocumentUI >
114                                                 m_xDocumentUI;
115         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
116                                                 m_xComponent;
117         SubComponentType                        m_eType;
118         SubComponentDescriptor                  m_aCompDesc;
119     };
120 
121 
122 //........................................................................
123 } // namespace dbaccess
124 //........................................................................
125 
126 #endif // SUBCOMPONENTRECOVERY_HXX
127