1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: componentresmodule.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_unotools.hxx"
33 #include <unotools/componentresmodule.hxx>
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
37 #include <tools/resmgr.hxx>
38 #include <osl/diagnose.h>
40 //........................................................................
43 //........................................................................
45 //====================================================================
46 //= OComponentResModuleImpl
47 //====================================================================
48 /** PIMPL-class for OComponentResourceModule
52 class OComponentResModuleImpl
55 ResMgr
* m_pRessources
;
57 ::rtl::OString m_sResFilePrefix
;
60 OComponentResModuleImpl( const ::rtl::OString
& _rResFilePrefix
)
61 :m_pRessources( NULL
)
62 ,m_bInitialized( false )
63 ,m_sResFilePrefix( _rResFilePrefix
)
67 ~OComponentResModuleImpl()
72 /** releases our resource manager
74 void freeResManager();
76 /** retrieves our resource manager
78 ResMgr
* getResManager();
81 OComponentResModuleImpl(); // never implemented
82 OComponentResModuleImpl( const OComponentResModuleImpl
& ); // never implemented
83 OComponentResModuleImpl
& operator=( const OComponentResModuleImpl
& ); // never implemented
86 //--------------------------------------------------------------------
87 void OComponentResModuleImpl::freeResManager()
89 delete m_pRessources
, m_pRessources
= NULL
;
90 m_bInitialized
= false;
93 //--------------------------------------------------------------------
94 ResMgr
* OComponentResModuleImpl::getResManager()
96 if ( !m_pRessources
&& !m_bInitialized
)
98 // create a manager with a fixed prefix
99 ByteString aMgrName
= m_sResFilePrefix
;
101 m_pRessources
= ResMgr::CreateResMgr( aMgrName
.GetBuffer() );
102 OSL_ENSURE( m_pRessources
,
103 ( ByteString( "OModuleImpl::getResManager: could not create the resource manager (file name: " )
105 += ByteString( ")!" ) ).GetBuffer() );
107 m_bInitialized
= sal_True
;
109 return m_pRessources
;
112 //====================================================================
113 //= OComponentResourceModule
114 //====================================================================
115 //--------------------------------------------------------------------
116 OComponentResourceModule::OComponentResourceModule( const ::rtl::OString
& _rResFilePrefix
)
118 ,m_pImpl( new OComponentResModuleImpl( _rResFilePrefix
) )
122 //--------------------------------------------------------------------
123 OComponentResourceModule::~OComponentResourceModule()
127 //-------------------------------------------------------------------------
128 ResMgr
* OComponentResourceModule::getResManager()
130 ::osl::MutexGuard
aGuard( m_aMutex
);
131 return m_pImpl
->getResManager();
134 //--------------------------------------------------------------------------
135 void OComponentResourceModule::onFirstClient()
137 BaseClass::onFirstClient();
140 //--------------------------------------------------------------------------
141 void OComponentResourceModule::onLastClient()
143 m_pImpl
->freeResManager();
144 BaseClass::onLastClient();
147 //........................................................................
149 //........................................................................