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 : virtual ~RootStorageWrapper() {}
56 :
57 : // XTransactedObject
58 : virtual void SAL_CALL commit() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
59 : {
60 : m_xRootCommit->commit();
61 : }
62 :
63 : virtual void SAL_CALL revert() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
64 : {
65 : m_xRootCommit->revert();
66 : }
67 :
68 : private:
69 : Reference< XTransactedObject > m_xRootCommit;
70 : };
71 :
72 : //*****************************************************************************************************************
73 : // XInterface, XTypeProvider, XServiceInfo
74 : //*****************************************************************************************************************
75 229403 : 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 3 : 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 1410 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE_2( ModuleUIConfigurationManagerSupplier ,
91 : ::cppu::OWeakObject ,
92 : DECLARE_ASCII("com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ),
93 : IMPLEMENTATIONNAME_MODULEUICONFIGURATIONMANAGERSUPPLIER
94 : )
95 :
96 60 : DEFINE_INIT_SERVICE ( ModuleUIConfigurationManagerSupplier, {} )
97 :
98 :
99 :
100 60 : ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XComponentContext >& xContext ) :
101 60 : ThreadHelpBase( &Application::GetSolarMutex() )
102 : , m_bDisposed( false )
103 : //TODO_AS , m_bInit( false )
104 : , m_xModuleMgr( ModuleManager::create( xContext ) )
105 : , m_xContext( xContext )
106 120 : , 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 60 : Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
113 120 : const Sequence< OUString > aNameSeq = xNameAccess->getElementNames();
114 60 : const OUString* pNameSeq = aNameSeq.getConstArray();
115 1362 : for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
116 1362 : m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type( pNameSeq[n], Reference< XUIConfigurationManager >() ));
117 : }
118 0 : catch(...)
119 : {
120 : }
121 60 : }
122 :
123 177 : ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
124 : {
125 59 : m_xUserRootCommit.clear();
126 :
127 : // dispose all our module user interface configuration managers
128 59 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
129 1398 : while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
130 : {
131 1280 : Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
132 1280 : if ( xComponent.is() )
133 76 : xComponent->dispose();
134 1280 : ++pIter;
135 1280 : }
136 118 : }
137 :
138 : // XComponent
139 59 : void SAL_CALL ModuleUIConfigurationManagerSupplier::dispose()
140 : throw ( RuntimeException )
141 : {
142 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::dispose" );
143 59 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
144 :
145 118 : css::lang::EventObject aEvent( xThis );
146 59 : m_aListenerContainer.disposeAndClear( aEvent );
147 :
148 : {
149 59 : ResetableGuard aGuard( m_aLock );
150 59 : m_bDisposed = true;
151 59 : }
152 59 : }
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 32279 : Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const OUString& ModuleIdentifier )
179 : throw ( NoSuchElementException, RuntimeException)
180 : {
181 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::getUIConfigurationManager" );
182 32279 : ResetableGuard aGuard( m_aLock );
183 :
184 : /* SAFE AREA ----------------------------------------------------------------------------------------------- */
185 32279 : if ( m_bDisposed )
186 0 : throw DisposedException();
187 :
188 32279 : ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( ModuleIdentifier );
189 32279 : if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
190 4 : throw NoSuchElementException();
191 : //TODO_AS impl_initStorages();
192 :
193 : // Create instance on demand
194 32275 : if ( !pIter->second.is() )
195 : {
196 77 : OUString sShort;
197 : try
198 : {
199 77 : Sequence< PropertyValue > lProps;
200 154 : Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
201 77 : xCont->getByName(ModuleIdentifier) >>= lProps;
202 693 : for (sal_Int32 i=0; i<lProps.getLength(); ++i)
203 : {
204 693 : if ( lProps[i].Name == "ooSetupFactoryShortName" )
205 : {
206 77 : lProps[i].Value >>= sShort;
207 77 : break;
208 : }
209 77 : }
210 : }
211 0 : catch( const Exception& )
212 : {
213 0 : sShort = OUString();
214 : }
215 :
216 77 : if (sShort.isEmpty())
217 0 : throw NoSuchElementException();
218 154 : PropertyValue aArg;
219 154 : Sequence< Any > aArgs( 2 );
220 77 : aArg.Name = OUString( "ModuleShortName" );
221 77 : aArg.Value <<= sShort;
222 77 : aArgs[0] <<= aArg;
223 77 : aArg.Name = OUString( "ModuleIdentifier" );
224 77 : aArg.Value <<= ModuleIdentifier;
225 77 : aArgs[1] <<= aArg;
226 :
227 154 : pIter->second.set( m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(SERVICENAME_MODULEUICONFIGURATIONMANAGER, aArgs, m_xContext ),UNO_QUERY );
228 : }
229 :
230 32279 : return pIter->second;
231 : }
232 :
233 402 : } // namespace framework
234 :
235 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|