1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_unotools.hxx" 30 #include <unotools/componentresmodule.hxx> 31 32 /** === begin UNO includes === **/ 33 /** === end UNO includes === **/ 34 #include <tools/resmgr.hxx> 35 #include <osl/diagnose.h> 36 37 //........................................................................ 38 namespace utl 39 { 40 //........................................................................ 41 42 //==================================================================== 43 //= OComponentResModuleImpl 44 //==================================================================== 45 /** PIMPL-class for OComponentResourceModule 46 47 not threadsafe! 48 */ 49 class OComponentResModuleImpl 50 { 51 private: 52 ResMgr* m_pRessources; 53 bool m_bInitialized; 54 ::rtl::OString m_sResFilePrefix; 55 56 public: 57 OComponentResModuleImpl( const ::rtl::OString& _rResFilePrefix ) 58 :m_pRessources( NULL ) 59 ,m_bInitialized( false ) 60 ,m_sResFilePrefix( _rResFilePrefix ) 61 { 62 } 63 64 ~OComponentResModuleImpl() 65 { 66 freeResManager(); 67 } 68 69 /** releases our resource manager 70 */ 71 void freeResManager(); 72 73 /** retrieves our resource manager 74 */ 75 ResMgr* getResManager(); 76 77 private: 78 OComponentResModuleImpl(); // never implemented 79 OComponentResModuleImpl( const OComponentResModuleImpl& ); // never implemented 80 OComponentResModuleImpl& operator=( const OComponentResModuleImpl& ); // never implemented 81 }; 82 83 //-------------------------------------------------------------------- 84 void OComponentResModuleImpl::freeResManager() 85 { 86 delete m_pRessources, m_pRessources = NULL; 87 m_bInitialized = false; 88 } 89 90 //-------------------------------------------------------------------- 91 ResMgr* OComponentResModuleImpl::getResManager() 92 { 93 if ( !m_pRessources && !m_bInitialized ) 94 { 95 // create a manager with a fixed prefix 96 ByteString aMgrName = m_sResFilePrefix; 97 98 m_pRessources = ResMgr::CreateResMgr( aMgrName.GetBuffer() ); 99 OSL_ENSURE( m_pRessources, 100 ( ByteString( "OModuleImpl::getResManager: could not create the resource manager (file name: " ) 101 += aMgrName 102 += ByteString( ")!" ) ).GetBuffer() ); 103 104 m_bInitialized = sal_True; 105 } 106 return m_pRessources; 107 } 108 109 //==================================================================== 110 //= OComponentResourceModule 111 //==================================================================== 112 //-------------------------------------------------------------------- 113 OComponentResourceModule::OComponentResourceModule( const ::rtl::OString& _rResFilePrefix ) 114 :BaseClass() 115 ,m_pImpl( new OComponentResModuleImpl( _rResFilePrefix ) ) 116 { 117 } 118 119 //-------------------------------------------------------------------- 120 OComponentResourceModule::~OComponentResourceModule() 121 { 122 } 123 124 //------------------------------------------------------------------------- 125 ResMgr* OComponentResourceModule::getResManager() 126 { 127 ::osl::MutexGuard aGuard( m_aMutex ); 128 return m_pImpl->getResManager(); 129 } 130 131 //-------------------------------------------------------------------------- 132 void OComponentResourceModule::onFirstClient() 133 { 134 BaseClass::onFirstClient(); 135 } 136 137 //-------------------------------------------------------------------------- 138 void OComponentResourceModule::onLastClient() 139 { 140 m_pImpl->freeResManager(); 141 BaseClass::onLastClient(); 142 } 143 144 //........................................................................ 145 } // namespace utl 146 //........................................................................ 147