12f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
32f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
42f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file
52f86921cSAndrew Rist * distributed with this work for additional information
62f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
72f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the
82f86921cSAndrew Rist * "License"); you may not use this file except in compliance
92f86921cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
112f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
132f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing,
142f86921cSAndrew Rist * software distributed under the License is distributed on an
152f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162f86921cSAndrew Rist * KIND, either express or implied. See the License for the
172f86921cSAndrew Rist * specific language governing permissions and limitations
182f86921cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
202f86921cSAndrew Rist *************************************************************/
212f86921cSAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_ucb.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir /**************************************************************************
26cdf0e10cSrcweir TODO
27cdf0e10cSrcweir **************************************************************************
28cdf0e10cSrcweir
29cdf0e10cSrcweir *************************************************************************/
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <list>
32cdf0e10cSrcweir #include <hash_map>
33cdf0e10cSrcweir #include <osl/diagnose.h>
34cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
35cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
36cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp>
38cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
40cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp>
41cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
42cdf0e10cSrcweir #include "ucbstore.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace com::sun::star::beans;
45cdf0e10cSrcweir using namespace com::sun::star::container;
46cdf0e10cSrcweir using namespace com::sun::star::lang;
47cdf0e10cSrcweir using namespace com::sun::star::ucb;
48cdf0e10cSrcweir using namespace com::sun::star::uno;
49cdf0e10cSrcweir using namespace com::sun::star::util;
50cdf0e10cSrcweir using namespace cppu;
51cdf0e10cSrcweir using namespace rtl;
52cdf0e10cSrcweir
53cdf0e10cSrcweir //=========================================================================
makeHierarchalNameSegment(const rtl::OUString & rIn)54cdf0e10cSrcweir rtl::OUString makeHierarchalNameSegment( const rtl::OUString & rIn )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir rtl::OUStringBuffer aBuffer;
57cdf0e10cSrcweir aBuffer.appendAscii( "['" );
58cdf0e10cSrcweir
59cdf0e10cSrcweir sal_Int32 nCount = rIn.getLength();
60cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir const sal_Unicode c = rIn.getStr()[ n ];
63cdf0e10cSrcweir switch ( c )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir case '&':
66cdf0e10cSrcweir aBuffer.appendAscii( "&" );
67cdf0e10cSrcweir break;
68cdf0e10cSrcweir
69cdf0e10cSrcweir case '"':
70cdf0e10cSrcweir aBuffer.appendAscii( """ );
71cdf0e10cSrcweir break;
72cdf0e10cSrcweir
73cdf0e10cSrcweir case '\'':
74cdf0e10cSrcweir aBuffer.appendAscii( "'" );
75cdf0e10cSrcweir break;
76cdf0e10cSrcweir
77cdf0e10cSrcweir case '<':
78cdf0e10cSrcweir aBuffer.appendAscii( "<" );
79cdf0e10cSrcweir break;
80cdf0e10cSrcweir
81cdf0e10cSrcweir case '>':
82cdf0e10cSrcweir aBuffer.appendAscii( ">" );
83cdf0e10cSrcweir break;
84cdf0e10cSrcweir
85cdf0e10cSrcweir default:
86cdf0e10cSrcweir aBuffer.append( c );
87cdf0e10cSrcweir break;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir aBuffer.appendAscii( "']" );
92cdf0e10cSrcweir return rtl::OUString( aBuffer.makeStringAndClear() );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir //=========================================================================
96cdf0e10cSrcweir
97cdf0e10cSrcweir #define STORE_CONTENTPROPERTIES_KEY "/org.openoffice.ucb.Store/ContentProperties"
98cdf0e10cSrcweir
99cdf0e10cSrcweir // describe path of cfg entry
100cdf0e10cSrcweir #define CFGPROPERTY_NODEPATH "nodepath"
101cdf0e10cSrcweir // true->async. update; false->sync. update
102cdf0e10cSrcweir #define CFGPROPERTY_LAZYWRITE "lazywrite"
103cdf0e10cSrcweir
104cdf0e10cSrcweir //=========================================================================
105cdf0e10cSrcweir
106cdf0e10cSrcweir struct equalString_Impl
107cdf0e10cSrcweir {
operator ()equalString_Impl108cdf0e10cSrcweir bool operator()( const OUString& s1, const OUString& s2 ) const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir return !!( s1 == s2 );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir };
113cdf0e10cSrcweir
114cdf0e10cSrcweir struct hashString_Impl
115cdf0e10cSrcweir {
operator ()hashString_Impl116cdf0e10cSrcweir size_t operator()( const OUString & rName ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir return rName.hashCode();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir };
121cdf0e10cSrcweir
122cdf0e10cSrcweir //=========================================================================
123cdf0e10cSrcweir //
124cdf0e10cSrcweir // PropertySetMap_Impl.
125cdf0e10cSrcweir //
126cdf0e10cSrcweir //=========================================================================
127cdf0e10cSrcweir
128cdf0e10cSrcweir typedef std::hash_map
129cdf0e10cSrcweir <
130cdf0e10cSrcweir OUString,
131cdf0e10cSrcweir PersistentPropertySet*,
132cdf0e10cSrcweir hashString_Impl,
133cdf0e10cSrcweir equalString_Impl
134cdf0e10cSrcweir >
135cdf0e10cSrcweir PropertySetMap_Impl;
136cdf0e10cSrcweir
137cdf0e10cSrcweir //=========================================================================
138cdf0e10cSrcweir //
139cdf0e10cSrcweir // class PropertySetInfo_Impl
140cdf0e10cSrcweir //
141cdf0e10cSrcweir //=========================================================================
142cdf0e10cSrcweir
143cdf0e10cSrcweir class PropertySetInfo_Impl :
144cdf0e10cSrcweir public OWeakObject, public XTypeProvider, public XPropertySetInfo
145cdf0e10cSrcweir {
146cdf0e10cSrcweir Reference< XMultiServiceFactory > m_xSMgr;
147cdf0e10cSrcweir Sequence< Property >* m_pProps;
148cdf0e10cSrcweir PersistentPropertySet* m_pOwner;
149cdf0e10cSrcweir
150cdf0e10cSrcweir public:
151cdf0e10cSrcweir PropertySetInfo_Impl( const Reference< XMultiServiceFactory >& rxSMgr,
152cdf0e10cSrcweir PersistentPropertySet* pOwner );
153cdf0e10cSrcweir virtual ~PropertySetInfo_Impl();
154cdf0e10cSrcweir
155cdf0e10cSrcweir // XInterface
156cdf0e10cSrcweir XINTERFACE_DECL()
157cdf0e10cSrcweir
158cdf0e10cSrcweir // XTypeProvider
159cdf0e10cSrcweir XTYPEPROVIDER_DECL()
160cdf0e10cSrcweir
161cdf0e10cSrcweir // XPropertySetInfo
162cdf0e10cSrcweir virtual Sequence< Property > SAL_CALL getProperties()
163cdf0e10cSrcweir throw( RuntimeException );
164cdf0e10cSrcweir virtual Property SAL_CALL getPropertyByName( const OUString& aName )
165cdf0e10cSrcweir throw( UnknownPropertyException, RuntimeException );
166cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name )
167cdf0e10cSrcweir throw( RuntimeException );
168cdf0e10cSrcweir
169cdf0e10cSrcweir // Non-interface methods.
reset()170cdf0e10cSrcweir void reset() { delete m_pProps; m_pProps = 0; }
171cdf0e10cSrcweir };
172cdf0e10cSrcweir
173cdf0e10cSrcweir //=========================================================================
174cdf0e10cSrcweir //
175cdf0e10cSrcweir // UcbStore_Impl.
176cdf0e10cSrcweir //
177cdf0e10cSrcweir //=========================================================================
178cdf0e10cSrcweir
179cdf0e10cSrcweir struct UcbStore_Impl
180cdf0e10cSrcweir {
181cdf0e10cSrcweir osl::Mutex m_aMutex;
182cdf0e10cSrcweir Sequence< Any > m_aInitArgs;
183cdf0e10cSrcweir Reference< XPropertySetRegistry > m_xTheRegistry;
184cdf0e10cSrcweir };
185cdf0e10cSrcweir
186cdf0e10cSrcweir //=========================================================================
187cdf0e10cSrcweir //=========================================================================
188cdf0e10cSrcweir //=========================================================================
189cdf0e10cSrcweir //
190cdf0e10cSrcweir // UcbStore Implementation.
191cdf0e10cSrcweir //
192cdf0e10cSrcweir //=========================================================================
193cdf0e10cSrcweir //=========================================================================
194cdf0e10cSrcweir //=========================================================================
195cdf0e10cSrcweir
UcbStore(const Reference<XMultiServiceFactory> & rXSMgr)196cdf0e10cSrcweir UcbStore::UcbStore( const Reference< XMultiServiceFactory >& rXSMgr )
197cdf0e10cSrcweir : m_xSMgr( rXSMgr ),
198cdf0e10cSrcweir m_pImpl( new UcbStore_Impl() )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
202cdf0e10cSrcweir //=========================================================================
203cdf0e10cSrcweir // virtual
~UcbStore()204cdf0e10cSrcweir UcbStore::~UcbStore()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir delete m_pImpl;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir //=========================================================================
210cdf0e10cSrcweir //
211cdf0e10cSrcweir // XInterface methods.
212cdf0e10cSrcweir //
213cdf0e10cSrcweir //=========================================================================
214cdf0e10cSrcweir
215cdf0e10cSrcweir XINTERFACE_IMPL_4( UcbStore,
216cdf0e10cSrcweir XTypeProvider,
217cdf0e10cSrcweir XServiceInfo,
218cdf0e10cSrcweir XPropertySetRegistryFactory,
219cdf0e10cSrcweir XInitialization );
220cdf0e10cSrcweir
221cdf0e10cSrcweir //=========================================================================
222cdf0e10cSrcweir //
223cdf0e10cSrcweir // XTypeProvider methods.
224cdf0e10cSrcweir //
225cdf0e10cSrcweir //=========================================================================
226cdf0e10cSrcweir
227cdf0e10cSrcweir XTYPEPROVIDER_IMPL_4( UcbStore,
228cdf0e10cSrcweir XTypeProvider,
229cdf0e10cSrcweir XServiceInfo,
230cdf0e10cSrcweir XPropertySetRegistryFactory,
231cdf0e10cSrcweir XInitialization );
232cdf0e10cSrcweir
233cdf0e10cSrcweir //=========================================================================
234cdf0e10cSrcweir //
235cdf0e10cSrcweir // XServiceInfo methods.
236cdf0e10cSrcweir //
237cdf0e10cSrcweir //=========================================================================
238cdf0e10cSrcweir
239cdf0e10cSrcweir XSERVICEINFO_IMPL_1( UcbStore,
240cdf0e10cSrcweir OUString::createFromAscii(
241cdf0e10cSrcweir "com.sun.star.comp.ucb.UcbStore" ),
242cdf0e10cSrcweir OUString::createFromAscii(
243cdf0e10cSrcweir STORE_SERVICE_NAME ) );
244cdf0e10cSrcweir
245cdf0e10cSrcweir //=========================================================================
246cdf0e10cSrcweir //
247cdf0e10cSrcweir // Service factory implementation.
248cdf0e10cSrcweir //
249cdf0e10cSrcweir //=========================================================================
250cdf0e10cSrcweir
251cdf0e10cSrcweir ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbStore );
252cdf0e10cSrcweir
253cdf0e10cSrcweir //=========================================================================
254cdf0e10cSrcweir //
255cdf0e10cSrcweir // XPropertySetRegistryFactory methods.
256cdf0e10cSrcweir //
257cdf0e10cSrcweir //=========================================================================
258cdf0e10cSrcweir
259cdf0e10cSrcweir // virtual
260cdf0e10cSrcweir Reference< XPropertySetRegistry > SAL_CALL
createPropertySetRegistry(const OUString &)261cdf0e10cSrcweir UcbStore::createPropertySetRegistry( const OUString& )
262cdf0e10cSrcweir throw( RuntimeException )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir // The URL parameter is ignored by this interface implementation. It always
265cdf0e10cSrcweir // uses the configuration server as storage medium.
266cdf0e10cSrcweir
267cdf0e10cSrcweir if ( !m_pImpl->m_xTheRegistry.is() )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
270cdf0e10cSrcweir if ( !m_pImpl->m_xTheRegistry.is() )
271cdf0e10cSrcweir m_pImpl->m_xTheRegistry = new PropertySetRegistry( m_xSMgr, getInitArgs() );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274cdf0e10cSrcweir return m_pImpl->m_xTheRegistry;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir //=========================================================================
278cdf0e10cSrcweir //
279cdf0e10cSrcweir // XInitialization methods.
280cdf0e10cSrcweir //
281cdf0e10cSrcweir //=========================================================================
282cdf0e10cSrcweir
283cdf0e10cSrcweir // virtual
initialize(const Sequence<Any> & aArguments)284cdf0e10cSrcweir void SAL_CALL UcbStore::initialize( const Sequence< Any >& aArguments )
285cdf0e10cSrcweir throw( Exception, RuntimeException )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
288cdf0e10cSrcweir m_pImpl->m_aInitArgs = aArguments;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
291cdf0e10cSrcweir //=========================================================================
getInitArgs() const292cdf0e10cSrcweir const Sequence< Any >& UcbStore::getInitArgs() const
293cdf0e10cSrcweir {
294cdf0e10cSrcweir return m_pImpl->m_aInitArgs;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir
297cdf0e10cSrcweir //=========================================================================
298cdf0e10cSrcweir //
299cdf0e10cSrcweir // PropertySetRegistry_Impl.
300cdf0e10cSrcweir //
301cdf0e10cSrcweir //=========================================================================
302cdf0e10cSrcweir
303cdf0e10cSrcweir struct PropertySetRegistry_Impl
304cdf0e10cSrcweir {
305cdf0e10cSrcweir const Sequence< Any > m_aInitArgs;
306cdf0e10cSrcweir PropertySetMap_Impl m_aPropSets;
307cdf0e10cSrcweir Reference< XMultiServiceFactory > m_xConfigProvider;
308cdf0e10cSrcweir Reference< XInterface > m_xRootReadAccess;
309cdf0e10cSrcweir Reference< XInterface > m_xRootWriteAccess;
310cdf0e10cSrcweir osl::Mutex m_aMutex;
311cdf0e10cSrcweir sal_Bool m_bTriedToGetRootReadAccess; // #82494#
312cdf0e10cSrcweir sal_Bool m_bTriedToGetRootWriteAccess; // #82494#
313cdf0e10cSrcweir
PropertySetRegistry_ImplPropertySetRegistry_Impl314cdf0e10cSrcweir PropertySetRegistry_Impl( const Sequence< Any > &rInitArgs )
315cdf0e10cSrcweir : m_aInitArgs( rInitArgs ),
316cdf0e10cSrcweir m_bTriedToGetRootReadAccess( sal_False ),
317cdf0e10cSrcweir m_bTriedToGetRootWriteAccess( sal_False )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir }
320cdf0e10cSrcweir };
321cdf0e10cSrcweir
322cdf0e10cSrcweir //=========================================================================
323cdf0e10cSrcweir //=========================================================================
324cdf0e10cSrcweir //=========================================================================
325cdf0e10cSrcweir //
326cdf0e10cSrcweir // PropertySetRegistry Implementation.
327cdf0e10cSrcweir //
328cdf0e10cSrcweir //=========================================================================
329cdf0e10cSrcweir //=========================================================================
330cdf0e10cSrcweir //=========================================================================
331cdf0e10cSrcweir
PropertySetRegistry(const Reference<XMultiServiceFactory> & rXSMgr,const Sequence<Any> & rInitArgs)332cdf0e10cSrcweir PropertySetRegistry::PropertySetRegistry(
333cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rXSMgr,
334cdf0e10cSrcweir const Sequence< Any > &rInitArgs )
335cdf0e10cSrcweir : m_xSMgr( rXSMgr ),
336cdf0e10cSrcweir m_pImpl( new PropertySetRegistry_Impl( rInitArgs ) )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir //=========================================================================
341cdf0e10cSrcweir // virtual
~PropertySetRegistry()342cdf0e10cSrcweir PropertySetRegistry::~PropertySetRegistry()
343cdf0e10cSrcweir {
344cdf0e10cSrcweir delete m_pImpl;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
347cdf0e10cSrcweir //=========================================================================
348cdf0e10cSrcweir //
349cdf0e10cSrcweir // XInterface methods.
350cdf0e10cSrcweir //
351cdf0e10cSrcweir //=========================================================================
352cdf0e10cSrcweir
353cdf0e10cSrcweir XINTERFACE_IMPL_5( PropertySetRegistry,
354cdf0e10cSrcweir XTypeProvider,
355cdf0e10cSrcweir XServiceInfo,
356cdf0e10cSrcweir XPropertySetRegistry,
357cdf0e10cSrcweir XElementAccess, /* base of XNameAccess */
358cdf0e10cSrcweir XNameAccess );
359cdf0e10cSrcweir
360cdf0e10cSrcweir //=========================================================================
361cdf0e10cSrcweir //
362cdf0e10cSrcweir // XTypeProvider methods.
363cdf0e10cSrcweir //
364cdf0e10cSrcweir //=========================================================================
365cdf0e10cSrcweir
366cdf0e10cSrcweir XTYPEPROVIDER_IMPL_4( PropertySetRegistry,
367cdf0e10cSrcweir XTypeProvider,
368cdf0e10cSrcweir XServiceInfo,
369cdf0e10cSrcweir XPropertySetRegistry,
370cdf0e10cSrcweir XNameAccess );
371cdf0e10cSrcweir
372cdf0e10cSrcweir //=========================================================================
373cdf0e10cSrcweir //
374cdf0e10cSrcweir // XServiceInfo methods.
375cdf0e10cSrcweir //
376cdf0e10cSrcweir //=========================================================================
377cdf0e10cSrcweir
378cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( PropertySetRegistry,
379cdf0e10cSrcweir OUString::createFromAscii(
380cdf0e10cSrcweir "com.sun.star.comp.ucb.PropertySetRegistry" ),
381cdf0e10cSrcweir OUString::createFromAscii(
382cdf0e10cSrcweir PROPSET_REG_SERVICE_NAME ) );
383cdf0e10cSrcweir
384cdf0e10cSrcweir //=========================================================================
385cdf0e10cSrcweir //
386cdf0e10cSrcweir // XPropertySetRegistry methods.
387cdf0e10cSrcweir //
388cdf0e10cSrcweir //=========================================================================
389cdf0e10cSrcweir
390cdf0e10cSrcweir // virtual
391cdf0e10cSrcweir Reference< XPersistentPropertySet > SAL_CALL
openPropertySet(const OUString & key,sal_Bool create)392cdf0e10cSrcweir PropertySetRegistry::openPropertySet( const OUString& key, sal_Bool create )
393cdf0e10cSrcweir throw( RuntimeException )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir if ( key.getLength() )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
398cdf0e10cSrcweir
399cdf0e10cSrcweir PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets;
400cdf0e10cSrcweir
401cdf0e10cSrcweir PropertySetMap_Impl::const_iterator it = rSets.find( key );
402cdf0e10cSrcweir if ( it != rSets.end() )
403cdf0e10cSrcweir {
404*5e7dbebbSJohn Bampton // Already instantiated.
405cdf0e10cSrcweir return Reference< XPersistentPropertySet >( (*it).second );
406cdf0e10cSrcweir }
407cdf0e10cSrcweir else
408cdf0e10cSrcweir {
409cdf0e10cSrcweir // Create new instance.
410cdf0e10cSrcweir Reference< XNameAccess > xRootNameAccess(
411cdf0e10cSrcweir getRootConfigReadAccess(), UNO_QUERY );
412cdf0e10cSrcweir if ( xRootNameAccess.is() )
413cdf0e10cSrcweir {
414cdf0e10cSrcweir // Propertyset in registry?
415cdf0e10cSrcweir if ( xRootNameAccess->hasByName( key ) )
416cdf0e10cSrcweir {
417cdf0e10cSrcweir // Yep!
418cdf0e10cSrcweir return Reference< XPersistentPropertySet >(
419cdf0e10cSrcweir new PersistentPropertySet(
420cdf0e10cSrcweir m_xSMgr, *this, key ) );
421cdf0e10cSrcweir }
422cdf0e10cSrcweir else if ( create )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir // No. Create entry for propertyset.
425cdf0e10cSrcweir
426cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac(
427cdf0e10cSrcweir getConfigWriteAccess( OUString() ), UNO_QUERY );
428cdf0e10cSrcweir Reference< XChangesBatch > xBatch( xFac, UNO_QUERY );
429cdf0e10cSrcweir Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
430cdf0e10cSrcweir
431cdf0e10cSrcweir OSL_ENSURE( xFac.is(),
432cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
433cdf0e10cSrcweir "No factory!" );
434cdf0e10cSrcweir
435cdf0e10cSrcweir OSL_ENSURE( xBatch.is(),
436cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
437cdf0e10cSrcweir "No batch!" );
438cdf0e10cSrcweir
439cdf0e10cSrcweir OSL_ENSURE( xContainer.is(),
440cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
4412cdca4f8Smseidel "No container!" );
442cdf0e10cSrcweir
443cdf0e10cSrcweir if ( xFac.is() && xBatch.is() && xContainer.is() )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir try
446cdf0e10cSrcweir {
447cdf0e10cSrcweir // Create new "Properties" config item.
448cdf0e10cSrcweir Reference< XNameReplace > xNameReplace(
449cdf0e10cSrcweir xFac->createInstance(), UNO_QUERY );
450cdf0e10cSrcweir
451cdf0e10cSrcweir if ( xNameReplace.is() )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir // Fill new item...
454cdf0e10cSrcweir
455cdf0e10cSrcweir // // Set Values
456cdf0e10cSrcweir // xNameReplace->replaceByName(
457cdf0e10cSrcweir // OUString::createFromAscii( "Values" ),
458cdf0e10cSrcweir // makeAny( ... ) );
459cdf0e10cSrcweir
460cdf0e10cSrcweir // Insert new item.
461cdf0e10cSrcweir xContainer->insertByName(
462cdf0e10cSrcweir key, makeAny( xNameReplace ) );
463cdf0e10cSrcweir // Commit changes.
464cdf0e10cSrcweir xBatch->commitChanges();
465cdf0e10cSrcweir
466cdf0e10cSrcweir return Reference< XPersistentPropertySet >(
467cdf0e10cSrcweir new PersistentPropertySet(
468cdf0e10cSrcweir m_xSMgr, *this, key ) );
469cdf0e10cSrcweir }
470cdf0e10cSrcweir }
471cdf0e10cSrcweir catch ( IllegalArgumentException& )
472cdf0e10cSrcweir {
473cdf0e10cSrcweir // insertByName
474cdf0e10cSrcweir
475cdf0e10cSrcweir OSL_ENSURE( sal_False,
476cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
477cdf0e10cSrcweir "caught IllegalArgumentException!" );
478cdf0e10cSrcweir }
479cdf0e10cSrcweir catch ( ElementExistException& )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir // insertByName
482cdf0e10cSrcweir
483cdf0e10cSrcweir OSL_ENSURE( sal_False,
484cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
485cdf0e10cSrcweir "caught ElementExistException!" );
486cdf0e10cSrcweir }
487cdf0e10cSrcweir catch ( WrappedTargetException& )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir // insertByName, commitChanges
490cdf0e10cSrcweir
491cdf0e10cSrcweir OSL_ENSURE( sal_False,
492cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
493cdf0e10cSrcweir "caught WrappedTargetException!" );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir catch ( RuntimeException& )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir OSL_ENSURE( sal_False,
498cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
499cdf0e10cSrcweir "caught RuntimeException!" );
500cdf0e10cSrcweir }
501cdf0e10cSrcweir catch ( Exception& )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir // createInstance
504cdf0e10cSrcweir
505cdf0e10cSrcweir OSL_ENSURE( sal_False,
506cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - "
507cdf0e10cSrcweir "caught Exception!" );
508cdf0e10cSrcweir }
509cdf0e10cSrcweir }
510cdf0e10cSrcweir }
511cdf0e10cSrcweir else
512cdf0e10cSrcweir {
513cdf0e10cSrcweir // No entry. Fail, but no error.
514cdf0e10cSrcweir return Reference< XPersistentPropertySet >();
515cdf0e10cSrcweir }
516cdf0e10cSrcweir }
517cdf0e10cSrcweir
518cdf0e10cSrcweir OSL_ENSURE( sal_False,
519cdf0e10cSrcweir "PropertySetRegistry::openPropertySet - Error!" );
520cdf0e10cSrcweir }
521cdf0e10cSrcweir }
522cdf0e10cSrcweir
523cdf0e10cSrcweir return Reference< XPersistentPropertySet >();
524cdf0e10cSrcweir }
525cdf0e10cSrcweir
526cdf0e10cSrcweir //=========================================================================
527cdf0e10cSrcweir // virtual
removePropertySet(const OUString & key)528cdf0e10cSrcweir void SAL_CALL PropertySetRegistry::removePropertySet( const OUString& key )
529cdf0e10cSrcweir throw( RuntimeException )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir if ( !key.getLength() )
532cdf0e10cSrcweir return;
533cdf0e10cSrcweir
534cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
535cdf0e10cSrcweir
536cdf0e10cSrcweir Reference< XNameAccess > xRootNameAccess(
537cdf0e10cSrcweir getRootConfigReadAccess(), UNO_QUERY );
538cdf0e10cSrcweir if ( xRootNameAccess.is() )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir // Propertyset in registry?
541cdf0e10cSrcweir if ( !xRootNameAccess->hasByName( key ) )
542cdf0e10cSrcweir return;
543cdf0e10cSrcweir Reference< XChangesBatch > xBatch(
544cdf0e10cSrcweir getConfigWriteAccess( OUString() ), UNO_QUERY );
545cdf0e10cSrcweir Reference< XNameContainer > xContainer( xBatch, UNO_QUERY );
546cdf0e10cSrcweir
547cdf0e10cSrcweir OSL_ENSURE( xBatch.is(),
548cdf0e10cSrcweir "PropertySetRegistry::removePropertySet - "
549cdf0e10cSrcweir "No batch!" );
550cdf0e10cSrcweir
551cdf0e10cSrcweir OSL_ENSURE( xContainer.is(),
552cdf0e10cSrcweir "PropertySetRegistry::removePropertySet - "
5532cdca4f8Smseidel "No container!" );
554cdf0e10cSrcweir
555cdf0e10cSrcweir if ( xBatch.is() && xContainer.is() )
556cdf0e10cSrcweir {
557cdf0e10cSrcweir try
558cdf0e10cSrcweir {
559cdf0e10cSrcweir // Remove item.
560cdf0e10cSrcweir xContainer->removeByName( key );
561cdf0e10cSrcweir // Commit changes.
562cdf0e10cSrcweir xBatch->commitChanges();
563cdf0e10cSrcweir
564cdf0e10cSrcweir // Success.
565cdf0e10cSrcweir return;
566cdf0e10cSrcweir }
567cdf0e10cSrcweir catch ( NoSuchElementException& )
568cdf0e10cSrcweir {
569cdf0e10cSrcweir // removeByName
570cdf0e10cSrcweir
571cdf0e10cSrcweir OSL_ENSURE( sal_False,
572cdf0e10cSrcweir "PropertySetRegistry::removePropertySet - "
573cdf0e10cSrcweir "caught NoSuchElementException!" );
574cdf0e10cSrcweir return;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir catch ( WrappedTargetException& )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir // commitChanges
579cdf0e10cSrcweir
580cdf0e10cSrcweir OSL_ENSURE( sal_False,
581cdf0e10cSrcweir "PropertySetRegistry::removePropertySet - "
582cdf0e10cSrcweir "caught WrappedTargetException!" );
583cdf0e10cSrcweir return;
584cdf0e10cSrcweir }
585cdf0e10cSrcweir }
586cdf0e10cSrcweir
587cdf0e10cSrcweir return;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir
590cdf0e10cSrcweir OSL_ENSURE( sal_False, "PropertySetRegistry::removePropertySet - Error!" );
591cdf0e10cSrcweir }
592cdf0e10cSrcweir
593cdf0e10cSrcweir //=========================================================================
594cdf0e10cSrcweir //
595cdf0e10cSrcweir // XElementAccess methods.
596cdf0e10cSrcweir //
597cdf0e10cSrcweir //=========================================================================
598cdf0e10cSrcweir
599cdf0e10cSrcweir // virtual
getElementType()600cdf0e10cSrcweir com::sun::star::uno::Type SAL_CALL PropertySetRegistry::getElementType()
601cdf0e10cSrcweir throw( RuntimeException )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir return getCppuType( ( Reference< XPersistentPropertySet > * ) 0 );
604cdf0e10cSrcweir }
605cdf0e10cSrcweir
606cdf0e10cSrcweir //=========================================================================
607cdf0e10cSrcweir // virtual
hasElements()608cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetRegistry::hasElements()
609cdf0e10cSrcweir throw( RuntimeException )
610cdf0e10cSrcweir {
611cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
612cdf0e10cSrcweir
613cdf0e10cSrcweir Reference< XElementAccess > xElemAccess(
614cdf0e10cSrcweir getRootConfigReadAccess(), UNO_QUERY );
615cdf0e10cSrcweir if ( xElemAccess.is() )
616cdf0e10cSrcweir return xElemAccess->hasElements();
617cdf0e10cSrcweir
618cdf0e10cSrcweir return sal_False;
619cdf0e10cSrcweir }
620cdf0e10cSrcweir
621cdf0e10cSrcweir //=========================================================================
622cdf0e10cSrcweir //
623cdf0e10cSrcweir // XNameAccess methods.
624cdf0e10cSrcweir //
625cdf0e10cSrcweir //=========================================================================
626cdf0e10cSrcweir
627cdf0e10cSrcweir // virtual
getByName(const OUString & aName)628cdf0e10cSrcweir Any SAL_CALL PropertySetRegistry::getByName( const OUString& aName )
629cdf0e10cSrcweir throw( NoSuchElementException, WrappedTargetException, RuntimeException )
630cdf0e10cSrcweir {
631cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
632cdf0e10cSrcweir
633cdf0e10cSrcweir Reference< XNameAccess > xNameAccess(
634cdf0e10cSrcweir getRootConfigReadAccess(), UNO_QUERY );
635cdf0e10cSrcweir if ( xNameAccess.is() )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir
638cdf0e10cSrcweir try
639cdf0e10cSrcweir {
640cdf0e10cSrcweir return xNameAccess->getByName( aName );
641cdf0e10cSrcweir }
642cdf0e10cSrcweir catch ( NoSuchElementException& )
643cdf0e10cSrcweir {
644cdf0e10cSrcweir // getByName
645cdf0e10cSrcweir }
646cdf0e10cSrcweir catch ( WrappedTargetException& )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir // getByName
649cdf0e10cSrcweir }
650cdf0e10cSrcweir }
651cdf0e10cSrcweir
652cdf0e10cSrcweir return Any();
653cdf0e10cSrcweir }
654cdf0e10cSrcweir
655cdf0e10cSrcweir //=========================================================================
656cdf0e10cSrcweir // virtual
getElementNames()657cdf0e10cSrcweir Sequence< OUString > SAL_CALL PropertySetRegistry::getElementNames()
658cdf0e10cSrcweir throw( RuntimeException )
659cdf0e10cSrcweir {
660cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
661cdf0e10cSrcweir
662cdf0e10cSrcweir Reference< XNameAccess > xNameAccess(
663cdf0e10cSrcweir getRootConfigReadAccess(), UNO_QUERY );
664cdf0e10cSrcweir if ( xNameAccess.is() )
665cdf0e10cSrcweir {
666cdf0e10cSrcweir return xNameAccess->getElementNames();
667cdf0e10cSrcweir }
668cdf0e10cSrcweir return Sequence< OUString >( 0 );
669cdf0e10cSrcweir }
670cdf0e10cSrcweir
671cdf0e10cSrcweir //=========================================================================
672cdf0e10cSrcweir // virtual
hasByName(const OUString & aName)673cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetRegistry::hasByName( const OUString& aName )
674cdf0e10cSrcweir throw( RuntimeException )
675cdf0e10cSrcweir {
676cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
677cdf0e10cSrcweir
678cdf0e10cSrcweir Reference< XNameAccess > xNameAccess(
679cdf0e10cSrcweir getRootConfigReadAccess(), UNO_QUERY );
680cdf0e10cSrcweir if ( xNameAccess.is() )
681cdf0e10cSrcweir {
682cdf0e10cSrcweir return xNameAccess->hasByName( aName );
683cdf0e10cSrcweir }
684cdf0e10cSrcweir
685cdf0e10cSrcweir return sal_False;
686cdf0e10cSrcweir }
687cdf0e10cSrcweir
688cdf0e10cSrcweir //=========================================================================
add(PersistentPropertySet * pSet)689cdf0e10cSrcweir void PropertySetRegistry::add( PersistentPropertySet* pSet )
690cdf0e10cSrcweir {
691cdf0e10cSrcweir OUString key( pSet->getKey() );
692cdf0e10cSrcweir
693cdf0e10cSrcweir if ( key.getLength() )
694cdf0e10cSrcweir {
695cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
696cdf0e10cSrcweir m_pImpl->m_aPropSets[ key ] = pSet;
697cdf0e10cSrcweir }
698cdf0e10cSrcweir }
699cdf0e10cSrcweir
700cdf0e10cSrcweir //=========================================================================
remove(PersistentPropertySet * pSet)701cdf0e10cSrcweir void PropertySetRegistry::remove( PersistentPropertySet* pSet )
702cdf0e10cSrcweir {
703cdf0e10cSrcweir OUString key( pSet->getKey() );
704cdf0e10cSrcweir
705cdf0e10cSrcweir if ( key.getLength() )
706cdf0e10cSrcweir {
707cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
708cdf0e10cSrcweir
709cdf0e10cSrcweir PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets;
710cdf0e10cSrcweir
711cdf0e10cSrcweir PropertySetMap_Impl::iterator it = rSets.find( key );
712cdf0e10cSrcweir if ( it != rSets.end() )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir // Found.
715cdf0e10cSrcweir rSets.erase( it );
716cdf0e10cSrcweir }
717cdf0e10cSrcweir }
718cdf0e10cSrcweir }
719cdf0e10cSrcweir
720cdf0e10cSrcweir //=========================================================================
renamePropertySet(const OUString & rOldKey,const OUString & rNewKey)721cdf0e10cSrcweir void PropertySetRegistry::renamePropertySet( const OUString& rOldKey,
722cdf0e10cSrcweir const OUString& rNewKey )
723cdf0e10cSrcweir {
724cdf0e10cSrcweir if ( rOldKey == rNewKey )
725cdf0e10cSrcweir return;
726cdf0e10cSrcweir
727cdf0e10cSrcweir Reference< XNameAccess > xRootNameAccess(
728cdf0e10cSrcweir getConfigWriteAccess( OUString() ), UNO_QUERY );
729cdf0e10cSrcweir if ( xRootNameAccess.is() )
730cdf0e10cSrcweir {
731cdf0e10cSrcweir // Old key present?
732cdf0e10cSrcweir if ( xRootNameAccess->hasByName( rOldKey ) )
733cdf0e10cSrcweir {
734cdf0e10cSrcweir // New key not present?
735cdf0e10cSrcweir if ( xRootNameAccess->hasByName( rNewKey ) )
736cdf0e10cSrcweir {
737cdf0e10cSrcweir OSL_ENSURE( sal_False,
738cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
739cdf0e10cSrcweir "New key exists!" );
740cdf0e10cSrcweir return;
741cdf0e10cSrcweir }
742cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac(
743cdf0e10cSrcweir xRootNameAccess, UNO_QUERY );
744cdf0e10cSrcweir Reference< XChangesBatch > xBatch( xFac, UNO_QUERY );
745cdf0e10cSrcweir Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
746cdf0e10cSrcweir
747cdf0e10cSrcweir OSL_ENSURE( xFac.is(),
748cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
749cdf0e10cSrcweir "No factory!" );
750cdf0e10cSrcweir
751cdf0e10cSrcweir OSL_ENSURE( xBatch.is(),
752cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
753cdf0e10cSrcweir "No batch!" );
754cdf0e10cSrcweir
755cdf0e10cSrcweir OSL_ENSURE( xContainer.is(),
756cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
757cdf0e10cSrcweir "No container!" );
758cdf0e10cSrcweir
759cdf0e10cSrcweir if ( xFac.is() && xBatch.is() && xContainer.is() )
760cdf0e10cSrcweir {
761cdf0e10cSrcweir //////////////////////////////////////////////////////
762cdf0e10cSrcweir // Create new "Properties" config item.
763cdf0e10cSrcweir //////////////////////////////////////////////////////
764cdf0e10cSrcweir
765cdf0e10cSrcweir try
766cdf0e10cSrcweir {
767cdf0e10cSrcweir Reference< XNameReplace > xNameReplace(
768cdf0e10cSrcweir xFac->createInstance(), UNO_QUERY );
769cdf0e10cSrcweir
770cdf0e10cSrcweir if ( xNameReplace.is() )
771cdf0e10cSrcweir {
772cdf0e10cSrcweir // Insert new item.
773cdf0e10cSrcweir xContainer->insertByName(
774cdf0e10cSrcweir rNewKey, makeAny( xNameReplace ) );
775cdf0e10cSrcweir // Commit changes.
776cdf0e10cSrcweir xBatch->commitChanges();
777cdf0e10cSrcweir }
778cdf0e10cSrcweir }
779cdf0e10cSrcweir catch ( IllegalArgumentException& )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir // insertByName
782cdf0e10cSrcweir
783cdf0e10cSrcweir OSL_ENSURE( sal_False,
784cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
785cdf0e10cSrcweir "caught IllegalArgumentException!" );
786cdf0e10cSrcweir return;
787cdf0e10cSrcweir }
788cdf0e10cSrcweir catch ( ElementExistException& )
789cdf0e10cSrcweir {
790cdf0e10cSrcweir // insertByName
791cdf0e10cSrcweir
792cdf0e10cSrcweir OSL_ENSURE( sal_False,
793cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
794cdf0e10cSrcweir "caught ElementExistException!" );
795cdf0e10cSrcweir return;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir catch ( WrappedTargetException& )
798cdf0e10cSrcweir {
799cdf0e10cSrcweir // insertByName, commitChanges
800cdf0e10cSrcweir
801cdf0e10cSrcweir OSL_ENSURE( sal_False,
802cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
803cdf0e10cSrcweir "caught WrappedTargetException!" );
804cdf0e10cSrcweir return;
805cdf0e10cSrcweir }
806cdf0e10cSrcweir catch ( RuntimeException& )
807cdf0e10cSrcweir {
808cdf0e10cSrcweir OSL_ENSURE( sal_False,
809cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
810cdf0e10cSrcweir "caught RuntimeException!" );
811cdf0e10cSrcweir return;
812cdf0e10cSrcweir }
813cdf0e10cSrcweir catch ( Exception& )
814cdf0e10cSrcweir {
815cdf0e10cSrcweir // createInstance
816cdf0e10cSrcweir
817cdf0e10cSrcweir OSL_ENSURE( sal_False,
818cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
819cdf0e10cSrcweir "caught Exception!" );
820cdf0e10cSrcweir return;
821cdf0e10cSrcweir }
822cdf0e10cSrcweir
823cdf0e10cSrcweir //////////////////////////////////////////////////////
824cdf0e10cSrcweir // Copy data...
825cdf0e10cSrcweir //////////////////////////////////////////////////////
826cdf0e10cSrcweir
827cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
828cdf0e10cSrcweir xRootNameAccess, UNO_QUERY );
829cdf0e10cSrcweir if ( !xRootHierNameAccess.is() )
830cdf0e10cSrcweir {
831cdf0e10cSrcweir OSL_ENSURE( sal_False,
832cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
833cdf0e10cSrcweir "No hierarchical name access!" );
834cdf0e10cSrcweir return;
835cdf0e10cSrcweir }
836cdf0e10cSrcweir
837cdf0e10cSrcweir try
838cdf0e10cSrcweir {
839cdf0e10cSrcweir rtl::OUString aOldValuesKey
840cdf0e10cSrcweir = makeHierarchalNameSegment( rOldKey );
841cdf0e10cSrcweir aOldValuesKey += OUString::createFromAscii( "/Values" );
842cdf0e10cSrcweir
843cdf0e10cSrcweir Reference< XNameAccess > xOldNameAccess;
844cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(
845cdf0e10cSrcweir aOldValuesKey )
846cdf0e10cSrcweir >>= xOldNameAccess;
847cdf0e10cSrcweir if ( !xOldNameAccess.is() )
848cdf0e10cSrcweir {
849cdf0e10cSrcweir OSL_ENSURE( sal_False,
850cdf0e10cSrcweir "PersistentPropertySet::renamePropertySet - "
851cdf0e10cSrcweir "No old name access!" );
852cdf0e10cSrcweir return;
853cdf0e10cSrcweir }
854cdf0e10cSrcweir
855cdf0e10cSrcweir // Obtain property names.
856cdf0e10cSrcweir Sequence< OUString > aElems
857cdf0e10cSrcweir = xOldNameAccess->getElementNames();
858cdf0e10cSrcweir sal_Int32 nCount = aElems.getLength();
859cdf0e10cSrcweir if ( nCount )
860cdf0e10cSrcweir {
861cdf0e10cSrcweir rtl::OUString aNewValuesKey
862cdf0e10cSrcweir = makeHierarchalNameSegment( rNewKey );
863cdf0e10cSrcweir aNewValuesKey += OUString::createFromAscii( "/Values" );
864cdf0e10cSrcweir
865cdf0e10cSrcweir Reference< XSingleServiceFactory > xNewFac;
866cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(
867cdf0e10cSrcweir aNewValuesKey )
868cdf0e10cSrcweir >>= xNewFac;
869cdf0e10cSrcweir if ( !xNewFac.is() )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir OSL_ENSURE( sal_False,
872cdf0e10cSrcweir "PersistentPropertySet::renamePropertySet - "
873cdf0e10cSrcweir "No new factory!" );
874cdf0e10cSrcweir return;
875cdf0e10cSrcweir }
876cdf0e10cSrcweir
877cdf0e10cSrcweir Reference< XNameContainer > xNewContainer(
878cdf0e10cSrcweir xNewFac, UNO_QUERY );
879cdf0e10cSrcweir if ( !xNewContainer.is() )
880cdf0e10cSrcweir {
881cdf0e10cSrcweir OSL_ENSURE( sal_False,
882cdf0e10cSrcweir "PersistentPropertySet::renamePropertySet - "
883cdf0e10cSrcweir "No new container!" );
884cdf0e10cSrcweir return;
885cdf0e10cSrcweir }
886cdf0e10cSrcweir
887cdf0e10cSrcweir aOldValuesKey += OUString::createFromAscii( "/" );
888cdf0e10cSrcweir
889cdf0e10cSrcweir OUString aHandleKey
890cdf0e10cSrcweir = OUString::createFromAscii( "/Handle" );
891cdf0e10cSrcweir OUString aValueKey
892cdf0e10cSrcweir = OUString::createFromAscii( "/Value" );
893cdf0e10cSrcweir OUString aStateKey
894cdf0e10cSrcweir = OUString::createFromAscii( "/State" );
895cdf0e10cSrcweir OUString aAttrKey
896cdf0e10cSrcweir = OUString::createFromAscii( "/Attributes" );
897cdf0e10cSrcweir
898cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
899cdf0e10cSrcweir {
900cdf0e10cSrcweir const OUString& rPropName = aElems[ n ];
901cdf0e10cSrcweir
902cdf0e10cSrcweir // Create new item.
903cdf0e10cSrcweir Reference< XNameReplace > xNewPropNameReplace(
904cdf0e10cSrcweir xNewFac->createInstance(), UNO_QUERY );
905cdf0e10cSrcweir
906cdf0e10cSrcweir if ( !xNewPropNameReplace.is() )
907cdf0e10cSrcweir {
908cdf0e10cSrcweir OSL_ENSURE( sal_False,
909cdf0e10cSrcweir "PersistentPropertySet::renamePropertySet - "
910cdf0e10cSrcweir "No new prop name replace!" );
911cdf0e10cSrcweir return;
912cdf0e10cSrcweir }
913cdf0e10cSrcweir
914cdf0e10cSrcweir // Fill new item...
915cdf0e10cSrcweir
916cdf0e10cSrcweir // Set Values
917cdf0e10cSrcweir OUString aKey = aOldValuesKey;
918cdf0e10cSrcweir aKey += makeHierarchalNameSegment( rPropName );
919cdf0e10cSrcweir
920cdf0e10cSrcweir // ... handle
921cdf0e10cSrcweir OUString aNewKey1 = aKey;
922cdf0e10cSrcweir aNewKey1 += aHandleKey;
923cdf0e10cSrcweir Any aAny =
924cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(
925cdf0e10cSrcweir aNewKey1 );
926cdf0e10cSrcweir xNewPropNameReplace->replaceByName(
927cdf0e10cSrcweir OUString::createFromAscii( "Handle" ),
928cdf0e10cSrcweir aAny );
929cdf0e10cSrcweir
930cdf0e10cSrcweir // ... value
931cdf0e10cSrcweir aNewKey1 = aKey;
932cdf0e10cSrcweir aNewKey1 += aValueKey;
933cdf0e10cSrcweir aAny =
934cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(
935cdf0e10cSrcweir aNewKey1 );
936cdf0e10cSrcweir xNewPropNameReplace->replaceByName(
937cdf0e10cSrcweir OUString::createFromAscii( "Value" ),
938cdf0e10cSrcweir aAny );
939cdf0e10cSrcweir
940cdf0e10cSrcweir // ... state
941cdf0e10cSrcweir aNewKey1 = aKey;
942cdf0e10cSrcweir aNewKey1 += aStateKey;
943cdf0e10cSrcweir aAny =
944cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(
945cdf0e10cSrcweir aNewKey1 );
946cdf0e10cSrcweir xNewPropNameReplace->replaceByName(
947cdf0e10cSrcweir OUString::createFromAscii( "State" ),
948cdf0e10cSrcweir aAny );
949cdf0e10cSrcweir
950cdf0e10cSrcweir // ... attributes
951cdf0e10cSrcweir aNewKey1 = aKey;
952cdf0e10cSrcweir aNewKey1 += aAttrKey;
953cdf0e10cSrcweir aAny =
954cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(
955cdf0e10cSrcweir aNewKey1 );
956cdf0e10cSrcweir xNewPropNameReplace->replaceByName(
957cdf0e10cSrcweir OUString::createFromAscii( "Attributes" ),
958cdf0e10cSrcweir aAny );
959cdf0e10cSrcweir
960cdf0e10cSrcweir // Insert new item.
961cdf0e10cSrcweir xNewContainer->insertByName(
962cdf0e10cSrcweir rPropName, makeAny( xNewPropNameReplace ) );
963cdf0e10cSrcweir
964cdf0e10cSrcweir // Commit changes.
965cdf0e10cSrcweir xBatch->commitChanges();
966cdf0e10cSrcweir }
967cdf0e10cSrcweir }
968cdf0e10cSrcweir }
969cdf0e10cSrcweir catch ( IllegalArgumentException& )
970cdf0e10cSrcweir {
971cdf0e10cSrcweir // insertByName, replaceByName
972cdf0e10cSrcweir
973cdf0e10cSrcweir OSL_ENSURE( sal_False,
974cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
975cdf0e10cSrcweir "caught IllegalArgumentException!" );
976cdf0e10cSrcweir return;
977cdf0e10cSrcweir }
978cdf0e10cSrcweir catch ( ElementExistException& )
979cdf0e10cSrcweir {
980cdf0e10cSrcweir // insertByName
981cdf0e10cSrcweir
982cdf0e10cSrcweir OSL_ENSURE( sal_False,
983cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
984cdf0e10cSrcweir "caught ElementExistException!" );
985cdf0e10cSrcweir return;
986cdf0e10cSrcweir }
987cdf0e10cSrcweir catch ( WrappedTargetException& )
988cdf0e10cSrcweir {
989cdf0e10cSrcweir // insertByName, replaceByName, commitChanges
990cdf0e10cSrcweir
991cdf0e10cSrcweir OSL_ENSURE( sal_False,
992cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
993cdf0e10cSrcweir "caught WrappedTargetException!" );
994cdf0e10cSrcweir return;
995cdf0e10cSrcweir }
996cdf0e10cSrcweir catch ( NoSuchElementException& )
997cdf0e10cSrcweir {
998cdf0e10cSrcweir // getByHierarchicalName, replaceByName
999cdf0e10cSrcweir
1000cdf0e10cSrcweir OSL_ENSURE( sal_False,
1001cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
1002cdf0e10cSrcweir "caught NoSuchElementException!" );
1003cdf0e10cSrcweir return;
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir catch ( RuntimeException& )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir OSL_ENSURE( sal_False,
1008cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
1009cdf0e10cSrcweir "caught RuntimeException!" );
1010cdf0e10cSrcweir return;
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir catch ( Exception& )
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir // createInstance
1015cdf0e10cSrcweir
1016cdf0e10cSrcweir OSL_ENSURE( sal_False,
1017cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
1018cdf0e10cSrcweir "caught Exception!" );
1019cdf0e10cSrcweir return;
1020cdf0e10cSrcweir }
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir //////////////////////////////////////////////////////
1023cdf0e10cSrcweir // Remove old entry...
1024cdf0e10cSrcweir //////////////////////////////////////////////////////
1025cdf0e10cSrcweir
1026cdf0e10cSrcweir try
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir // Remove item.
1029cdf0e10cSrcweir xContainer->removeByName( rOldKey );
1030cdf0e10cSrcweir // Commit changes.
1031cdf0e10cSrcweir xBatch->commitChanges();
1032cdf0e10cSrcweir
1033cdf0e10cSrcweir // Success.
1034cdf0e10cSrcweir return;
1035cdf0e10cSrcweir }
1036cdf0e10cSrcweir catch ( NoSuchElementException& )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir // removeByName
1039cdf0e10cSrcweir
1040cdf0e10cSrcweir OSL_ENSURE( sal_False,
1041cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
1042cdf0e10cSrcweir "caught NoSuchElementException!" );
1043cdf0e10cSrcweir return;
1044cdf0e10cSrcweir }
1045cdf0e10cSrcweir catch ( WrappedTargetException& )
1046cdf0e10cSrcweir {
1047cdf0e10cSrcweir // commitChanges
1048cdf0e10cSrcweir
1049cdf0e10cSrcweir OSL_ENSURE( sal_False,
1050cdf0e10cSrcweir "PropertySetRegistry::renamePropertySet - "
1051cdf0e10cSrcweir "caught WrappedTargetException!" );
1052cdf0e10cSrcweir return;
1053cdf0e10cSrcweir }
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir }
1057cdf0e10cSrcweir
1058cdf0e10cSrcweir OSL_ENSURE( sal_False, "PropertySetRegistry::renamePropertySet - Error!" );
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir //=========================================================================
getConfigProvider()1062cdf0e10cSrcweir Reference< XMultiServiceFactory > PropertySetRegistry::getConfigProvider()
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir if ( !m_pImpl->m_xConfigProvider.is() )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1067cdf0e10cSrcweir if ( !m_pImpl->m_xConfigProvider.is() )
1068cdf0e10cSrcweir {
1069cdf0e10cSrcweir const Sequence< Any >& rInitArgs = m_pImpl->m_aInitArgs;
1070cdf0e10cSrcweir
1071cdf0e10cSrcweir if ( rInitArgs.getLength() > 0 )
1072cdf0e10cSrcweir {
1073cdf0e10cSrcweir // Extract config provider from service init args.
1074cdf0e10cSrcweir rInitArgs[ 0 ] >>= m_pImpl->m_xConfigProvider;
1075cdf0e10cSrcweir
1076cdf0e10cSrcweir OSL_ENSURE( m_pImpl->m_xConfigProvider.is(),
1077cdf0e10cSrcweir "PropertySetRegistry::getConfigProvider - "
1078cdf0e10cSrcweir "No config provider!" );
1079cdf0e10cSrcweir }
1080cdf0e10cSrcweir else
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir try
1083cdf0e10cSrcweir {
1084cdf0e10cSrcweir m_pImpl->m_xConfigProvider
1085cdf0e10cSrcweir = Reference< XMultiServiceFactory >(
1086cdf0e10cSrcweir m_xSMgr->createInstance(
1087cdf0e10cSrcweir OUString::createFromAscii(
1088cdf0e10cSrcweir "com.sun.star.configuration."
1089cdf0e10cSrcweir "ConfigurationProvider" ) ),
1090cdf0e10cSrcweir UNO_QUERY );
1091cdf0e10cSrcweir
1092cdf0e10cSrcweir OSL_ENSURE( m_pImpl->m_xConfigProvider.is(),
1093cdf0e10cSrcweir "PropertySetRegistry::getConfigProvider - "
1094cdf0e10cSrcweir "No config provider!" );
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir catch ( Exception& )
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir OSL_ENSURE( sal_False,
1100cdf0e10cSrcweir "PropertySetRegistry::getConfigProvider - "
1101cdf0e10cSrcweir "caught exception!" );
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir }
1104cdf0e10cSrcweir }
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir return m_pImpl->m_xConfigProvider;
1108cdf0e10cSrcweir }
1109cdf0e10cSrcweir
1110cdf0e10cSrcweir //=========================================================================
getRootConfigReadAccess()1111cdf0e10cSrcweir Reference< XInterface > PropertySetRegistry::getRootConfigReadAccess()
1112cdf0e10cSrcweir {
1113cdf0e10cSrcweir try
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1116cdf0e10cSrcweir
1117cdf0e10cSrcweir if ( !m_pImpl->m_xRootReadAccess.is() )
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir if ( m_pImpl->m_bTriedToGetRootReadAccess ) // #82494#
1120cdf0e10cSrcweir {
1121cdf0e10cSrcweir OSL_ENSURE( sal_False,
1122cdf0e10cSrcweir "PropertySetRegistry::getRootConfigReadAccess - "
1123cdf0e10cSrcweir "Unable to read any config data! -> #82494#" );
1124cdf0e10cSrcweir return Reference< XInterface >();
1125cdf0e10cSrcweir }
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir getConfigProvider();
1128cdf0e10cSrcweir
1129cdf0e10cSrcweir if ( m_pImpl->m_xConfigProvider.is() )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir Sequence< Any > aArguments( 1 );
1132cdf0e10cSrcweir PropertyValue aProperty;
1133cdf0e10cSrcweir aProperty.Name
1134cdf0e10cSrcweir = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1135cdf0e10cSrcweir CFGPROPERTY_NODEPATH ) );
1136cdf0e10cSrcweir aProperty.Value
1137cdf0e10cSrcweir <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1138cdf0e10cSrcweir STORE_CONTENTPROPERTIES_KEY ) );
1139cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty;
1140cdf0e10cSrcweir
1141cdf0e10cSrcweir m_pImpl->m_bTriedToGetRootReadAccess = sal_True;
1142cdf0e10cSrcweir
1143cdf0e10cSrcweir m_pImpl->m_xRootReadAccess =
1144cdf0e10cSrcweir m_pImpl->m_xConfigProvider->createInstanceWithArguments(
1145cdf0e10cSrcweir OUString::createFromAscii(
1146cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationAccess" ),
1147cdf0e10cSrcweir aArguments );
1148cdf0e10cSrcweir
1149cdf0e10cSrcweir if ( m_pImpl->m_xRootReadAccess.is() )
1150cdf0e10cSrcweir return m_pImpl->m_xRootReadAccess;
1151cdf0e10cSrcweir }
1152cdf0e10cSrcweir }
1153cdf0e10cSrcweir else
1154cdf0e10cSrcweir return m_pImpl->m_xRootReadAccess;
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir catch ( RuntimeException& )
1157cdf0e10cSrcweir {
1158cdf0e10cSrcweir throw;
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir catch ( Exception& )
1161cdf0e10cSrcweir {
1162cdf0e10cSrcweir // createInstance, createInstanceWithArguments
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir OSL_ENSURE( sal_False,
1165cdf0e10cSrcweir "PropertySetRegistry::getRootConfigReadAccess - caught Exception!" );
1166cdf0e10cSrcweir return Reference< XInterface >();
1167cdf0e10cSrcweir }
1168cdf0e10cSrcweir
1169cdf0e10cSrcweir OSL_ENSURE( sal_False,
1170cdf0e10cSrcweir "PropertySetRegistry::getRootConfigReadAccess - Error!" );
1171cdf0e10cSrcweir return Reference< XInterface >();
1172cdf0e10cSrcweir }
1173cdf0e10cSrcweir
1174cdf0e10cSrcweir //=========================================================================
getConfigWriteAccess(const OUString & rPath)1175cdf0e10cSrcweir Reference< XInterface > PropertySetRegistry::getConfigWriteAccess(
1176cdf0e10cSrcweir const OUString& rPath )
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir try
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1181cdf0e10cSrcweir
1182cdf0e10cSrcweir if ( !m_pImpl->m_xRootWriteAccess.is() )
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir if ( m_pImpl->m_bTriedToGetRootWriteAccess ) // #82494#
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir OSL_ENSURE( sal_False,
1187cdf0e10cSrcweir "PropertySetRegistry::getConfigWriteAccess - "
1188cdf0e10cSrcweir "Unable to write any config data! -> #82494#" );
1189cdf0e10cSrcweir return Reference< XInterface >();
1190cdf0e10cSrcweir }
1191cdf0e10cSrcweir
1192cdf0e10cSrcweir getConfigProvider();
1193cdf0e10cSrcweir
1194cdf0e10cSrcweir if ( m_pImpl->m_xConfigProvider.is() )
1195cdf0e10cSrcweir {
1196cdf0e10cSrcweir Sequence< Any > aArguments( 2 );
1197cdf0e10cSrcweir PropertyValue aProperty;
1198cdf0e10cSrcweir
1199cdf0e10cSrcweir aProperty.Name
1200cdf0e10cSrcweir = OUString( RTL_CONSTASCII_USTRINGPARAM(
1201cdf0e10cSrcweir CFGPROPERTY_NODEPATH ) );
1202cdf0e10cSrcweir aProperty.Value
1203cdf0e10cSrcweir <<= OUString( RTL_CONSTASCII_USTRINGPARAM(
1204cdf0e10cSrcweir STORE_CONTENTPROPERTIES_KEY ) );
1205cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty;
1206cdf0e10cSrcweir
1207cdf0e10cSrcweir aProperty.Name
1208cdf0e10cSrcweir = OUString( RTL_CONSTASCII_USTRINGPARAM(
1209cdf0e10cSrcweir CFGPROPERTY_LAZYWRITE ) );
1210cdf0e10cSrcweir aProperty.Value <<= sal_True;
1211cdf0e10cSrcweir aArguments[ 1 ] <<= aProperty;
1212cdf0e10cSrcweir
1213cdf0e10cSrcweir m_pImpl->m_bTriedToGetRootWriteAccess = sal_True;
1214cdf0e10cSrcweir
1215cdf0e10cSrcweir m_pImpl->m_xRootWriteAccess =
1216cdf0e10cSrcweir m_pImpl->m_xConfigProvider->createInstanceWithArguments(
1217cdf0e10cSrcweir OUString::createFromAscii(
1218cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationUpdateAccess" ),
1219cdf0e10cSrcweir aArguments );
1220cdf0e10cSrcweir
1221cdf0e10cSrcweir OSL_ENSURE( m_pImpl->m_xRootWriteAccess.is(),
1222cdf0e10cSrcweir "PropertySetRegistry::getConfigWriteAccess - "
1223cdf0e10cSrcweir "No config update access!" );
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir
1227cdf0e10cSrcweir if ( m_pImpl->m_xRootWriteAccess.is() )
1228cdf0e10cSrcweir {
1229cdf0e10cSrcweir if ( rPath.getLength() )
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xNA(
1232cdf0e10cSrcweir m_pImpl->m_xRootWriteAccess, UNO_QUERY );
1233cdf0e10cSrcweir if ( xNA.is() )
1234cdf0e10cSrcweir {
1235cdf0e10cSrcweir Reference< XInterface > xInterface;
1236cdf0e10cSrcweir xNA->getByHierarchicalName( rPath ) >>= xInterface;
1237cdf0e10cSrcweir
1238cdf0e10cSrcweir if ( xInterface.is() )
1239cdf0e10cSrcweir return xInterface;
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir else
1243cdf0e10cSrcweir return m_pImpl->m_xRootWriteAccess;
1244cdf0e10cSrcweir }
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir catch ( RuntimeException& )
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir throw;
1249cdf0e10cSrcweir }
1250cdf0e10cSrcweir catch ( NoSuchElementException& )
1251cdf0e10cSrcweir {
1252cdf0e10cSrcweir // getByHierarchicalName
1253cdf0e10cSrcweir
1254cdf0e10cSrcweir OSL_ENSURE( sal_False,
1255cdf0e10cSrcweir "PropertySetRegistry::getConfigWriteAccess - "
1256cdf0e10cSrcweir "caught NoSuchElementException!" );
1257cdf0e10cSrcweir return Reference< XInterface >();
1258cdf0e10cSrcweir }
1259cdf0e10cSrcweir catch ( Exception& )
1260cdf0e10cSrcweir {
1261cdf0e10cSrcweir // createInstance, createInstanceWithArguments
1262cdf0e10cSrcweir
1263cdf0e10cSrcweir OSL_ENSURE( sal_False,
1264cdf0e10cSrcweir "PropertySetRegistry::getConfigWriteAccess - "
1265cdf0e10cSrcweir "caught Exception!" );
1266cdf0e10cSrcweir return Reference< XInterface >();
1267cdf0e10cSrcweir }
1268cdf0e10cSrcweir
1269cdf0e10cSrcweir OSL_ENSURE( sal_False,
1270cdf0e10cSrcweir "PropertySetRegistry::getConfigWriteAccess - Error!" );
1271cdf0e10cSrcweir return Reference< XInterface >();
1272cdf0e10cSrcweir }
1273cdf0e10cSrcweir
1274cdf0e10cSrcweir //=========================================================================
1275cdf0e10cSrcweir //
1276cdf0e10cSrcweir // PropertyListeners_Impl.
1277cdf0e10cSrcweir //
1278cdf0e10cSrcweir //=========================================================================
1279cdf0e10cSrcweir
1280cdf0e10cSrcweir typedef OMultiTypeInterfaceContainerHelperVar
1281cdf0e10cSrcweir <
1282cdf0e10cSrcweir OUString,
1283cdf0e10cSrcweir hashString_Impl,
1284cdf0e10cSrcweir equalString_Impl
1285cdf0e10cSrcweir > PropertyListeners_Impl;
1286cdf0e10cSrcweir
1287cdf0e10cSrcweir //=========================================================================
1288cdf0e10cSrcweir //
1289cdf0e10cSrcweir // PersistentPropertySet_Impl.
1290cdf0e10cSrcweir //
1291cdf0e10cSrcweir //=========================================================================
1292cdf0e10cSrcweir
1293cdf0e10cSrcweir struct PersistentPropertySet_Impl
1294cdf0e10cSrcweir {
1295cdf0e10cSrcweir PropertySetRegistry* m_pCreator;
1296cdf0e10cSrcweir PropertySetInfo_Impl* m_pInfo;
1297cdf0e10cSrcweir OUString m_aKey;
1298cdf0e10cSrcweir OUString m_aFullKey;
1299cdf0e10cSrcweir osl::Mutex m_aMutex;
1300cdf0e10cSrcweir OInterfaceContainerHelper* m_pDisposeEventListeners;
1301cdf0e10cSrcweir OInterfaceContainerHelper* m_pPropSetChangeListeners;
1302cdf0e10cSrcweir PropertyListeners_Impl* m_pPropertyChangeListeners;
1303cdf0e10cSrcweir
PersistentPropertySet_ImplPersistentPropertySet_Impl1304cdf0e10cSrcweir PersistentPropertySet_Impl( PropertySetRegistry& rCreator,
1305cdf0e10cSrcweir const OUString& rKey )
1306cdf0e10cSrcweir : m_pCreator( &rCreator ), m_pInfo( NULL ), m_aKey( rKey ),
1307cdf0e10cSrcweir m_pDisposeEventListeners( NULL ), m_pPropSetChangeListeners( NULL ),
1308cdf0e10cSrcweir m_pPropertyChangeListeners( NULL )
1309cdf0e10cSrcweir {
1310cdf0e10cSrcweir m_pCreator->acquire();
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir
~PersistentPropertySet_ImplPersistentPropertySet_Impl1313cdf0e10cSrcweir ~PersistentPropertySet_Impl()
1314cdf0e10cSrcweir {
1315cdf0e10cSrcweir m_pCreator->release();
1316cdf0e10cSrcweir
1317cdf0e10cSrcweir if ( m_pInfo )
1318cdf0e10cSrcweir m_pInfo->release();
1319cdf0e10cSrcweir
1320cdf0e10cSrcweir delete m_pDisposeEventListeners;
1321cdf0e10cSrcweir delete m_pPropSetChangeListeners;
1322cdf0e10cSrcweir delete m_pPropertyChangeListeners;
1323cdf0e10cSrcweir }
1324cdf0e10cSrcweir };
1325cdf0e10cSrcweir
1326cdf0e10cSrcweir //=========================================================================
1327cdf0e10cSrcweir //=========================================================================
1328cdf0e10cSrcweir //=========================================================================
1329cdf0e10cSrcweir //
1330cdf0e10cSrcweir // PersistentPropertySet Implementation.
1331cdf0e10cSrcweir //
1332cdf0e10cSrcweir //=========================================================================
1333cdf0e10cSrcweir //=========================================================================
1334cdf0e10cSrcweir //=========================================================================
1335cdf0e10cSrcweir
PersistentPropertySet(const Reference<XMultiServiceFactory> & rXSMgr,PropertySetRegistry & rCreator,const OUString & rKey)1336cdf0e10cSrcweir PersistentPropertySet::PersistentPropertySet(
1337cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rXSMgr,
1338cdf0e10cSrcweir PropertySetRegistry& rCreator,
1339cdf0e10cSrcweir const OUString& rKey )
1340cdf0e10cSrcweir : m_xSMgr( rXSMgr ),
1341cdf0e10cSrcweir m_pImpl( new PersistentPropertySet_Impl( rCreator, rKey ) )
1342cdf0e10cSrcweir {
1343cdf0e10cSrcweir // register at creator.
1344cdf0e10cSrcweir rCreator.add( this );
1345cdf0e10cSrcweir }
1346cdf0e10cSrcweir
1347cdf0e10cSrcweir //=========================================================================
1348cdf0e10cSrcweir // virtual
~PersistentPropertySet()1349cdf0e10cSrcweir PersistentPropertySet::~PersistentPropertySet()
1350cdf0e10cSrcweir {
1351cdf0e10cSrcweir // deregister at creator.
1352cdf0e10cSrcweir m_pImpl->m_pCreator->remove( this );
1353cdf0e10cSrcweir
1354cdf0e10cSrcweir delete m_pImpl;
1355cdf0e10cSrcweir }
1356cdf0e10cSrcweir
1357cdf0e10cSrcweir //=========================================================================
1358cdf0e10cSrcweir //
1359cdf0e10cSrcweir // XInterface methods.
1360cdf0e10cSrcweir //
1361cdf0e10cSrcweir //=========================================================================
1362cdf0e10cSrcweir
1363cdf0e10cSrcweir XINTERFACE_IMPL_9( PersistentPropertySet,
1364cdf0e10cSrcweir XTypeProvider,
1365cdf0e10cSrcweir XServiceInfo,
1366cdf0e10cSrcweir XComponent,
1367cdf0e10cSrcweir XPropertySet, /* base of XPersistentPropertySet */
1368cdf0e10cSrcweir XNamed,
1369cdf0e10cSrcweir XPersistentPropertySet,
1370cdf0e10cSrcweir XPropertyContainer,
1371cdf0e10cSrcweir XPropertySetInfoChangeNotifier,
1372cdf0e10cSrcweir XPropertyAccess );
1373cdf0e10cSrcweir
1374cdf0e10cSrcweir //=========================================================================
1375cdf0e10cSrcweir //
1376cdf0e10cSrcweir // XTypeProvider methods.
1377cdf0e10cSrcweir //
1378cdf0e10cSrcweir //=========================================================================
1379cdf0e10cSrcweir
1380cdf0e10cSrcweir XTYPEPROVIDER_IMPL_8( PersistentPropertySet,
1381cdf0e10cSrcweir XTypeProvider,
1382cdf0e10cSrcweir XServiceInfo,
1383cdf0e10cSrcweir XComponent,
1384cdf0e10cSrcweir XPersistentPropertySet,
1385cdf0e10cSrcweir XNamed,
1386cdf0e10cSrcweir XPropertyContainer,
1387cdf0e10cSrcweir XPropertySetInfoChangeNotifier,
1388cdf0e10cSrcweir XPropertyAccess );
1389cdf0e10cSrcweir
1390cdf0e10cSrcweir //=========================================================================
1391cdf0e10cSrcweir //
1392cdf0e10cSrcweir // XServiceInfo methods.
1393cdf0e10cSrcweir //
1394cdf0e10cSrcweir //=========================================================================
1395cdf0e10cSrcweir
1396cdf0e10cSrcweir XSERVICEINFO_NOFACTORY_IMPL_1( PersistentPropertySet,
1397cdf0e10cSrcweir OUString::createFromAscii(
1398cdf0e10cSrcweir "com.sun.star.comp.ucb.PersistentPropertySet" ),
1399cdf0e10cSrcweir OUString::createFromAscii(
1400cdf0e10cSrcweir PERS_PROPSET_SERVICE_NAME ) );
1401cdf0e10cSrcweir
1402cdf0e10cSrcweir //=========================================================================
1403cdf0e10cSrcweir //
1404cdf0e10cSrcweir // XComponent methods.
1405cdf0e10cSrcweir //
1406cdf0e10cSrcweir //=========================================================================
1407cdf0e10cSrcweir
1408cdf0e10cSrcweir // virtual
dispose()1409cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::dispose()
1410cdf0e10cSrcweir throw( RuntimeException )
1411cdf0e10cSrcweir {
1412cdf0e10cSrcweir if ( m_pImpl->m_pDisposeEventListeners &&
1413cdf0e10cSrcweir m_pImpl->m_pDisposeEventListeners->getLength() )
1414cdf0e10cSrcweir {
1415cdf0e10cSrcweir EventObject aEvt;
1416cdf0e10cSrcweir aEvt.Source = static_cast< XComponent * >( this );
1417cdf0e10cSrcweir m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
1418cdf0e10cSrcweir }
1419cdf0e10cSrcweir
1420cdf0e10cSrcweir if ( m_pImpl->m_pPropSetChangeListeners &&
1421cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners->getLength() )
1422cdf0e10cSrcweir {
1423cdf0e10cSrcweir EventObject aEvt;
1424cdf0e10cSrcweir aEvt.Source = static_cast< XPropertySetInfoChangeNotifier * >( this );
1425cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
1426cdf0e10cSrcweir }
1427cdf0e10cSrcweir
1428cdf0e10cSrcweir if ( m_pImpl->m_pPropertyChangeListeners )
1429cdf0e10cSrcweir {
1430cdf0e10cSrcweir EventObject aEvt;
1431cdf0e10cSrcweir aEvt.Source = static_cast< XPropertySet * >( this );
1432cdf0e10cSrcweir m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
1433cdf0e10cSrcweir }
1434cdf0e10cSrcweir }
1435cdf0e10cSrcweir
1436cdf0e10cSrcweir //=========================================================================
1437cdf0e10cSrcweir // virtual
addEventListener(const Reference<XEventListener> & Listener)1438cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::addEventListener(
1439cdf0e10cSrcweir const Reference< XEventListener >& Listener )
1440cdf0e10cSrcweir throw( RuntimeException )
1441cdf0e10cSrcweir {
1442cdf0e10cSrcweir if ( !m_pImpl->m_pDisposeEventListeners )
1443cdf0e10cSrcweir m_pImpl->m_pDisposeEventListeners =
1444cdf0e10cSrcweir new OInterfaceContainerHelper( m_pImpl->m_aMutex );
1445cdf0e10cSrcweir
1446cdf0e10cSrcweir m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
1447cdf0e10cSrcweir }
1448cdf0e10cSrcweir
1449cdf0e10cSrcweir //=========================================================================
1450cdf0e10cSrcweir // virtual
removeEventListener(const Reference<XEventListener> & Listener)1451cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::removeEventListener(
1452cdf0e10cSrcweir const Reference< XEventListener >& Listener )
1453cdf0e10cSrcweir throw( RuntimeException )
1454cdf0e10cSrcweir {
1455cdf0e10cSrcweir if ( m_pImpl->m_pDisposeEventListeners )
1456cdf0e10cSrcweir m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
1457cdf0e10cSrcweir
1458cdf0e10cSrcweir // Note: Don't want to delete empty container here -> performance.
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir
1461cdf0e10cSrcweir //=========================================================================
1462cdf0e10cSrcweir //
1463cdf0e10cSrcweir // XPropertySet methods.
1464cdf0e10cSrcweir //
1465cdf0e10cSrcweir //=========================================================================
1466cdf0e10cSrcweir
1467cdf0e10cSrcweir // virtual
1468cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL
getPropertySetInfo()1469cdf0e10cSrcweir PersistentPropertySet::getPropertySetInfo()
1470cdf0e10cSrcweir throw( RuntimeException )
1471cdf0e10cSrcweir {
1472cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1473cdf0e10cSrcweir
1474cdf0e10cSrcweir PropertySetInfo_Impl*& rpInfo = m_pImpl->m_pInfo;
1475cdf0e10cSrcweir if ( !rpInfo )
1476cdf0e10cSrcweir {
1477cdf0e10cSrcweir rpInfo = new PropertySetInfo_Impl( m_xSMgr, this );
1478cdf0e10cSrcweir rpInfo->acquire();
1479cdf0e10cSrcweir }
1480cdf0e10cSrcweir return Reference< XPropertySetInfo >( rpInfo );
1481cdf0e10cSrcweir }
1482cdf0e10cSrcweir
1483cdf0e10cSrcweir //=========================================================================
1484cdf0e10cSrcweir // virtual
setPropertyValue(const OUString & aPropertyName,const Any & aValue)1485cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::setPropertyValue(
1486cdf0e10cSrcweir const OUString& aPropertyName, const Any& aValue )
1487cdf0e10cSrcweir throw( UnknownPropertyException,
1488cdf0e10cSrcweir PropertyVetoException,
1489cdf0e10cSrcweir IllegalArgumentException,
1490cdf0e10cSrcweir WrappedTargetException,
1491cdf0e10cSrcweir RuntimeException )
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir if ( !aPropertyName.getLength() )
1494cdf0e10cSrcweir throw UnknownPropertyException();
1495cdf0e10cSrcweir
1496cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aCGuard( m_pImpl->m_aMutex );
1497cdf0e10cSrcweir
1498cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1499cdf0e10cSrcweir m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1500cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
1501cdf0e10cSrcweir {
1502cdf0e10cSrcweir OUString aFullPropName( getFullKey() );
1503cdf0e10cSrcweir aFullPropName += OUString::createFromAscii( "/" );
1504cdf0e10cSrcweir aFullPropName += makeHierarchalNameSegment( aPropertyName );
1505cdf0e10cSrcweir
1506cdf0e10cSrcweir // Does property exist?
1507cdf0e10cSrcweir if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
1508cdf0e10cSrcweir {
1509cdf0e10cSrcweir Reference< XNameReplace > xNameReplace(
1510cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess(
1511cdf0e10cSrcweir aFullPropName ), UNO_QUERY );
1512cdf0e10cSrcweir Reference< XChangesBatch > xBatch(
1513cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess(
1514cdf0e10cSrcweir OUString() ), UNO_QUERY );
1515cdf0e10cSrcweir
1516cdf0e10cSrcweir if ( xNameReplace.is() && xBatch.is() )
1517cdf0e10cSrcweir {
1518cdf0e10cSrcweir try
1519cdf0e10cSrcweir {
1520cdf0e10cSrcweir // Obtain old value
1521cdf0e10cSrcweir OUString aValueName = aFullPropName;
1522cdf0e10cSrcweir aValueName += OUString::createFromAscii( "/Value" );
1523cdf0e10cSrcweir Any aOldValue
1524cdf0e10cSrcweir = xRootHierNameAccess->getByHierarchicalName(
1525cdf0e10cSrcweir aValueName );
1526cdf0e10cSrcweir // Check value type.
1527cdf0e10cSrcweir if ( aOldValue.getValueType() != aValue.getValueType() )
1528cdf0e10cSrcweir {
1529cdf0e10cSrcweir aCGuard.clear();
1530cdf0e10cSrcweir throw IllegalArgumentException();
1531cdf0e10cSrcweir }
1532cdf0e10cSrcweir
1533cdf0e10cSrcweir // Write value
1534cdf0e10cSrcweir xNameReplace->replaceByName(
1535cdf0e10cSrcweir OUString::createFromAscii( "Value" ),
1536cdf0e10cSrcweir aValue );
1537cdf0e10cSrcweir
1538cdf0e10cSrcweir // Write state ( Now it is a directly set value )
1539cdf0e10cSrcweir xNameReplace->replaceByName(
1540cdf0e10cSrcweir OUString::createFromAscii( "State" ),
1541cdf0e10cSrcweir makeAny(
1542cdf0e10cSrcweir sal_Int32(
1543cdf0e10cSrcweir PropertyState_DIRECT_VALUE ) ) );
1544cdf0e10cSrcweir
1545cdf0e10cSrcweir // Commit changes.
1546cdf0e10cSrcweir xBatch->commitChanges();
1547cdf0e10cSrcweir
1548cdf0e10cSrcweir PropertyChangeEvent aEvt;
1549cdf0e10cSrcweir if ( m_pImpl->m_pPropertyChangeListeners )
1550cdf0e10cSrcweir {
1551cdf0e10cSrcweir // Obtain handle
1552cdf0e10cSrcweir aValueName = aFullPropName;
1553cdf0e10cSrcweir aValueName += OUString::createFromAscii( "/Handle" );
1554cdf0e10cSrcweir sal_Int32 nHandle = -1;
1555cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName( aValueName )
1556cdf0e10cSrcweir >>= nHandle;
1557cdf0e10cSrcweir
1558cdf0e10cSrcweir aEvt.Source = (OWeakObject*)this;
1559cdf0e10cSrcweir aEvt.PropertyName = aPropertyName;
1560cdf0e10cSrcweir aEvt.PropertyHandle = nHandle;
1561cdf0e10cSrcweir aEvt.Further = sal_False;
1562cdf0e10cSrcweir aEvt.OldValue = aOldValue;
1563cdf0e10cSrcweir aEvt.NewValue = aValue;
1564cdf0e10cSrcweir
1565cdf0e10cSrcweir // Callback follows!
1566cdf0e10cSrcweir aCGuard.clear();
1567cdf0e10cSrcweir
1568cdf0e10cSrcweir notifyPropertyChangeEvent( aEvt );
1569cdf0e10cSrcweir }
1570cdf0e10cSrcweir return;
1571cdf0e10cSrcweir }
1572cdf0e10cSrcweir catch ( IllegalArgumentException& )
1573cdf0e10cSrcweir {
1574cdf0e10cSrcweir // replaceByName
1575cdf0e10cSrcweir }
1576cdf0e10cSrcweir catch ( NoSuchElementException& )
1577cdf0e10cSrcweir {
1578cdf0e10cSrcweir // getByHierarchicalName, replaceByName
1579cdf0e10cSrcweir }
1580cdf0e10cSrcweir catch ( WrappedTargetException& )
1581cdf0e10cSrcweir {
1582cdf0e10cSrcweir // replaceByName, commitChanges
1583cdf0e10cSrcweir }
1584cdf0e10cSrcweir }
1585cdf0e10cSrcweir }
1586cdf0e10cSrcweir }
1587cdf0e10cSrcweir
1588cdf0e10cSrcweir throw UnknownPropertyException();
1589cdf0e10cSrcweir }
1590cdf0e10cSrcweir
1591cdf0e10cSrcweir //=========================================================================
1592cdf0e10cSrcweir // virtual
getPropertyValue(const OUString & PropertyName)1593cdf0e10cSrcweir Any SAL_CALL PersistentPropertySet::getPropertyValue(
1594cdf0e10cSrcweir const OUString& PropertyName )
1595cdf0e10cSrcweir throw( UnknownPropertyException,
1596cdf0e10cSrcweir WrappedTargetException,
1597cdf0e10cSrcweir RuntimeException )
1598cdf0e10cSrcweir {
1599cdf0e10cSrcweir if ( !PropertyName.getLength() )
1600cdf0e10cSrcweir throw UnknownPropertyException();
1601cdf0e10cSrcweir
1602cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1603cdf0e10cSrcweir
1604cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xNameAccess(
1605cdf0e10cSrcweir m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1606cdf0e10cSrcweir if ( xNameAccess.is() )
1607cdf0e10cSrcweir {
1608cdf0e10cSrcweir OUString aFullPropName( getFullKey() );
1609cdf0e10cSrcweir aFullPropName += OUString::createFromAscii( "/" );
1610cdf0e10cSrcweir aFullPropName += makeHierarchalNameSegment( PropertyName );
1611cdf0e10cSrcweir aFullPropName += OUString::createFromAscii( "/Value" );
1612cdf0e10cSrcweir try
1613cdf0e10cSrcweir {
1614cdf0e10cSrcweir return xNameAccess->getByHierarchicalName( aFullPropName );
1615cdf0e10cSrcweir }
1616cdf0e10cSrcweir catch ( NoSuchElementException& )
1617cdf0e10cSrcweir {
1618cdf0e10cSrcweir throw UnknownPropertyException();
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir }
1621cdf0e10cSrcweir
1622cdf0e10cSrcweir throw UnknownPropertyException();
1623cdf0e10cSrcweir }
1624cdf0e10cSrcweir
1625cdf0e10cSrcweir //=========================================================================
1626cdf0e10cSrcweir // virtual
addPropertyChangeListener(const OUString & aPropertyName,const Reference<XPropertyChangeListener> & xListener)1627cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::addPropertyChangeListener(
1628cdf0e10cSrcweir const OUString& aPropertyName,
1629cdf0e10cSrcweir const Reference< XPropertyChangeListener >& xListener )
1630cdf0e10cSrcweir throw( UnknownPropertyException,
1631cdf0e10cSrcweir WrappedTargetException,
1632cdf0e10cSrcweir RuntimeException )
1633cdf0e10cSrcweir {
1634cdf0e10cSrcweir // load();
1635cdf0e10cSrcweir
1636cdf0e10cSrcweir if ( !m_pImpl->m_pPropertyChangeListeners )
1637cdf0e10cSrcweir m_pImpl->m_pPropertyChangeListeners =
1638cdf0e10cSrcweir new PropertyListeners_Impl( m_pImpl->m_aMutex );
1639cdf0e10cSrcweir
1640cdf0e10cSrcweir m_pImpl->m_pPropertyChangeListeners->addInterface(
1641cdf0e10cSrcweir aPropertyName, xListener );
1642cdf0e10cSrcweir }
1643cdf0e10cSrcweir
1644cdf0e10cSrcweir //=========================================================================
1645cdf0e10cSrcweir // virtual
removePropertyChangeListener(const OUString & aPropertyName,const Reference<XPropertyChangeListener> & aListener)1646cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::removePropertyChangeListener(
1647cdf0e10cSrcweir const OUString& aPropertyName,
1648cdf0e10cSrcweir const Reference< XPropertyChangeListener >& aListener )
1649cdf0e10cSrcweir throw( UnknownPropertyException,
1650cdf0e10cSrcweir WrappedTargetException,
1651cdf0e10cSrcweir RuntimeException )
1652cdf0e10cSrcweir {
1653cdf0e10cSrcweir // load();
1654cdf0e10cSrcweir
1655cdf0e10cSrcweir if ( m_pImpl->m_pPropertyChangeListeners )
1656cdf0e10cSrcweir m_pImpl->m_pPropertyChangeListeners->removeInterface(
1657cdf0e10cSrcweir aPropertyName, aListener );
1658cdf0e10cSrcweir
1659cdf0e10cSrcweir // Note: Don't want to delete empty container here -> performance.
1660cdf0e10cSrcweir }
1661cdf0e10cSrcweir
1662cdf0e10cSrcweir //=========================================================================
1663cdf0e10cSrcweir // virtual
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)1664cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::addVetoableChangeListener(
1665cdf0e10cSrcweir const OUString&,
1666cdf0e10cSrcweir const Reference< XVetoableChangeListener >& )
1667cdf0e10cSrcweir throw( UnknownPropertyException,
1668cdf0e10cSrcweir WrappedTargetException,
1669cdf0e10cSrcweir RuntimeException )
1670cdf0e10cSrcweir {
1671cdf0e10cSrcweir // load();
1672cdf0e10cSrcweir // OSL_ENSURE( sal_False,
1673cdf0e10cSrcweir // "PersistentPropertySet::addVetoableChangeListener - N.Y.I." );
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir
1676cdf0e10cSrcweir //=========================================================================
1677cdf0e10cSrcweir // virtual
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)1678cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::removeVetoableChangeListener(
1679cdf0e10cSrcweir const OUString&,
1680cdf0e10cSrcweir const Reference< XVetoableChangeListener >& )
1681cdf0e10cSrcweir throw( UnknownPropertyException,
1682cdf0e10cSrcweir WrappedTargetException,
1683cdf0e10cSrcweir RuntimeException )
1684cdf0e10cSrcweir {
1685cdf0e10cSrcweir // load();
1686cdf0e10cSrcweir // OSL_ENSURE( sal_False,
1687cdf0e10cSrcweir // "PersistentPropertySet::removeVetoableChangeListener - N.Y.I." );
1688cdf0e10cSrcweir }
1689cdf0e10cSrcweir
1690cdf0e10cSrcweir //=========================================================================
1691cdf0e10cSrcweir //
1692cdf0e10cSrcweir // XPersistentPropertySet methods.
1693cdf0e10cSrcweir //
1694cdf0e10cSrcweir //=========================================================================
1695cdf0e10cSrcweir
1696cdf0e10cSrcweir // virtual
getRegistry()1697cdf0e10cSrcweir Reference< XPropertySetRegistry > SAL_CALL PersistentPropertySet::getRegistry()
1698cdf0e10cSrcweir throw( RuntimeException )
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir return Reference< XPropertySetRegistry >( m_pImpl->m_pCreator );
1701cdf0e10cSrcweir }
1702cdf0e10cSrcweir
1703cdf0e10cSrcweir //=========================================================================
1704cdf0e10cSrcweir // virtual
getKey()1705cdf0e10cSrcweir OUString SAL_CALL PersistentPropertySet::getKey()
1706cdf0e10cSrcweir throw( RuntimeException )
1707cdf0e10cSrcweir {
1708cdf0e10cSrcweir return m_pImpl->m_aKey;
1709cdf0e10cSrcweir }
1710cdf0e10cSrcweir
1711cdf0e10cSrcweir //=========================================================================
1712cdf0e10cSrcweir //
1713cdf0e10cSrcweir // XNamed methods.
1714cdf0e10cSrcweir //
1715cdf0e10cSrcweir //=========================================================================
1716cdf0e10cSrcweir
1717cdf0e10cSrcweir // virtual
getName()1718cdf0e10cSrcweir rtl::OUString SAL_CALL PersistentPropertySet::getName()
1719cdf0e10cSrcweir throw( RuntimeException )
1720cdf0e10cSrcweir {
1721cdf0e10cSrcweir // same as getKey()
1722cdf0e10cSrcweir return m_pImpl->m_aKey;
1723cdf0e10cSrcweir }
1724cdf0e10cSrcweir
1725cdf0e10cSrcweir //=========================================================================
1726cdf0e10cSrcweir // virtual
setName(const OUString & aName)1727cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::setName( const OUString& aName )
1728cdf0e10cSrcweir throw( RuntimeException )
1729cdf0e10cSrcweir {
1730cdf0e10cSrcweir if ( aName != m_pImpl->m_aKey )
1731cdf0e10cSrcweir m_pImpl->m_pCreator->renamePropertySet( m_pImpl->m_aKey, aName );
1732cdf0e10cSrcweir }
1733cdf0e10cSrcweir
1734cdf0e10cSrcweir //=========================================================================
1735cdf0e10cSrcweir //
1736cdf0e10cSrcweir // XPropertyContainer methods.
1737cdf0e10cSrcweir //
1738cdf0e10cSrcweir //=========================================================================
1739cdf0e10cSrcweir
1740cdf0e10cSrcweir // virtual
addProperty(const OUString & Name,sal_Int16 Attributes,const Any & DefaultValue)1741cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::addProperty(
1742cdf0e10cSrcweir const OUString& Name, sal_Int16 Attributes, const Any& DefaultValue )
1743cdf0e10cSrcweir throw( PropertyExistException,
1744cdf0e10cSrcweir IllegalTypeException,
1745cdf0e10cSrcweir IllegalArgumentException,
1746cdf0e10cSrcweir RuntimeException )
1747cdf0e10cSrcweir {
1748cdf0e10cSrcweir if ( !Name.getLength() )
1749cdf0e10cSrcweir throw IllegalArgumentException();
1750cdf0e10cSrcweir
1751cdf0e10cSrcweir // @@@ What other types can't be written to config server?
1752cdf0e10cSrcweir
1753cdf0e10cSrcweir // Check type class ( Not all types can be written to storage )
1754cdf0e10cSrcweir TypeClass eTypeClass = DefaultValue.getValueTypeClass();
1755cdf0e10cSrcweir if ( eTypeClass == TypeClass_INTERFACE )
1756cdf0e10cSrcweir throw IllegalTypeException();
1757cdf0e10cSrcweir
1758cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1759cdf0e10cSrcweir
1760cdf0e10cSrcweir // Property already in set?
1761cdf0e10cSrcweir
1762cdf0e10cSrcweir OUString aFullValuesName;
1763cdf0e10cSrcweir
1764cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1765cdf0e10cSrcweir m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1766cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
1767cdf0e10cSrcweir {
1768cdf0e10cSrcweir aFullValuesName = getFullKey();
1769cdf0e10cSrcweir OUString aFullPropName = aFullValuesName;
1770cdf0e10cSrcweir aFullPropName += OUString::createFromAscii( "/" );
1771cdf0e10cSrcweir aFullPropName += makeHierarchalNameSegment( Name );
1772cdf0e10cSrcweir
1773cdf0e10cSrcweir if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
1774cdf0e10cSrcweir {
1775cdf0e10cSrcweir // Already in set.
1776cdf0e10cSrcweir throw PropertyExistException();
1777cdf0e10cSrcweir }
1778cdf0e10cSrcweir }
1779cdf0e10cSrcweir
1780cdf0e10cSrcweir // Property is always removeable.
1781cdf0e10cSrcweir Attributes |= PropertyAttribute::REMOVEABLE;
1782cdf0e10cSrcweir
1783cdf0e10cSrcweir // Add property.
1784cdf0e10cSrcweir
1785cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac(
1786cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ),
1787cdf0e10cSrcweir UNO_QUERY );
1788cdf0e10cSrcweir Reference< XNameContainer > xContainer( xFac, UNO_QUERY );
1789cdf0e10cSrcweir Reference< XChangesBatch > xBatch(
1790cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ),
1791cdf0e10cSrcweir UNO_QUERY );
1792cdf0e10cSrcweir
1793cdf0e10cSrcweir OSL_ENSURE( xFac.is(),
1794cdf0e10cSrcweir "PersistentPropertySet::addProperty - No factory!" );
1795cdf0e10cSrcweir
1796cdf0e10cSrcweir OSL_ENSURE( xBatch.is(),
1797cdf0e10cSrcweir "PersistentPropertySet::addProperty - No batch!" );
1798cdf0e10cSrcweir
1799cdf0e10cSrcweir OSL_ENSURE( xContainer.is(),
1800cdf0e10cSrcweir "PersistentPropertySet::addProperty - No container!" );
1801cdf0e10cSrcweir
1802cdf0e10cSrcweir if ( xFac.is() && xBatch.is() && xContainer.is() )
1803cdf0e10cSrcweir {
1804cdf0e10cSrcweir try
1805cdf0e10cSrcweir {
1806cdf0e10cSrcweir // Create new "PropertyValue" config item.
1807cdf0e10cSrcweir Reference< XNameReplace > xNameReplace(
1808cdf0e10cSrcweir xFac->createInstance(), UNO_QUERY );
1809cdf0e10cSrcweir
1810cdf0e10cSrcweir if ( xNameReplace.is() )
1811cdf0e10cSrcweir {
1812cdf0e10cSrcweir // Fill new item...
1813cdf0e10cSrcweir
1814cdf0e10cSrcweir // Set handle
1815cdf0e10cSrcweir xNameReplace->replaceByName(
1816cdf0e10cSrcweir OUString::createFromAscii( "Handle" ),
1817cdf0e10cSrcweir makeAny( sal_Int32( -1 ) ) );
1818cdf0e10cSrcweir
1819cdf0e10cSrcweir // Set default value
1820cdf0e10cSrcweir xNameReplace->replaceByName(
1821cdf0e10cSrcweir OUString::createFromAscii( "Value" ),
1822cdf0e10cSrcweir DefaultValue );
1823cdf0e10cSrcweir
1824cdf0e10cSrcweir // Set state ( always "default" )
1825cdf0e10cSrcweir xNameReplace->replaceByName(
1826cdf0e10cSrcweir OUString::createFromAscii( "State" ),
1827cdf0e10cSrcweir makeAny(
1828cdf0e10cSrcweir sal_Int32(
1829cdf0e10cSrcweir PropertyState_DEFAULT_VALUE ) ) );
1830cdf0e10cSrcweir
1831cdf0e10cSrcweir // Set attributes
1832cdf0e10cSrcweir xNameReplace->replaceByName(
1833cdf0e10cSrcweir OUString::createFromAscii( "Attributes" ),
1834cdf0e10cSrcweir makeAny( sal_Int32( Attributes ) ) );
1835cdf0e10cSrcweir
1836cdf0e10cSrcweir // Insert new item.
1837cdf0e10cSrcweir xContainer->insertByName( Name, makeAny( xNameReplace ) );
1838cdf0e10cSrcweir
1839cdf0e10cSrcweir // Commit changes.
1840cdf0e10cSrcweir xBatch->commitChanges();
1841cdf0e10cSrcweir
1842cdf0e10cSrcweir // Property set info is invalid.
1843cdf0e10cSrcweir if ( m_pImpl->m_pInfo )
1844cdf0e10cSrcweir m_pImpl->m_pInfo->reset();
1845cdf0e10cSrcweir
1846cdf0e10cSrcweir // Notify propertyset info change listeners.
1847cdf0e10cSrcweir if ( m_pImpl->m_pPropSetChangeListeners &&
1848cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners->getLength() )
1849cdf0e10cSrcweir {
1850cdf0e10cSrcweir PropertySetInfoChangeEvent evt(
1851cdf0e10cSrcweir static_cast< OWeakObject * >( this ),
1852cdf0e10cSrcweir Name,
1853cdf0e10cSrcweir -1,
1854cdf0e10cSrcweir PropertySetInfoChange::PROPERTY_INSERTED );
1855cdf0e10cSrcweir notifyPropertySetInfoChange( evt );
1856cdf0e10cSrcweir }
1857cdf0e10cSrcweir
1858cdf0e10cSrcweir // Success.
1859cdf0e10cSrcweir return;
1860cdf0e10cSrcweir }
1861cdf0e10cSrcweir }
1862cdf0e10cSrcweir catch ( IllegalArgumentException& )
1863cdf0e10cSrcweir {
1864cdf0e10cSrcweir // insertByName
1865cdf0e10cSrcweir
1866cdf0e10cSrcweir OSL_ENSURE( sal_False,
1867cdf0e10cSrcweir "PersistentPropertySet::addProperty - "
1868cdf0e10cSrcweir "caught IllegalArgumentException!" );
1869cdf0e10cSrcweir return;
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir catch ( ElementExistException& )
1872cdf0e10cSrcweir {
1873cdf0e10cSrcweir // insertByName
1874cdf0e10cSrcweir
1875cdf0e10cSrcweir OSL_ENSURE( sal_False,
1876cdf0e10cSrcweir "PersistentPropertySet::addProperty - "
1877cdf0e10cSrcweir "caught ElementExistException!" );
1878cdf0e10cSrcweir return;
1879cdf0e10cSrcweir }
1880cdf0e10cSrcweir catch ( WrappedTargetException& )
1881cdf0e10cSrcweir {
1882cdf0e10cSrcweir // replaceByName, insertByName, commitChanges
1883cdf0e10cSrcweir
1884cdf0e10cSrcweir OSL_ENSURE( sal_False,
1885cdf0e10cSrcweir "PersistentPropertySet::addProperty - "
1886cdf0e10cSrcweir "caught WrappedTargetException!" );
1887cdf0e10cSrcweir return;
1888cdf0e10cSrcweir }
1889cdf0e10cSrcweir catch ( RuntimeException& )
1890cdf0e10cSrcweir {
1891cdf0e10cSrcweir throw;
1892cdf0e10cSrcweir }
1893cdf0e10cSrcweir catch ( Exception& )
1894cdf0e10cSrcweir {
1895cdf0e10cSrcweir // createInstance
1896cdf0e10cSrcweir
1897cdf0e10cSrcweir OSL_ENSURE( sal_False,
1898cdf0e10cSrcweir "PersistentPropertySet::addProperty - "
1899cdf0e10cSrcweir "caught Exception!" );
1900cdf0e10cSrcweir return;
1901cdf0e10cSrcweir }
1902cdf0e10cSrcweir }
1903cdf0e10cSrcweir
1904cdf0e10cSrcweir OSL_ENSURE( sal_False,
1905cdf0e10cSrcweir "PersistentPropertySet::addProperty - Error!" );
1906cdf0e10cSrcweir }
1907cdf0e10cSrcweir
1908cdf0e10cSrcweir //=========================================================================
1909cdf0e10cSrcweir // virtual
removeProperty(const OUString & Name)1910cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::removeProperty( const OUString& Name )
1911cdf0e10cSrcweir throw( UnknownPropertyException,
1912cdf0e10cSrcweir NotRemoveableException,
1913cdf0e10cSrcweir RuntimeException )
1914cdf0e10cSrcweir {
1915cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
1916cdf0e10cSrcweir
1917cdf0e10cSrcweir OUString aFullValuesName;
1918cdf0e10cSrcweir OUString aFullPropName;
1919cdf0e10cSrcweir
1920cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
1921cdf0e10cSrcweir m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
1922cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
1923cdf0e10cSrcweir {
1924cdf0e10cSrcweir aFullValuesName = getFullKey();
1925cdf0e10cSrcweir aFullPropName = aFullValuesName;
1926cdf0e10cSrcweir aFullPropName += OUString::createFromAscii( "/" );
1927cdf0e10cSrcweir aFullPropName += makeHierarchalNameSegment( Name );
1928cdf0e10cSrcweir
1929cdf0e10cSrcweir // Property in set?
1930cdf0e10cSrcweir if ( !xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
1931cdf0e10cSrcweir throw UnknownPropertyException();
1932cdf0e10cSrcweir
1933cdf0e10cSrcweir // Property removeable?
1934cdf0e10cSrcweir try
1935cdf0e10cSrcweir {
1936cdf0e10cSrcweir OUString aFullAttrName = aFullPropName;
1937cdf0e10cSrcweir aFullAttrName += OUString::createFromAscii( "/Attributes" );
1938cdf0e10cSrcweir
1939cdf0e10cSrcweir sal_Int32 nAttribs = 0;
1940cdf0e10cSrcweir if ( xRootHierNameAccess->getByHierarchicalName( aFullAttrName )
1941cdf0e10cSrcweir >>= nAttribs )
1942cdf0e10cSrcweir {
1943cdf0e10cSrcweir if ( !( nAttribs & PropertyAttribute::REMOVEABLE ) )
1944cdf0e10cSrcweir {
1945cdf0e10cSrcweir // Not removeable!
1946cdf0e10cSrcweir throw NotRemoveableException();
1947cdf0e10cSrcweir }
1948cdf0e10cSrcweir }
1949cdf0e10cSrcweir else
1950cdf0e10cSrcweir {
1951cdf0e10cSrcweir OSL_ENSURE( sal_False,
1952cdf0e10cSrcweir "PersistentPropertySet::removeProperty - "
1953cdf0e10cSrcweir "No attributes!" );
1954cdf0e10cSrcweir return;
1955cdf0e10cSrcweir }
1956cdf0e10cSrcweir }
1957cdf0e10cSrcweir catch ( NoSuchElementException& )
1958cdf0e10cSrcweir {
1959cdf0e10cSrcweir // getByHierarchicalName
1960cdf0e10cSrcweir
1961cdf0e10cSrcweir OSL_ENSURE( sal_False,
1962cdf0e10cSrcweir "PersistentPropertySet::removeProperty - "
1963cdf0e10cSrcweir "caught NoSuchElementException!" );
1964cdf0e10cSrcweir }
1965cdf0e10cSrcweir
1966cdf0e10cSrcweir // Remove property...
1967cdf0e10cSrcweir
1968cdf0e10cSrcweir Reference< XNameContainer > xContainer(
1969cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ),
1970cdf0e10cSrcweir UNO_QUERY );
1971cdf0e10cSrcweir Reference< XChangesBatch > xBatch(
1972cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ),
1973cdf0e10cSrcweir UNO_QUERY );
1974cdf0e10cSrcweir
1975cdf0e10cSrcweir OSL_ENSURE( xBatch.is(),
1976cdf0e10cSrcweir "PersistentPropertySet::removeProperty - No batch!" );
1977cdf0e10cSrcweir
1978cdf0e10cSrcweir OSL_ENSURE( xContainer.is(),
1979cdf0e10cSrcweir "PersistentPropertySet::removeProperty - No container!" );
1980cdf0e10cSrcweir
1981cdf0e10cSrcweir if ( xBatch.is() && xContainer.is() )
1982cdf0e10cSrcweir {
1983cdf0e10cSrcweir try
1984cdf0e10cSrcweir {
1985cdf0e10cSrcweir sal_Int32 nHandle = -1;
1986cdf0e10cSrcweir
1987cdf0e10cSrcweir if ( m_pImpl->m_pPropSetChangeListeners &&
1988cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners->getLength() )
1989cdf0e10cSrcweir {
1990cdf0e10cSrcweir // Obtain property handle ( needed for propertysetinfo
1991cdf0e10cSrcweir // change event )...
1992cdf0e10cSrcweir
1993cdf0e10cSrcweir try
1994cdf0e10cSrcweir {
1995cdf0e10cSrcweir OUString aFullHandleName = aFullPropName;
1996cdf0e10cSrcweir aFullHandleName
1997cdf0e10cSrcweir += OUString::createFromAscii( "/Handle" );
1998cdf0e10cSrcweir
1999cdf0e10cSrcweir if ( ! ( xRootHierNameAccess->getByHierarchicalName(
2000cdf0e10cSrcweir aFullHandleName ) >>= nHandle ) )
2001cdf0e10cSrcweir nHandle = -1;
2002cdf0e10cSrcweir
2003cdf0e10cSrcweir }
2004cdf0e10cSrcweir catch ( NoSuchElementException& )
2005cdf0e10cSrcweir {
2006cdf0e10cSrcweir // getByHierarchicalName
2007cdf0e10cSrcweir
2008cdf0e10cSrcweir OSL_ENSURE( sal_False,
2009cdf0e10cSrcweir "PersistentPropertySet::removeProperty - "
2010cdf0e10cSrcweir "caught NoSuchElementException!" );
2011cdf0e10cSrcweir nHandle = -1;
2012cdf0e10cSrcweir }
2013cdf0e10cSrcweir }
2014cdf0e10cSrcweir
2015cdf0e10cSrcweir xContainer->removeByName( Name );
2016cdf0e10cSrcweir xBatch->commitChanges();
2017cdf0e10cSrcweir
2018cdf0e10cSrcweir // Property set info is invalid.
2019cdf0e10cSrcweir if ( m_pImpl->m_pInfo )
2020cdf0e10cSrcweir m_pImpl->m_pInfo->reset();
2021cdf0e10cSrcweir
2022cdf0e10cSrcweir // Notify propertyset info change listeners.
2023cdf0e10cSrcweir if ( m_pImpl->m_pPropSetChangeListeners &&
2024cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners->getLength() )
2025cdf0e10cSrcweir {
2026cdf0e10cSrcweir PropertySetInfoChangeEvent evt(
2027cdf0e10cSrcweir static_cast< OWeakObject * >( this ),
2028cdf0e10cSrcweir Name,
2029cdf0e10cSrcweir nHandle,
2030cdf0e10cSrcweir PropertySetInfoChange::PROPERTY_REMOVED );
2031cdf0e10cSrcweir notifyPropertySetInfoChange( evt );
2032cdf0e10cSrcweir }
2033cdf0e10cSrcweir
2034cdf0e10cSrcweir // Success.
2035cdf0e10cSrcweir return;
2036cdf0e10cSrcweir }
2037cdf0e10cSrcweir catch ( NoSuchElementException& )
2038cdf0e10cSrcweir {
2039cdf0e10cSrcweir // removeByName
2040cdf0e10cSrcweir
2041cdf0e10cSrcweir OSL_ENSURE( sal_False,
2042cdf0e10cSrcweir "PersistentPropertySet::removeProperty - "
2043cdf0e10cSrcweir "caught NoSuchElementException!" );
2044cdf0e10cSrcweir return;
2045cdf0e10cSrcweir }
2046cdf0e10cSrcweir catch ( WrappedTargetException& )
2047cdf0e10cSrcweir {
2048cdf0e10cSrcweir // commitChanges
2049cdf0e10cSrcweir
2050cdf0e10cSrcweir OSL_ENSURE( sal_False,
2051cdf0e10cSrcweir "PersistentPropertySet::removeProperty - "
2052cdf0e10cSrcweir "caught WrappedTargetException!" );
2053cdf0e10cSrcweir return;
2054cdf0e10cSrcweir }
2055cdf0e10cSrcweir }
2056cdf0e10cSrcweir }
2057cdf0e10cSrcweir
2058cdf0e10cSrcweir OSL_ENSURE( sal_False,
2059cdf0e10cSrcweir "PersistentPropertySet::removeProperty - Error!" );
2060cdf0e10cSrcweir }
2061cdf0e10cSrcweir
2062cdf0e10cSrcweir //=========================================================================
2063cdf0e10cSrcweir //
2064cdf0e10cSrcweir // XPropertySetInfoChangeNotifier methods.
2065cdf0e10cSrcweir //
2066cdf0e10cSrcweir //=========================================================================
2067cdf0e10cSrcweir
2068cdf0e10cSrcweir // virtual
addPropertySetInfoChangeListener(const Reference<XPropertySetInfoChangeListener> & Listener)2069cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::addPropertySetInfoChangeListener(
2070cdf0e10cSrcweir const Reference< XPropertySetInfoChangeListener >& Listener )
2071cdf0e10cSrcweir throw( RuntimeException )
2072cdf0e10cSrcweir {
2073cdf0e10cSrcweir if ( !m_pImpl->m_pPropSetChangeListeners )
2074cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners =
2075cdf0e10cSrcweir new OInterfaceContainerHelper( m_pImpl->m_aMutex );
2076cdf0e10cSrcweir
2077cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
2078cdf0e10cSrcweir }
2079cdf0e10cSrcweir
2080cdf0e10cSrcweir //=========================================================================
2081cdf0e10cSrcweir // virtual
removePropertySetInfoChangeListener(const Reference<XPropertySetInfoChangeListener> & Listener)2082cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::removePropertySetInfoChangeListener(
2083cdf0e10cSrcweir const Reference< XPropertySetInfoChangeListener >& Listener )
2084cdf0e10cSrcweir throw( RuntimeException )
2085cdf0e10cSrcweir {
2086cdf0e10cSrcweir if ( m_pImpl->m_pPropSetChangeListeners )
2087cdf0e10cSrcweir m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
2088cdf0e10cSrcweir }
2089cdf0e10cSrcweir
2090cdf0e10cSrcweir //=========================================================================
2091cdf0e10cSrcweir //
2092cdf0e10cSrcweir // XPropertyAccess methods.
2093cdf0e10cSrcweir //
2094cdf0e10cSrcweir //=========================================================================
2095cdf0e10cSrcweir
2096cdf0e10cSrcweir // virtual
getPropertyValues()2097cdf0e10cSrcweir Sequence< PropertyValue > SAL_CALL PersistentPropertySet::getPropertyValues()
2098cdf0e10cSrcweir throw( RuntimeException )
2099cdf0e10cSrcweir {
2100cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
2101cdf0e10cSrcweir
2102cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2103cdf0e10cSrcweir m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
2104cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
2105cdf0e10cSrcweir {
2106cdf0e10cSrcweir try
2107cdf0e10cSrcweir {
2108cdf0e10cSrcweir Reference< XNameAccess > xNameAccess;
2109cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(getFullKey())
2110cdf0e10cSrcweir >>= xNameAccess;
2111cdf0e10cSrcweir if ( xNameAccess.is() )
2112cdf0e10cSrcweir {
2113cdf0e10cSrcweir // Obtain property names.
2114cdf0e10cSrcweir
2115cdf0e10cSrcweir Sequence< OUString > aElems = xNameAccess->getElementNames();
2116cdf0e10cSrcweir
2117cdf0e10cSrcweir sal_Int32 nCount = aElems.getLength();
2118cdf0e10cSrcweir if ( nCount )
2119cdf0e10cSrcweir {
2120cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xHierNameAccess(
2121cdf0e10cSrcweir xNameAccess, UNO_QUERY );
2122cdf0e10cSrcweir
2123cdf0e10cSrcweir OSL_ENSURE( xHierNameAccess.is(),
2124cdf0e10cSrcweir "PersistentPropertySet::getPropertyValues - "
2125cdf0e10cSrcweir "No hierarchical name access!" );
2126cdf0e10cSrcweir
2127cdf0e10cSrcweir if ( xHierNameAccess.is() )
2128cdf0e10cSrcweir {
2129cdf0e10cSrcweir Sequence< PropertyValue > aValues( nCount );
2130cdf0e10cSrcweir
2131cdf0e10cSrcweir const OUString aHandleName
2132cdf0e10cSrcweir = OUString::createFromAscii( "/Handle" );
2133cdf0e10cSrcweir const OUString aValueName
2134cdf0e10cSrcweir = OUString::createFromAscii( "/Value" );
2135cdf0e10cSrcweir const OUString aStateName
2136cdf0e10cSrcweir = OUString::createFromAscii( "/State" );
2137cdf0e10cSrcweir
2138cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
2139cdf0e10cSrcweir {
2140cdf0e10cSrcweir PropertyValue& rValue = aValues[ n ];
2141cdf0e10cSrcweir OUString rName = aElems[ n ];
2142cdf0e10cSrcweir OUString aXMLName
2143cdf0e10cSrcweir = makeHierarchalNameSegment( rName );
2144cdf0e10cSrcweir
2145cdf0e10cSrcweir // Set property name.
2146cdf0e10cSrcweir
2147cdf0e10cSrcweir rValue.Name = rName;
2148cdf0e10cSrcweir
2149cdf0e10cSrcweir try
2150cdf0e10cSrcweir {
2151cdf0e10cSrcweir // Obtain and set property handle
2152cdf0e10cSrcweir OUString aHierName = aXMLName;
2153cdf0e10cSrcweir aHierName += aHandleName;
2154cdf0e10cSrcweir Any aKeyValue
2155cdf0e10cSrcweir = xHierNameAccess->getByHierarchicalName(
2156cdf0e10cSrcweir aHierName );
2157cdf0e10cSrcweir
2158cdf0e10cSrcweir if ( !( aKeyValue >>= rValue.Handle ) )
2159cdf0e10cSrcweir OSL_ENSURE( sal_False,
2160cdf0e10cSrcweir "PersistentPropertySet::getPropertyValues - "
2161cdf0e10cSrcweir "Error getting property handle!" );
2162cdf0e10cSrcweir }
2163cdf0e10cSrcweir catch ( NoSuchElementException& )
2164cdf0e10cSrcweir {
2165cdf0e10cSrcweir // getByHierarchicalName
2166cdf0e10cSrcweir
2167cdf0e10cSrcweir OSL_ENSURE( sal_False,
2168cdf0e10cSrcweir "PersistentPropertySet::getPropertyValues - "
2169cdf0e10cSrcweir "NoSuchElementException!" );
2170cdf0e10cSrcweir }
2171cdf0e10cSrcweir
2172cdf0e10cSrcweir try
2173cdf0e10cSrcweir {
2174cdf0e10cSrcweir // Obtain and set property value
2175cdf0e10cSrcweir OUString aHierName = aXMLName;
2176cdf0e10cSrcweir aHierName += aValueName;
2177cdf0e10cSrcweir rValue.Value
2178cdf0e10cSrcweir = xHierNameAccess->getByHierarchicalName(
2179cdf0e10cSrcweir aHierName );
2180cdf0e10cSrcweir
2181cdf0e10cSrcweir // Note: The value may be void if addProperty
2182cdf0e10cSrcweir // was called with a default value
2183cdf0e10cSrcweir // of type void.
2184cdf0e10cSrcweir }
2185cdf0e10cSrcweir catch ( NoSuchElementException& )
2186cdf0e10cSrcweir {
2187cdf0e10cSrcweir // getByHierarchicalName
2188cdf0e10cSrcweir
2189cdf0e10cSrcweir OSL_ENSURE( sal_False,
2190cdf0e10cSrcweir "PersistentPropertySet::getPropertyValues - "
2191cdf0e10cSrcweir "NoSuchElementException!" );
2192cdf0e10cSrcweir }
2193cdf0e10cSrcweir
2194cdf0e10cSrcweir try
2195cdf0e10cSrcweir {
2196cdf0e10cSrcweir // Obtain and set property state
2197cdf0e10cSrcweir OUString aHierName = aXMLName;
2198cdf0e10cSrcweir aHierName += aStateName;
2199cdf0e10cSrcweir Any aKeyValue
2200cdf0e10cSrcweir = xHierNameAccess->getByHierarchicalName(
2201cdf0e10cSrcweir aHierName );
2202cdf0e10cSrcweir
2203cdf0e10cSrcweir sal_Int32 nState = 0;
2204cdf0e10cSrcweir if ( !( aKeyValue >>= nState ) )
2205cdf0e10cSrcweir OSL_ENSURE( sal_False,
2206cdf0e10cSrcweir "PersistentPropertySet::getPropertyValues - "
2207cdf0e10cSrcweir "Error getting property state!" );
2208cdf0e10cSrcweir else
2209cdf0e10cSrcweir rValue.State = PropertyState( nState );
2210cdf0e10cSrcweir }
2211cdf0e10cSrcweir catch ( NoSuchElementException& )
2212cdf0e10cSrcweir {
2213cdf0e10cSrcweir // getByHierarchicalName
2214cdf0e10cSrcweir
2215cdf0e10cSrcweir OSL_ENSURE( sal_False,
2216cdf0e10cSrcweir "PersistentPropertySet::getPropertyValues - "
2217cdf0e10cSrcweir "NoSuchElementException!" );
2218cdf0e10cSrcweir }
2219cdf0e10cSrcweir }
2220cdf0e10cSrcweir
2221cdf0e10cSrcweir return aValues;
2222cdf0e10cSrcweir }
2223cdf0e10cSrcweir }
2224cdf0e10cSrcweir }
2225cdf0e10cSrcweir }
2226cdf0e10cSrcweir catch ( NoSuchElementException& )
2227cdf0e10cSrcweir {
2228cdf0e10cSrcweir // getByHierarchicalName
2229cdf0e10cSrcweir }
2230cdf0e10cSrcweir }
2231cdf0e10cSrcweir
2232cdf0e10cSrcweir return Sequence< PropertyValue >( 0 );
2233cdf0e10cSrcweir }
2234cdf0e10cSrcweir
2235cdf0e10cSrcweir //=========================================================================
2236cdf0e10cSrcweir // virtual
setPropertyValues(const Sequence<PropertyValue> & aProps)2237cdf0e10cSrcweir void SAL_CALL PersistentPropertySet::setPropertyValues(
2238cdf0e10cSrcweir const Sequence< PropertyValue >& aProps )
2239cdf0e10cSrcweir throw( UnknownPropertyException,
2240cdf0e10cSrcweir PropertyVetoException,
2241cdf0e10cSrcweir IllegalArgumentException,
2242cdf0e10cSrcweir WrappedTargetException,
2243cdf0e10cSrcweir RuntimeException )
2244cdf0e10cSrcweir {
2245cdf0e10cSrcweir sal_Int32 nCount = aProps.getLength();
2246cdf0e10cSrcweir if ( !nCount )
2247cdf0e10cSrcweir return;
2248cdf0e10cSrcweir
2249cdf0e10cSrcweir osl::ClearableGuard< osl::Mutex > aCGuard( m_pImpl->m_aMutex );
2250cdf0e10cSrcweir
2251cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2252cdf0e10cSrcweir m_pImpl->m_pCreator->getRootConfigReadAccess(), UNO_QUERY );
2253cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
2254cdf0e10cSrcweir {
2255cdf0e10cSrcweir const PropertyValue* pNewValues = aProps.getConstArray();
2256cdf0e10cSrcweir
2257cdf0e10cSrcweir typedef std::list< PropertyChangeEvent > Events;
2258cdf0e10cSrcweir Events aEvents;
2259cdf0e10cSrcweir
2260cdf0e10cSrcweir OUString aFullPropNamePrefix( getFullKey() );
2261cdf0e10cSrcweir aFullPropNamePrefix += OUString::createFromAscii( "/" );
2262cdf0e10cSrcweir
2263cdf0e10cSrcweir // Iterate over given property value sequence.
2264cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
2265cdf0e10cSrcweir {
2266cdf0e10cSrcweir const PropertyValue& rNewValue = pNewValues[ n ];
2267cdf0e10cSrcweir const OUString& rName = rNewValue.Name;
2268cdf0e10cSrcweir
2269cdf0e10cSrcweir OUString aFullPropName = aFullPropNamePrefix;
2270cdf0e10cSrcweir aFullPropName += makeHierarchalNameSegment( rName );
2271cdf0e10cSrcweir
2272cdf0e10cSrcweir // Does property exist?
2273cdf0e10cSrcweir if ( xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
2274cdf0e10cSrcweir {
2275cdf0e10cSrcweir Reference< XNameReplace > xNameReplace(
2276cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess(
2277cdf0e10cSrcweir aFullPropName ), UNO_QUERY );
2278cdf0e10cSrcweir Reference< XChangesBatch > xBatch(
2279cdf0e10cSrcweir m_pImpl->m_pCreator->getConfigWriteAccess(
2280cdf0e10cSrcweir OUString() ), UNO_QUERY );
2281cdf0e10cSrcweir
2282cdf0e10cSrcweir if ( xNameReplace.is() && xBatch.is() )
2283cdf0e10cSrcweir {
2284cdf0e10cSrcweir try
2285cdf0e10cSrcweir {
2286cdf0e10cSrcweir // Write handle
2287cdf0e10cSrcweir xNameReplace->replaceByName(
2288cdf0e10cSrcweir OUString::createFromAscii( "Handle" ),
2289cdf0e10cSrcweir makeAny( rNewValue.Handle ) );
2290cdf0e10cSrcweir
2291cdf0e10cSrcweir // Save old value
2292cdf0e10cSrcweir OUString aValueName = aFullPropName;
2293cdf0e10cSrcweir aValueName += OUString::createFromAscii( "/Value" );
2294cdf0e10cSrcweir Any aOldValue
2295cdf0e10cSrcweir = xRootHierNameAccess->getByHierarchicalName(
2296cdf0e10cSrcweir aValueName );
2297cdf0e10cSrcweir // Write value
2298cdf0e10cSrcweir xNameReplace->replaceByName(
2299cdf0e10cSrcweir OUString::createFromAscii( "Value" ),
2300cdf0e10cSrcweir rNewValue.Value );
2301cdf0e10cSrcweir
2302cdf0e10cSrcweir // Write state ( Now it is a directly set value )
2303cdf0e10cSrcweir xNameReplace->replaceByName(
2304cdf0e10cSrcweir OUString::createFromAscii( "State" ),
2305cdf0e10cSrcweir makeAny(
2306cdf0e10cSrcweir sal_Int32(
2307cdf0e10cSrcweir PropertyState_DIRECT_VALUE ) ) );
2308cdf0e10cSrcweir
2309cdf0e10cSrcweir // Commit changes.
2310cdf0e10cSrcweir xBatch->commitChanges();
2311cdf0e10cSrcweir
2312cdf0e10cSrcweir if ( m_pImpl->m_pPropertyChangeListeners )
2313cdf0e10cSrcweir {
2314cdf0e10cSrcweir PropertyChangeEvent aEvt;
2315cdf0e10cSrcweir aEvt.Source = (OWeakObject*)this;
2316cdf0e10cSrcweir aEvt.PropertyName = rNewValue.Name;
2317cdf0e10cSrcweir aEvt.PropertyHandle = rNewValue.Handle;
2318cdf0e10cSrcweir aEvt.Further = sal_False;
2319cdf0e10cSrcweir aEvt.OldValue = aOldValue;
2320cdf0e10cSrcweir aEvt.NewValue = rNewValue.Value;
2321cdf0e10cSrcweir
2322cdf0e10cSrcweir aEvents.push_back( aEvt );
2323cdf0e10cSrcweir }
2324cdf0e10cSrcweir }
2325cdf0e10cSrcweir catch ( IllegalArgumentException& )
2326cdf0e10cSrcweir {
2327cdf0e10cSrcweir // replaceByName
2328cdf0e10cSrcweir }
2329cdf0e10cSrcweir catch ( NoSuchElementException& )
2330cdf0e10cSrcweir {
2331cdf0e10cSrcweir // getByHierarchicalName, replaceByName
2332cdf0e10cSrcweir }
2333cdf0e10cSrcweir catch ( WrappedTargetException& )
2334cdf0e10cSrcweir {
2335cdf0e10cSrcweir // replaceByName, commitChanges
2336cdf0e10cSrcweir }
2337cdf0e10cSrcweir }
2338cdf0e10cSrcweir }
2339cdf0e10cSrcweir }
2340cdf0e10cSrcweir
2341cdf0e10cSrcweir // Callback follows!
2342cdf0e10cSrcweir aCGuard.clear();
2343cdf0e10cSrcweir
2344cdf0e10cSrcweir if ( m_pImpl->m_pPropertyChangeListeners )
2345cdf0e10cSrcweir {
2346cdf0e10cSrcweir // Notify property changes.
2347cdf0e10cSrcweir Events::const_iterator it = aEvents.begin();
2348cdf0e10cSrcweir Events::const_iterator end = aEvents.end();
2349cdf0e10cSrcweir
2350cdf0e10cSrcweir while ( it != end )
2351cdf0e10cSrcweir {
2352cdf0e10cSrcweir notifyPropertyChangeEvent( (*it) );
2353cdf0e10cSrcweir it++;
2354cdf0e10cSrcweir }
2355cdf0e10cSrcweir }
2356cdf0e10cSrcweir
2357cdf0e10cSrcweir return;
2358cdf0e10cSrcweir }
2359cdf0e10cSrcweir
2360cdf0e10cSrcweir OSL_ENSURE( sal_False,
2361cdf0e10cSrcweir "PersistentPropertySet::setPropertyValues - Nothing set!" );
2362cdf0e10cSrcweir }
2363cdf0e10cSrcweir
2364cdf0e10cSrcweir //=========================================================================
2365cdf0e10cSrcweir //
2366cdf0e10cSrcweir // Non-interface methods
2367cdf0e10cSrcweir //
2368cdf0e10cSrcweir //=========================================================================
2369cdf0e10cSrcweir
notifyPropertyChangeEvent(const PropertyChangeEvent & rEvent) const2370cdf0e10cSrcweir void PersistentPropertySet::notifyPropertyChangeEvent(
2371cdf0e10cSrcweir const PropertyChangeEvent& rEvent ) const
2372cdf0e10cSrcweir {
2373cdf0e10cSrcweir // Get "normal" listeners for the property.
2374cdf0e10cSrcweir OInterfaceContainerHelper* pContainer =
2375cdf0e10cSrcweir m_pImpl->m_pPropertyChangeListeners->getContainer(
2376cdf0e10cSrcweir rEvent.PropertyName );
2377cdf0e10cSrcweir if ( pContainer && pContainer->getLength() )
2378cdf0e10cSrcweir {
2379cdf0e10cSrcweir OInterfaceIteratorHelper aIter( *pContainer );
2380cdf0e10cSrcweir while ( aIter.hasMoreElements() )
2381cdf0e10cSrcweir {
2382cdf0e10cSrcweir // Propagate event.
2383cdf0e10cSrcweir Reference< XPropertyChangeListener > xListener(
2384cdf0e10cSrcweir aIter.next(), UNO_QUERY );
2385cdf0e10cSrcweir if ( xListener.is() )
2386cdf0e10cSrcweir xListener->propertyChange( rEvent );
2387cdf0e10cSrcweir }
2388cdf0e10cSrcweir }
2389cdf0e10cSrcweir
2390cdf0e10cSrcweir // Get "normal" listeners for all properties.
2391cdf0e10cSrcweir OInterfaceContainerHelper* pNoNameContainer =
2392cdf0e10cSrcweir m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() );
2393cdf0e10cSrcweir if ( pNoNameContainer && pNoNameContainer->getLength() )
2394cdf0e10cSrcweir {
2395cdf0e10cSrcweir OInterfaceIteratorHelper aIter( *pNoNameContainer );
2396cdf0e10cSrcweir while ( aIter.hasMoreElements() )
2397cdf0e10cSrcweir {
2398cdf0e10cSrcweir // Propagate event.
2399cdf0e10cSrcweir Reference< XPropertyChangeListener > xListener(
2400cdf0e10cSrcweir aIter.next(), UNO_QUERY );
2401cdf0e10cSrcweir if ( xListener.is() )
2402cdf0e10cSrcweir xListener->propertyChange( rEvent );
2403cdf0e10cSrcweir }
2404cdf0e10cSrcweir }
2405cdf0e10cSrcweir }
2406cdf0e10cSrcweir
2407cdf0e10cSrcweir //=========================================================================
notifyPropertySetInfoChange(const PropertySetInfoChangeEvent & evt) const2408cdf0e10cSrcweir void PersistentPropertySet::notifyPropertySetInfoChange(
2409cdf0e10cSrcweir const PropertySetInfoChangeEvent& evt ) const
2410cdf0e10cSrcweir {
2411cdf0e10cSrcweir if ( !m_pImpl->m_pPropSetChangeListeners )
2412cdf0e10cSrcweir return;
2413cdf0e10cSrcweir
2414cdf0e10cSrcweir // Notify event listeners.
2415cdf0e10cSrcweir OInterfaceIteratorHelper aIter( *( m_pImpl->m_pPropSetChangeListeners ) );
2416cdf0e10cSrcweir while ( aIter.hasMoreElements() )
2417cdf0e10cSrcweir {
2418cdf0e10cSrcweir // Propagate event.
2419cdf0e10cSrcweir Reference< XPropertySetInfoChangeListener >
2420cdf0e10cSrcweir xListener( aIter.next(), UNO_QUERY );
2421cdf0e10cSrcweir if ( xListener.is() )
2422cdf0e10cSrcweir xListener->propertySetInfoChange( evt );
2423cdf0e10cSrcweir }
2424cdf0e10cSrcweir }
2425cdf0e10cSrcweir
2426cdf0e10cSrcweir //=========================================================================
getFullKey()2427cdf0e10cSrcweir const OUString& PersistentPropertySet::getFullKey()
2428cdf0e10cSrcweir {
2429cdf0e10cSrcweir if ( !m_pImpl->m_aFullKey.getLength() )
2430cdf0e10cSrcweir {
2431cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
2432cdf0e10cSrcweir if ( !m_pImpl->m_aFullKey.getLength() )
2433cdf0e10cSrcweir {
2434cdf0e10cSrcweir m_pImpl->m_aFullKey
2435cdf0e10cSrcweir = makeHierarchalNameSegment( m_pImpl->m_aKey );
2436cdf0e10cSrcweir m_pImpl->m_aFullKey
2437cdf0e10cSrcweir += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/Values" ) );
2438cdf0e10cSrcweir }
2439cdf0e10cSrcweir }
2440cdf0e10cSrcweir
2441cdf0e10cSrcweir return m_pImpl->m_aFullKey;
2442cdf0e10cSrcweir }
2443cdf0e10cSrcweir
2444cdf0e10cSrcweir //=========================================================================
getPropertySetRegistry()2445cdf0e10cSrcweir PropertySetRegistry& PersistentPropertySet::getPropertySetRegistry()
2446cdf0e10cSrcweir {
2447cdf0e10cSrcweir return *m_pImpl->m_pCreator;
2448cdf0e10cSrcweir }
2449cdf0e10cSrcweir
2450cdf0e10cSrcweir //=========================================================================
2451cdf0e10cSrcweir //=========================================================================
2452cdf0e10cSrcweir //
2453cdf0e10cSrcweir // PropertySetInfo_Impl Implementation.
2454cdf0e10cSrcweir //
2455cdf0e10cSrcweir //=========================================================================
2456cdf0e10cSrcweir //=========================================================================
2457cdf0e10cSrcweir
PropertySetInfo_Impl(const Reference<XMultiServiceFactory> & rxSMgr,PersistentPropertySet * pOwner)2458cdf0e10cSrcweir PropertySetInfo_Impl::PropertySetInfo_Impl(
2459cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rxSMgr,
2460cdf0e10cSrcweir PersistentPropertySet* pOwner )
2461cdf0e10cSrcweir : m_xSMgr( rxSMgr ),
2462cdf0e10cSrcweir m_pProps( NULL ),
2463cdf0e10cSrcweir m_pOwner( pOwner )
2464cdf0e10cSrcweir {
2465cdf0e10cSrcweir }
2466cdf0e10cSrcweir
2467cdf0e10cSrcweir //=========================================================================
2468cdf0e10cSrcweir // virtual
~PropertySetInfo_Impl()2469cdf0e10cSrcweir PropertySetInfo_Impl::~PropertySetInfo_Impl()
2470cdf0e10cSrcweir {
2471cdf0e10cSrcweir delete m_pProps;
2472cdf0e10cSrcweir
2473cdf0e10cSrcweir // !!! Do not delete m_pOwner !!!
2474cdf0e10cSrcweir }
2475cdf0e10cSrcweir
2476cdf0e10cSrcweir //=========================================================================
2477cdf0e10cSrcweir //
2478cdf0e10cSrcweir // XInterface methods.
2479cdf0e10cSrcweir //
2480cdf0e10cSrcweir //=========================================================================
2481cdf0e10cSrcweir
2482cdf0e10cSrcweir XINTERFACE_IMPL_2( PropertySetInfo_Impl,
2483cdf0e10cSrcweir XTypeProvider,
2484cdf0e10cSrcweir XPropertySetInfo );
2485cdf0e10cSrcweir
2486cdf0e10cSrcweir //=========================================================================
2487cdf0e10cSrcweir //
2488cdf0e10cSrcweir // XTypeProvider methods.
2489cdf0e10cSrcweir //
2490cdf0e10cSrcweir //=========================================================================
2491cdf0e10cSrcweir
2492cdf0e10cSrcweir XTYPEPROVIDER_IMPL_2( PropertySetInfo_Impl,
2493cdf0e10cSrcweir XTypeProvider,
2494cdf0e10cSrcweir XPropertySetInfo );
2495cdf0e10cSrcweir
2496cdf0e10cSrcweir //=========================================================================
2497cdf0e10cSrcweir //
2498cdf0e10cSrcweir // XPropertySetInfo methods.
2499cdf0e10cSrcweir //
2500cdf0e10cSrcweir //=========================================================================
2501cdf0e10cSrcweir
2502cdf0e10cSrcweir // virtual
getProperties()2503cdf0e10cSrcweir Sequence< Property > SAL_CALL PropertySetInfo_Impl::getProperties()
2504cdf0e10cSrcweir throw( RuntimeException )
2505cdf0e10cSrcweir {
2506cdf0e10cSrcweir if ( !m_pProps )
2507cdf0e10cSrcweir {
2508cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2509cdf0e10cSrcweir m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2510cdf0e10cSrcweir UNO_QUERY );
2511cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
2512cdf0e10cSrcweir {
2513cdf0e10cSrcweir try
2514cdf0e10cSrcweir {
2515cdf0e10cSrcweir Reference< XNameAccess > xNameAccess;
2516cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName(
2517cdf0e10cSrcweir m_pOwner->getFullKey() )
2518cdf0e10cSrcweir >>= xNameAccess;
2519cdf0e10cSrcweir if ( xNameAccess.is() )
2520cdf0e10cSrcweir {
2521cdf0e10cSrcweir // Obtain property names.
2522cdf0e10cSrcweir
2523cdf0e10cSrcweir Sequence< OUString > aElems
2524cdf0e10cSrcweir = xNameAccess->getElementNames();
2525cdf0e10cSrcweir
2526cdf0e10cSrcweir sal_uInt32 nCount = aElems.getLength();
2527cdf0e10cSrcweir Sequence< Property >* pPropSeq
2528cdf0e10cSrcweir = new Sequence< Property >( nCount );
2529cdf0e10cSrcweir
2530cdf0e10cSrcweir if ( nCount )
2531cdf0e10cSrcweir {
2532cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xHierNameAccess(
2533cdf0e10cSrcweir xNameAccess, UNO_QUERY );
2534cdf0e10cSrcweir
2535cdf0e10cSrcweir OSL_ENSURE( xHierNameAccess.is(),
2536cdf0e10cSrcweir "PropertySetInfo_Impl::getProperties - "
2537cdf0e10cSrcweir "No hierarchical name access!" );
2538cdf0e10cSrcweir
2539cdf0e10cSrcweir if ( xHierNameAccess.is() )
2540cdf0e10cSrcweir {
2541cdf0e10cSrcweir const OUString aHandleName
2542cdf0e10cSrcweir = OUString::createFromAscii( "/Handle" );
2543cdf0e10cSrcweir const OUString aValueName
2544cdf0e10cSrcweir = OUString::createFromAscii( "/Value" );
2545cdf0e10cSrcweir const OUString aAttrName
2546cdf0e10cSrcweir = OUString::createFromAscii( "/Attributes" );
2547cdf0e10cSrcweir
2548cdf0e10cSrcweir Property* pProps = pPropSeq->getArray();
2549cdf0e10cSrcweir
2550cdf0e10cSrcweir for ( sal_uInt32 n = 0; n < nCount; ++n )
2551cdf0e10cSrcweir {
2552cdf0e10cSrcweir Property& rProp = pProps[ n ];
2553cdf0e10cSrcweir OUString rName = aElems[ n ];
2554cdf0e10cSrcweir OUString aXMLName
2555cdf0e10cSrcweir = makeHierarchalNameSegment( rName );
2556cdf0e10cSrcweir
2557cdf0e10cSrcweir // Set property name.
2558cdf0e10cSrcweir
2559cdf0e10cSrcweir rProp.Name = rName;
2560cdf0e10cSrcweir
2561cdf0e10cSrcweir try
2562cdf0e10cSrcweir {
2563cdf0e10cSrcweir // Obtain and set property handle
2564cdf0e10cSrcweir rtl::OUString aHierName = aXMLName;
2565cdf0e10cSrcweir aHierName += aHandleName;
2566cdf0e10cSrcweir Any aKeyValue
2567cdf0e10cSrcweir = xHierNameAccess->getByHierarchicalName(
2568cdf0e10cSrcweir aHierName );
2569cdf0e10cSrcweir
2570cdf0e10cSrcweir if ( !( aKeyValue >>= rProp.Handle ) )
2571cdf0e10cSrcweir OSL_ENSURE( sal_False,
2572cdf0e10cSrcweir "PropertySetInfo_Impl::getProperties - "
2573cdf0e10cSrcweir "Error getting property handle!" );
2574cdf0e10cSrcweir }
2575cdf0e10cSrcweir catch ( NoSuchElementException& )
2576cdf0e10cSrcweir {
2577cdf0e10cSrcweir // getByHierarchicalName
2578cdf0e10cSrcweir
2579cdf0e10cSrcweir OSL_ENSURE( sal_False,
2580cdf0e10cSrcweir "PropertySetInfo_Impl::getProperties - "
2581cdf0e10cSrcweir "NoSuchElementException!" );
2582cdf0e10cSrcweir }
2583cdf0e10cSrcweir
2584cdf0e10cSrcweir try
2585cdf0e10cSrcweir {
2586cdf0e10cSrcweir // Obtain and set property type
2587cdf0e10cSrcweir rtl::OUString aHierName = aXMLName;
2588cdf0e10cSrcweir aHierName += aValueName;
2589cdf0e10cSrcweir Any aKeyValue
2590cdf0e10cSrcweir = xHierNameAccess->getByHierarchicalName(
2591cdf0e10cSrcweir aHierName );
2592cdf0e10cSrcweir
2593cdf0e10cSrcweir // Note: The type may be void if addProperty
2594cdf0e10cSrcweir // was called with a default value
2595cdf0e10cSrcweir // of type void.
2596cdf0e10cSrcweir
2597cdf0e10cSrcweir rProp.Type = aKeyValue.getValueType();
2598cdf0e10cSrcweir }
2599cdf0e10cSrcweir catch ( NoSuchElementException& )
2600cdf0e10cSrcweir {
2601cdf0e10cSrcweir // getByHierarchicalName
2602cdf0e10cSrcweir
2603cdf0e10cSrcweir OSL_ENSURE( sal_False,
2604cdf0e10cSrcweir "PropertySetInfo_Impl::getProperties - "
2605cdf0e10cSrcweir "NoSuchElementException!" );
2606cdf0e10cSrcweir }
2607cdf0e10cSrcweir
2608cdf0e10cSrcweir try
2609cdf0e10cSrcweir {
2610cdf0e10cSrcweir // Obtain and set property attributes
2611cdf0e10cSrcweir rtl::OUString aHierName = aXMLName;
2612cdf0e10cSrcweir aHierName += aAttrName;
2613cdf0e10cSrcweir Any aKeyValue
2614cdf0e10cSrcweir = xHierNameAccess->getByHierarchicalName(
2615cdf0e10cSrcweir aHierName );
2616cdf0e10cSrcweir
2617cdf0e10cSrcweir sal_Int32 nAttribs = 0;
2618cdf0e10cSrcweir if ( aKeyValue >>= nAttribs )
2619cdf0e10cSrcweir rProp.Attributes
2620cdf0e10cSrcweir = sal_Int16( nAttribs );
2621cdf0e10cSrcweir else
2622cdf0e10cSrcweir OSL_ENSURE( sal_False,
2623cdf0e10cSrcweir "PropertySetInfo_Impl::getProperties - "
2624cdf0e10cSrcweir "Error getting property attributes!" );
2625cdf0e10cSrcweir }
2626cdf0e10cSrcweir catch ( NoSuchElementException& )
2627cdf0e10cSrcweir {
2628cdf0e10cSrcweir // getByHierarchicalName
2629cdf0e10cSrcweir
2630cdf0e10cSrcweir OSL_ENSURE( sal_False,
2631cdf0e10cSrcweir "PropertySetInfo_Impl::getProperties - "
2632cdf0e10cSrcweir "NoSuchElementException!" );
2633cdf0e10cSrcweir }
2634cdf0e10cSrcweir }
2635cdf0e10cSrcweir }
2636cdf0e10cSrcweir }
2637cdf0e10cSrcweir
2638cdf0e10cSrcweir // Success.
2639cdf0e10cSrcweir m_pProps = pPropSeq;
2640cdf0e10cSrcweir return *m_pProps;
2641cdf0e10cSrcweir }
2642cdf0e10cSrcweir }
2643cdf0e10cSrcweir catch ( NoSuchElementException& )
2644cdf0e10cSrcweir {
2645cdf0e10cSrcweir // getByHierarchicalName
2646cdf0e10cSrcweir }
2647cdf0e10cSrcweir }
2648cdf0e10cSrcweir
2649cdf0e10cSrcweir OSL_ENSURE( sal_False, "PropertySetInfo_Impl::getProperties - Error!" );
2650cdf0e10cSrcweir m_pProps = new Sequence< Property >( 0 );
2651cdf0e10cSrcweir }
2652cdf0e10cSrcweir
2653cdf0e10cSrcweir return *m_pProps;
2654cdf0e10cSrcweir }
2655cdf0e10cSrcweir
2656cdf0e10cSrcweir //=========================================================================
2657cdf0e10cSrcweir // virtual
getPropertyByName(const OUString & aName)2658cdf0e10cSrcweir Property SAL_CALL PropertySetInfo_Impl::getPropertyByName(
2659cdf0e10cSrcweir const OUString& aName )
2660cdf0e10cSrcweir throw( UnknownPropertyException, RuntimeException )
2661cdf0e10cSrcweir {
2662cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2663cdf0e10cSrcweir m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2664cdf0e10cSrcweir UNO_QUERY );
2665cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
2666cdf0e10cSrcweir {
2667cdf0e10cSrcweir OUString aFullPropName( m_pOwner->getFullKey() );
2668cdf0e10cSrcweir aFullPropName += OUString::createFromAscii( "/" );
2669cdf0e10cSrcweir aFullPropName += makeHierarchalNameSegment( aName );
2670cdf0e10cSrcweir
2671cdf0e10cSrcweir // Does property exist?
2672cdf0e10cSrcweir if ( !xRootHierNameAccess->hasByHierarchicalName( aFullPropName ) )
2673cdf0e10cSrcweir throw UnknownPropertyException();
2674cdf0e10cSrcweir
2675cdf0e10cSrcweir try
2676cdf0e10cSrcweir {
2677cdf0e10cSrcweir Property aProp;
2678cdf0e10cSrcweir
2679cdf0e10cSrcweir // Obtain handle.
2680cdf0e10cSrcweir OUString aKey = aFullPropName;
2681cdf0e10cSrcweir aKey += OUString::createFromAscii( "/Handle" );
2682cdf0e10cSrcweir
2683cdf0e10cSrcweir if ( !( xRootHierNameAccess->getByHierarchicalName( aKey )
2684cdf0e10cSrcweir >>= aProp.Handle ) )
2685cdf0e10cSrcweir {
2686cdf0e10cSrcweir OSL_ENSURE( sal_False,
2687cdf0e10cSrcweir "PropertySetInfo_Impl::getPropertyByName - "
2688cdf0e10cSrcweir "No handle!" );
2689cdf0e10cSrcweir return Property();
2690cdf0e10cSrcweir }
2691cdf0e10cSrcweir
2692cdf0e10cSrcweir // Obtain Value and extract type.
2693cdf0e10cSrcweir aKey = aFullPropName;
2694cdf0e10cSrcweir aKey += OUString::createFromAscii( "/Value" );
2695cdf0e10cSrcweir
2696cdf0e10cSrcweir Any aValue = xRootHierNameAccess->getByHierarchicalName( aKey );
2697cdf0e10cSrcweir if ( !aValue.hasValue() )
2698cdf0e10cSrcweir {
2699cdf0e10cSrcweir OSL_ENSURE( sal_False,
2700cdf0e10cSrcweir "PropertySetInfo_Impl::getPropertyByName - "
2701cdf0e10cSrcweir "No Value!" );
2702cdf0e10cSrcweir return Property();
2703cdf0e10cSrcweir }
2704cdf0e10cSrcweir
2705cdf0e10cSrcweir aProp.Type = aValue.getValueType();
2706cdf0e10cSrcweir
2707cdf0e10cSrcweir // Obtain Attributes.
2708cdf0e10cSrcweir aKey = aFullPropName;
2709cdf0e10cSrcweir aKey += OUString::createFromAscii( "/Attributes" );
2710cdf0e10cSrcweir
2711cdf0e10cSrcweir sal_Int32 nAttribs = 0;
2712cdf0e10cSrcweir if ( xRootHierNameAccess->getByHierarchicalName( aKey )
2713cdf0e10cSrcweir >>= nAttribs )
2714cdf0e10cSrcweir aProp.Attributes = sal_Int16( nAttribs );
2715cdf0e10cSrcweir else
2716cdf0e10cSrcweir {
2717cdf0e10cSrcweir OSL_ENSURE( sal_False,
2718cdf0e10cSrcweir "PropertySetInfo_Impl::getPropertyByName - "
2719cdf0e10cSrcweir "No attributes!" );
2720cdf0e10cSrcweir return Property();
2721cdf0e10cSrcweir }
2722cdf0e10cSrcweir
2723cdf0e10cSrcweir // set name.
2724cdf0e10cSrcweir aProp.Name = aName;
2725cdf0e10cSrcweir
2726cdf0e10cSrcweir // Success.
2727cdf0e10cSrcweir return aProp;
2728cdf0e10cSrcweir }
2729cdf0e10cSrcweir catch ( NoSuchElementException& )
2730cdf0e10cSrcweir {
2731cdf0e10cSrcweir // getByHierarchicalName
2732cdf0e10cSrcweir
2733cdf0e10cSrcweir OSL_ENSURE( sal_False,
2734cdf0e10cSrcweir "PropertySetInfo_Impl::getPropertyByName - "
2735cdf0e10cSrcweir "caught NoSuchElementException!" );
2736cdf0e10cSrcweir }
2737cdf0e10cSrcweir
2738cdf0e10cSrcweir }
2739cdf0e10cSrcweir
2740cdf0e10cSrcweir OSL_ENSURE( sal_False, "PropertySetInfo_Impl::getPropertyByName - Error!" );
2741cdf0e10cSrcweir return Property();
2742cdf0e10cSrcweir }
2743cdf0e10cSrcweir
2744cdf0e10cSrcweir //=========================================================================
2745cdf0e10cSrcweir // virtual
hasPropertyByName(const OUString & Name)2746cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetInfo_Impl::hasPropertyByName(
2747cdf0e10cSrcweir const OUString& Name )
2748cdf0e10cSrcweir throw( RuntimeException )
2749cdf0e10cSrcweir {
2750cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xRootHierNameAccess(
2751cdf0e10cSrcweir m_pOwner->getPropertySetRegistry().getRootConfigReadAccess(),
2752cdf0e10cSrcweir UNO_QUERY );
2753cdf0e10cSrcweir if ( xRootHierNameAccess.is() )
2754cdf0e10cSrcweir {
2755cdf0e10cSrcweir OUString aFullPropName( m_pOwner->getFullKey() );
2756cdf0e10cSrcweir aFullPropName += OUString::createFromAscii( "/" );
2757cdf0e10cSrcweir aFullPropName += makeHierarchalNameSegment( Name );
2758cdf0e10cSrcweir
2759cdf0e10cSrcweir return xRootHierNameAccess->hasByHierarchicalName( aFullPropName );
2760cdf0e10cSrcweir }
2761cdf0e10cSrcweir
2762cdf0e10cSrcweir return sal_False;
2763cdf0e10cSrcweir }
2764cdf0e10cSrcweir
27652cdca4f8Smseidel /* vim: set noet sw=4 ts=4: */
2766