Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <uiconfiguration/moduleuicfgsupplier.hxx>
30 : : #include <threadhelp/resetableguard.hxx>
31 : : #include <services.h>
32 : :
33 : : #include <com/sun/star/lang/DisposedException.hpp>
34 : : #include <com/sun/star/beans/XPropertySet.hpp>
35 : : #include <com/sun/star/container/XNameAccess.hpp>
36 : : #include <com/sun/star/embed/ElementModes.hpp>
37 : : #include <com/sun/star/io/XOutputStream.hpp>
38 : : #include <com/sun/star/io/XInputStream.hpp>
39 : : #include <com/sun/star/io/XSeekable.hpp>
40 : : #include <com/sun/star/embed/XPackageStructureCreator.hpp>
41 : :
42 : : #include <rtl/logfile.hxx>
43 : : #include <cppuhelper/implbase1.hxx>
44 : : #include <vcl/svapp.hxx>
45 : :
46 : : using namespace com::sun::star::uno;
47 : : using namespace com::sun::star::io;
48 : : using namespace com::sun::star::lang;
49 : : using namespace com::sun::star::container;
50 : : using namespace com::sun::star::beans;
51 : : using namespace com::sun::star::embed;
52 : : using namespace ::com::sun::star::ui;
53 : : using namespace ::com::sun::star::frame;
54 : :
55 : : namespace framework
56 : : {
57 : :
58 : : class RootStorageWrapper : public ::cppu::WeakImplHelper1< com::sun::star::embed::XTransactedObject >
59 : : {
60 : : public:
61 : : // XInterface, XTypeProvider
62 : : RootStorageWrapper( const Reference< XTransactedObject >& xRootCommit ) : m_xRootCommit( xRootCommit ) {}
63 [ # # ]: 0 : virtual ~RootStorageWrapper() {}
64 : :
65 : : // XTransactedObject
66 : 0 : virtual void SAL_CALL commit() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
67 : : {
68 : 0 : m_xRootCommit->commit();
69 : 0 : }
70 : :
71 : 0 : virtual void SAL_CALL revert() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
72 : : {
73 : 0 : m_xRootCommit->revert();
74 : 0 : }
75 : :
76 : : private:
77 : : Reference< XTransactedObject > m_xRootCommit;
78 : : };
79 : :
80 : : //*****************************************************************************************************************
81 : : // XInterface, XTypeProvider, XServiceInfo
82 : : //*****************************************************************************************************************
83 [ + + ][ + - ]: 293741 : DEFINE_XINTERFACE_4 ( ModuleUIConfigurationManagerSupplier ,
84 : : OWeakObject ,
85 : : DIRECT_INTERFACE( css::lang::XTypeProvider ),
86 : : DIRECT_INTERFACE( css::lang::XServiceInfo ),
87 : : DIRECT_INTERFACE( css::lang::XComponent ),
88 : : DIRECT_INTERFACE( ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier )
89 : : )
90 : :
91 [ + + ][ + - ]: 6 : DEFINE_XTYPEPROVIDER_4 ( ModuleUIConfigurationManagerSupplier ,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
92 : : css::lang::XTypeProvider ,
93 : : css::lang::XServiceInfo ,
94 : : css::lang::XComponent ,
95 : : ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier
96 : : )
97 : :
98 [ + - ][ + - ]: 2354 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ModuleUIConfigurationManagerSupplier ,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
99 : : ::cppu::OWeakObject ,
100 : : SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ,
101 : : IMPLEMENTATIONNAME_MODULEUICONFIGURATIONMANAGERSUPPLIER
102 : : )
103 : :
104 : 113 : DEFINE_INIT_SERVICE ( ModuleUIConfigurationManagerSupplier, {} )
105 : :
106 : :
107 : :
108 : 113 : ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XMultiServiceFactory >& xServiceManager ) :
109 [ + - ]: 113 : ThreadHelpBase( &Application::GetSolarMutex() )
110 : : , m_bDisposed( false )
111 : : //TODO_AS , m_bInit( false )
112 [ + - ]: 113 : , m_xModuleMgr( Reference< XModuleManager >( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ))
113 : : , m_xServiceManager( xServiceManager )
114 [ + - ][ + - ]: 339 : , m_aListenerContainer( m_aLock.getShareableOslMutex() )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
115 : : {
116 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier" );
117 : : try
118 : : {
119 : : // Retrieve known modules and insert them into our boost::unordered_map to speed-up access time.
120 [ + - ]: 113 : Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
121 [ + - ][ + - ]: 113 : const Sequence< ::rtl::OUString > aNameSeq = xNameAccess->getElementNames();
122 : 113 : const ::rtl::OUString* pNameSeq = aNameSeq.getConstArray();
123 [ + + ]: 2548 : for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
124 [ + - ][ + - ]: 2548 : m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type( pNameSeq[n], Reference< XUIConfigurationManager >() ));
[ + - ][ + - ]
125 : : }
126 [ # # ]: 0 : catch(...)
127 : : {
128 : : }
129 : 113 : }
130 : :
131 [ + - ][ + - ]: 113 : ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
[ + - ][ + - ]
132 : : {
133 : 113 : m_xUserRootCommit.clear();
134 : :
135 : : // dispose all our module user interface configuration managers
136 [ + - ]: 113 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
137 [ + - ][ + + ]: 2548 : while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
138 : : {
139 [ + - ][ + - ]: 2435 : Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
140 [ + + ]: 2435 : if ( xComponent.is() )
141 [ + - ][ + - ]: 149 : xComponent->dispose();
142 : 2435 : ++pIter;
143 : 2435 : }
144 [ - + ]: 226 : }
145 : :
146 : : // XComponent
147 : 113 : void SAL_CALL ModuleUIConfigurationManagerSupplier::dispose()
148 : : throw ( RuntimeException )
149 : : {
150 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::dispose" );
151 [ + - ]: 113 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
152 : :
153 [ + - ]: 113 : css::lang::EventObject aEvent( xThis );
154 [ + - ]: 113 : m_aListenerContainer.disposeAndClear( aEvent );
155 : :
156 : : {
157 [ + - ]: 113 : ResetableGuard aGuard( m_aLock );
158 [ + - ]: 113 : m_bDisposed = true;
159 [ + - ]: 113 : }
160 : 113 : }
161 : :
162 : 0 : void SAL_CALL ModuleUIConfigurationManagerSupplier::addEventListener( const Reference< XEventListener >& xListener )
163 : : throw ( RuntimeException )
164 : : {
165 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::addEventListener" );
166 : : {
167 [ # # ]: 0 : ResetableGuard aGuard( m_aLock );
168 : :
169 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
170 [ # # ]: 0 : if ( m_bDisposed )
171 [ # # ][ # # ]: 0 : throw DisposedException();
172 : : }
173 : :
174 : 0 : m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
175 : 0 : }
176 : :
177 : 0 : void SAL_CALL ModuleUIConfigurationManagerSupplier::removeEventListener( const Reference< XEventListener >& xListener )
178 : : throw ( RuntimeException )
179 : : {
180 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::removeEventListener" );
181 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
182 : 0 : m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
183 : 0 : }
184 : :
185 : : // XModuleUIConfigurationManagerSupplier
186 : 57554 : Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const ::rtl::OUString& ModuleIdentifier )
187 : : throw ( NoSuchElementException, RuntimeException)
188 : : {
189 : : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::getUIConfigurationManager" );
190 [ + - ]: 57554 : ResetableGuard aGuard( m_aLock );
191 : :
192 : : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
193 [ - + ]: 57554 : if ( m_bDisposed )
194 [ # # ]: 0 : throw DisposedException();
195 : :
196 [ + - ]: 57554 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( ModuleIdentifier );
197 [ + - ][ - + ]: 57554 : if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
198 [ # # ]: 0 : throw NoSuchElementException();
199 : : //TODO_AS impl_initStorages();
200 : :
201 : : // Create instance on demand
202 [ + - ][ + + ]: 57554 : if ( !pIter->second.is() )
203 : : {
204 : 149 : ::rtl::OUString sShort;
205 : : try
206 : : {
207 [ + - ]: 149 : Sequence< PropertyValue > lProps;
208 [ + - ]: 149 : Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
209 [ + - ][ + - ]: 149 : xCont->getByName(ModuleIdentifier) >>= lProps;
[ + - ]
210 [ + - ]: 894 : for (sal_Int32 i=0; i<lProps.getLength(); ++i)
211 : : {
212 [ + - ][ + + ]: 894 : if ( lProps[i].Name == "ooSetupFactoryShortName" )
213 : : {
214 [ + - ]: 149 : lProps[i].Value >>= sShort;
215 : 149 : break;
216 : : }
217 [ + - ][ # # ]: 149 : }
218 : : }
219 [ # # ]: 0 : catch( const Exception& )
220 : : {
221 : 0 : sShort = ::rtl::OUString();
222 : : }
223 : :
224 [ - + ]: 149 : if (sShort.isEmpty())
225 [ # # ]: 0 : throw NoSuchElementException();
226 : 149 : PropertyValue aArg;
227 [ + - ]: 149 : Sequence< Any > aArgs( 2 );
228 [ + - ]: 149 : aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleShortName" ));
229 [ + - ]: 149 : aArg.Value <<= sShort;
230 [ + - ][ + - ]: 149 : aArgs[0] <<= aArg;
231 [ + - ]: 149 : aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ));
232 [ + - ]: 149 : aArg.Value <<= ModuleIdentifier;
233 [ + - ][ + - ]: 149 : aArgs[1] <<= aArg;
234 : :
235 [ + - ][ + - ]: 149 : pIter->second.set( m_xServiceManager->createInstanceWithArguments(SERVICENAME_MODULEUICONFIGURATIONMANAGER, aArgs ),UNO_QUERY );
[ + - ][ + - ]
[ + - ][ + - ]
236 : : }
237 : :
238 [ + - ][ + - ]: 57554 : return pIter->second;
239 : : }
240 : :
241 : : } // namespace framework
242 : :
243 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|