LibreOffice Module forms (master) 1
binding.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <com/sun/star/uno/Reference.hxx>
24#include "propertysetbase.hxx"
25#include <com/sun/star/form/binding/XValueBinding.hpp>
26#include <com/sun/star/form/binding/XListEntrySource.hpp>
27#include <com/sun/star/form/validation/XValidator.hpp>
28#include <com/sun/star/util/XModifyBroadcaster.hpp>
29#include <com/sun/star/container/XNamed.hpp>
30#include <com/sun/star/xml/dom/events/XEventListener.hpp>
31#include <com/sun/star/lang/XUnoTunnel.hpp>
32#include <com/sun/star/util/XCloneable.hpp>
33
34#include "pathexpression.hxx"
35#include "boolexpression.hxx"
36#include "mip.hxx"
37#include <rtl/ustring.hxx>
38#include <vector>
39
40// forward declaractions
41namespace xforms
42{
43 class Model;
45}
46namespace com::sun::star {
47 namespace xml {
48 namespace xpath { class XXPathAPI; }
49 namespace dom
50 {
51 class XNode;
52 class XNodeList;
53 }
54 }
55 namespace container { class XNameContainer; }
56 namespace xforms { class XModel; }
57 namespace xsd { class XDataType; }
58}
59
60
61namespace xforms
62{
63
74typedef cppu::ImplInheritanceHelper<
76 css::form::binding::XValueBinding,
77 css::form::binding::XListEntrySource,
78 css::form::validation::XValidator,
79 css::util::XModifyBroadcaster,
80 css::container::XNamed,
81 css::xml::dom::events::XEventListener,
82 css::lang::XUnoTunnel,
83 css::util::XCloneable
85
86class Binding : public Binding_t
87{
88public:
89 typedef std::vector<css::uno::Reference<css::util::XModifyListener> > ModifyListeners_t;
90 typedef std::vector<css::uno::Reference<css::form::validation::XValidityConstraintListener> > XValidityConstraintListeners_t;
91 typedef std::vector<css::uno::Reference<css::form::binding::XListEntryListener> > XListEntryListeners_t;
92
93
94private:
95
97 css::uno::Reference<css::xforms::XModel> mxModel;
98
100 OUString msBindingID;
101
104
107
110
113
116
119
122
124 css::uno::Reference<css::container::XNameContainer> mxNamespaces;
125
127 OUString msTypeName;
128
131
134
137
139 std::vector<css::uno::Reference<css::xml::dom::XNode> > maEventNodes;
140
143
146
147 // flags to manage deferred notifications:
152
153
155
156
157public:
158 Binding();
159 virtual ~Binding() override;
160
161
162 // property methods: get/set value
163
164
165 css::uno::Reference<css::xforms::XModel> getModel() const { return mxModel;}
166 void _setModel( const css::uno::Reference<css::xforms::XModel>& );
167
168
169 OUString getModelID() const;
170
171 OUString getBindingID() const { return msBindingID;}
172 void setBindingID( const OUString& );
173
174 OUString getBindingExpression() const;
175 void setBindingExpression( const OUString& );
176
177 // MIPs (model item properties)
178
179 OUString getReadonlyExpression() const;
180 void setReadonlyExpression( const OUString& );
181
182 OUString getRelevantExpression() const;
183 void setRelevantExpression( const OUString& );
184
185 OUString getRequiredExpression() const;
186 void setRequiredExpression( const OUString& );
187
188 OUString getConstraintExpression() const;
189 void setConstraintExpression( const OUString& );
190
191 OUString getCalculateExpression() const;
192 void setCalculateExpression( const OUString& );
193
194 OUString getType() const { return msTypeName;}
195 void setType( const OUString& );
196
197 // a binding expression can only be interpreted with respect to
198 // suitable namespace declarations. We collect those in the model and in a binding.
199
200 // access to a binding's namespace
201 // (set-method only changes local namespaces (but may add to model))
202 css::uno::Reference<css::container::XNameContainer> getBindingNamespaces() const { return mxNamespaces; }
203 void setBindingNamespaces( const css::uno::Reference<css::container::XNameContainer>& );
204
205 // access to the model's namespaces
206 // (set-method changes model's namespaces (unless a local one is present))
207 css::uno::Reference<css::container::XNameContainer> getModelNamespaces() const;
208 void setModelNamespaces( const css::uno::Reference<css::container::XNameContainer>& );
209
210
211 // read-only properties that map MIPs to control data source properties
212 bool getReadOnly() const; // MIP readonly
213 bool getRelevant() const; // MIP relevant
214 bool getExternalData() const; // mapped from model's ExternalData property
215
216
217 // missing binding properties:
218 // - type (static; default: xsd:string)
219 // - minOccurs/maxOccurs (computed XPath; default: 0/inf)
220 // - p3ptype (static; no default)
221
222
225
227 std::vector<xforms::EvaluationContext> getMIPEvaluationContexts();
228
230 css::uno::Reference<css::xml::dom::XNodeList> getXNodeList();
231
235 bool isSimpleBinding() const;
236
239 bool isSimpleBindingExpression() const;
240
242 void update();
243
245 void deferNotifications( bool );
246
248 bool isValid() const;
249
252 bool isUseful() const;
253
255 OUString explainInvalid();
256
257
258 // the ID for XUnoTunnel calls
259 static css::uno::Sequence<sal_Int8> getUnoTunnelId();
260
261
262private:
267 void checkLive();
268
271 bool isLive() const;
272
275
278 std::vector<xforms::EvaluationContext> _getMIPEvaluationContexts() const;
279
281 void bind( bool bForceRebind = false );
282
285 void valueModified();
286
289 void bindingModified();
290
291
293 MIP getLocalMIP() const;
294
296 css::uno::Reference<css::xsd::XDataType> getDataType() const;
297
299 bool isValid_DataType() const;
300
302 OUString explainInvalid_DataType();
303
305 void clear();
306
308 void distributeMIP( const css::uno::Reference<css::xml::dom::XNode> &rxNode );
309
311 css::uno::Reference<css::container::XNameContainer> _getNamespaces() const;
312
314 void _setNamespaces( const css::uno::Reference<css::container::XNameContainer>&, bool bBinding );
315
317 void _checkBindingID();
318
319public:
320
321 virtual css::uno::Sequence<css::uno::Type> SAL_CALL getSupportedValueTypes() override;
322
323 virtual sal_Bool SAL_CALL supportsType( const css::uno::Type& aType ) override;
324
325 virtual css::uno::Any SAL_CALL getValue( const css::uno::Type& aType ) override;
326
327 virtual void SAL_CALL setValue( const css::uno::Any& aValue ) override;
328
329
330 // XListEntrySource
331
332
333 virtual sal_Int32 SAL_CALL getListEntryCount() override;
334
335 virtual OUString SAL_CALL getListEntry( sal_Int32 nPosition ) override;
336
337 virtual css::uno::Sequence<OUString> SAL_CALL getAllListEntries() override;
338
339 virtual void SAL_CALL addListEntryListener( const css::uno::Reference<css::form::binding::XListEntryListener>& ) override;
340
341 virtual void SAL_CALL removeListEntryListener( const css::uno::Reference<css::form::binding::XListEntryListener>&) override;
342
343
344 // XValidator:
345
346
347 virtual sal_Bool SAL_CALL isValid(
348 const css::uno::Any& ) override;
349
350 virtual OUString SAL_CALL explainInvalid(
351 const css::uno::Any& ) override;
352
353 virtual void SAL_CALL addValidityConstraintListener(
354 const css::uno::Reference<css::form::validation::XValidityConstraintListener>& xListener ) override;
355
356 virtual void SAL_CALL removeValidityConstraintListener(
357 const css::uno::Reference<css::form::validation::XValidityConstraintListener>& xListener ) override;
358
359
360 // XModifyBroadcaster & friends:
361 // inform listeners about changes in our values
362
363
364public:
365
366 virtual void SAL_CALL addModifyListener(
367 const css::uno::Reference<css::util::XModifyListener>& xListener ) override;
368
369 virtual void SAL_CALL removeModifyListener(
370 const css::uno::Reference<css::util::XModifyListener>& xListener ) override;
371
372
373 // XNamed:
374 // get/set name
375
376
377public:
378
379 virtual OUString SAL_CALL getName() override;
380
381 virtual void SAL_CALL setName( const OUString& ) override;
382
383
384 // xml::dom::event::XEventListener
385 // receive an event if our node changed
386
387
388 virtual void SAL_CALL handleEvent(
389 const css::uno::Reference<css::xml::dom::events::XEvent>& xEvent ) override;
390
391
392 // XUnoTunnel
393
394
395 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence<sal_Int8>& ) override;
396
397
398 // XCloneable
399
400
401 virtual css::uno::Reference<css::util::XCloneable> SAL_CALL createClone() override;
402};
403
404
405} // namespace xforms
406
407/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bridges two XPropertySet helper implementations
bool isSimpleBindingExpression() const
heuristically determine whether this binding's binding expression is simple
Definition: binding.cxx:169
void setRelevantExpression(const OUString &)
get relevant MIP
Definition: binding.cxx:343
void setReadonlyExpression(const OUString &)
get read-only MIP
Definition: binding.cxx:332
OUString getRelevantExpression() const
set read-only MIP
Definition: binding.cxx:338
void update()
update this binding (e.g. called by model for refresh )
Definition: binding.cxx:174
OUString explainInvalid_DataType()
explain validity of binding with respect to the given data type
Definition: binding.cxx:760
virtual void SAL_CALL handleEvent(const css::uno::Reference< css::xml::dom::events::XEvent > &xEvent) override
Definition: binding.cxx:1137
void checkLive()
check whether object is live, and throw suitable exception if not (to be used be API methods before a...
Definition: binding.cxx:440
virtual void SAL_CALL removeValidityConstraintListener(const css::uno::Reference< css::form::validation::XValidityConstraintListener > &xListener) override
Definition: binding.cxx:1123
xforms::EvaluationContext getEvaluationContext() const
get this binding's context node
Definition: binding.cxx:286
PathExpression maBindingExpression
an XPath-expression to be instantiated on the data instance
Definition: binding.hxx:103
void setBindingExpression(const OUString &)
get binding expression
Definition: binding.cxx:321
css::uno::Reference< css::xsd::XDataType > getDataType() const
get the data type that applies to this binding
Definition: binding.cxx:739
bool mbValueModified
Definition: binding.hxx:150
bool isLive() const
determine whether object is live live: has model, and model has been initialized
Definition: binding.cxx:446
void setConstraintExpression(const OUString &)
get constraint MIP
Definition: binding.cxx:365
BoolExpression maRelevant
an XPath-expression to determine relevance
Definition: binding.hxx:109
bool getExternalData() const
Definition: binding.cxx:420
void _setModel(const css::uno::Reference< css::xforms::XModel > &)
get XForms model
Definition: binding.cxx:124
css::uno::Reference< css::container::XNameContainer > getBindingNamespaces() const
set type name MIP (static)
Definition: binding.hxx:202
void valueModified()
the binding value has been changed: trigger a modified event on all modified listeners
Definition: binding.cxx:628
static css::uno::Sequence< sal_Int8 > getUnoTunnelId()
Definition: binding.cxx:304
sal_Int32 mnDeferModifyNotifications
if >0, valueModified() and bindingModified() will only set flags
Definition: binding.hxx:149
bool mbBindingModified
if true, valueModified needs to be called
Definition: binding.hxx:151
XValidityConstraintListeners_t maValidityListeners
validity listeners;
Definition: binding.hxx:136
virtual css::uno::Any SAL_CALL getValue(const css::uno::Type &aType) override
Definition: binding.cxx:961
bool getReadOnly() const
get model nmsp.
Definition: binding.cxx:410
css::uno::Reference< css::xforms::XModel > getModel() const
Definition: binding.hxx:165
OUString getType() const
set calculate MIP
Definition: binding.hxx:194
void _checkBindingID()
set a useful default binding ID (if none is set)
Definition: binding.cxx:925
OUString getBindingExpression() const
set ID for this binding
Definition: binding.cxx:316
void bindingModified()
the binding itself has changed: force rebind, then call valueModified()
Definition: binding.cxx:694
std::vector< xforms::EvaluationContext > _getMIPEvaluationContexts() const
get MIP evaluation contexts (only valid if control has already been bound)
Definition: binding.cxx:495
ModifyListeners_t maModifyListeners
modify listeners
Definition: binding.hxx:130
void setCalculateExpression(const OUString &)
get calculate MIP
Definition: binding.cxx:382
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
Definition: binding.cxx:1247
MIP maMIP
the current MIP object for the first node we are bound to
Definition: binding.hxx:142
bool mbInCalculate
flag to detect recursions in calculate
Definition: binding.hxx:145
bool isUseful() const
determine whether this binding currently performs a useful function, r whether is may be discarded
Definition: binding.cxx:224
virtual void SAL_CALL removeListEntryListener(const css::uno::Reference< css::form::binding::XListEntryListener > &) override
Definition: binding.cxx:1082
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: binding.cxx:1177
void clear()
'clear' this binding - remove all listeners, etc.
Definition: binding.cxx:768
virtual void SAL_CALL setName(const OUString &) override
Definition: binding.cxx:1276
void deferNotifications(bool)
prevent change notifications being sent to controls
Definition: binding.cxx:188
void initializePropertySet()
if true, bindingModified needs to be called
Definition: binding.cxx:1195
BoolExpression maReadonly
an XPath-expression to determine read-only status
Definition: binding.hxx:106
void bind(bool bForceRebind=false)
bind this binding, and pre-compute the affected nodes
Definition: binding.cxx:513
virtual void SAL_CALL addValidityConstraintListener(const css::uno::Reference< css::form::validation::XValidityConstraintListener > &xListener) override
Definition: binding.cxx:1114
OUString msBindingID
binding-ID. A document-wide unique ID for this binding element.
Definition: binding.hxx:100
std::vector< css::uno::Reference< css::form::binding::XListEntryListener > > XListEntryListeners_t
Definition: binding.hxx:91
css::uno::Reference< css::xml::dom::XNodeList > getXNodeList()
get nodeset the bind is bound to
Definition: binding.cxx:150
void setBindingID(const OUString &)
get ID for this binding
Definition: binding.cxx:311
OUString getConstraintExpression() const
set required MIP
Definition: binding.cxx:360
OUString msTypeName
a type name
Definition: binding.hxx:127
virtual void SAL_CALL setValue(const css::uno::Any &aValue) override
Definition: binding.cxx:981
void distributeMIP(const css::uno::Reference< css::xml::dom::XNode > &rxNode)
distribute MIPs from current node recursively to children
Definition: binding.cxx:668
bool getRelevant() const
Definition: binding.cxx:415
xforms::Model * getModelImpl() const
get the model implementation
Definition: binding.cxx:452
bool isSimpleBinding() const
heuristically determine whether this binding is simple binding (here: simple binding == does not depe...
Definition: binding.cxx:159
void setType(const OUString &)
get type name MIP (static)
Definition: binding.cxx:389
virtual ~Binding() override
Definition: binding.cxx:119
ComputedExpression maCalculate
an XPath-expression to calculate values
Definition: binding.hxx:121
css::uno::Reference< css::container::XNameContainer > mxNamespaces
the XML namespaces used for XML names/XPath-expressions in this binding
Definition: binding.hxx:124
void setRequiredExpression(const OUString &)
get required MIP
Definition: binding.cxx:354
void setBindingNamespaces(const css::uno::Reference< css::container::XNameContainer > &)
Definition: binding.cxx:395
std::vector< css::uno::Reference< css::form::validation::XValidityConstraintListener > > XValidityConstraintListeners_t
Definition: binding.hxx:90
OUString getBindingID() const
get ID of XForms model
Definition: binding.hxx:171
BoolExpression maRequired
an XPath-expression to determine if item is required
Definition: binding.hxx:112
OUString getCalculateExpression() const
set constraint MIP
Definition: binding.cxx:377
virtual sal_Int32 SAL_CALL getListEntryCount() override
Definition: binding.cxx:1009
css::uno::Reference< css::xforms::XModel > mxModel
the Model to which this Binding belongs; may be NULL
Definition: binding.hxx:97
virtual sal_Bool SAL_CALL supportsType(const css::uno::Type &aType) override
Definition: binding.cxx:956
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getSupportedValueTypes() override
Definition: binding.cxx:951
std::vector< xforms::EvaluationContext > getMIPEvaluationContexts()
get evaluation contexts for this binding's MIPs
Definition: binding.cxx:294
BoolExpression maConstraint
an XPath-expression to determine if item is valid
Definition: binding.hxx:115
std::vector< css::uno::Reference< css::xml::dom::XNode > > maEventNodes
nodes on which we are listening for events
Definition: binding.hxx:139
void setModelNamespaces(const css::uno::Reference< css::container::XNameContainer > &)
set model namespaces
Definition: binding.cxx:405
virtual OUString SAL_CALL getListEntry(sal_Int32 nPosition) override
Definition: binding.cxx:1043
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &xListener) override
Definition: binding.cxx:1261
css::uno::Reference< css::container::XNameContainer > _getNamespaces() const
implement get*Namespaces()
Definition: binding.cxx:856
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &) override
Definition: binding.cxx:1168
virtual void SAL_CALL addListEntryListener(const css::uno::Reference< css::form::binding::XListEntryListener > &) override
Definition: binding.cxx:1072
OUString getRequiredExpression() const
set relevant MIP
Definition: binding.cxx:349
void _setNamespaces(const css::uno::Reference< css::container::XNameContainer > &, bool bBinding)
implement set*Namespaces()
Definition: binding.cxx:871
XListEntryListeners_t maListEntryListeners
list entry listener
Definition: binding.hxx:133
virtual OUString SAL_CALL getName() override
Definition: binding.cxx:1271
std::vector< css::uno::Reference< css::util::XModifyListener > > ModifyListeners_t
Definition: binding.hxx:89
bool isValid_DataType() const
determine whether binding is valid according to the given data type
Definition: binding.cxx:753
MIP getLocalMIP() const
set MIPs defined by this binding on MIP item
Definition: binding.cxx:714
OUString getModelID() const
set XForms model (only called by Model)
Definition: binding.cxx:143
OUString msExplainConstraint
user-readable explanation of the constraint
Definition: binding.hxx:118
bool isValid() const
is this binding valid? (are constraint, type and required MIPs ok?)
Definition: binding.cxx:206
OUString getReadonlyExpression() const
set binding exp.
Definition: binding.cxx:327
virtual css::uno::Sequence< OUString > SAL_CALL getAllListEntries() override
Definition: binding.cxx:1055
OUString explainInvalid()
explain why binding is invalid
Definition: binding.cxx:249
css::uno::Reference< css::container::XNameContainer > getModelNamespaces() const
get binding nmsp.
Definition: binding.cxx:400
BoolExpression represents a computed XPath expression that returns a bool value and caches the result...
ComputedExpression represents an XPath Expression and caches results.
define the context for the evaluation of an XPath expression
represents the XForms *m*odel *i*tem *p*roperties (MIPs) for a given XNode in the instance data at a ...
Definition: mip.hxx:31
PathExpression represents an XPath Expression and caches results.
cppu::ImplInheritanceHelper< PropertySetBase, css::form::binding::XValueBinding, css::form::binding::XListEntrySource, css::form::validation::XValidator, css::util::XModifyBroadcaster, css::container::XNamed, css::xml::dom::events::XEventListener, css::lang::XUnoTunnel, css::util::XCloneable > Binding_t
An XForms Binding.
Definition: binding.hxx:84
unsigned char sal_Bool