LCOV - code coverage report
Current view: top level - configmgr/source - childaccess.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 137 154 89.0 %
Date: 2014-04-11 Functions: 25 28 89.3 %
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 "sal/config.h"
      21             : 
      22             : #include <cassert>
      23             : #include <vector>
      24             : 
      25             : #include "com/sun/star/container/XChild.hpp"
      26             : #include "com/sun/star/lang/NoSupportException.hpp"
      27             : #include "com/sun/star/lang/XUnoTunnel.hpp"
      28             : #include "com/sun/star/uno/Any.hxx"
      29             : #include "com/sun/star/uno/Reference.hxx"
      30             : #include "com/sun/star/uno/RuntimeException.hpp"
      31             : #include "com/sun/star/uno/Sequence.hxx"
      32             : #include "com/sun/star/uno/Type.hxx"
      33             : #include "com/sun/star/uno/XInterface.hpp"
      34             : #include "cppu/unotype.hxx"
      35             : #include "cppuhelper/queryinterface.hxx"
      36             : #include "cppuhelper/weak.hxx"
      37             : #include "comphelper/servicehelper.hxx"
      38             : #include "osl/mutex.hxx"
      39             : #include "rtl/ref.hxx"
      40             : #include "rtl/string.h"
      41             : #include "rtl/ustrbuf.hxx"
      42             : #include "rtl/ustring.h"
      43             : #include "rtl/ustring.hxx"
      44             : #include "sal/types.h"
      45             : 
      46             : #include "access.hxx"
      47             : #include "childaccess.hxx"
      48             : #include "components.hxx"
      49             : #include "data.hxx"
      50             : #include "groupnode.hxx"
      51             : #include "localizedpropertynode.hxx"
      52             : #include "localizedvaluenode.hxx"
      53             : #include "lock.hxx"
      54             : #include "modifications.hxx"
      55             : #include "node.hxx"
      56             : #include "path.hxx"
      57             : #include "propertynode.hxx"
      58             : #include "rootaccess.hxx"
      59             : #include "setnode.hxx"
      60             : #include "type.hxx"
      61             : 
      62             : namespace configmgr {
      63             : 
      64             : namespace
      65             : {
      66             :     class theChildAccessUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theChildAccessUnoTunnelId > {};
      67             : }
      68             : 
      69        3614 : css::uno::Sequence< sal_Int8 > ChildAccess::getTunnelId()
      70             : {
      71        3614 :     return theChildAccessUnoTunnelId::get().getSeq();
      72             : }
      73             : 
      74     6735105 : ChildAccess::ChildAccess(
      75             :     Components & components, rtl::Reference< RootAccess > const & root,
      76             :     rtl::Reference< Access > const & parent, OUString const & name,
      77             :     rtl::Reference< Node > const & node):
      78             :     Access(components), root_(root), parent_(parent), name_(name), node_(node),
      79     6735105 :     inTransaction_(false)
      80             : {
      81     6735105 :     lock_ = lock();
      82             :     assert(root.is() && parent.is() && node.is());
      83     6735105 : }
      84             : 
      85        1807 : ChildAccess::ChildAccess(
      86             :     Components & components, rtl::Reference< RootAccess > const & root,
      87             :     rtl::Reference< Node > const & node):
      88        1807 :     Access(components), root_(root), node_(node), inTransaction_(false)
      89             : {
      90        1807 :     lock_ = lock();
      91             :     assert(root.is() && node.is());
      92        1807 : }
      93             : 
      94      399802 : Path ChildAccess::getAbsolutePath() {
      95             :     assert(getParentAccess().is());
      96      399802 :     Path path(getParentAccess()->getAbsolutePath());
      97      399802 :     path.push_back(name_);
      98      399802 :     return path;
      99             : }
     100             : 
     101      246887 : Path ChildAccess::getRelativePath() {
     102      246887 :     Path path;
     103      493774 :     rtl::Reference< Access > parent(getParentAccess());
     104      246887 :     if (parent.is()) {
     105      246887 :         path = parent->getRelativePath();
     106             :     }
     107      246887 :     path.push_back(name_);
     108      493774 :     return path;
     109             : }
     110             : 
     111       25654 : OUString ChildAccess::getRelativePathRepresentation() {
     112       25654 :     OUStringBuffer path;
     113       51308 :     rtl::Reference< Access > parent(getParentAccess());
     114       25654 :     if (parent.is()) {
     115       25654 :         path.append(parent->getRelativePathRepresentation());
     116       25654 :         if (!path.isEmpty()) {
     117       11070 :             path.append('/');
     118             :         }
     119             :     }
     120       25654 :     path.append(Data::createSegment(node_->getTemplateName(), name_));
     121       51308 :     return path.makeStringAndClear();
     122             : }
     123             : 
     124    19312227 : rtl::Reference< Node > ChildAccess::getNode() {
     125    19312227 :     return node_;
     126             : }
     127             : 
     128      653722 : bool ChildAccess::isFinalized() {
     129     1307444 :     return node_->getFinalized() != Data::NO_LAYER ||
     130     1961166 :         (parent_.is() && parent_->isFinalized());
     131             : }
     132             : 
     133     1446734 : OUString ChildAccess::getNameInternal() {
     134     1446734 :     return name_;
     135             : }
     136             : 
     137     6056496 : rtl::Reference< RootAccess > ChildAccess::getRootAccess() {
     138     6056496 :     return root_;
     139             : }
     140             : 
     141     1511208 : rtl::Reference< Access > ChildAccess::getParentAccess() {
     142     1511208 :     return parent_;
     143             : }
     144             : 
     145    35140425 : void ChildAccess::acquire() throw () {
     146    35140425 :     Access::acquire();
     147    35140425 : }
     148             : 
     149    35140185 : void ChildAccess::release() throw () {
     150    35140185 :     Access::release();
     151    35140185 : }
     152             : 
     153           0 : css::uno::Reference< css::uno::XInterface > ChildAccess::getParent()
     154             :     throw (css::uno::RuntimeException, std::exception)
     155             : {
     156             :     assert(thisIs(IS_ANY));
     157           0 :     osl::MutexGuard g(*lock_);
     158           0 :     checkLocalizedPropertyAccess();
     159           0 :     return static_cast< cppu::OWeakObject * >(parent_.get());
     160             : }
     161             : 
     162           0 : void ChildAccess::setParent(css::uno::Reference< css::uno::XInterface > const &)
     163             :     throw (css::lang::NoSupportException, css::uno::RuntimeException, std::exception)
     164             : {
     165             :     assert(thisIs(IS_ANY));
     166           0 :     osl::MutexGuard g(*lock_);
     167           0 :     checkLocalizedPropertyAccess();
     168             :     throw css::lang::NoSupportException(
     169           0 :         "setParent", static_cast< cppu::OWeakObject * >(this));
     170             : }
     171             : 
     172        1807 : sal_Int64 ChildAccess::getSomething(
     173             :     css::uno::Sequence< sal_Int8 > const & aIdentifier)
     174             :     throw (css::uno::RuntimeException, std::exception)
     175             : {
     176             :     assert(thisIs(IS_ANY));
     177        1807 :     osl::MutexGuard g(*lock_);
     178        1807 :     checkLocalizedPropertyAccess();
     179        3614 :     return aIdentifier == getTunnelId()
     180        3614 :         ? reinterpret_cast< sal_Int64 >(this) : 0;
     181             : }
     182             : 
     183        1807 : void ChildAccess::bind(
     184             :     rtl::Reference< RootAccess > const & root,
     185             :     rtl::Reference< Access > const & parent, OUString const & name)
     186             :     throw ()
     187             : {
     188             :     assert(!parent_.is() && root.is() && parent.is() && !name.isEmpty());
     189        1807 :     root_ = root;
     190        1807 :     parent_ = parent;
     191        1807 :     name_ = name;
     192        1807 : }
     193             : 
     194         874 : void ChildAccess::unbind() throw () {
     195             :     assert(parent_.is());
     196         874 :     parent_->releaseChild(name_);
     197         874 :     parent_.clear();
     198         874 :     inTransaction_ = true;
     199         874 : }
     200             : 
     201      158358 : void ChildAccess::committed() {
     202      158358 :     inTransaction_ = false;
     203      158358 : }
     204             : 
     205       43322 : void ChildAccess::setNode(rtl::Reference< Node > const & node) {
     206       43322 :     node_ = node;
     207       43322 : }
     208             : 
     209       81234 : void ChildAccess::setProperty(
     210             :     css::uno::Any const & value, Modifications * localModifications)
     211             : {
     212             :     assert(localModifications != 0);
     213       81234 :     Type type = TYPE_ERROR;
     214       81234 :     bool nillable = false;
     215       81234 :     switch (node_->kind()) {
     216             :     case Node::KIND_PROPERTY:
     217             :         {
     218       77362 :             PropertyNode * prop = static_cast< PropertyNode * >(node_.get());
     219       77362 :             type = prop->getStaticType();
     220       77362 :             nillable = prop->isNillable();
     221             :         }
     222       77362 :         break;
     223             :     case Node::KIND_LOCALIZED_PROPERTY:
     224             :         {
     225        1936 :             OUString locale(getRootAccess()->getLocale());
     226        1936 :             if (!Components::allLocales(locale)) {
     227        1936 :                 rtl::Reference< ChildAccess > child(getChild(locale));
     228        1936 :                 if (child.is()) {
     229        1936 :                     child->setProperty(value, localModifications);
     230             :                 } else {
     231             :                     insertLocalizedValueChild(
     232           0 :                         locale, value, localModifications);
     233             :                 }
     234       83170 :                 return;
     235           0 :             }
     236             :         }
     237           0 :         break;
     238             :     case Node::KIND_LOCALIZED_VALUE:
     239             :         {
     240             :             LocalizedPropertyNode * locprop =
     241        1936 :                 static_cast< LocalizedPropertyNode * >(getParentNode().get());
     242        1936 :             type = locprop->getStaticType();
     243        1936 :             nillable = locprop->isNillable();
     244             :         }
     245        1936 :         break;
     246             :     default:
     247           0 :         break;
     248             :     }
     249       79298 :     checkValue(value, type, nillable);
     250       79298 :     getParentAccess()->markChildAsModified(this);
     251       79298 :     changedValue_.reset(new css::uno::Any(value));
     252       79298 :     localModifications->add(getRelativePath());
     253             : }
     254             : 
     255     2617453 : css::uno::Any ChildAccess::asValue() {
     256     2617453 :     if (changedValue_.get() != 0) {
     257        9186 :         return *changedValue_;
     258             :     }
     259     2608267 :     switch (node_->kind()) {
     260             :     case Node::KIND_PROPERTY:
     261     1809375 :         return static_cast< PropertyNode * >(node_.get())->getValue(
     262     3618750 :             getComponents());
     263             :     case Node::KIND_LOCALIZED_PROPERTY:
     264             :         {
     265      208248 :             OUString locale(getRootAccess()->getLocale());
     266      208248 :             if (!Components::allLocales(locale)) {
     267      116997 :                 rtl::Reference< ChildAccess > child(getChild("*" + locale));
     268             :                 // As a last resort, return a nil value even though it may be
     269             :                 // illegal for the given property:
     270      116997 :                 return child.is() ? child->asValue() : css::uno::Any();
     271       91251 :             }
     272             :         }
     273       91251 :         break;
     274             :     case Node::KIND_LOCALIZED_VALUE:
     275      156853 :         return static_cast< LocalizedValueNode * >(node_.get())->getValue();
     276             :     default:
     277      433791 :         break;
     278             :     }
     279             :     return css::uno::makeAny(
     280             :         css::uno::Reference< css::uno::XInterface >(
     281      525042 :             static_cast< cppu::OWeakObject * >(this)));
     282             : }
     283             : 
     284      157484 : void ChildAccess::commitChanges(bool valid, Modifications * globalModifications)
     285             : {
     286             :     assert(globalModifications != 0);
     287      157484 :     commitChildChanges(valid, globalModifications);
     288      157484 :     if (valid && changedValue_.get() != 0) {
     289       79298 :         Path path(getAbsolutePath());
     290       79298 :         getComponents().addModification(path);
     291       79298 :         globalModifications->add(path);
     292       79298 :         switch (node_->kind()) {
     293             :         case Node::KIND_PROPERTY:
     294       77362 :             static_cast< PropertyNode * >(node_.get())->setValue(
     295      154724 :                 Data::NO_LAYER, *changedValue_);
     296       77362 :             break;
     297             :         case Node::KIND_LOCALIZED_VALUE:
     298        1936 :             static_cast< LocalizedValueNode * >(node_.get())->setValue(
     299        3872 :                 Data::NO_LAYER, *changedValue_);
     300        1936 :             break;
     301             :         default:
     302             :             assert(false); // this cannot happen
     303           0 :             break;
     304       79298 :         }
     305             :     }
     306      157484 :     changedValue_.reset();
     307      157484 : }
     308             : 
     309    20210016 : ChildAccess::~ChildAccess() {
     310     6736672 :     osl::MutexGuard g(*lock_);
     311     6736672 :     if (parent_.is()) {
     312     6735798 :         parent_->releaseChild(name_);
     313     6736672 :     }
     314    13473344 : }
     315             : 
     316           0 : void ChildAccess::addTypes(std::vector< css::uno::Type > * types) const {
     317             :     assert(types != 0);
     318           0 :     types->push_back(cppu::UnoType< css::container::XChild >::get());
     319           0 :     types->push_back(cppu::UnoType< css::lang::XUnoTunnel >::get());
     320           0 : }
     321             : 
     322        2972 : void ChildAccess::addSupportedServiceNames(
     323             :     std::vector< OUString > * services)
     324             : {
     325             :     assert(services != 0);
     326             :     services->push_back(
     327        5944 :         getParentNode()->kind() == Node::KIND_GROUP
     328             :         ? OUString("com.sun.star.configuration.GroupElement")
     329        2972 :         : OUString("com.sun.star.configuration.SetElement"));
     330        2972 : }
     331             : 
     332      554114 : css::uno::Any ChildAccess::queryInterface(css::uno::Type const & aType)
     333             :     throw (css::uno::RuntimeException, std::exception)
     334             : {
     335             :     assert(thisIs(IS_ANY));
     336      554114 :     osl::MutexGuard g(*lock_);
     337      554114 :     checkLocalizedPropertyAccess();
     338     1108228 :     css::uno::Any res(Access::queryInterface(aType));
     339      554114 :     return res.hasValue()
     340             :         ? res
     341             :         : cppu::queryInterface(
     342             :             aType, static_cast< css::container::XChild * >(this),
     343     1108228 :             static_cast< css::lang::XUnoTunnel * >(this));
     344             : }
     345             : 
     346             : }
     347             : 
     348             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10