LCOV - code coverage report
Current view: top level - unotools/source/config - confignode.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 224 0.0 %
Date: 2014-04-14 Functions: 0 28 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <unotools/confignode.hxx>
      21             : #include <unotools/configpaths.hxx>
      22             : #include <tools/diagnose_ex.h>
      23             : #include <osl/diagnose.h>
      24             : #include <com/sun/star/container/XHierarchicalName.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      27             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      28             : #include <com/sun/star/lang/XComponent.hpp>
      29             : #include <com/sun/star/util/XStringEscape.hpp>
      30             : #include <com/sun/star/lang/XServiceInfo.hpp>
      31             : #include <com/sun/star/container/XNamed.hpp>
      32             : #include <comphelper/namedvaluecollection.hxx>
      33             : #include <rtl/string.hxx>
      34             : #if OSL_DEBUG_LEVEL > 0
      35             : #include <rtl/strbuf.hxx>
      36             : #endif
      37             : 
      38             : namespace utl
      39             : {
      40             : 
      41             :     using namespace ::com::sun::star::uno;
      42             :     using namespace ::com::sun::star::lang;
      43             :     using namespace ::com::sun::star::util;
      44             :     using namespace ::com::sun::star::beans;
      45             :     using namespace ::com::sun::star::container;
      46             :     using namespace ::com::sun::star::configuration;
      47             : 
      48             :     //= OConfigurationNode
      49             : 
      50           0 :     OConfigurationNode::OConfigurationNode(const Reference< XInterface >& _rxNode )
      51           0 :         :m_bEscapeNames(false)
      52             :     {
      53             :         OSL_ENSURE(_rxNode.is(), "OConfigurationNode::OConfigurationNode: invalid node interface!");
      54           0 :         if (_rxNode.is())
      55             :         {
      56             :             // collect all interfaces necessary
      57           0 :             m_xHierarchyAccess = Reference< XHierarchicalNameAccess >(_rxNode, UNO_QUERY);
      58           0 :             m_xDirectAccess = Reference< XNameAccess >(_rxNode, UNO_QUERY);
      59             : 
      60             :             // reset _all_ interfaces if _one_ of them is not supported
      61           0 :             if (!m_xHierarchyAccess.is() || !m_xDirectAccess.is())
      62             :             {
      63           0 :                 m_xHierarchyAccess = NULL;
      64           0 :                 m_xDirectAccess = NULL;
      65             :             }
      66             : 
      67             :             // now for the non-critical interfaces
      68           0 :             m_xReplaceAccess = Reference< XNameReplace >(_rxNode, UNO_QUERY);
      69           0 :             m_xContainerAccess = Reference< XNameContainer >(_rxNode, UNO_QUERY);
      70             :         }
      71             : 
      72           0 :         Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
      73           0 :         if (xConfigNodeComp.is())
      74           0 :             startComponentListening(xConfigNodeComp);
      75             : 
      76           0 :         if (isValid())
      77           0 :             setEscape(isSetNode());
      78           0 :     }
      79             : 
      80           0 :     OConfigurationNode::OConfigurationNode(const OConfigurationNode& _rSource)
      81             :         :OEventListenerAdapter()
      82             :         ,m_xHierarchyAccess(_rSource.m_xHierarchyAccess)
      83             :         ,m_xDirectAccess(_rSource.m_xDirectAccess)
      84             :         ,m_xReplaceAccess(_rSource.m_xReplaceAccess)
      85             :         ,m_xContainerAccess(_rSource.m_xContainerAccess)
      86             :         ,m_bEscapeNames(_rSource.m_bEscapeNames)
      87           0 :         ,m_sCompletePath(_rSource.m_sCompletePath)
      88             :     {
      89           0 :         Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
      90           0 :         if (xConfigNodeComp.is())
      91           0 :             startComponentListening(xConfigNodeComp);
      92           0 :     }
      93             : 
      94           0 :     const OConfigurationNode& OConfigurationNode::operator=(const OConfigurationNode& _rSource)
      95             :     {
      96           0 :         stopAllComponentListening();
      97             : 
      98           0 :         m_xHierarchyAccess = _rSource.m_xHierarchyAccess;
      99           0 :         m_xDirectAccess = _rSource.m_xDirectAccess;
     100           0 :         m_xContainerAccess = _rSource.m_xContainerAccess;
     101           0 :         m_xReplaceAccess = _rSource.m_xReplaceAccess;
     102           0 :         m_bEscapeNames = _rSource.m_bEscapeNames;
     103           0 :         m_sCompletePath = _rSource.m_sCompletePath;
     104             : 
     105           0 :         Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
     106           0 :         if (xConfigNodeComp.is())
     107           0 :             startComponentListening(xConfigNodeComp);
     108             : 
     109           0 :         return *this;
     110             :     }
     111             : 
     112           0 :     void OConfigurationNode::_disposing( const EventObject& _rSource )
     113             :     {
     114           0 :         Reference< XComponent > xDisposingSource(_rSource.Source, UNO_QUERY);
     115           0 :         Reference< XComponent > xConfigNodeComp(m_xDirectAccess, UNO_QUERY);
     116           0 :         if (xDisposingSource.get() == xConfigNodeComp.get())
     117           0 :             clear();
     118           0 :     }
     119             : 
     120           0 :     OUString OConfigurationNode::getLocalName() const
     121             :     {
     122           0 :         OUString sLocalName;
     123             :         try
     124             :         {
     125           0 :             Reference< XNamed > xNamed( m_xDirectAccess, UNO_QUERY_THROW );
     126           0 :             sLocalName = xNamed->getName();
     127             :         }
     128           0 :         catch( const Exception& )
     129             :         {
     130             :             DBG_UNHANDLED_EXCEPTION();
     131             :         }
     132           0 :         return sLocalName;
     133             :     }
     134             : 
     135           0 :     OUString OConfigurationNode::getNodePath() const
     136             :     {
     137           0 :         OUString sNodePath;
     138             :         try
     139             :         {
     140           0 :             Reference< XHierarchicalName > xNamed( m_xDirectAccess, UNO_QUERY_THROW );
     141           0 :             sNodePath = xNamed->getHierarchicalName();
     142             :         }
     143           0 :         catch( const Exception& )
     144             :         {
     145             :             DBG_UNHANDLED_EXCEPTION();
     146             :         }
     147           0 :         return sNodePath;
     148             :     }
     149             : 
     150           0 :     OUString OConfigurationNode::normalizeName(const OUString& _rName, NAMEORIGIN _eOrigin) const
     151             :     {
     152           0 :         OUString sName(_rName);
     153           0 :         if (getEscape())
     154             :         {
     155           0 :             Reference< XStringEscape > xEscaper(m_xDirectAccess, UNO_QUERY);
     156           0 :             if (xEscaper.is() && !sName.isEmpty())
     157             :             {
     158             :                 try
     159             :                 {
     160           0 :                     if (NO_CALLER == _eOrigin)
     161           0 :                         sName = xEscaper->escapeString(sName);
     162             :                     else
     163           0 :                         sName = xEscaper->unescapeString(sName);
     164             :                 }
     165           0 :                 catch(Exception&)
     166             :                 {
     167             :                     DBG_UNHANDLED_EXCEPTION();
     168             :                 }
     169           0 :             }
     170             :         }
     171           0 :         return sName;
     172             :     }
     173             : 
     174           0 :     Sequence< OUString > OConfigurationNode::getNodeNames() const throw()
     175             :     {
     176             :         OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::getNodeNames: object is invalid!");
     177           0 :         Sequence< OUString > aReturn;
     178           0 :         if (m_xDirectAccess.is())
     179             :         {
     180             :             try
     181             :             {
     182           0 :                 aReturn = m_xDirectAccess->getElementNames();
     183             :                 // normalize the names
     184           0 :                 OUString* pNames = aReturn.getArray();
     185           0 :                 for (sal_Int32 i=0; i<aReturn.getLength(); ++i, ++pNames)
     186           0 :                     *pNames = normalizeName(*pNames, NO_CONFIGURATION);
     187             :             }
     188           0 :             catch(Exception&)
     189             :             {
     190             :                 OSL_FAIL("OConfigurationNode::getNodeNames: caught a generic exception!");
     191             :             }
     192             :         }
     193             : 
     194           0 :         return aReturn;
     195             :     }
     196             : 
     197           0 :     bool OConfigurationNode::removeNode(const OUString& _rName) const throw()
     198             :     {
     199             :         OSL_ENSURE(m_xContainerAccess.is(), "OConfigurationNode::removeNode: object is invalid!");
     200           0 :         if (m_xContainerAccess.is())
     201             :         {
     202             :             try
     203             :             {
     204           0 :                 OUString sName = normalizeName(_rName, NO_CALLER);
     205           0 :                 m_xContainerAccess->removeByName(sName);
     206           0 :                 return true;
     207             :             }
     208           0 :             catch (NoSuchElementException&)
     209             :             {
     210             :                 #if OSL_DEBUG_LEVEL > 0
     211             :                 OStringBuffer aBuf( 256 );
     212             :                 aBuf.append("OConfigurationNode::removeNode: there is no element named!");
     213             :                 aBuf.append( OUStringToOString( _rName, RTL_TEXTENCODING_ASCII_US ) );
     214             :                 aBuf.append( "!" );
     215             :                 OSL_FAIL(aBuf.getStr());
     216             :                 #endif
     217             :             }
     218           0 :             catch (WrappedTargetException&)
     219             :             {
     220             :                 OSL_FAIL("OConfigurationNode::removeNode: caught a WrappedTargetException!");
     221             :             }
     222           0 :             catch(Exception&)
     223             :             {
     224             :                 OSL_FAIL("OConfigurationNode::removeNode: caught a generic exception!");
     225             :             }
     226             :         }
     227           0 :         return false;
     228             :     }
     229             : 
     230           0 :     OConfigurationNode OConfigurationNode::insertNode(const OUString& _rName,const Reference< XInterface >& _xNode) const throw()
     231             :     {
     232           0 :         if(_xNode.is())
     233             :         {
     234             :             try
     235             :             {
     236           0 :                 OUString sName = normalizeName(_rName, NO_CALLER);
     237           0 :                 m_xContainerAccess->insertByName(sName, makeAny(_xNode));
     238             :                 // if we're here, all was ok ...
     239           0 :                 return OConfigurationNode( _xNode );
     240             :             }
     241           0 :             catch(const Exception&)
     242             :             {
     243             :                 DBG_UNHANDLED_EXCEPTION();
     244             :             }
     245             : 
     246             :             // dispose the child if it has already been created, but could not be inserted
     247           0 :             Reference< XComponent > xChildComp(_xNode, UNO_QUERY);
     248           0 :             if (xChildComp.is())
     249           0 :                 try { xChildComp->dispose(); } catch(Exception&) { }
     250             :         }
     251             : 
     252           0 :         return OConfigurationNode();
     253             :     }
     254             : 
     255           0 :     OConfigurationNode OConfigurationNode::createNode(const OUString& _rName) const throw()
     256             :     {
     257           0 :         Reference< XSingleServiceFactory > xChildFactory(m_xContainerAccess, UNO_QUERY);
     258             :         OSL_ENSURE(xChildFactory.is(), "OConfigurationNode::createNode: object is invalid or read-only!");
     259             : 
     260           0 :         if (xChildFactory.is()) // implies m_xContainerAccess.is()
     261             :         {
     262           0 :             Reference< XInterface > xNewChild;
     263             :             try
     264             :             {
     265           0 :                 xNewChild = xChildFactory->createInstance();
     266             :             }
     267           0 :             catch(const Exception&)
     268             :             {
     269             :                 DBG_UNHANDLED_EXCEPTION();
     270             :             }
     271           0 :             return insertNode(_rName,xNewChild);
     272             :         }
     273             : 
     274           0 :         return OConfigurationNode();
     275             :     }
     276             : 
     277           0 :     OConfigurationNode OConfigurationNode::openNode(const OUString& _rPath) const throw()
     278             :     {
     279             :         OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::openNode: object is invalid!");
     280             :         OSL_ENSURE(m_xHierarchyAccess.is(), "OConfigurationNode::openNode: object is invalid!");
     281             :         try
     282             :         {
     283           0 :             OUString sNormalized = normalizeName(_rPath, NO_CALLER);
     284             : 
     285           0 :             Reference< XInterface > xNode;
     286           0 :             if (m_xDirectAccess.is() && m_xDirectAccess->hasByName(sNormalized))
     287             :             {
     288             :                 xNode.set(
     289           0 :                     m_xDirectAccess->getByName(sNormalized), css::uno::UNO_QUERY);
     290           0 :                 if (!xNode.is())
     291             :                     OSL_FAIL("OConfigurationNode::openNode: could not open the node!");
     292             :             }
     293           0 :             else if (m_xHierarchyAccess.is())
     294             :             {
     295             :                 xNode.set(
     296           0 :                     m_xHierarchyAccess->getByHierarchicalName(_rPath),
     297           0 :                     css::uno::UNO_QUERY);
     298           0 :                 if (!xNode.is())
     299             :                     OSL_FAIL("OConfigurationNode::openNode: could not open the node!");
     300             :             }
     301           0 :             if (xNode.is())
     302           0 :                 return OConfigurationNode( xNode );
     303             :         }
     304           0 :         catch(const NoSuchElementException&)
     305             :         {
     306             :             #if OSL_DEBUG_LEVEL > 0
     307             :             OStringBuffer aBuf( 256 );
     308             :             aBuf.append("OConfigurationNode::openNode: there is no element named ");
     309             :             aBuf.append( OUStringToOString( _rPath, RTL_TEXTENCODING_ASCII_US ) );
     310             :             aBuf.append("!");
     311             :             OSL_FAIL(aBuf.getStr());
     312             :             #endif
     313             :         }
     314           0 :         catch(Exception&)
     315             :         {
     316             :             OSL_FAIL("OConfigurationNode::openNode: caught an exception while retrieving the node!");
     317             :         }
     318           0 :         return OConfigurationNode();
     319             :     }
     320             : 
     321           0 :     void OConfigurationNode::setEscape(bool _bEnable)
     322             :     {
     323           0 :         m_bEscapeNames = _bEnable && Reference< XStringEscape >::query(m_xDirectAccess).is();
     324           0 :     }
     325             : 
     326           0 :     bool OConfigurationNode::isSetNode() const
     327             :     {
     328           0 :         bool bIsSet = false;
     329           0 :         Reference< XServiceInfo > xSI(m_xHierarchyAccess, UNO_QUERY);
     330           0 :         if (xSI.is())
     331             :         {
     332           0 :             try { bIsSet = xSI->supportsService("com.sun.star.configuration.SetAccess"); }
     333           0 :             catch(Exception&) { }
     334             :         }
     335           0 :         return bIsSet;
     336             :     }
     337             : 
     338           0 :     bool OConfigurationNode::hasByHierarchicalName( const OUString& _rName ) const throw()
     339             :     {
     340             :         OSL_ENSURE( m_xHierarchyAccess.is(), "OConfigurationNode::hasByHierarchicalName: no hierarchy access!" );
     341             :         try
     342             :         {
     343           0 :             if ( m_xHierarchyAccess.is() )
     344             :             {
     345           0 :                 OUString sName = normalizeName( _rName, NO_CALLER );
     346           0 :                 return m_xHierarchyAccess->hasByHierarchicalName( sName );
     347             :             }
     348             :         }
     349           0 :         catch(Exception&)
     350             :         {
     351             :         }
     352           0 :         return false;
     353             :     }
     354             : 
     355           0 :     bool OConfigurationNode::hasByName(const OUString& _rName) const throw()
     356             :     {
     357             :         OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::hasByName: object is invalid!");
     358             :         try
     359             :         {
     360           0 :             OUString sName = normalizeName(_rName, NO_CALLER);
     361           0 :             if (m_xDirectAccess.is())
     362           0 :                 return m_xDirectAccess->hasByName(sName);
     363             :         }
     364           0 :         catch(Exception&)
     365             :         {
     366             :         }
     367           0 :         return false;
     368             :     }
     369             : 
     370           0 :     bool OConfigurationNode::setNodeValue(const OUString& _rPath, const Any& _rValue) const throw()
     371             :     {
     372           0 :         bool bResult = false;
     373             : 
     374             :         OSL_ENSURE(m_xReplaceAccess.is(), "OConfigurationNode::setNodeValue: object is invalid!");
     375           0 :         if (m_xReplaceAccess.is())
     376             :         {
     377             :             try
     378             :             {
     379             :                 // check if _rPath is a level-1 path
     380           0 :                 OUString sNormalizedName = normalizeName(_rPath, NO_CALLER);
     381           0 :                 if (m_xReplaceAccess->hasByName(sNormalizedName))
     382             :                 {
     383           0 :                     m_xReplaceAccess->replaceByName(sNormalizedName, _rValue);
     384           0 :                     bResult = true;
     385             :                 }
     386             : 
     387             :                 // check if the name refers to a indirect descendant
     388           0 :                 else if (m_xHierarchyAccess.is() && m_xHierarchyAccess->hasByHierarchicalName(_rPath))
     389             :                 {
     390             :                     OSL_ASSERT(!_rPath.isEmpty());
     391             : 
     392           0 :                     OUString sParentPath, sLocalName;
     393             : 
     394           0 :                     if ( splitLastFromConfigurationPath(_rPath, sParentPath, sLocalName) )
     395             :                     {
     396           0 :                         OConfigurationNode aParentAccess = openNode(sParentPath);
     397           0 :                         if (aParentAccess.isValid())
     398           0 :                             bResult = aParentAccess.setNodeValue(sLocalName, _rValue);
     399             :                     }
     400             :                     else
     401             :                     {
     402           0 :                         m_xReplaceAccess->replaceByName(sLocalName, _rValue);
     403           0 :                         bResult = true;
     404           0 :                     }
     405           0 :                 }
     406             : 
     407             :             }
     408           0 :             catch(IllegalArgumentException&)
     409             :             {
     410             :                 OSL_FAIL("OConfigurationNode::setNodeValue: could not replace the value: caught an IllegalArgumentException!");
     411             :             }
     412           0 :             catch(NoSuchElementException&)
     413             :             {
     414             :                 OSL_FAIL("OConfigurationNode::setNodeValue: could not replace the value: caught a NoSuchElementException!");
     415             :             }
     416           0 :             catch(WrappedTargetException&)
     417             :             {
     418             :                 OSL_FAIL("OConfigurationNode::setNodeValue: could not replace the value: caught a WrappedTargetException!");
     419             :             }
     420           0 :             catch(Exception&)
     421             :             {
     422             :                 OSL_FAIL("OConfigurationNode::setNodeValue: could not replace the value: caught a generic Exception!");
     423             :             }
     424             : 
     425             :         }
     426           0 :         return bResult;
     427             :     }
     428             : 
     429           0 :     Any OConfigurationNode::getNodeValue(const OUString& _rPath) const throw()
     430             :     {
     431             :         OSL_ENSURE(m_xDirectAccess.is(), "OConfigurationNode::hasByName: object is invalid!");
     432             :         OSL_ENSURE(m_xHierarchyAccess.is(), "OConfigurationNode::hasByName: object is invalid!");
     433           0 :         Any aReturn;
     434             :         try
     435             :         {
     436           0 :             OUString sNormalizedPath = normalizeName(_rPath, NO_CALLER);
     437           0 :             if (m_xDirectAccess.is() && m_xDirectAccess->hasByName(sNormalizedPath) )
     438             :             {
     439           0 :                 aReturn = m_xDirectAccess->getByName(sNormalizedPath);
     440             :             }
     441           0 :             else if (m_xHierarchyAccess.is())
     442             :             {
     443           0 :                 aReturn = m_xHierarchyAccess->getByHierarchicalName(_rPath);
     444           0 :             }
     445             :         }
     446           0 :         catch(const NoSuchElementException&)
     447             :         {
     448             :             DBG_UNHANDLED_EXCEPTION();
     449             :         }
     450           0 :         return aReturn;
     451             :     }
     452             : 
     453           0 :     void OConfigurationNode::clear() throw()
     454             :     {
     455           0 :         m_xHierarchyAccess.clear();
     456           0 :         m_xDirectAccess.clear();
     457           0 :         m_xReplaceAccess.clear();
     458           0 :         m_xContainerAccess.clear();
     459           0 :     }
     460             : 
     461             :     //= helper
     462             : 
     463             :     namespace
     464             :     {
     465             : 
     466           0 :         Reference< XMultiServiceFactory > lcl_getConfigProvider( const Reference<XComponentContext> & i_rContext )
     467             :         {
     468             :             try
     469             :             {
     470           0 :                 Reference< XMultiServiceFactory > xProvider = theDefaultProvider::get( i_rContext );
     471           0 :                 return xProvider;
     472             :             }
     473           0 :             catch ( const Exception& )
     474             :             {
     475             :                 DBG_UNHANDLED_EXCEPTION();
     476             :             }
     477           0 :             return NULL;
     478             :         }
     479             : 
     480           0 :         Reference< XInterface > lcl_createConfigurationRoot( const Reference< XMultiServiceFactory >& i_rxConfigProvider,
     481             :             const OUString& i_rNodePath, const bool i_bUpdatable, const sal_Int32 i_nDepth, const bool i_bLazyWrite )
     482             :         {
     483           0 :             ENSURE_OR_RETURN( i_rxConfigProvider.is(), "invalid provider", NULL );
     484             :             try
     485             :             {
     486           0 :                 ::comphelper::NamedValueCollection aArgs;
     487           0 :                 aArgs.put( "nodepath", i_rNodePath );
     488           0 :                 aArgs.put( "lazywrite", i_bLazyWrite );
     489           0 :                 aArgs.put( "depth", i_nDepth );
     490             : 
     491             :                 OUString sAccessService( i_bUpdatable ?
     492             :                                 OUString( "com.sun.star.configuration.ConfigurationUpdateAccess" ) :
     493           0 :                                 OUString( "com.sun.star.configuration.ConfigurationAccess" ));
     494             : 
     495             :                 Reference< XInterface > xRoot(
     496           0 :                     i_rxConfigProvider->createInstanceWithArguments( sAccessService, aArgs.getWrappedPropertyValues() ),
     497             :                     UNO_SET_THROW
     498           0 :                 );
     499           0 :                 return xRoot;
     500             :             }
     501           0 :             catch ( const Exception& )
     502             :             {
     503             :                 DBG_UNHANDLED_EXCEPTION();
     504             :             }
     505           0 :             return NULL;
     506             :         }
     507             :     }
     508             : 
     509           0 :     OConfigurationTreeRoot::OConfigurationTreeRoot( const Reference< XInterface >& _rxRootNode )
     510             :         :OConfigurationNode( _rxRootNode )
     511           0 :         ,m_xCommitter( _rxRootNode, UNO_QUERY )
     512             :     {
     513           0 :     }
     514             : 
     515           0 :     OConfigurationTreeRoot::OConfigurationTreeRoot( const Reference<XComponentContext> & i_rContext, const OUString& i_rNodePath, const bool i_bUpdatable )
     516             :         :OConfigurationNode( lcl_createConfigurationRoot( lcl_getConfigProvider( i_rContext ),
     517             :             i_rNodePath, i_bUpdatable, -1, false ).get() )
     518           0 :         ,m_xCommitter()
     519             :     {
     520           0 :         if ( i_bUpdatable )
     521             :         {
     522           0 :             m_xCommitter.set( getUNONode(), UNO_QUERY );
     523             :             OSL_ENSURE( m_xCommitter.is(), "OConfigurationTreeRoot::OConfigurationTreeRoot: could not create an updatable node!" );
     524             :         }
     525           0 :     }
     526             : 
     527           0 :     void OConfigurationTreeRoot::clear() throw()
     528             :     {
     529           0 :         OConfigurationNode::clear();
     530           0 :         m_xCommitter.clear();
     531           0 :     }
     532             : 
     533           0 :     bool OConfigurationTreeRoot::commit() const throw()
     534             :     {
     535             :         OSL_ENSURE(isValid(), "OConfigurationTreeRoot::commit: object is invalid!");
     536           0 :         if (!isValid())
     537           0 :             return false;
     538             :         OSL_ENSURE(m_xCommitter.is(), "OConfigurationTreeRoot::commit: I'm a readonly node!");
     539           0 :         if (!m_xCommitter.is())
     540           0 :             return false;
     541             : 
     542             :         try
     543             :         {
     544           0 :             m_xCommitter->commitChanges();
     545           0 :             return true;
     546             :         }
     547           0 :         catch(const Exception&)
     548             :         {
     549             :             DBG_UNHANDLED_EXCEPTION();
     550             :         }
     551           0 :         return false;
     552             :     }
     553             : 
     554           0 :     OConfigurationTreeRoot OConfigurationTreeRoot::createWithProvider(const Reference< XMultiServiceFactory >& _rxConfProvider, const OUString& _rPath, sal_Int32 _nDepth, CREATION_MODE _eMode, bool _bLazyWrite)
     555             :     {
     556             :         Reference< XInterface > xRoot( lcl_createConfigurationRoot(
     557           0 :             _rxConfProvider, _rPath, _eMode != CM_READONLY, _nDepth, _bLazyWrite ) );
     558           0 :         if ( xRoot.is() )
     559           0 :             return OConfigurationTreeRoot( xRoot );
     560           0 :         return OConfigurationTreeRoot();
     561             :     }
     562             : 
     563           0 :     OConfigurationTreeRoot OConfigurationTreeRoot::createWithComponentContext( const Reference< XComponentContext >& _rxContext, const OUString& _rPath, sal_Int32 _nDepth, CREATION_MODE _eMode, bool _bLazyWrite )
     564             :     {
     565           0 :         return createWithProvider( lcl_getConfigProvider( _rxContext ), _rPath, _nDepth, _eMode, _bLazyWrite );
     566             :     }
     567             : 
     568           0 :     OConfigurationTreeRoot OConfigurationTreeRoot::tryCreateWithComponentContext( const Reference< XComponentContext >& rxContext,
     569             :         const OUString& _rPath, sal_Int32 _nDepth , CREATION_MODE _eMode , bool _bLazyWrite )
     570             :     {
     571             :         OSL_ENSURE( rxContext.is(), "OConfigurationTreeRoot::tryCreateWithComponentContext: invalid XComponentContext!" );
     572             :         try
     573             :         {
     574           0 :             Reference< XMultiServiceFactory > xConfigFactory = theDefaultProvider::get( rxContext );
     575           0 :             return createWithProvider( xConfigFactory, _rPath, _nDepth, _eMode, _bLazyWrite );
     576             :         }
     577           0 :         catch(const Exception&)
     578             :         {
     579             :             // silence this, 'cause the contract of this method states "no assertions"
     580             :         }
     581           0 :         return OConfigurationTreeRoot();
     582             :     }
     583             : 
     584             : }   // namespace utl
     585             : 
     586             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10