Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <uiconfiguration/moduleuicfgsupplier.hxx>
21 : #include <threadhelp/resetableguard.hxx>
22 : #include <services.h>
23 :
24 : #include <com/sun/star/lang/DisposedException.hpp>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/container/XNameAccess.hpp>
27 : #include <com/sun/star/embed/ElementModes.hpp>
28 : #include <com/sun/star/frame/ModuleManager.hpp>
29 : #include <com/sun/star/io/XOutputStream.hpp>
30 : #include <com/sun/star/io/XInputStream.hpp>
31 : #include <com/sun/star/io/XSeekable.hpp>
32 : #include <com/sun/star/embed/XPackageStructureCreator.hpp>
33 :
34 : #include <rtl/logfile.hxx>
35 : #include <cppuhelper/implbase1.hxx>
36 : #include <vcl/svapp.hxx>
37 :
38 : using namespace com::sun::star::uno;
39 : using namespace com::sun::star::io;
40 : using namespace com::sun::star::lang;
41 : using namespace com::sun::star::container;
42 : using namespace com::sun::star::beans;
43 : using namespace com::sun::star::embed;
44 : using namespace ::com::sun::star::ui;
45 : using namespace ::com::sun::star::frame;
46 :
47 : namespace framework
48 : {
49 :
50 : class RootStorageWrapper : public ::cppu::WeakImplHelper1< com::sun::star::embed::XTransactedObject >
51 : {
52 : public:
53 : // XInterface, XTypeProvider
54 : RootStorageWrapper( const Reference< XTransactedObject >& xRootCommit ) : m_xRootCommit( xRootCommit ) {}
55 0 : virtual ~RootStorageWrapper() {}
56 :
57 : // XTransactedObject
58 0 : virtual void SAL_CALL commit() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
59 : {
60 0 : m_xRootCommit->commit();
61 0 : }
62 :
63 0 : virtual void SAL_CALL revert() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
64 : {
65 0 : m_xRootCommit->revert();
66 0 : }
67 :
68 : private:
69 : Reference< XTransactedObject > m_xRootCommit;
70 : };
71 :
72 : //*****************************************************************************************************************
73 : // XInterface, XTypeProvider, XServiceInfo
74 : //*****************************************************************************************************************
75 10734 : DEFINE_XINTERFACE_4 ( ModuleUIConfigurationManagerSupplier ,
76 : OWeakObject ,
77 : DIRECT_INTERFACE( css::lang::XTypeProvider ),
78 : DIRECT_INTERFACE( css::lang::XServiceInfo ),
79 : DIRECT_INTERFACE( css::lang::XComponent ),
80 : DIRECT_INTERFACE( ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier )
81 : )
82 :
83 0 : DEFINE_XTYPEPROVIDER_4 ( ModuleUIConfigurationManagerSupplier ,
84 : css::lang::XTypeProvider ,
85 : css::lang::XServiceInfo ,
86 : css::lang::XComponent ,
87 : ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier
88 : )
89 :
90 166 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ModuleUIConfigurationManagerSupplier ,
91 : ::cppu::OWeakObject ,
92 : DECLARE_ASCII("com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ),
93 : IMPLEMENTATIONNAME_MODULEUICONFIGURATIONMANAGERSUPPLIER
94 : )
95 :
96 9 : DEFINE_INIT_SERVICE ( ModuleUIConfigurationManagerSupplier, {} )
97 :
98 :
99 :
100 9 : ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XMultiServiceFactory >& xServiceManager ) :
101 9 : ThreadHelpBase( &Application::GetSolarMutex() )
102 : , m_bDisposed( false )
103 : //TODO_AS , m_bInit( false )
104 : , m_xModuleMgr( ModuleManager::create( comphelper::getComponentContext(xServiceManager) ) )
105 : , m_xServiceManager( xServiceManager )
106 18 : , m_aListenerContainer( m_aLock.getShareableOslMutex() )
107 : {
108 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier" );
109 : try
110 : {
111 : // Retrieve known modules and insert them into our boost::unordered_map to speed-up access time.
112 9 : Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
113 9 : const Sequence< ::rtl::OUString > aNameSeq = xNameAccess->getElementNames();
114 9 : const ::rtl::OUString* pNameSeq = aNameSeq.getConstArray();
115 181 : for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
116 181 : m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type( pNameSeq[n], Reference< XUIConfigurationManager >() ));
117 : }
118 0 : catch(...)
119 : {
120 : }
121 9 : }
122 :
123 27 : ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
124 : {
125 9 : m_xUserRootCommit.clear();
126 :
127 : // dispose all our module user interface configuration managers
128 9 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
129 190 : while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
130 : {
131 172 : Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
132 172 : if ( xComponent.is() )
133 8 : xComponent->dispose();
134 172 : ++pIter;
135 172 : }
136 18 : }
137 :
138 : // XComponent
139 9 : void SAL_CALL ModuleUIConfigurationManagerSupplier::dispose()
140 : throw ( RuntimeException )
141 : {
142 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::dispose" );
143 9 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
144 :
145 9 : css::lang::EventObject aEvent( xThis );
146 9 : m_aListenerContainer.disposeAndClear( aEvent );
147 :
148 : {
149 9 : ResetableGuard aGuard( m_aLock );
150 9 : m_bDisposed = true;
151 9 : }
152 9 : }
153 :
154 0 : void SAL_CALL ModuleUIConfigurationManagerSupplier::addEventListener( const Reference< XEventListener >& xListener )
155 : throw ( RuntimeException )
156 : {
157 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::addEventListener" );
158 : {
159 0 : ResetableGuard aGuard( m_aLock );
160 :
161 : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
162 0 : if ( m_bDisposed )
163 0 : throw DisposedException();
164 : }
165 :
166 0 : m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
167 0 : }
168 :
169 0 : void SAL_CALL ModuleUIConfigurationManagerSupplier::removeEventListener( const Reference< XEventListener >& xListener )
170 : throw ( RuntimeException )
171 : {
172 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::removeEventListener" );
173 : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
174 0 : m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
175 0 : }
176 :
177 : // XModuleUIConfigurationManagerSupplier
178 1443 : Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const ::rtl::OUString& ModuleIdentifier )
179 : throw ( NoSuchElementException, RuntimeException)
180 : {
181 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::getUIConfigurationManager" );
182 1443 : ResetableGuard aGuard( m_aLock );
183 :
184 : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
185 1443 : if ( m_bDisposed )
186 0 : throw DisposedException();
187 :
188 1443 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( ModuleIdentifier );
189 1443 : if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
190 4 : throw NoSuchElementException();
191 : //TODO_AS impl_initStorages();
192 :
193 : // Create instance on demand
194 1439 : if ( !pIter->second.is() )
195 : {
196 8 : ::rtl::OUString sShort;
197 : try
198 : {
199 8 : Sequence< PropertyValue > lProps;
200 8 : Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
201 8 : xCont->getByName(ModuleIdentifier) >>= lProps;
202 48 : for (sal_Int32 i=0; i<lProps.getLength(); ++i)
203 : {
204 48 : if ( lProps[i].Name == "ooSetupFactoryShortName" )
205 : {
206 8 : lProps[i].Value >>= sShort;
207 8 : break;
208 : }
209 8 : }
210 : }
211 0 : catch( const Exception& )
212 : {
213 0 : sShort = ::rtl::OUString();
214 : }
215 :
216 8 : if (sShort.isEmpty())
217 0 : throw NoSuchElementException();
218 8 : PropertyValue aArg;
219 8 : Sequence< Any > aArgs( 2 );
220 8 : aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleShortName" ));
221 8 : aArg.Value <<= sShort;
222 8 : aArgs[0] <<= aArg;
223 8 : aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ));
224 8 : aArg.Value <<= ModuleIdentifier;
225 8 : aArgs[1] <<= aArg;
226 :
227 8 : pIter->second.set( m_xServiceManager->createInstanceWithArguments(SERVICENAME_MODULEUICONFIGURATIONMANAGER, aArgs ),UNO_QUERY );
228 : }
229 :
230 1443 : return pIter->second;
231 : }
232 :
233 : } // namespace framework
234 :
235 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|