merge the formfield patch from ooo-build
[ooovba.git] / unotools / source / config / confignode.cxx
blob00724207fa2757cfbb619620dfdd8042fa78578a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: confignode.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_unotools.hxx"
34 #include <unotools/confignode.hxx>
35 #include <unotools/configpathes.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <osl/diagnose.h>
38 #include <com/sun/star/container/XHierarchicalName.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/lang/XComponent.hpp>
42 #include <com/sun/star/util/XStringEscape.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <comphelper/extract.hxx>
45 #include <rtl/string.hxx>
46 #if OSL_DEBUG_LEVEL > 0
47 #include <rtl/strbuf.hxx>
48 #endif
50 //........................................................................
51 namespace utl
53 //........................................................................
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::util;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::container;
61 //========================================================================
62 //= OConfigurationNode
63 //========================================================================
64 //------------------------------------------------------------------------
65 OConfigurationNode::OConfigurationNode(const Reference< XInterface >& _rxNode, const Reference< XMultiServiceFactory >& _rxProvider)
66 :m_xProvider(_rxProvider)
67 ,m_bEscapeNames(sal_False)
69 OSL_ENSURE(_rxNode.is(), "OConfigurationNode::OConfigurationNode: invalid node interface!");
70 if (_rxNode.is())
72 // collect all interfaces necessary
73 m_xHierarchyAccess = Reference< XHierarchicalNameAccess >(_rxNode, UNO_QUERY);
74 m_xDirectAccess = Reference< XNameAccess >(_rxNode, UNO_QUERY);
76 // reset _all_ interfaces if _one_ of them is not supported
77 if (!m_xHierarchyAccess.is() || !m_xDirectAccess.is())
79 m_xHierarchyAccess = NULL;
80 m_xDirectAccess = NULL;
83 // now for the non-critical interfaces
84 m_xReplaceAccess = Reference< XNameReplace >(_rxNode, UNO_QUERY);
85 m_xContainerAccess = Reference< XNameContainer >(_rxNode, UNO_QUERY);
88 Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
89 if (xConfigNodeComp.is())
90 startComponentListening(xConfigNodeComp);
92 if (isValid())
93 setEscape(isSetNode());
96 //------------------------------------------------------------------------
97 OConfigurationNode::OConfigurationNode(const OConfigurationNode& _rSource)
98 :OEventListenerAdapter()
99 ,m_xHierarchyAccess(_rSource.m_xHierarchyAccess)
100 ,m_xDirectAccess(_rSource.m_xDirectAccess)
101 ,m_xReplaceAccess(_rSource.m_xReplaceAccess)
102 ,m_xContainerAccess(_rSource.m_xContainerAccess)
103 ,m_xProvider(_rSource.m_xProvider)
104 ,m_bEscapeNames(_rSource.m_bEscapeNames)
105 ,m_sCompletePath(_rSource.m_sCompletePath)
107 Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
108 if (xConfigNodeComp.is())
109 startComponentListening(xConfigNodeComp);
112 //------------------------------------------------------------------------
113 const OConfigurationNode& OConfigurationNode::operator=(const OConfigurationNode& _rSource)
115 stopAllComponentListening();
117 m_xHierarchyAccess = _rSource.m_xHierarchyAccess;
118 m_xDirectAccess = _rSource.m_xDirectAccess;
119 m_xContainerAccess = _rSource.m_xContainerAccess;
120 m_xReplaceAccess = _rSource.m_xReplaceAccess;
121 m_xProvider = _rSource.m_xProvider;
122 m_bEscapeNames = _rSource.m_bEscapeNames;
123 m_sCompletePath = _rSource.m_sCompletePath;
125 Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
126 if (xConfigNodeComp.is())
127 startComponentListening(xConfigNodeComp);
129 return *this;
132 //------------------------------------------------------------------------
133 void OConfigurationNode::_disposing( const EventObject& _rSource )
135 Reference< XComponent > xDisposingSource(_rSource.Source, UNO_QUERY);
136 Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
137 if (xDisposingSource.get() == xConfigNodeComp.get())
138 clear();
141 //------------------------------------------------------------------------
142 ::rtl::OUString OConfigurationNode::normalizeName(const ::rtl::OUString& _rName, NAMEORIGIN _eOrigin) const
144 ::rtl::OUString sName(_rName);
145 if (getEscape())
147 Reference< XStringEscape > xEscaper(m_xDirectAccess, UNO_QUERY);
148 OSL_ENSURE(xEscaper.is(), "OConfigurationNode::normalizeName: missing an interface!");
149 if (xEscaper.is() && sName.getLength())
153 if (NO_CALLER == _eOrigin)
154 sName = xEscaper->escapeString(sName);
155 else
156 sName = xEscaper->unescapeString(sName);
158 catch(IllegalArgumentException&)
160 OSL_ENSURE(sal_False, "OConfigurationNode::normalizeName: illegal argument (caught an exception saying so)!");
162 catch(Exception&)
164 OSL_ENSURE(sal_False, "OConfigurationNode::normalizeName: caught an exception!");
168 return sName;
171 //------------------------------------------------------------------------
172 Sequence< ::rtl::OUString > OConfigurationNode::getNodeNames() const throw()
174 OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::getNodeNames: object is invalid!");
175 Sequence< ::rtl::OUString > aReturn;
176 if (m_xDirectAccess.is())
180 aReturn = m_xDirectAccess->getElementNames();
181 // normalize the names
182 ::rtl::OUString* pNames = aReturn.getArray();
183 for (sal_Int32 i=0; i<aReturn.getLength(); ++i, ++pNames)
184 *pNames = normalizeName(*pNames, NO_CONFIGURATION);
186 catch(Exception&)
188 OSL_ENSURE(sal_False, "OConfigurationNode::getNodeNames: caught a generic exception!");
192 return aReturn;
195 //------------------------------------------------------------------------
196 sal_Bool OConfigurationNode::removeNode(const ::rtl::OUString& _rName) const throw()
198 OSL_ENSURE(m_xContainerAccess.is(), "OConfigurationNode::removeNode: object is invalid!");
199 if (m_xContainerAccess.is())
203 ::rtl::OUString sName = normalizeName(_rName, NO_CALLER);
204 m_xContainerAccess->removeByName(sName);
205 return sal_True;
207 catch (NoSuchElementException&)
209 #if OSL_DEBUG_LEVEL > 0
210 rtl::OStringBuffer aBuf( 256 );
211 aBuf.append("OConfigurationNode::removeNode: there is no element named!");
212 aBuf.append( rtl::OUStringToOString( _rName, RTL_TEXTENCODING_ASCII_US ) );
213 aBuf.append( "!" );
214 OSL_ENSURE(sal_False, aBuf.getStr());
215 #endif
217 catch (WrappedTargetException&)
219 OSL_ENSURE(sal_False, "OConfigurationNode::removeNode: caught a WrappedTargetException!");
221 catch(Exception&)
223 OSL_ENSURE(sal_False, "OConfigurationNode::removeNode: caught a generic exception!");
226 return sal_False;
228 //------------------------------------------------------------------------
229 OConfigurationNode OConfigurationNode::insertNode(const ::rtl::OUString& _rName,const Reference< XInterface >& _xNode) const throw()
231 if(_xNode.is())
235 ::rtl::OUString sName = normalizeName(_rName, NO_CALLER);
236 m_xContainerAccess->insertByName(sName, makeAny(_xNode));
237 // if we're here, all was ok ...
238 return OConfigurationNode(_xNode, m_xProvider);
240 catch(const Exception&)
242 DBG_UNHANDLED_EXCEPTION();
245 // dispose the child if it has already been created, but could not be inserted
246 Reference< XComponent > xChildComp(_xNode, UNO_QUERY);
247 if (xChildComp.is())
248 try { xChildComp->dispose(); } catch(Exception&) { }
251 return OConfigurationNode();
253 //------------------------------------------------------------------------
254 OConfigurationNode OConfigurationNode::createNode(const ::rtl::OUString& _rName) const throw()
256 Reference< XSingleServiceFactory > xChildFactory(m_xContainerAccess, UNO_QUERY);
257 OSL_ENSURE(xChildFactory.is(), "OConfigurationNode::createNode: object is invalid or read-only!");
259 if (xChildFactory.is()) // implies m_xContainerAccess.is()
261 Reference< XInterface > xNewChild;
264 xNewChild = xChildFactory->createInstance();
266 catch(const Exception&)
268 DBG_UNHANDLED_EXCEPTION();
270 return insertNode(_rName,xNewChild);
273 return OConfigurationNode();
276 //------------------------------------------------------------------------
277 OConfigurationNode OConfigurationNode::appendNode(const ::rtl::OUString& _rName,const OConfigurationNode& _aNewNode) const throw()
279 return insertNode(_rName,_aNewNode.m_xDirectAccess);
281 //------------------------------------------------------------------------
282 OConfigurationNode OConfigurationNode::openNode(const ::rtl::OUString& _rPath) const throw()
284 OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::openNode: object is invalid!");
285 OSL_ENSURE(m_xHierarchyAccess.is(), "OConfigurationNode::openNode: object is invalid!");
288 ::rtl::OUString sNormalized = normalizeName(_rPath, NO_CALLER);
290 Reference< XInterface > xNode;
291 if (m_xDirectAccess.is() && m_xDirectAccess->hasByName(sNormalized))
293 if (!::cppu::extractInterface(xNode, m_xDirectAccess->getByName(sNormalized)))
294 OSL_ENSURE(sal_False, "OConfigurationNode::openNode: could not open the node!");
296 else if (m_xHierarchyAccess.is())
298 if (!::cppu::extractInterface(xNode, m_xHierarchyAccess->getByHierarchicalName(_rPath)))
299 OSL_ENSURE(sal_False, "OConfigurationNode::openNode: could not open the node!");
301 if (xNode.is())
302 return OConfigurationNode(xNode, m_xProvider);
304 catch(NoSuchElementException& e)
306 (void)e;
307 #if OSL_DEBUG_LEVEL > 0
308 rtl::OStringBuffer aBuf( 256 );
309 aBuf.append("OConfigurationNode::openNode: there is no element named ");
310 aBuf.append( rtl::OUStringToOString( _rPath, RTL_TEXTENCODING_ASCII_US ) );
311 aBuf.append("!");
312 OSL_ENSURE(sal_False, aBuf.getStr());
313 #endif
315 catch(Exception&)
317 OSL_ENSURE(sal_False, "OConfigurationNode::openNode: caught an exception while retrieving the node!");
319 return OConfigurationNode();
322 //------------------------------------------------------------------------
323 void OConfigurationNode::setEscape(sal_Bool _bEnable)
325 m_bEscapeNames = _bEnable && Reference< XStringEscape >::query(m_xDirectAccess).is();
326 OSL_ENSURE(m_bEscapeNames || !_bEnable,
327 "OConfigurationNode::setEscape: escaping not enabled - missing the appropriate interface on the node!");
330 //------------------------------------------------------------------------
331 sal_Bool OConfigurationNode::isSetNode() const
333 sal_Bool bIsSet = sal_False;
334 Reference< XServiceInfo > xSI(m_xHierarchyAccess, UNO_QUERY);
335 if (xSI.is())
337 try { bIsSet = xSI->supportsService(::rtl::OUString::createFromAscii("com.sun.star.configuration.SetAccess")); }
338 catch(Exception&) { }
340 return bIsSet;
343 //---------------------------------------------------------------------
344 //--- 20.08.01 19:03:20 -----------------------------------------------
346 sal_Bool OConfigurationNode::hasByHierarchicalName( const ::rtl::OUString& _rName ) const throw()
348 OSL_ENSURE( m_xHierarchyAccess.is(), "OConfigurationNode::hasByHierarchicalName: no hierarchy access!" );
351 if ( m_xHierarchyAccess.is() )
353 ::rtl::OUString sName = normalizeName( _rName, NO_CALLER );
354 return m_xHierarchyAccess->hasByHierarchicalName( sName );
357 catch(Exception&)
360 return sal_False;
363 //------------------------------------------------------------------------
364 sal_Bool OConfigurationNode::hasByName(const ::rtl::OUString& _rName) const throw()
366 OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::hasByName: object is invalid!");
369 ::rtl::OUString sName = normalizeName(_rName, NO_CALLER);
370 if (m_xDirectAccess.is())
371 return m_xDirectAccess->hasByName(sName);
373 catch(Exception&)
376 return sal_False;
379 //------------------------------------------------------------------------
380 sal_Bool OConfigurationNode::setNodeValue(const ::rtl::OUString& _rPath, const Any& _rValue) const throw()
382 sal_Bool bResult = false;
384 OSL_ENSURE(m_xReplaceAccess.is(), "OConfigurationNode::setNodeValue: object is invalid!");
385 if (m_xReplaceAccess.is())
389 // check if _rPath is a level-1 path
390 ::rtl::OUString sNormalizedName = normalizeName(_rPath, NO_CALLER);
391 if (m_xReplaceAccess->hasByName(sNormalizedName))
393 m_xReplaceAccess->replaceByName(sNormalizedName, _rValue);
394 bResult = true;
397 // check if the name refers to a indirect descendant
398 else if (m_xHierarchyAccess.is() && m_xHierarchyAccess->hasByHierarchicalName(_rPath))
400 OSL_ASSERT(_rPath.getLength());
402 ::rtl::OUString sParentPath, sLocalName;
404 if ( splitLastFromConfigurationPath(_rPath, sParentPath, sLocalName) )
406 OConfigurationNode aParentAccess = openNode(sParentPath);
407 if (aParentAccess.isValid())
408 bResult = aParentAccess.setNodeValue(sLocalName, _rValue);
410 else
412 m_xReplaceAccess->replaceByName(sLocalName, _rValue);
413 bResult = true;
418 catch(IllegalArgumentException&)
420 OSL_ENSURE(sal_False, "OConfigurationNode::setNodeValue: could not replace the value: caught an IllegalArgumentException!");
422 catch(NoSuchElementException&)
424 OSL_ENSURE(sal_False, "OConfigurationNode::setNodeValue: could not replace the value: caught a NoSuchElementException!");
426 catch(WrappedTargetException&)
428 OSL_ENSURE(sal_False, "OConfigurationNode::setNodeValue: could not replace the value: caught a WrappedTargetException!");
430 catch(Exception&)
432 OSL_ENSURE(sal_False, "OConfigurationNode::setNodeValue: could not replace the value: caught a generic Exception!");
437 return bResult;
440 //------------------------------------------------------------------------
441 Any OConfigurationNode::getNodeValue(const ::rtl::OUString& _rPath) const throw()
443 OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::hasByName: object is invalid!");
444 OSL_ENSURE(m_xHierarchyAccess.is(), "OConfigurationNode::hasByName: object is invalid!");
445 Any aReturn;
448 ::rtl::OUString sNormalizedPath = normalizeName(_rPath, NO_CALLER);
449 if (m_xDirectAccess.is() && m_xDirectAccess->hasByName(sNormalizedPath) )
451 aReturn = m_xDirectAccess->getByName(sNormalizedPath);
453 else if (m_xHierarchyAccess.is())
455 aReturn = m_xHierarchyAccess->getByHierarchicalName(_rPath);
458 catch(NoSuchElementException& e)
460 #if OSL_DEBUG_LEVEL > 0
461 rtl::OStringBuffer aBuf( 256 );
462 aBuf.append("OConfigurationNode::getNodeValue: caught a NoSuchElementException while trying to open ");
463 aBuf.append( rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ) );
464 OSL_ENSURE(sal_False, aBuf.getStr());
465 #else
466 (void)e;
467 #endif
469 return aReturn;
472 //------------------------------------------------------------------------
473 OConfigurationTreeRoot OConfigurationNode::cloneAsRoot() const throw()
475 OSL_ENSURE(m_xHierarchyAccess.is(), "OConfigurationNode::cloneAsRoot: object is invalid!");
476 if (m_xHierarchyAccess.is())
478 // first get the complete path of the node we represent
479 ::rtl::OUString sCompletePath;
480 Reference< XHierarchicalName > xNodeNameAccess(m_xHierarchyAccess, UNO_QUERY);
481 if (xNodeNameAccess.is())
485 sCompletePath = xNodeNameAccess->getHierarchicalName();
486 OSL_ENSURE(sCompletePath.getLength(), "OConfigurationNode::cloneAsRoot: invalid path retrieved!");
488 catch(Exception&)
490 OSL_ENSURE(sal_False, "OConfigurationNode::cloneAsRoot: could not retrieve the node path!");
494 // then create a new tree root object with that path and our provider
495 OSL_ENSURE(m_xProvider.is(), "OConfigurationNode::cloneAsRoot: have an invalid provider!");
496 if (sCompletePath.getLength() && m_xProvider.is())
498 return OConfigurationTreeRoot::createWithProvider(m_xProvider, sCompletePath, -1, isReadonly() ? OConfigurationTreeRoot::CM_READONLY : OConfigurationTreeRoot::CM_PREFER_UPDATABLE);
501 return OConfigurationTreeRoot();
504 //------------------------------------------------------------------------
505 void OConfigurationNode::clear() throw()
507 m_xHierarchyAccess.clear();
508 m_xDirectAccess.clear();
509 m_xReplaceAccess.clear();
510 m_xContainerAccess.clear();
513 //========================================================================
514 //= OConfigurationTreeRoot
515 //========================================================================
516 //------------------------------------------------------------------------
517 OConfigurationTreeRoot::OConfigurationTreeRoot(const Reference< XChangesBatch >& _rxRootNode, const Reference< XMultiServiceFactory >& _rxProvider)
518 :OConfigurationNode(_rxRootNode.get(), _rxProvider)
519 ,m_xCommitter(_rxRootNode)
523 //------------------------------------------------------------------------
524 OConfigurationTreeRoot::OConfigurationTreeRoot(const Reference< XInterface >& _rxRootNode, const Reference< XMultiServiceFactory >& _rxProvider)
525 :OConfigurationNode(_rxRootNode.get(), _rxProvider)
529 //------------------------------------------------------------------------
530 void OConfigurationTreeRoot::clear() throw()
532 OConfigurationNode::clear();
533 m_xCommitter.clear();
536 //------------------------------------------------------------------------
537 sal_Bool OConfigurationTreeRoot::commit() const throw()
539 OSL_ENSURE(isValid(), "OConfigurationTreeRoot::commit: object is invalid!");
540 if (!isValid())
541 return sal_False;
542 OSL_ENSURE(m_xCommitter.is(), "OConfigurationTreeRoot::commit: I'm a readonly node!");
543 if (!m_xCommitter.is())
544 return sal_False;
548 m_xCommitter->commitChanges();
549 return sal_True;
551 catch(WrappedTargetException&)
553 OSL_ENSURE(sal_False, "OConfigurationTreeRoot::commit: caught a WrappedTargetException!");
555 catch(RuntimeException&)
557 OSL_ENSURE(sal_False, "OConfigurationTreeRoot::commit: caught a RuntimeException!");
559 return sal_False;
562 namespace
564 static const ::rtl::OUString& lcl_getProviderServiceName( )
566 static ::rtl::OUString s_sProviderServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) );
567 return s_sProviderServiceName;
571 //------------------------------------------------------------------------
572 OConfigurationTreeRoot OConfigurationTreeRoot::createWithProvider(const Reference< XMultiServiceFactory >& _rxConfProvider, const ::rtl::OUString& _rPath, sal_Int32 _nDepth, CREATION_MODE _eMode, sal_Bool _bLazyWrite)
574 OSL_ENSURE(_rxConfProvider.is(), "OConfigurationTreeRoot::createWithProvider: invalid provider!");
576 #ifdef DBG_UTIL
577 if (_rxConfProvider.is())
581 Reference< XServiceInfo > xSI(_rxConfProvider, UNO_QUERY);
582 if (!xSI.is())
584 OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithProvider: no XServiceInfo interface on the provider!");
586 else
588 OSL_ENSURE(xSI->supportsService( lcl_getProviderServiceName( ) ),
589 "OConfigurationTreeRoot::createWithProvider: sure this is a provider? Missing the ConfigurationProvider service!");
592 catch(const Exception&)
594 OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithProvider: unable to check the service conformance of the provider given!");
597 #endif
599 sal_Bool bTryAgain(sal_False);
602 if (_rxConfProvider.is())
606 Sequence< Any > aCreationArgs(3);
607 aCreationArgs[0] = makeAny(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")), 0, makeAny(_rPath), PropertyState_DIRECT_VALUE));
608 aCreationArgs[1] = makeAny(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")), 0, makeAny((sal_Int32)_nDepth), PropertyState_DIRECT_VALUE));
609 aCreationArgs[2] = makeAny(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("lazywrite")), 0, ::cppu::bool2any(_bLazyWrite), PropertyState_DIRECT_VALUE));
611 ::rtl::OUString sAccessService = ::rtl::OUString::createFromAscii(CM_READONLY == _eMode
612 ? "com.sun.star.configuration.ConfigurationAccess"
613 : "com.sun.star.configuration.ConfigurationUpdateAccess");
615 Reference< XInterface > xRoot = _rxConfProvider->createInstanceWithArguments(sAccessService, aCreationArgs);
616 if (!xRoot.is())
618 OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithProvider: could not create the node access!");
620 else if (CM_READONLY == _eMode)
622 return OConfigurationTreeRoot(xRoot, _rxConfProvider);
624 else
625 { // get the changes batch interface
626 Reference< XChangesBatch > xCommitter(xRoot, UNO_QUERY);
627 if (xCommitter.is())
628 return OConfigurationTreeRoot(xCommitter, _rxConfProvider);
629 else
630 OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithProvider: invalid root object (missing interface XChangesBatch)!");
632 // dispose the object if it is already created, but unusable
633 Reference< XComponent > xComp(xRoot, UNO_QUERY);
634 if (xComp.is())
635 try { xComp->dispose(); } catch(Exception&) { }
638 catch(Exception& e)
640 #if OSL_DEBUG_LEVEL > 0
641 ::rtl::OString sMessage( "OConfigurationTreeRoot::createWithProvider: caught an exception while creating the access object!\nmessage:\n" );
642 sMessage += ::rtl::OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US );
643 OSL_ENSURE( sal_False, sMessage.getStr() );
644 #else
645 (void)e;
646 #endif
649 bTryAgain = CM_PREFER_UPDATABLE == _eMode;
650 if (bTryAgain)
651 _eMode = CM_READONLY;
653 while (bTryAgain);
655 return OConfigurationTreeRoot();
658 //------------------------------------------------------------------------
659 OConfigurationTreeRoot OConfigurationTreeRoot::createWithServiceFactory(const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rPath, sal_Int32 _nDepth, CREATION_MODE _eMode, sal_Bool _bLazyWrite)
661 OSL_ENSURE(_rxORB.is(), "OConfigurationTreeRoot::createWithServiceFactory: invalid service factory!");
662 if (_rxORB.is())
666 Reference< XInterface > xProvider = _rxORB->createInstance( lcl_getProviderServiceName( ) );
667 OSL_ENSURE(xProvider.is(), "OConfigurationTreeRoot::createWithServiceFactory: could not instantiate the config provider service!");
668 Reference< XMultiServiceFactory > xProviderAsFac(xProvider, UNO_QUERY);
669 OSL_ENSURE(xProviderAsFac.is() || !xProvider.is(), "OConfigurationTreeRoot::createWithServiceFactory: the provider is missing an interface!");
670 if (xProviderAsFac.is())
671 return createWithProvider(xProviderAsFac, _rPath, _nDepth, _eMode, _bLazyWrite);
673 catch(Exception&)
675 OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithServiceFactory: error while instantiating the provider service!");
678 return OConfigurationTreeRoot();
681 //------------------------------------------------------------------------
682 OConfigurationTreeRoot OConfigurationTreeRoot::tryCreateWithServiceFactory( const Reference< XMultiServiceFactory >& _rxORB,
683 const ::rtl::OUString& _rPath, sal_Int32 _nDepth , CREATION_MODE _eMode , sal_Bool _bLazyWrite )
685 OSL_ENSURE( _rxORB.is(), "OConfigurationTreeRoot::tryCreateWithServiceFactory: invalid service factory!" );
686 if ( _rxORB.is() )
690 Reference< XMultiServiceFactory > xConfigFactory( _rxORB->createInstance( lcl_getProviderServiceName( ) ), UNO_QUERY );
691 if ( xConfigFactory.is() )
692 return createWithProvider( xConfigFactory, _rPath, _nDepth, _eMode, _bLazyWrite );
694 catch(Exception&)
696 // silent this, 'cause the contract of this method states "no assertions"
699 return OConfigurationTreeRoot();
702 //........................................................................
703 } // namespace utl
704 //........................................................................