LCOV - code coverage report
Current view: top level - libreoffice/configmgr/source - readonlyaccess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 36 69.4 %
Date: 2012-12-27 Functions: 9 13 69.2 %
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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2011 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
      17             :  * (initial developer)
      18             :  *
      19             :  * All Rights Reserved.
      20             :  *
      21             :  * For minor contributions see the git repository.
      22             :  *
      23             :  * Alternatively, the contents of this file may be used under the terms of
      24             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      25             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      26             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      27             :  * instead of those above.
      28             :  */
      29             : 
      30             : #include "sal/config.h"
      31             : 
      32             : #include "boost/noncopyable.hpp"
      33             : #include "com/sun/star/container/NoSuchElementException.hpp"
      34             : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
      35             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      36             : #include "com/sun/star/lang/NotInitializedException.hpp"
      37             : #include "com/sun/star/lang/XInitialization.hpp"
      38             : #include "com/sun/star/lang/XServiceInfo.hpp"
      39             : #include "com/sun/star/uno/Any.hxx"
      40             : #include "com/sun/star/uno/Exception.hpp"
      41             : #include "com/sun/star/uno/Reference.hxx"
      42             : #include "com/sun/star/uno/RuntimeException.hpp"
      43             : #include "com/sun/star/uno/Sequence.hxx"
      44             : #include "com/sun/star/uno/XComponentContext.hpp"
      45             : #include "com/sun/star/uno/XInterface.hpp"
      46             : #include "cppuhelper/implbase3.hxx"
      47             : #include "cppuhelper/weak.hxx"
      48             : #include "osl/mutex.hxx"
      49             : #include "rtl/ref.hxx"
      50             : #include "rtl/ustring.h"
      51             : #include "rtl/ustring.hxx"
      52             : #include "sal/types.h"
      53             : 
      54             : #include "components.hxx"
      55             : #include "lock.hxx"
      56             : #include "readonlyaccess.hxx"
      57             : #include "rootaccess.hxx"
      58             : 
      59             : namespace configmgr { namespace read_only_access {
      60             : 
      61             : namespace {
      62             : 
      63             : class Service:
      64             :     public cppu::WeakImplHelper3<
      65             :         css::lang::XServiceInfo, css::lang::XInitialization,
      66             :         css::container::XHierarchicalNameAccess >,
      67             :     private boost::noncopyable
      68             : {
      69             : public:
      70         419 :     explicit Service(
      71             :         css::uno::Reference< css::uno::XComponentContext > const & context):
      72         419 :         context_(context) {}
      73             : 
      74             : private:
      75         838 :     virtual ~Service() {}
      76             : 
      77           0 :     virtual OUString SAL_CALL getImplementationName()
      78             :         throw (css::uno::RuntimeException)
      79           0 :     { return read_only_access::getImplementationName(); }
      80             : 
      81           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const &)
      82             :         throw (css::uno::RuntimeException)
      83           0 :     { return false; }
      84             : 
      85             :     virtual css::uno::Sequence< OUString > SAL_CALL
      86           0 :     getSupportedServiceNames() throw (css::uno::RuntimeException)
      87           0 :     { return read_only_access::getSupportedServiceNames(); }
      88             : 
      89             :     virtual void SAL_CALL initialize(
      90             :         css::uno::Sequence< css::uno::Any > const & aArguments)
      91             :         throw (css::uno::Exception, css::uno::RuntimeException);
      92             : 
      93        6023 :     virtual css::uno::Any SAL_CALL getByHierarchicalName(
      94             :         OUString const & aName)
      95             :         throw (
      96             :             css::container::NoSuchElementException, css::uno::RuntimeException)
      97        6023 :     { return getRoot()->getByHierarchicalName(aName); }
      98             : 
      99           0 :     virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
     100             :         throw (css::uno::RuntimeException)
     101           0 :     { return getRoot()->hasByHierarchicalName(aName); }
     102             : 
     103             :     rtl::Reference< RootAccess > getRoot();
     104             : 
     105             :     css::uno::Reference< css::uno::XComponentContext > context_;
     106             : 
     107             :     osl::Mutex mutex_;
     108             :     rtl::Reference< RootAccess > root_;
     109             : };
     110             : 
     111         419 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
     112             :     throw (css::uno::Exception, css::uno::RuntimeException)
     113             : {
     114         419 :     OUString locale;
     115         419 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
     116             :         throw css::lang::IllegalArgumentException(
     117             :             "not exactly one string argument",
     118           0 :             static_cast< cppu::OWeakObject * >(this), -1);
     119             :     }
     120         419 :     osl::MutexGuard g1(mutex_);
     121         419 :     if (root_.is()) {
     122             :         throw css::uno::RuntimeException(
     123           0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     124             :     }
     125         419 :     osl::MutexGuard g2(*lock());
     126         419 :     Components & components = Components::getSingleton(context_);
     127         419 :     root_ = new RootAccess(components, "/", locale, false);
     128         419 :     components.addRootAccess(root_);
     129         419 : }
     130             : 
     131        6023 : rtl::Reference< RootAccess > Service::getRoot() {
     132        6023 :     osl::MutexGuard g(mutex_);
     133        6023 :     if (!root_.is()) {
     134             :         throw css::lang::NotInitializedException(
     135           0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     136             :     }
     137        6023 :     return root_;
     138             : }
     139             : 
     140             : }
     141             : 
     142         419 : css::uno::Reference< css::uno::XInterface > create(
     143             :     css::uno::Reference< css::uno::XComponentContext > const & context)
     144             : {
     145         419 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     146             : }
     147             : 
     148          66 : OUString getImplementationName() {
     149          66 :     return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
     150             : }
     151             : 
     152          21 : css::uno::Sequence< OUString > getSupportedServiceNames() {
     153          21 :     return css::uno::Sequence< OUString >();
     154             : }
     155             : 
     156             : } }
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10