LCOV - code coverage report
Current view: top level - configmgr/source - readonlyaccess.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 37 0.0 %
Date: 2014-04-14 Functions: 0 13 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             : 
      10             : #include "sal/config.h"
      11             : 
      12             : #include "boost/noncopyable.hpp"
      13             : #include "com/sun/star/container/NoSuchElementException.hpp"
      14             : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
      15             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      16             : #include "com/sun/star/lang/NotInitializedException.hpp"
      17             : #include "com/sun/star/lang/XInitialization.hpp"
      18             : #include "com/sun/star/lang/XServiceInfo.hpp"
      19             : #include "com/sun/star/uno/Any.hxx"
      20             : #include "com/sun/star/uno/Exception.hpp"
      21             : #include "com/sun/star/uno/Reference.hxx"
      22             : #include "com/sun/star/uno/RuntimeException.hpp"
      23             : #include "com/sun/star/uno/Sequence.hxx"
      24             : #include "com/sun/star/uno/XComponentContext.hpp"
      25             : #include "com/sun/star/uno/XInterface.hpp"
      26             : #include "cppuhelper/implbase3.hxx"
      27             : #include "cppuhelper/supportsservice.hxx"
      28             : #include "cppuhelper/weak.hxx"
      29             : #include "osl/mutex.hxx"
      30             : #include "rtl/ref.hxx"
      31             : #include "rtl/ustring.h"
      32             : #include "rtl/ustring.hxx"
      33             : #include "sal/types.h"
      34             : 
      35             : #include "components.hxx"
      36             : #include "lock.hxx"
      37             : #include "readonlyaccess.hxx"
      38             : #include "rootaccess.hxx"
      39             : 
      40             : namespace configmgr { namespace read_only_access {
      41             : 
      42             : namespace {
      43             : 
      44             : class Service:
      45             :     public cppu::WeakImplHelper3<
      46             :         css::lang::XServiceInfo, css::lang::XInitialization,
      47             :         css::container::XHierarchicalNameAccess >,
      48             :     private boost::noncopyable
      49             : {
      50             : public:
      51           0 :     explicit Service(
      52             :         css::uno::Reference< css::uno::XComponentContext > const & context):
      53           0 :         context_(context) {}
      54             : 
      55             : private:
      56           0 :     virtual ~Service() {}
      57             : 
      58           0 :     virtual OUString SAL_CALL getImplementationName()
      59             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      60           0 :     { return read_only_access::getImplementationName(); }
      61             : 
      62           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      63             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      64           0 :     { return cppu::supportsService(this, ServiceName); }
      65             : 
      66             :     virtual css::uno::Sequence< OUString > SAL_CALL
      67           0 :     getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      68           0 :     { return read_only_access::getSupportedServiceNames(); }
      69             : 
      70             :     virtual void SAL_CALL initialize(
      71             :         css::uno::Sequence< css::uno::Any > const & aArguments)
      72             :         throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      73             : 
      74           0 :     virtual css::uno::Any SAL_CALL getByHierarchicalName(
      75             :         OUString const & aName)
      76             :         throw (
      77             :             css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      78           0 :     { return getRoot()->getByHierarchicalName(aName); }
      79             : 
      80           0 :     virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
      81             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      82           0 :     { return getRoot()->hasByHierarchicalName(aName); }
      83             : 
      84             :     rtl::Reference< RootAccess > getRoot();
      85             : 
      86             :     css::uno::Reference< css::uno::XComponentContext > context_;
      87             : 
      88             :     osl::Mutex mutex_;
      89             :     rtl::Reference< RootAccess > root_;
      90             : };
      91             : 
      92           0 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
      93             :     throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
      94             : {
      95           0 :     OUString locale;
      96           0 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
      97             :         throw css::lang::IllegalArgumentException(
      98             :             "not exactly one string argument",
      99           0 :             static_cast< cppu::OWeakObject * >(this), -1);
     100             :     }
     101           0 :     osl::MutexGuard g1(mutex_);
     102           0 :     if (root_.is()) {
     103             :         throw css::uno::RuntimeException(
     104           0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     105             :     }
     106           0 :     osl::MutexGuard g2(*lock());
     107           0 :     Components & components = Components::getSingleton(context_);
     108           0 :     root_ = new RootAccess(components, "/", locale, false);
     109           0 :     components.addRootAccess(root_);
     110           0 : }
     111             : 
     112           0 : rtl::Reference< RootAccess > Service::getRoot() {
     113           0 :     osl::MutexGuard g(mutex_);
     114           0 :     if (!root_.is()) {
     115             :         throw css::lang::NotInitializedException(
     116           0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     117             :     }
     118           0 :     return root_;
     119             : }
     120             : 
     121             : }
     122             : 
     123           0 : css::uno::Reference< css::uno::XInterface > create(
     124             :     css::uno::Reference< css::uno::XComponentContext > const & context)
     125             : {
     126           0 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     127             : }
     128             : 
     129           0 : OUString getImplementationName() {
     130           0 :     return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
     131             : }
     132             : 
     133           0 : css::uno::Sequence< OUString > getSupportedServiceNames() {
     134           0 :     OUString name("com.sun.star.configuration.ReadOnlyAccess");
     135           0 :     return css::uno::Sequence< OUString >(&name, 1);
     136             : }
     137             : 
     138             : } }
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10