1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_unotools.hxx" 30*cdf0e10cSrcweir #include <unotools/configvaluecontainer.hxx> 31*cdf0e10cSrcweir #include <unotools/confignode.hxx> 32*cdf0e10cSrcweir #include <tools/debug.hxx> 33*cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 34*cdf0e10cSrcweir #include <uno/data.h> 35*cdf0e10cSrcweir #include <algorithm> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #ifdef DBG_UTIL 38*cdf0e10cSrcweir #include <rtl/strbuf.hxx> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //......................................................................... 42*cdf0e10cSrcweir namespace utl 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir //......................................................................... 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 47*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //===================================================================== 50*cdf0e10cSrcweir //= NodeValueAccessor 51*cdf0e10cSrcweir //===================================================================== 52*cdf0e10cSrcweir enum LocationType 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir ltSimplyObjectInstance, 55*cdf0e10cSrcweir ltAnyInstance, 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir ltUnbound 58*cdf0e10cSrcweir }; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir struct NodeValueAccessor 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir private: 63*cdf0e10cSrcweir ::rtl::OUString sRelativePath; // the relative path of the node 64*cdf0e10cSrcweir LocationType eLocationType; // the type of location where the value is stored 65*cdf0e10cSrcweir void* pLocation; // the pointer to the location 66*cdf0e10cSrcweir Type aDataType; // the type object pointed to by pLocation 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir public: 69*cdf0e10cSrcweir NodeValueAccessor( const ::rtl::OUString& _rNodePath ); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir void bind( void* _pLocation, const Type& _rType ); 72*cdf0e10cSrcweir void bind( Any* _pLocation ); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir bool isBound( ) const { return ( ltUnbound != eLocationType ) && ( NULL != pLocation ); } 75*cdf0e10cSrcweir const ::rtl::OUString& getPath( ) const { return sRelativePath; } 76*cdf0e10cSrcweir LocationType getLocType( ) const { return eLocationType; } 77*cdf0e10cSrcweir void* getLocation( ) const { return pLocation; } 78*cdf0e10cSrcweir const Type& getDataType( ) const { return aDataType; } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir bool operator == ( const NodeValueAccessor& rhs ) const; 81*cdf0e10cSrcweir bool operator != ( const NodeValueAccessor& rhs ) const { return !operator == ( rhs ); } 82*cdf0e10cSrcweir }; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir //--------------------------------------------------------------------- 85*cdf0e10cSrcweir //--- 20.08.01 17:21:13 ----------------------------------------------- 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir NodeValueAccessor::NodeValueAccessor( const ::rtl::OUString& _rNodePath ) 88*cdf0e10cSrcweir :sRelativePath( _rNodePath ) 89*cdf0e10cSrcweir ,eLocationType( ltUnbound ) 90*cdf0e10cSrcweir ,pLocation( NULL ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //--------------------------------------------------------------------- 95*cdf0e10cSrcweir //--- 20.08.01 17:06:36 ----------------------------------------------- 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir bool NodeValueAccessor::operator == ( const NodeValueAccessor& rhs ) const 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir return ( sRelativePath == rhs.sRelativePath ) 100*cdf0e10cSrcweir && ( eLocationType == rhs.eLocationType ) 101*cdf0e10cSrcweir && ( pLocation == rhs.pLocation ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir //--------------------------------------------------------------------- 105*cdf0e10cSrcweir //--- 20.08.01 17:47:43 ----------------------------------------------- 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void NodeValueAccessor::bind( void* _pLocation, const Type& _rType ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir DBG_ASSERT( !isBound(), "NodeValueAccessor::bind: already bound!" ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir eLocationType = ltSimplyObjectInstance; 112*cdf0e10cSrcweir pLocation = _pLocation; 113*cdf0e10cSrcweir aDataType = _rType; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir //--------------------------------------------------------------------- 117*cdf0e10cSrcweir //--- 20.08.01 17:48:47 ----------------------------------------------- 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir void NodeValueAccessor::bind( Any* _pLocation ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir DBG_ASSERT( !isBound(), "NodeValueAccessor::bind: already bound!" ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir eLocationType = ltAnyInstance; 124*cdf0e10cSrcweir pLocation = _pLocation; 125*cdf0e10cSrcweir aDataType = ::getCppuType( _pLocation ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //--------------------------------------------------------------------- 129*cdf0e10cSrcweir //--- 20.08.01 17:42:17 ----------------------------------------------- 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir #ifndef UNX 132*cdf0e10cSrcweir static 133*cdf0e10cSrcweir #endif 134*cdf0e10cSrcweir void lcl_copyData( const NodeValueAccessor& _rAccessor, const Any& _rData, ::osl::Mutex& _rMutex ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir ::osl::MutexGuard aGuard( _rMutex ); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir DBG_ASSERT( _rAccessor.isBound(), "::utl::lcl_copyData: invalid accessor!" ); 139*cdf0e10cSrcweir switch ( _rAccessor.getLocType() ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir case ltSimplyObjectInstance: 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir if ( _rData.hasValue() ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir #ifdef DBG_UTIL 146*cdf0e10cSrcweir sal_Bool bSuccess = 147*cdf0e10cSrcweir #endif 148*cdf0e10cSrcweir // assign the value 149*cdf0e10cSrcweir uno_type_assignData( 150*cdf0e10cSrcweir _rAccessor.getLocation(), _rAccessor.getDataType().getTypeLibType(), 151*cdf0e10cSrcweir const_cast< void* >( _rData.getValue() ), _rData.getValueType().getTypeLibType(), 152*cdf0e10cSrcweir (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release 153*cdf0e10cSrcweir ); 154*cdf0e10cSrcweir #ifdef DBG_UTIL 155*cdf0e10cSrcweir rtl::OStringBuffer aBuf( 256 ); 156*cdf0e10cSrcweir aBuf.append("::utl::lcl_copyData( Accessor, Any ): could not assign the data (node path: "); 157*cdf0e10cSrcweir aBuf.append( rtl::OUStringToOString( _rAccessor.getPath(), RTL_TEXTENCODING_ASCII_US ) ); 158*cdf0e10cSrcweir aBuf.append( " !" ); 159*cdf0e10cSrcweir DBG_ASSERT( bSuccess, aBuf.getStr() ); 160*cdf0e10cSrcweir #endif 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir else { 163*cdf0e10cSrcweir DBG_WARNING( "::utl::lcl_copyData: NULL value lost!" ); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir break; 167*cdf0e10cSrcweir case ltAnyInstance: 168*cdf0e10cSrcweir // a simple assignment of an Any ... 169*cdf0e10cSrcweir *static_cast< Any* >( _rAccessor.getLocation() ) = _rData; 170*cdf0e10cSrcweir break; 171*cdf0e10cSrcweir default: 172*cdf0e10cSrcweir break; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //--------------------------------------------------------------------- 177*cdf0e10cSrcweir //--- 21.08.01 12:06:43 ----------------------------------------------- 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir #ifndef UNX 180*cdf0e10cSrcweir static 181*cdf0e10cSrcweir #endif 182*cdf0e10cSrcweir void lcl_copyData( Any& _rData, const NodeValueAccessor& _rAccessor, ::osl::Mutex& _rMutex ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir ::osl::MutexGuard aGuard( _rMutex ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir DBG_ASSERT( _rAccessor.isBound(), "::utl::lcl_copyData: invalid accessor!" ); 187*cdf0e10cSrcweir switch ( _rAccessor.getLocType() ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir case ltSimplyObjectInstance: 190*cdf0e10cSrcweir // a simple setValue .... 191*cdf0e10cSrcweir _rData.setValue( _rAccessor.getLocation(), _rAccessor.getDataType() ); 192*cdf0e10cSrcweir break; 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir case ltAnyInstance: 195*cdf0e10cSrcweir // a simple assignment of an Any ... 196*cdf0e10cSrcweir _rData = *static_cast< Any* >( _rAccessor.getLocation() ); 197*cdf0e10cSrcweir break; 198*cdf0e10cSrcweir default: 199*cdf0e10cSrcweir break; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir //===================================================================== 204*cdf0e10cSrcweir //= functors on NodeValueAccessor instances 205*cdf0e10cSrcweir //===================================================================== 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir //--------------------------------------------------------------------- 208*cdf0e10cSrcweir //--- 21.08.01 12:01:16 ----------------------------------------------- 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir /// base class for functors syncronizing between exchange locations and config sub nodes 211*cdf0e10cSrcweir struct SubNodeAccess : public ::std::unary_function< NodeValueAccessor, void > 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir protected: 214*cdf0e10cSrcweir const OConfigurationNode& m_rRootNode; 215*cdf0e10cSrcweir ::osl::Mutex& m_rMutex; 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir public: 218*cdf0e10cSrcweir SubNodeAccess( const OConfigurationNode& _rRootNode, ::osl::Mutex& _rMutex ) 219*cdf0e10cSrcweir :m_rRootNode( _rRootNode ) 220*cdf0e10cSrcweir ,m_rMutex( _rMutex ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir }; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir //--------------------------------------------------------------------- 226*cdf0e10cSrcweir //--- 21.08.01 11:25:56 ----------------------------------------------- 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir struct UpdateFromConfig : public SubNodeAccess 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir public: 231*cdf0e10cSrcweir UpdateFromConfig( const OConfigurationNode& _rRootNode, ::osl::Mutex& _rMutex ) : SubNodeAccess( _rRootNode, _rMutex ) { } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir void operator() ( NodeValueAccessor& _rAccessor ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir ::utl::lcl_copyData( _rAccessor, m_rRootNode.getNodeValue( _rAccessor.getPath( ) ), m_rMutex ); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir }; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir //--------------------------------------------------------------------- 240*cdf0e10cSrcweir //--- 21.08.01 11:25:56 ----------------------------------------------- 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir struct UpdateToConfig : public SubNodeAccess 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir public: 245*cdf0e10cSrcweir UpdateToConfig( const OConfigurationNode& _rRootNode, ::osl::Mutex& _rMutex ) : SubNodeAccess( _rRootNode, _rMutex ) { } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir void operator() ( NodeValueAccessor& _rAccessor ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir Any aNewValue; 250*cdf0e10cSrcweir lcl_copyData( aNewValue, _rAccessor, m_rMutex ); 251*cdf0e10cSrcweir m_rRootNode.setNodeValue( _rAccessor.getPath( ), aNewValue ); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir }; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir //--------------------------------------------------------------------- 256*cdf0e10cSrcweir //--- 20.08.01 16:58:24 ----------------------------------------------- 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir DECLARE_STL_VECTOR( NodeValueAccessor, NodeValueAccessors ); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir //===================================================================== 261*cdf0e10cSrcweir //= OConfigurationValueContainerImpl 262*cdf0e10cSrcweir //===================================================================== 263*cdf0e10cSrcweir struct OConfigurationValueContainerImpl 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir Reference< XMultiServiceFactory > xORB; // the service factory 266*cdf0e10cSrcweir ::osl::Mutex& rMutex; // the mutex for accessing the data containers 267*cdf0e10cSrcweir OConfigurationTreeRoot aConfigRoot; // the configuration node we're accessing 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir NodeValueAccessors aAccessors; // the accessors to the node values 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir OConfigurationValueContainerImpl( const Reference< XMultiServiceFactory >& _rxORB, ::osl::Mutex& _rMutex ) 272*cdf0e10cSrcweir :xORB( _rxORB ) 273*cdf0e10cSrcweir ,rMutex( _rMutex ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir }; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir //===================================================================== 279*cdf0e10cSrcweir //= OConfigurationValueContainer 280*cdf0e10cSrcweir //===================================================================== 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir //--------------------------------------------------------------------- 283*cdf0e10cSrcweir //--- 20.08.01 15:53:35 ----------------------------------------------- 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir OConfigurationValueContainer::OConfigurationValueContainer( 286*cdf0e10cSrcweir const Reference< XMultiServiceFactory >& _rxORB, ::osl::Mutex& _rAccessSafety, 287*cdf0e10cSrcweir const sal_Char* _pConfigLocation, const sal_uInt16 _nAccessFlags, const sal_Int32 _nLevels ) 288*cdf0e10cSrcweir :m_pImpl( new OConfigurationValueContainerImpl( _rxORB, _rAccessSafety ) ) 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir implConstruct( ::rtl::OUString::createFromAscii( _pConfigLocation ), _nAccessFlags, _nLevels ); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir //--------------------------------------------------------------------- 294*cdf0e10cSrcweir //--- 20.08.01 15:55:20 ----------------------------------------------- 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir OConfigurationValueContainer::OConfigurationValueContainer( 297*cdf0e10cSrcweir const Reference< XMultiServiceFactory >& _rxORB, ::osl::Mutex& _rAccessSafety, 298*cdf0e10cSrcweir const ::rtl::OUString& _rConfigLocation, const sal_uInt16 _nAccessFlags, const sal_Int32 _nLevels ) 299*cdf0e10cSrcweir :m_pImpl( new OConfigurationValueContainerImpl( _rxORB, _rAccessSafety ) ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir implConstruct( _rConfigLocation, _nAccessFlags, _nLevels ); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //--------------------------------------------------------------------- 305*cdf0e10cSrcweir //--- 20.08.01 16:01:29 ----------------------------------------------- 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir OConfigurationValueContainer::~OConfigurationValueContainer() 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir delete m_pImpl; 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir //--------------------------------------------------------------------- 313*cdf0e10cSrcweir //--- 20.08.01 15:59:13 ----------------------------------------------- 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir const Reference< XMultiServiceFactory >& OConfigurationValueContainer::getServiceFactory( ) const 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir return m_pImpl->xORB; 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir //--------------------------------------------------------------------- 321*cdf0e10cSrcweir //--- 20.08.01 16:02:07 ----------------------------------------------- 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir void OConfigurationValueContainer::implConstruct( const ::rtl::OUString& _rConfigLocation, 324*cdf0e10cSrcweir const sal_uInt16 _nAccessFlags, const sal_Int32 _nLevels ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir DBG_ASSERT( !m_pImpl->aConfigRoot.isValid(), "OConfigurationValueContainer::implConstruct: already initialized!" ); 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir // ................................. 329*cdf0e10cSrcweir // create the configuration node we're about to work with 330*cdf0e10cSrcweir m_pImpl->aConfigRoot = OConfigurationTreeRoot::createWithServiceFactory( 331*cdf0e10cSrcweir m_pImpl->xORB, 332*cdf0e10cSrcweir _rConfigLocation, 333*cdf0e10cSrcweir _nLevels, 334*cdf0e10cSrcweir ( _nAccessFlags & CVC_UPDATE_ACCESS ) ? OConfigurationTreeRoot::CM_UPDATABLE : OConfigurationTreeRoot::CM_READONLY, 335*cdf0e10cSrcweir ( _nAccessFlags & CVC_IMMEDIATE_UPDATE ) ? sal_False : sal_True 336*cdf0e10cSrcweir ); 337*cdf0e10cSrcweir #ifdef DBG_UTIL 338*cdf0e10cSrcweir rtl::OStringBuffer aBuf(256); 339*cdf0e10cSrcweir aBuf.append("Could not access the configuration node located at "); 340*cdf0e10cSrcweir aBuf.append( rtl::OUStringToOString( _rConfigLocation, RTL_TEXTENCODING_ASCII_US ) ); 341*cdf0e10cSrcweir aBuf.append( " !" ); 342*cdf0e10cSrcweir DBG_ASSERT( m_pImpl->aConfigRoot.isValid(), aBuf.getStr() ); 343*cdf0e10cSrcweir #endif 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir //--------------------------------------------------------------------- 347*cdf0e10cSrcweir //--- 20.08.01 16:39:05 ----------------------------------------------- 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir void OConfigurationValueContainer::registerExchangeLocation( const sal_Char* _pRelativePath, 350*cdf0e10cSrcweir void* _pContainer, const Type& _rValueType ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir // checks .... 353*cdf0e10cSrcweir DBG_ASSERT( _pContainer, "OConfigurationValueContainer::registerExchangeLocation: invalid container location!" ); 354*cdf0e10cSrcweir DBG_ASSERT( ( TypeClass_CHAR == _rValueType.getTypeClass( ) ) 355*cdf0e10cSrcweir || ( TypeClass_BOOLEAN == _rValueType.getTypeClass( ) ) 356*cdf0e10cSrcweir || ( TypeClass_BYTE == _rValueType.getTypeClass( ) ) 357*cdf0e10cSrcweir || ( TypeClass_SHORT == _rValueType.getTypeClass( ) ) 358*cdf0e10cSrcweir || ( TypeClass_LONG == _rValueType.getTypeClass( ) ) 359*cdf0e10cSrcweir || ( TypeClass_DOUBLE == _rValueType.getTypeClass( ) ) 360*cdf0e10cSrcweir || ( TypeClass_STRING == _rValueType.getTypeClass( ) ) 361*cdf0e10cSrcweir || ( TypeClass_SEQUENCE == _rValueType.getTypeClass( ) ), 362*cdf0e10cSrcweir "OConfigurationValueContainer::registerExchangeLocation: invalid type!" ); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir // build an accessor for this container 365*cdf0e10cSrcweir NodeValueAccessor aNewAccessor( ::rtl::OUString::createFromAscii( _pRelativePath ) ); 366*cdf0e10cSrcweir aNewAccessor.bind( _pContainer, _rValueType ); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir // insert it into our structure 369*cdf0e10cSrcweir implRegisterExchangeLocation( aNewAccessor ); 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir //--------------------------------------------------------------------- 373*cdf0e10cSrcweir //--- 21.08.01 14:44:45 ----------------------------------------------- 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir void OConfigurationValueContainer::registerNullValueExchangeLocation( const sal_Char* _pRelativePath, Any* _pContainer ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir // build an accessor for this container 378*cdf0e10cSrcweir NodeValueAccessor aNewAccessor( ::rtl::OUString::createFromAscii( _pRelativePath ) ); 379*cdf0e10cSrcweir aNewAccessor.bind( _pContainer ); 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir // insert it into our structure 382*cdf0e10cSrcweir implRegisterExchangeLocation( aNewAccessor ); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir //--------------------------------------------------------------------- 386*cdf0e10cSrcweir //--- 21.08.01 10:23:34 ----------------------------------------------- 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir void OConfigurationValueContainer::read( ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir for_each( 391*cdf0e10cSrcweir m_pImpl->aAccessors.begin(), 392*cdf0e10cSrcweir m_pImpl->aAccessors.end(), 393*cdf0e10cSrcweir UpdateFromConfig( m_pImpl->aConfigRoot, m_pImpl->rMutex ) 394*cdf0e10cSrcweir ); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir //--------------------------------------------------------------------- 398*cdf0e10cSrcweir //--- 21.08.01 12:04:48 ----------------------------------------------- 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir void OConfigurationValueContainer::write( sal_Bool _bCommit ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir // collect the current values in the exchange locations 403*cdf0e10cSrcweir for_each( 404*cdf0e10cSrcweir m_pImpl->aAccessors.begin(), 405*cdf0e10cSrcweir m_pImpl->aAccessors.end(), 406*cdf0e10cSrcweir UpdateToConfig( m_pImpl->aConfigRoot, m_pImpl->rMutex ) 407*cdf0e10cSrcweir ); 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir // commit the changes done (if requested) 410*cdf0e10cSrcweir if ( _bCommit ) 411*cdf0e10cSrcweir commit( sal_False ); 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir //--------------------------------------------------------------------- 415*cdf0e10cSrcweir //--- 21.08.01 12:09:45 ----------------------------------------------- 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir void OConfigurationValueContainer::commit( sal_Bool _bWrite ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir // write the current values in the exchange locations (if requested) 420*cdf0e10cSrcweir if ( _bWrite ) 421*cdf0e10cSrcweir write( sal_False ); 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir // commit the changes done 424*cdf0e10cSrcweir m_pImpl->aConfigRoot.commit( ); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir //--------------------------------------------------------------------- 428*cdf0e10cSrcweir //--- 20.08.01 17:29:27 ----------------------------------------------- 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir void OConfigurationValueContainer::implRegisterExchangeLocation( const NodeValueAccessor& _rAccessor ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir // some checks 433*cdf0e10cSrcweir DBG_ASSERT( !m_pImpl->aConfigRoot.isValid() || m_pImpl->aConfigRoot.hasByHierarchicalName( _rAccessor.getPath() ), 434*cdf0e10cSrcweir "OConfigurationValueContainer::implRegisterExchangeLocation: invalid relative path!" ); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir #ifdef DBG_UTIL 437*cdf0e10cSrcweir // another check (should be the first container for this node) 438*cdf0e10cSrcweir ConstNodeValueAccessorsIterator aExistent = ::std::find( 439*cdf0e10cSrcweir m_pImpl->aAccessors.begin(), 440*cdf0e10cSrcweir m_pImpl->aAccessors.end(), 441*cdf0e10cSrcweir _rAccessor 442*cdf0e10cSrcweir ); 443*cdf0e10cSrcweir DBG_ASSERT( m_pImpl->aAccessors.end() == aExistent, "OConfigurationValueContainer::implRegisterExchangeLocation: already registered a container for this subnode!" ); 444*cdf0e10cSrcweir #endif 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir // remember the accessor 447*cdf0e10cSrcweir m_pImpl->aAccessors.push_back( _rAccessor ); 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir // and initially fill the value 450*cdf0e10cSrcweir lcl_copyData( _rAccessor, m_pImpl->aConfigRoot.getNodeValue( _rAccessor.getPath() ), m_pImpl->rMutex ); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir //......................................................................... 454*cdf0e10cSrcweir } // namespace utl 455*cdf0e10cSrcweir //......................................................................... 456*cdf0e10cSrcweir 457