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