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