LCOV - code coverage report
Current view: top level - configmgr/source - childaccess.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 154 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 "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           0 : css::uno::Sequence< sal_Int8 > ChildAccess::getTunnelId()
      70             : {
      71           0 :     return theChildAccessUnoTunnelId::get().getSeq();
      72             : }
      73             : 
      74           0 : 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           0 :     inTransaction_(false)
      80             : {
      81           0 :     lock_ = lock();
      82             :     assert(root.is() && parent.is() && node.is());
      83           0 : }
      84             : 
      85           0 : ChildAccess::ChildAccess(
      86             :     Components & components, rtl::Reference< RootAccess > const & root,
      87             :     rtl::Reference< Node > const & node):
      88           0 :     Access(components), root_(root), node_(node), inTransaction_(false)
      89             : {
      90           0 :     lock_ = lock();
      91             :     assert(root.is() && node.is());
      92           0 : }
      93             : 
      94           0 : Path ChildAccess::getAbsolutePath() {
      95             :     assert(getParentAccess().is());
      96           0 :     Path path(getParentAccess()->getAbsolutePath());
      97           0 :     path.push_back(name_);
      98           0 :     return path;
      99             : }
     100             : 
     101           0 : Path ChildAccess::getRelativePath() {
     102           0 :     Path path;
     103           0 :     rtl::Reference< Access > parent(getParentAccess());
     104           0 :     if (parent.is()) {
     105           0 :         path = parent->getRelativePath();
     106             :     }
     107           0 :     path.push_back(name_);
     108           0 :     return path;
     109             : }
     110             : 
     111           0 : OUString ChildAccess::getRelativePathRepresentation() {
     112           0 :     OUStringBuffer path;
     113           0 :     rtl::Reference< Access > parent(getParentAccess());
     114           0 :     if (parent.is()) {
     115           0 :         path.append(parent->getRelativePathRepresentation());
     116           0 :         if (!path.isEmpty()) {
     117           0 :             path.append('/');
     118             :         }
     119             :     }
     120           0 :     path.append(Data::createSegment(node_->getTemplateName(), name_));
     121           0 :     return path.makeStringAndClear();
     122             : }
     123             : 
     124           0 : rtl::Reference< Node > ChildAccess::getNode() {
     125           0 :     return node_;
     126             : }
     127             : 
     128           0 : bool ChildAccess::isFinalized() {
     129           0 :     return node_->getFinalized() != Data::NO_LAYER ||
     130           0 :         (parent_.is() && parent_->isFinalized());
     131             : }
     132             : 
     133           0 : OUString ChildAccess::getNameInternal() {
     134           0 :     return name_;
     135             : }
     136             : 
     137           0 : rtl::Reference< RootAccess > ChildAccess::getRootAccess() {
     138           0 :     return root_;
     139             : }
     140             : 
     141           0 : rtl::Reference< Access > ChildAccess::getParentAccess() {
     142           0 :     return parent_;
     143             : }
     144             : 
     145           0 : void ChildAccess::acquire() throw () {
     146           0 :     Access::acquire();
     147           0 : }
     148             : 
     149           0 : void ChildAccess::release() throw () {
     150           0 :     Access::release();
     151           0 : }
     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           0 : 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           0 :     osl::MutexGuard g(*lock_);
     178           0 :     checkLocalizedPropertyAccess();
     179           0 :     return aIdentifier == getTunnelId()
     180           0 :         ? reinterpret_cast< sal_Int64 >(this) : 0;
     181             : }
     182             : 
     183           0 : 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           0 :     root_ = root;
     190           0 :     parent_ = parent;
     191           0 :     name_ = name;
     192           0 : }
     193             : 
     194           0 : void ChildAccess::unbind() throw () {
     195             :     assert(parent_.is());
     196           0 :     parent_->releaseChild(name_);
     197           0 :     parent_.clear();
     198           0 :     inTransaction_ = true;
     199           0 : }
     200             : 
     201           0 : void ChildAccess::committed() {
     202           0 :     inTransaction_ = false;
     203           0 : }
     204             : 
     205           0 : void ChildAccess::setNode(rtl::Reference< Node > const & node) {
     206           0 :     node_ = node;
     207           0 : }
     208             : 
     209           0 : void ChildAccess::setProperty(
     210             :     css::uno::Any const & value, Modifications * localModifications)
     211             : {
     212             :     assert(localModifications != 0);
     213           0 :     Type type = TYPE_ERROR;
     214           0 :     bool nillable = false;
     215           0 :     switch (node_->kind()) {
     216             :     case Node::KIND_PROPERTY:
     217             :         {
     218           0 :             PropertyNode * prop = static_cast< PropertyNode * >(node_.get());
     219           0 :             type = prop->getStaticType();
     220           0 :             nillable = prop->isNillable();
     221             :         }
     222           0 :         break;
     223             :     case Node::KIND_LOCALIZED_PROPERTY:
     224             :         {
     225           0 :             OUString locale(getRootAccess()->getLocale());
     226           0 :             if (!Components::allLocales(locale)) {
     227           0 :                 rtl::Reference< ChildAccess > child(getChild(locale));
     228           0 :                 if (child.is()) {
     229           0 :                     child->setProperty(value, localModifications);
     230             :                 } else {
     231             :                     insertLocalizedValueChild(
     232           0 :                         locale, value, localModifications);
     233             :                 }
     234           0 :                 return;
     235           0 :             }
     236             :         }
     237           0 :         break;
     238             :     case Node::KIND_LOCALIZED_VALUE:
     239             :         {
     240             :             LocalizedPropertyNode * locprop =
     241           0 :                 static_cast< LocalizedPropertyNode * >(getParentNode().get());
     242           0 :             type = locprop->getStaticType();
     243           0 :             nillable = locprop->isNillable();
     244             :         }
     245           0 :         break;
     246             :     default:
     247           0 :         break;
     248             :     }
     249           0 :     checkValue(value, type, nillable);
     250           0 :     getParentAccess()->markChildAsModified(this);
     251           0 :     changedValue_.reset(new css::uno::Any(value));
     252           0 :     localModifications->add(getRelativePath());
     253             : }
     254             : 
     255           0 : css::uno::Any ChildAccess::asValue() {
     256           0 :     if (changedValue_.get() != 0) {
     257           0 :         return *changedValue_;
     258             :     }
     259           0 :     switch (node_->kind()) {
     260             :     case Node::KIND_PROPERTY:
     261           0 :         return static_cast< PropertyNode * >(node_.get())->getValue(
     262           0 :             getComponents());
     263             :     case Node::KIND_LOCALIZED_PROPERTY:
     264             :         {
     265           0 :             OUString locale(getRootAccess()->getLocale());
     266           0 :             if (!Components::allLocales(locale)) {
     267           0 :                 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           0 :                 return child.is() ? child->asValue() : css::uno::Any();
     271           0 :             }
     272             :         }
     273           0 :         break;
     274             :     case Node::KIND_LOCALIZED_VALUE:
     275           0 :         return static_cast< LocalizedValueNode * >(node_.get())->getValue();
     276             :     default:
     277           0 :         break;
     278             :     }
     279             :     return css::uno::makeAny(
     280             :         css::uno::Reference< css::uno::XInterface >(
     281           0 :             static_cast< cppu::OWeakObject * >(this)));
     282             : }
     283             : 
     284           0 : void ChildAccess::commitChanges(bool valid, Modifications * globalModifications)
     285             : {
     286             :     assert(globalModifications != 0);
     287           0 :     commitChildChanges(valid, globalModifications);
     288           0 :     if (valid && changedValue_.get() != 0) {
     289           0 :         Path path(getAbsolutePath());
     290           0 :         getComponents().addModification(path);
     291           0 :         globalModifications->add(path);
     292           0 :         switch (node_->kind()) {
     293             :         case Node::KIND_PROPERTY:
     294           0 :             static_cast< PropertyNode * >(node_.get())->setValue(
     295           0 :                 Data::NO_LAYER, *changedValue_);
     296           0 :             break;
     297             :         case Node::KIND_LOCALIZED_VALUE:
     298           0 :             static_cast< LocalizedValueNode * >(node_.get())->setValue(
     299           0 :                 Data::NO_LAYER, *changedValue_);
     300           0 :             break;
     301             :         default:
     302             :             assert(false); // this cannot happen
     303           0 :             break;
     304           0 :         }
     305             :     }
     306           0 :     changedValue_.reset();
     307           0 : }
     308             : 
     309           0 : ChildAccess::~ChildAccess() {
     310           0 :     osl::MutexGuard g(*lock_);
     311           0 :     if (parent_.is()) {
     312           0 :         parent_->releaseChild(name_);
     313           0 :     }
     314           0 : }
     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           0 : void ChildAccess::addSupportedServiceNames(
     323             :     std::vector< OUString > * services)
     324             : {
     325             :     assert(services != 0);
     326             :     services->push_back(
     327           0 :         getParentNode()->kind() == Node::KIND_GROUP
     328             :         ? OUString("com.sun.star.configuration.GroupElement")
     329           0 :         : OUString("com.sun.star.configuration.SetElement"));
     330           0 : }
     331             : 
     332           0 : css::uno::Any ChildAccess::queryInterface(css::uno::Type const & aType)
     333             :     throw (css::uno::RuntimeException, std::exception)
     334             : {
     335             :     assert(thisIs(IS_ANY));
     336           0 :     osl::MutexGuard g(*lock_);
     337           0 :     checkLocalizedPropertyAccess();
     338           0 :     css::uno::Any res(Access::queryInterface(aType));
     339           0 :     return res.hasValue()
     340             :         ? res
     341             :         : cppu::queryInterface(
     342             :             aType, static_cast< css::container::XChild * >(this),
     343           0 :             static_cast< css::lang::XUnoTunnel * >(this));
     344             : }
     345             : 
     346             : }
     347             : 
     348             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10