2009-05-15 18:00:17 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* Copyright 2009 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* $RCSfile: code,v $
|
|
|
|
*
|
|
|
|
* $Revision: 1.4 $
|
|
|
|
*
|
|
|
|
* This file is part of OpenOffice.org.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include "precompiled_configmgr.hxx"
|
|
|
|
#include "sal/config.h"
|
|
|
|
|
2009-07-02 14:21:36 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2009-05-26 17:25:36 +02:00
|
|
|
#include "com/sun/star/lang/NoSupportException.hpp"
|
2009-05-20 17:20:08 +02:00
|
|
|
#include "com/sun/star/uno/Any.hxx"
|
|
|
|
#include "com/sun/star/uno/Reference.hxx"
|
2009-05-18 15:03:21 +02:00
|
|
|
#include "com/sun/star/uno/RuntimeException.hpp"
|
|
|
|
#include "com/sun/star/uno/Sequence.hxx"
|
2009-05-20 17:20:08 +02:00
|
|
|
#include "com/sun/star/uno/XInterface.hpp"
|
2009-05-18 15:03:21 +02:00
|
|
|
#include "cppuhelper/implbase1.hxx"
|
2009-05-20 17:20:08 +02:00
|
|
|
#include "cppuhelper/weak.hxx"
|
2009-05-20 13:33:52 +02:00
|
|
|
#include "osl/diagnose.h"
|
2009-05-29 15:19:40 +02:00
|
|
|
#include "osl/interlck.h"
|
2009-05-26 17:25:36 +02:00
|
|
|
#include "osl/mutex.hxx"
|
2009-05-15 18:00:17 +02:00
|
|
|
#include "rtl/ref.hxx"
|
2009-07-02 14:21:36 +02:00
|
|
|
#include "rtl/string.h"
|
2009-05-26 17:25:36 +02:00
|
|
|
#include "rtl/ustring.h"
|
|
|
|
#include "rtl/ustring.hxx"
|
2009-05-18 15:03:21 +02:00
|
|
|
#include "rtl/uuid.h"
|
|
|
|
#include "sal/types.h"
|
2009-05-15 18:00:17 +02:00
|
|
|
|
|
|
|
#include "access.hxx"
|
|
|
|
#include "childaccess.hxx"
|
2009-05-20 17:20:08 +02:00
|
|
|
#include "components.hxx"
|
2009-08-07 10:25:27 +02:00
|
|
|
#include "data.hxx"
|
2009-06-02 16:14:38 +02:00
|
|
|
#include "groupnode.hxx"
|
2009-07-23 12:42:37 +02:00
|
|
|
#include "layer.hxx"
|
2009-05-20 17:20:08 +02:00
|
|
|
#include "localizedpropertynode.hxx"
|
2009-09-04 11:42:31 +02:00
|
|
|
#include "localizedvaluenode.hxx"
|
2009-05-26 17:25:36 +02:00
|
|
|
#include "lock.hxx"
|
2009-05-15 18:00:17 +02:00
|
|
|
#include "node.hxx"
|
2009-05-20 17:20:08 +02:00
|
|
|
#include "propertynode.hxx"
|
2009-05-15 18:00:17 +02:00
|
|
|
#include "rootaccess.hxx"
|
2009-06-04 18:08:16 +02:00
|
|
|
#include "setnode.hxx"
|
2009-06-24 16:53:49 +02:00
|
|
|
#include "type.hxx"
|
2009-05-15 18:00:17 +02:00
|
|
|
|
|
|
|
namespace configmgr {
|
|
|
|
|
2009-05-18 15:03:21 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
namespace css = com::sun::star;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Sequence< sal_Int8 > ChildAccess::getTunnelId() {
|
|
|
|
static css::uno::Sequence< sal_Int8 > id;
|
|
|
|
if (id.getLength() == 0) {
|
|
|
|
css::uno::Sequence< sal_Int8 > uuid(16);
|
|
|
|
rtl_createUuid(
|
|
|
|
reinterpret_cast< sal_uInt8 * >(uuid.getArray()), 0, false);
|
|
|
|
id = uuid;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2009-05-20 13:33:52 +02:00
|
|
|
ChildAccess::ChildAccess(
|
2009-05-29 15:19:40 +02:00
|
|
|
rtl::Reference< RootAccess > const & root,
|
2009-05-29 16:48:52 +02:00
|
|
|
rtl::Reference< Access > const & parent, rtl::OUString const & name,
|
2009-05-29 15:19:40 +02:00
|
|
|
rtl::Reference< Node > const & node):
|
2009-07-23 12:42:37 +02:00
|
|
|
root_(root), parent_(parent), name_(name), node_(node), modified_(false),
|
2009-06-24 16:10:18 +02:00
|
|
|
inTransaction_(false)
|
2009-05-20 13:33:52 +02:00
|
|
|
{
|
2009-05-29 15:19:40 +02:00
|
|
|
OSL_ASSERT(root.is() && parent.is() && node.is());
|
2009-05-20 13:33:52 +02:00
|
|
|
}
|
|
|
|
|
2009-05-15 18:00:17 +02:00
|
|
|
ChildAccess::ChildAccess(
|
2009-05-19 10:49:37 +02:00
|
|
|
rtl::Reference< RootAccess > const & root,
|
2009-05-19 17:32:24 +02:00
|
|
|
rtl::Reference< Node > const & node):
|
2009-07-23 12:42:37 +02:00
|
|
|
root_(root), node_(node), modified_(false), inTransaction_(false)
|
2009-05-20 13:33:52 +02:00
|
|
|
{
|
|
|
|
OSL_ASSERT(root.is() && node.is());
|
|
|
|
}
|
2009-05-15 18:00:17 +02:00
|
|
|
|
2009-07-13 17:15:58 +02:00
|
|
|
rtl::OUString ChildAccess::getPath() {
|
|
|
|
rtl::OUString path;
|
|
|
|
rtl::Reference< Access > parent(getParentAccess());
|
|
|
|
if (parent.is()) {
|
|
|
|
path = parent->getPath() +
|
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
|
|
|
|
}
|
2009-08-07 10:25:27 +02:00
|
|
|
return path + Data::createSegment(node_->getTemplateName(), name_);
|
2009-07-13 17:15:58 +02:00
|
|
|
}
|
|
|
|
|
2009-05-19 10:49:37 +02:00
|
|
|
rtl::Reference< Node > ChildAccess::getNode() {
|
|
|
|
return node_;
|
|
|
|
}
|
|
|
|
|
2009-07-29 15:30:40 +02:00
|
|
|
bool ChildAccess::isFinalized() {
|
|
|
|
return node_->getFinalized() != NO_LAYER ||
|
|
|
|
(parent_.is() && parent_->isFinalized());
|
|
|
|
}
|
|
|
|
|
2009-06-04 10:46:43 +02:00
|
|
|
rtl::Reference< RootAccess > ChildAccess::getRootAccess() {
|
2009-05-19 10:49:37 +02:00
|
|
|
return root_;
|
|
|
|
}
|
|
|
|
|
2009-06-04 10:46:43 +02:00
|
|
|
rtl::Reference< Access > ChildAccess::getParentAccess() {
|
|
|
|
return parent_;
|
|
|
|
}
|
|
|
|
|
2009-06-03 18:02:52 +02:00
|
|
|
rtl::OUString ChildAccess::getName() throw (css::uno::RuntimeException) {
|
2009-07-02 14:21:36 +02:00
|
|
|
OSL_ASSERT(thisIs(IS_ANY));
|
|
|
|
osl::MutexGuard g(lock);
|
|
|
|
checkLocalizedPropertyAccess();
|
2009-06-03 18:02:52 +02:00
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::uno::XInterface > ChildAccess::getParent()
|
|
|
|
throw (css::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(thisIs(IS_ANY));
|
|
|
|
osl::MutexGuard g(lock);
|
2009-07-02 14:21:36 +02:00
|
|
|
checkLocalizedPropertyAccess();
|
2009-06-03 18:02:52 +02:00
|
|
|
return static_cast< cppu::OWeakObject * >(parent_.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChildAccess::setParent(css::uno::Reference< css::uno::XInterface > const &)
|
|
|
|
throw (css::lang::NoSupportException, css::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(thisIs(IS_ANY));
|
2009-07-02 14:21:36 +02:00
|
|
|
osl::MutexGuard g(lock);
|
|
|
|
checkLocalizedPropertyAccess();
|
2009-06-03 18:02:52 +02:00
|
|
|
throw css::lang::NoSupportException(
|
|
|
|
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("setParent")),
|
|
|
|
static_cast< cppu::OWeakObject * >(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int64 ChildAccess::getSomething(
|
|
|
|
css::uno::Sequence< sal_Int8 > const & aIdentifier)
|
|
|
|
throw (css::uno::RuntimeException)
|
|
|
|
{
|
2009-07-02 14:21:36 +02:00
|
|
|
OSL_ASSERT(thisIs(IS_ANY));
|
|
|
|
osl::MutexGuard g(lock);
|
|
|
|
checkLocalizedPropertyAccess();
|
2009-06-03 18:02:52 +02:00
|
|
|
return aIdentifier == getTunnelId()
|
|
|
|
? reinterpret_cast< sal_Int64 >(this) : 0;
|
|
|
|
}
|
|
|
|
|
2009-05-29 15:19:40 +02:00
|
|
|
oslInterlockedCount ChildAccess::acquireCounting() {
|
|
|
|
return osl_incrementInterlockedCount(&m_refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChildAccess::releaseNondeleting() {
|
|
|
|
osl_decrementInterlockedCount(&m_refCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChildAccess::bind(
|
|
|
|
rtl::Reference< RootAccess > const & root,
|
2009-06-04 17:06:02 +02:00
|
|
|
rtl::Reference< Access > const & parent, rtl::OUString const & name)
|
|
|
|
throw ()
|
2009-05-29 15:19:40 +02:00
|
|
|
{
|
2009-06-04 17:06:02 +02:00
|
|
|
OSL_ASSERT(
|
|
|
|
!parent_.is() && root.is() && parent.is() && name.getLength() != 0);
|
2009-05-19 17:32:24 +02:00
|
|
|
root_ = root;
|
|
|
|
parent_ = parent;
|
2009-06-04 17:06:02 +02:00
|
|
|
name_ = name;
|
2009-05-18 15:03:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-20 13:33:52 +02:00
|
|
|
void ChildAccess::unbind() throw () {
|
2009-05-29 15:19:40 +02:00
|
|
|
OSL_ASSERT(parent_.is());
|
2009-06-24 16:10:18 +02:00
|
|
|
parent_->releaseChild(name_);
|
2009-05-29 15:19:40 +02:00
|
|
|
parent_.clear();
|
2009-06-04 17:06:02 +02:00
|
|
|
//TODO: clear name_?
|
2009-06-24 16:10:18 +02:00
|
|
|
inTransaction_ = true;
|
2009-05-20 13:33:52 +02:00
|
|
|
}
|
|
|
|
|
2009-06-24 16:10:18 +02:00
|
|
|
void ChildAccess::markAsModified() {
|
2009-07-23 12:42:37 +02:00
|
|
|
modified_ = true;
|
2009-06-24 16:10:18 +02:00
|
|
|
for (ChildAccess * p = this; p != 0 && p->parent_.is();
|
|
|
|
p = dynamic_cast< ChildAccess * >(p->parent_.get()))
|
2009-06-04 18:08:16 +02:00
|
|
|
{
|
2009-06-24 16:10:18 +02:00
|
|
|
p->parent_->modifiedChildren_[p->name_] = p;
|
2009-05-28 10:19:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 12:42:37 +02:00
|
|
|
void ChildAccess::committed() {
|
|
|
|
modified_ = false;
|
|
|
|
inTransaction_ = false;
|
|
|
|
}
|
|
|
|
|
2009-06-23 17:14:12 +02:00
|
|
|
void ChildAccess::setNode(rtl::Reference< Node > const & node) {
|
|
|
|
node_ = node;
|
|
|
|
}
|
|
|
|
|
2009-06-24 16:10:18 +02:00
|
|
|
void ChildAccess::setProperty(css::uno::Any const & value) {
|
|
|
|
Type type = TYPE_ERROR;
|
|
|
|
bool nillable = false;
|
2009-09-04 11:24:45 +02:00
|
|
|
switch (node_->kind()) {
|
|
|
|
case Node::KIND_PROPERTY:
|
|
|
|
{
|
|
|
|
PropertyNode * prop = dynamic_cast< PropertyNode * >(node_.get());
|
|
|
|
type = prop->getType();
|
|
|
|
nillable = prop->isNillable();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Node::KIND_LOCALIZED_PROPERTY:
|
|
|
|
{
|
|
|
|
rtl::OUString locale(getRootAccess()->getLocale());
|
|
|
|
if (!Components::allLocales(locale)) {
|
|
|
|
rtl::Reference< ChildAccess > child(getChild(locale));
|
|
|
|
if (child.is()) {
|
|
|
|
child->setProperty(value);
|
|
|
|
} else {
|
2009-09-04 11:42:31 +02:00
|
|
|
insertLocalizedValueChild(locale, value);
|
2009-09-04 11:24:45 +02:00
|
|
|
}
|
|
|
|
return;
|
2009-06-25 13:51:29 +02:00
|
|
|
}
|
2009-06-24 16:10:18 +02:00
|
|
|
}
|
2009-09-04 11:24:45 +02:00
|
|
|
break;
|
|
|
|
case Node::KIND_LOCALIZED_VALUE:
|
|
|
|
{
|
|
|
|
LocalizedPropertyNode * locprop =
|
|
|
|
dynamic_cast< LocalizedPropertyNode * >(getParentNode().get());
|
|
|
|
type = locprop->getType();
|
|
|
|
nillable = locprop->isNillable();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-06-24 16:10:18 +02:00
|
|
|
}
|
2009-06-24 16:53:49 +02:00
|
|
|
checkValue(value, type, nillable);
|
2009-06-24 16:10:18 +02:00
|
|
|
markAsModified();
|
|
|
|
changedValue_.reset(new css::uno::Any(value));
|
|
|
|
//TODO notify change
|
2009-05-26 17:25:36 +02:00
|
|
|
}
|
|
|
|
|
2009-05-20 17:20:08 +02:00
|
|
|
css::uno::Any ChildAccess::asValue() {
|
2009-09-04 11:24:45 +02:00
|
|
|
if (changedValue_.get() != 0) {
|
2009-06-24 16:10:18 +02:00
|
|
|
return *changedValue_;
|
2009-05-26 17:25:36 +02:00
|
|
|
}
|
2009-09-04 11:24:45 +02:00
|
|
|
switch (node_->kind()) {
|
|
|
|
case Node::KIND_PROPERTY:
|
|
|
|
return dynamic_cast< PropertyNode * >(node_.get())->getValue();
|
|
|
|
case Node::KIND_LOCALIZED_PROPERTY:
|
|
|
|
{
|
|
|
|
rtl::OUString locale(getRootAccess()->getLocale());
|
|
|
|
if (!Components::allLocales(locale)) {
|
|
|
|
rtl::Reference< ChildAccess > child(getChild(locale));
|
2009-06-25 13:51:29 +02:00
|
|
|
if (!child.is()) {
|
2009-09-04 11:24:45 +02:00
|
|
|
//TODO: find best match
|
|
|
|
child = getChild(rtl::OUString());
|
2009-06-25 13:51:29 +02:00
|
|
|
if (!child.is()) {
|
2009-09-04 11:24:45 +02:00
|
|
|
child = getChild(
|
|
|
|
rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM("en-US")));
|
|
|
|
if (!child.is()) {
|
|
|
|
std::vector< rtl::Reference< ChildAccess > > all(
|
|
|
|
getAllChildren());
|
|
|
|
if (all.empty()) {
|
|
|
|
return css::uno::Any();
|
|
|
|
}
|
|
|
|
child = all.front();
|
2009-06-25 13:51:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-04 11:24:45 +02:00
|
|
|
return child->asValue();
|
2009-06-25 13:51:29 +02:00
|
|
|
}
|
2009-05-20 17:20:08 +02:00
|
|
|
}
|
2009-09-04 11:24:45 +02:00
|
|
|
break;
|
|
|
|
case Node::KIND_LOCALIZED_VALUE:
|
2009-09-04 11:42:31 +02:00
|
|
|
return dynamic_cast< LocalizedValueNode * >(node_.get())->getValue();
|
2009-09-04 11:24:45 +02:00
|
|
|
default:
|
|
|
|
break;
|
2009-05-20 17:20:08 +02:00
|
|
|
}
|
|
|
|
return css::uno::makeAny(
|
|
|
|
css::uno::Reference< css::uno::XInterface >(
|
|
|
|
static_cast< cppu::OWeakObject * >(this)));
|
|
|
|
}
|
|
|
|
|
2009-07-29 15:30:40 +02:00
|
|
|
void ChildAccess::commitChanges(bool valid) {
|
|
|
|
commitChildChanges(valid);
|
|
|
|
if (valid && changedValue_.get() != 0) {
|
2009-07-13 17:15:58 +02:00
|
|
|
Components::singleton().addModification(getPath());
|
2009-09-04 11:24:45 +02:00
|
|
|
switch (node_->kind()) {
|
|
|
|
case Node::KIND_PROPERTY:
|
|
|
|
dynamic_cast< PropertyNode * >(node_.get())->setValue(
|
|
|
|
NO_LAYER, *changedValue_);
|
|
|
|
break;
|
|
|
|
case Node::KIND_LOCALIZED_VALUE:
|
2009-09-04 11:42:31 +02:00
|
|
|
dynamic_cast< LocalizedValueNode * >(node_.get())->setValue(
|
2009-09-04 11:24:45 +02:00
|
|
|
NO_LAYER, *changedValue_);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OSL_ASSERT(false); // this cannot happen
|
|
|
|
break;
|
2009-06-24 16:10:18 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-29 15:30:40 +02:00
|
|
|
changedValue_.reset();
|
2009-06-24 16:10:18 +02:00
|
|
|
}
|
|
|
|
|
2009-05-29 15:19:40 +02:00
|
|
|
ChildAccess::~ChildAccess() {
|
|
|
|
osl::MutexGuard g(lock);
|
|
|
|
if (parent_.is()) {
|
2009-05-29 16:48:52 +02:00
|
|
|
parent_->releaseChild(name_);
|
2009-05-29 15:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
2009-05-15 18:00:17 +02:00
|
|
|
|
2009-07-02 14:21:36 +02:00
|
|
|
void ChildAccess::addSupportedServiceNames(
|
|
|
|
std::vector< rtl::OUString > * services)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(services != 0);
|
|
|
|
services->push_back(
|
2009-09-04 11:24:45 +02:00
|
|
|
getParentNode()->kind() == Node::KIND_GROUP
|
2009-07-02 14:21:36 +02:00
|
|
|
? rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
2009-09-04 11:24:45 +02:00
|
|
|
"com.sun.star.configuration.GroupElement"))
|
2009-07-02 14:21:36 +02:00
|
|
|
: rtl::OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
2009-09-04 11:24:45 +02:00
|
|
|
"com.sun.star.configuration.SetElement")));
|
2009-07-02 14:21:36 +02:00
|
|
|
}
|
|
|
|
|
2009-05-15 18:00:17 +02:00
|
|
|
}
|