masterfix DEV300: #i10000# build fix
[LibreOffice.git] / forms / source / xforms / binding.hxx
blob7a69b154741853cab2a4a0cc4c6911f8a9e37451
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _BINDING_HXX
29 #define _BINDING_HXX
31 #include <com/sun/star/uno/Reference.hxx>
33 // forward declaractions
34 namespace xforms
36 class Model;
37 class EvaluationContext;
39 namespace com { namespace sun { namespace star {
40 namespace xml {
41 namespace xpath { class XXPathAPI; }
42 namespace dom
44 class XNode;
45 class XNodeList;
48 namespace container { class XNameContainer; }
49 namespace xforms { class XModel; }
50 namespace xsd { class XDataType; }
51 } } }
53 // includes for parent classes
54 #include <cppuhelper/implbase8.hxx>
55 #include <propertysetbase.hxx>
56 #include <com/sun/star/form/binding/XValueBinding.hpp>
57 #include <com/sun/star/form/binding/XListEntrySource.hpp>
58 #include <com/sun/star/form/validation/XValidator.hpp>
59 #include <com/sun/star/util/XModifyBroadcaster.hpp>
60 #include <com/sun/star/container/XNamed.hpp>
61 #include <com/sun/star/xml/dom/events/XEventListener.hpp>
62 #include <com/sun/star/lang/XUnoTunnel.hpp>
63 #include <com/sun/star/util/XCloneable.hpp>
65 // includes for member variables
66 #include "pathexpression.hxx"
67 #include "boolexpression.hxx"
68 #include "mip.hxx"
69 #include <rtl/ustring.hxx>
70 #include <vector>
71 #include <memory> // auto_ptr
75 namespace xforms
78 /** An XForms Binding. Contains:
79 * # a connection to its model
80 * # an ID
81 * # an binding expression
82 * # model item properties
83 * # (NOT YET IMPLEMENTED) child bindings (sequence of)
85 * See http://www.w3.org/TR/xforms/ for more information.
88 typedef cppu::ImplInheritanceHelper8<
89 PropertySetBase,
90 com::sun::star::form::binding::XValueBinding,
91 com::sun::star::form::binding::XListEntrySource,
92 com::sun::star::form::validation::XValidator,
93 com::sun::star::util::XModifyBroadcaster,
94 com::sun::star::container::XNamed,
95 com::sun::star::xml::dom::events::XEventListener,
96 com::sun::star::lang::XUnoTunnel,
97 com::sun::star::util::XCloneable
98 > Binding_t;
100 class Binding : public Binding_t
102 public:
103 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XModel> Model_t;
104 typedef com::sun::star::uno::Reference<com::sun::star::util::XModifyListener> XModifyListener_t;
105 typedef std::vector<XModifyListener_t> ModifyListeners_t;
106 typedef com::sun::star::uno::Reference<com::sun::star::form::validation::XValidityConstraintListener> XValidityConstraintListener_t;
107 typedef std::vector<XValidityConstraintListener_t> XValidityConstraintListeners_t;
108 typedef com::sun::star::uno::Reference<com::sun::star::form::binding::XListEntryListener> XListEntryListener_t;
109 typedef std::vector<XListEntryListener_t> XListEntryListeners_t;
110 typedef com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> XNameContainer_t;
111 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode> XNode_t;
112 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XNodeList> XNodeList_t;
113 typedef com::sun::star::uno::Reference<com::sun::star::util::XCloneable> XCloneable_t;
114 typedef com::sun::star::uno::Sequence<sal_Int8> IntSequence_t;
115 typedef com::sun::star::uno::Sequence<rtl::OUString> StringSequence_t;
116 typedef std::vector<MIP> MIPs_t;
117 typedef std::vector<XNode_t> XNodes_t;
121 private:
123 /// the Model to which this Binding belongs; may be NULL
124 Model_t mxModel;
126 /// binding-ID. A document-wide unique ID for this binding element.
127 rtl::OUString msBindingID;
129 /// an XPath-expression to be instantiated on the data instance
130 PathExpression maBindingExpression;
132 /// an XPath-expression to determine read-only status
133 BoolExpression maReadonly;
135 /// an XPath-expression to determine relevance
136 BoolExpression maRelevant;
138 /// an XPath-expression to determine if item is required
139 BoolExpression maRequired;
141 /// an XPath-expression to determine if item is valid
142 BoolExpression maConstraint;
144 /// user-readable explanation of the constraint
145 rtl::OUString msExplainConstraint;
147 /// an XPath-expression to calculate values
148 ComputedExpression maCalculate;
150 /// the XML namespaces used for XML names/XPath-expressions in this binding
151 XNameContainer_t mxNamespaces;
153 /// a type name
154 rtl::OUString msTypeName;
156 /// modify listeners
157 ModifyListeners_t maModifyListeners;
159 /// list entry listener
160 XListEntryListeners_t maListEntryListeners;
162 /// validity listeners;
163 XValidityConstraintListeners_t maValidityListeners;
165 /// nodes on which we are listening for events
166 XNodes_t maEventNodes;
168 /// the current MIP object for the first node we are bound to
169 MIP maMIP;
171 /// flag to detect recursions in calculate
172 bool mbInCalculate;
174 // flags to manage deferred notifications:
175 /// if >0, valueModified() and bindingModified() will only set flags
176 sal_Int32 mnDeferModifyNotifications;
177 bool mbValueModified; /// if true, valueModified needs to be called
178 bool mbBindingModified; /// if true, bindingModified needs to be called
181 void initializePropertySet();
184 public:
185 Binding();
186 virtual ~Binding() throw();
189 // property methods: get/set value
192 Model_t getModel() const; /// get XForms model
193 void _setModel( const Model_t& ); /// set XForms model (only called by Model)
196 rtl::OUString getModelID() const; /// get ID of XForms model
198 rtl::OUString getBindingID() const; /// get ID for this binding
199 void setBindingID( const rtl::OUString& ); /// set ID for this binding
201 rtl::OUString getBindingExpression() const; /// get binding expression
202 void setBindingExpression( const rtl::OUString& ); /// set binding exp.
204 // MIPs (model item properties)
206 rtl::OUString getReadonlyExpression() const; /// get read-only MIP
207 void setReadonlyExpression( const rtl::OUString& ); /// set read-only MIP
209 rtl::OUString getRelevantExpression() const; /// get relevant MIP
210 void setRelevantExpression( const rtl::OUString& ); /// set relevant MIP
212 rtl::OUString getRequiredExpression() const; /// get required MIP
213 void setRequiredExpression( const rtl::OUString& ); /// set required MIP
215 rtl::OUString getConstraintExpression() const; /// get constraint MIP
216 void setConstraintExpression( const rtl::OUString& );/// set constraint MIP
218 rtl::OUString getCalculateExpression() const; /// get calculate MIP
219 void setCalculateExpression( const rtl::OUString& ); /// set calculate MIP
221 rtl::OUString getType() const; /// get type name MIP (static)
222 void setType( const rtl::OUString& ); /// set type name MIP (static)
224 // a binding expression can only be interpreted with respect to
225 // suitable namespace declarations. We collect those in the model and in a binding.
227 // access to a binding's namespace
228 // (set-method only changes local namespaces (but may add to model))
229 XNameContainer_t getBindingNamespaces() const; /// set binding namespaces
230 void setBindingNamespaces( const XNameContainer_t& ); /// get binding nmsp.
232 // access to the model's namespaces
233 // (set-method changes model's namespaces (unless a local one is present))
234 XNameContainer_t getModelNamespaces() const; /// set model namespaces
235 void setModelNamespaces( const XNameContainer_t& ); /// get model nmsp.
238 // read-only properties that map MIPs to control data source properties
239 bool getReadOnly() const; // MIP readonly
240 bool getRelevant() const; // MIP relevant
241 bool getExternalData() const; // mapped from model's ExternalData property
244 // missing binding properties:
245 // - type (static; default: xsd:string)
246 // - minOccurs/maxOccurs (computed XPath; default: 0/inf)
247 // - p3ptype (static; no default)
252 /// get this binding's context node
253 xforms::EvaluationContext getEvaluationContext() const;
255 /// get evalation contexts for this binding's MIPs
256 std::vector<xforms::EvaluationContext> getMIPEvaluationContexts();
258 /// get nodeset the bind is bound to
259 XNodeList_t getXNodeList();
261 /// heuristically determine whether this binding is simple binding
262 /// (here: simple binding == does not depend on other parts of the
263 /// instance, it's not a 'dynamic' binding)
264 bool isSimpleBinding() const;
266 /// heuristically determine whether this binding's binding
267 /// expression is simple
268 bool isSimpleBindingExpression() const;
270 /// update this binding (e.g. called by model for refresh )
271 void update();
273 /// prevent change notifications being sent to controls
274 void deferNotifications( bool );
276 /// is this binding valid? (are constraint, type and required MIPs ok?)
277 bool isValid();
279 /// determine whether this binding currently performs a useful
280 /// function, r whether is may be discarded
281 bool isUseful();
283 /// explain why binding is invalid
284 rtl::OUString explainInvalid();
287 // the ID for XUnoTunnel calls
288 static IntSequence_t getUnoTunnelID();
289 static Binding* getBinding( const com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& );
292 // class-scoped typedef for easy-to-read UNO interfaces
295 // basic types
296 typedef com::sun::star::uno::Any Any_t;
297 typedef com::sun::star::uno::Sequence<com::sun::star::uno::Type> Sequence_Type_t;
298 typedef com::sun::star::uno::Type Type_t;
300 // reference types
301 typedef com::sun::star::uno::Reference<com::sun::star::beans::XPropertyChangeListener> XPropertyChangeListener_t;
302 typedef com::sun::star::uno::Reference<com::sun::star::beans::XPropertySetInfo> XPropertySetInfo_t;
303 typedef com::sun::star::uno::Reference<com::sun::star::beans::XVetoableChangeListener> XVetoableChangeListener_t;
304 typedef com::sun::star::uno::Reference<com::sun::star::xml::xpath::XXPathAPI> XXPathAPI_t;
305 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::events::XEvent> XEvent_t;
306 typedef com::sun::star::uno::Reference<com::sun::star::xsd::XDataType> XDataType_t;
308 // exceptions
309 typedef com::sun::star::beans::PropertyVetoException PropertyVetoException_t;
310 typedef com::sun::star::beans::UnknownPropertyException UnknownPropertyException_t;
311 typedef com::sun::star::lang::IllegalArgumentException IllegalArgumentException_t;
312 typedef com::sun::star::lang::NoSupportException NoSupportException_t;
313 typedef com::sun::star::lang::WrappedTargetException WrappedTargetException_t;
314 typedef com::sun::star::uno::RuntimeException RuntimeException_t;
315 typedef com::sun::star::form::binding::IncompatibleTypesException IncompatibleTypesException_t;
316 typedef com::sun::star::form::binding::InvalidBindingStateException InvalidBindingStateException_t;
317 typedef com::sun::star::lang::NullPointerException NullPointerException_t;
318 typedef com::sun::star::lang::IndexOutOfBoundsException IndexOutOfBoundsException_t;
322 private:
323 /// check whether object is live, and throw suitable exception if not
324 /// (to be used be API methods before acting on the object)
325 void checkLive() throw( RuntimeException_t );
327 /// check whether binding has a model, and throw exception if not
328 /// (to be used be API methods before acting on the object)
329 void checkModel() throw( RuntimeException_t );
331 /// determine whether object is live
332 /// live: has model, and model has been initialized
333 bool isLive() const;
335 /// get the model implementation
336 xforms::Model* getModelImpl() const;
337 xforms::Model* getModelImpl( const Model_t& xModel ) const;
339 /// get MIP evaluation contexts
340 /// (only valid if control has already been bound)
341 std::vector<xforms::EvaluationContext> _getMIPEvaluationContexts() const;
343 /// bind this binding, and pre-compute the affected nodes
344 void bind( bool bForceRebind = false );
346 /// the binding value has been changed:
347 /// trigger a modified event on all modified listeners
348 void valueModified();
350 /// the binding itself has changed:
351 /// force rebind, then call valueModified()
352 void bindingModified();
355 /// register the event listeners for
356 void registerListeners();
358 /// set MIPs defined by this binding on MIP item
359 MIP getLocalMIP() const;
361 /// get the data type that applies to this binding
362 XDataType_t getDataType();
364 /// determine whether binding is valid according to the given data type
365 bool isValid_DataType();
367 /// explain validity of binding with respect to the given data type
368 rtl::OUString explainInvalid_DataType();
370 /// 'clear' this binding - remove all listeners, etc.
371 void clear();
373 /// distribute MIPs from current node recursively to childs
374 void distributeMIP( const XNode_t &rxNode );
376 /// implement get*Namespaces()
377 XNameContainer_t _getNamespaces() const;
379 /// implement set*Namespaces()
380 void _setNamespaces( const XNameContainer_t&, bool bBinding );
382 /// set a useful default binding ID (if none is set)
383 void _checkBindingID();
385 public:
386 /// for debugging purposes only: get the MIPs defined by this binding
387 const MIP* _getMIP();
394 // XValueBinding:
397 public:
399 virtual Sequence_Type_t SAL_CALL getSupportedValueTypes()
400 throw( RuntimeException_t );
402 virtual sal_Bool SAL_CALL supportsType( const Type_t& aType )
403 throw( RuntimeException_t );
405 virtual Any_t SAL_CALL getValue( const Type_t& aType )
406 throw( IncompatibleTypesException_t,
407 RuntimeException_t );
409 virtual void SAL_CALL setValue( const Any_t& aValue )
410 throw( IncompatibleTypesException_t,
411 InvalidBindingStateException_t,
412 NoSupportException_t,
413 RuntimeException_t );
418 // XListEntry Source
421 virtual sal_Int32 SAL_CALL getListEntryCount()
422 throw( RuntimeException_t );
424 virtual rtl::OUString SAL_CALL getListEntry( sal_Int32 nPosition )
425 throw( IndexOutOfBoundsException_t,
426 RuntimeException_t );
428 virtual StringSequence_t SAL_CALL getAllListEntries()
429 throw( RuntimeException_t );
431 virtual void SAL_CALL addListEntryListener( const XListEntryListener_t& )
432 throw( NullPointerException_t,
433 RuntimeException_t );
435 virtual void SAL_CALL removeListEntryListener( const XListEntryListener_t&)
436 throw( NullPointerException_t,
437 RuntimeException_t );
442 // XValidator:
445 virtual sal_Bool SAL_CALL isValid(
446 const Any_t& )
447 throw( RuntimeException_t );
449 virtual rtl::OUString SAL_CALL explainInvalid(
450 const Any_t& )
451 throw( RuntimeException_t );
453 virtual void SAL_CALL addValidityConstraintListener(
454 const XValidityConstraintListener_t& xListener )
455 throw( NullPointerException_t,
456 RuntimeException_t );
458 virtual void SAL_CALL removeValidityConstraintListener(
459 const XValidityConstraintListener_t& xListener )
460 throw( NullPointerException_t,
461 RuntimeException_t );
465 // XModifyBroadcaster & friends:
466 // inform listeners about changes in our values
469 public:
471 virtual void SAL_CALL addModifyListener(
472 const XModifyListener_t& xListener )
473 throw( RuntimeException_t );
475 virtual void SAL_CALL removeModifyListener(
476 const XModifyListener_t& xListener )
477 throw( RuntimeException_t );
483 // XNamed:
484 // get/set name
487 public:
489 virtual rtl::OUString SAL_CALL getName()
490 throw( RuntimeException_t );
492 virtual void SAL_CALL setName( const rtl::OUString& )
493 throw( RuntimeException_t );
498 // xml::dom::event::XEventListener
499 // receive an event if our node changed
502 virtual void SAL_CALL handleEvent(
503 const XEvent_t& xEvent )
504 throw( RuntimeException_t );
509 // XUnoTunnel
512 virtual sal_Int64 SAL_CALL getSomething( const IntSequence_t& )
513 throw( RuntimeException_t );
517 // XCloneable
520 virtual XCloneable_t SAL_CALL createClone()
521 throw( RuntimeException_t );
525 } // namespace xforms
527 #endif