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

Generated by: LCOV version 1.10