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 24130 : 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 836 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ModuleUIConfigurationManagerSupplier ,
91 : ::cppu::OWeakObject ,
92 : DECLARE_ASCII("com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ),
93 : IMPLEMENTATIONNAME_MODULEUICONFIGURATIONMANAGERSUPPLIER
94 : )
95 :
96 46 : DEFINE_INIT_SERVICE ( ModuleUIConfigurationManagerSupplier, {} )
97 :
98 :
99 :
100 46 : ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XMultiServiceFactory >& xServiceManager ) :
101 46 : 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 92 : , 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 46 : Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
113 46 : const Sequence< ::rtl::OUString > aNameSeq = xNameAccess->getElementNames();
114 46 : const ::rtl::OUString* pNameSeq = aNameSeq.getConstArray();
115 980 : for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
116 980 : m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type( pNameSeq[n], Reference< XUIConfigurationManager >() ));
117 : }
118 0 : catch(...)
119 : {
120 : }
121 46 : }
122 :
123 138 : ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
124 : {
125 46 : m_xUserRootCommit.clear();
126 :
127 : // dispose all our module user interface configuration managers
128 46 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
129 1026 : while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
130 : {
131 934 : Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
132 934 : if ( xComponent.is() )
133 44 : xComponent->dispose();
134 934 : ++pIter;
135 934 : }
136 92 : }
137 :
138 : // XComponent
139 46 : void SAL_CALL ModuleUIConfigurationManagerSupplier::dispose()
140 : throw ( RuntimeException )
141 : {
142 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::dispose" );
143 46 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
144 :
145 46 : css::lang::EventObject aEvent( xThis );
146 46 : m_aListenerContainer.disposeAndClear( aEvent );
147 :
148 : {
149 46 : ResetableGuard aGuard( m_aLock );
150 46 : m_bDisposed = true;
151 46 : }
152 46 : }
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 3186 : 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 3186 : ResetableGuard aGuard( m_aLock );
183 :
184 : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
185 3186 : if ( m_bDisposed )
186 0 : throw DisposedException();
187 :
188 3186 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( ModuleIdentifier );
189 3186 : if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
190 8 : throw NoSuchElementException();
191 : //TODO_AS impl_initStorages();
192 :
193 : // Create instance on demand
194 3178 : if ( !pIter->second.is() )
195 : {
196 44 : ::rtl::OUString sShort;
197 : try
198 : {
199 44 : Sequence< PropertyValue > lProps;
200 44 : Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
201 44 : xCont->getByName(ModuleIdentifier) >>= lProps;
202 264 : for (sal_Int32 i=0; i<lProps.getLength(); ++i)
203 : {
204 264 : if ( lProps[i].Name == "ooSetupFactoryShortName" )
205 : {
206 44 : lProps[i].Value >>= sShort;
207 44 : break;
208 : }
209 44 : }
210 : }
211 0 : catch( const Exception& )
212 : {
213 0 : sShort = ::rtl::OUString();
214 : }
215 :
216 44 : if (sShort.isEmpty())
217 0 : throw NoSuchElementException();
218 44 : PropertyValue aArg;
219 44 : Sequence< Any > aArgs( 2 );
220 44 : aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleShortName" ));
221 44 : aArg.Value <<= sShort;
222 44 : aArgs[0] <<= aArg;
223 44 : aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ));
224 44 : aArg.Value <<= ModuleIdentifier;
225 44 : aArgs[1] <<= aArg;
226 :
227 44 : pIter->second.set( m_xServiceManager->createInstanceWithArguments(SERVICENAME_MODULEUICONFIGURATIONMANAGER, aArgs ),UNO_QUERY );
228 : }
229 :
230 3186 : return pIter->second;
231 : }
232 :
233 : } // namespace framework
234 :
235 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|