1*3a7cf181SAndrew Rist /**************************************************************
2*3a7cf181SAndrew Rist *
3*3a7cf181SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*3a7cf181SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*3a7cf181SAndrew Rist * distributed with this work for additional information
6*3a7cf181SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*3a7cf181SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*3a7cf181SAndrew Rist * "License"); you may not use this file except in compliance
9*3a7cf181SAndrew Rist * with the License. You may obtain a copy of the License at
10*3a7cf181SAndrew Rist *
11*3a7cf181SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*3a7cf181SAndrew Rist *
13*3a7cf181SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*3a7cf181SAndrew Rist * software distributed under the License is distributed on an
15*3a7cf181SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3a7cf181SAndrew Rist * KIND, either express or implied. See the License for the
17*3a7cf181SAndrew Rist * specific language governing permissions and limitations
18*3a7cf181SAndrew Rist * under the License.
19*3a7cf181SAndrew Rist *
20*3a7cf181SAndrew Rist *************************************************************/
21*3a7cf181SAndrew Rist
22*3a7cf181SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_configmgr.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "com/sun/star/beans/Optional.hpp"
28cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
29cdf0e10cSrcweir #include "osl/diagnose.h"
30cdf0e10cSrcweir #include "rtl/ref.hxx"
31cdf0e10cSrcweir #include "rtl/ustring.h"
32cdf0e10cSrcweir #include "rtl/ustring.hxx"
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "components.hxx"
35cdf0e10cSrcweir #include "node.hxx"
36cdf0e10cSrcweir #include "propertynode.hxx"
37cdf0e10cSrcweir #include "type.hxx"
38cdf0e10cSrcweir
39cdf0e10cSrcweir namespace configmgr {
40cdf0e10cSrcweir
41cdf0e10cSrcweir namespace {
42cdf0e10cSrcweir
43cdf0e10cSrcweir namespace css = com::sun::star;
44cdf0e10cSrcweir
45cdf0e10cSrcweir }
46cdf0e10cSrcweir
PropertyNode(int layer,Type staticType,bool nillable,css::uno::Any const & value,bool extension)47cdf0e10cSrcweir PropertyNode::PropertyNode(
48cdf0e10cSrcweir int layer, Type staticType, bool nillable, css::uno::Any const & value,
49cdf0e10cSrcweir bool extension):
50cdf0e10cSrcweir Node(layer), staticType_(staticType), nillable_(nillable), value_(value),
51cdf0e10cSrcweir extension_(extension)
52cdf0e10cSrcweir {}
53cdf0e10cSrcweir
clone(bool) const54cdf0e10cSrcweir rtl::Reference< Node > PropertyNode::clone(bool) const {
55cdf0e10cSrcweir return new PropertyNode(*this);
56cdf0e10cSrcweir }
57cdf0e10cSrcweir
getStaticType() const58cdf0e10cSrcweir Type PropertyNode::getStaticType() const {
59cdf0e10cSrcweir return staticType_;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
isNillable() const62cdf0e10cSrcweir bool PropertyNode::isNillable() const {
63cdf0e10cSrcweir return nillable_;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
getValue(Components & components)66cdf0e10cSrcweir css::uno::Any PropertyNode::getValue(Components & components) {
67cdf0e10cSrcweir if (externalDescriptor_.getLength() != 0) {
68cdf0e10cSrcweir css::beans::Optional< css::uno::Any > val(
69cdf0e10cSrcweir components.getExternalValue(externalDescriptor_));
70cdf0e10cSrcweir if (val.IsPresent) {
71cdf0e10cSrcweir value_ = val.Value; //TODO: check value type
72cdf0e10cSrcweir }
73cdf0e10cSrcweir externalDescriptor_ = rtl::OUString(); // must not throw
74cdf0e10cSrcweir }
75cdf0e10cSrcweir return value_;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
setValue(int layer,css::uno::Any const & value)78cdf0e10cSrcweir void PropertyNode::setValue(int layer, css::uno::Any const & value) {
79cdf0e10cSrcweir setLayer(layer);
80cdf0e10cSrcweir value_ = value;
81cdf0e10cSrcweir externalDescriptor_ = rtl::OUString();
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
setExternal(int layer,rtl::OUString const & descriptor)84cdf0e10cSrcweir void PropertyNode::setExternal(int layer, rtl::OUString const & descriptor) {
85cdf0e10cSrcweir OSL_ASSERT(descriptor.getLength() != 0);
86cdf0e10cSrcweir setLayer(layer);
87cdf0e10cSrcweir externalDescriptor_ = descriptor;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
isExtension() const90cdf0e10cSrcweir bool PropertyNode::isExtension() const {
91cdf0e10cSrcweir return extension_;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
PropertyNode(PropertyNode const & other)94cdf0e10cSrcweir PropertyNode::PropertyNode(PropertyNode const & other):
95cdf0e10cSrcweir Node(other), staticType_(other.staticType_), nillable_(other.nillable_),
96cdf0e10cSrcweir value_(other.value_), externalDescriptor_(other.externalDescriptor_),
97cdf0e10cSrcweir extension_(other.extension_)
98cdf0e10cSrcweir {}
99cdf0e10cSrcweir
~PropertyNode()100cdf0e10cSrcweir PropertyNode::~PropertyNode() {}
101cdf0e10cSrcweir
kind() const102cdf0e10cSrcweir Node::Kind PropertyNode::kind() const {
103cdf0e10cSrcweir return KIND_PROPERTY;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir }
107