1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 #ifndef _BINDING_HXX 29 #define _BINDING_HXX 30 31 #include <com/sun/star/uno/Reference.hxx> 32 33 // forward declaractions 34 namespace xforms 35 { 36 class Model; 37 class EvaluationContext; 38 } 39 namespace com { namespace sun { namespace star { 40 namespace xml { 41 namespace xpath { class XXPathAPI; } 42 namespace dom 43 { 44 class XNode; 45 class XNodeList; 46 } 47 } 48 namespace container { class XNameContainer; } 49 namespace xforms { class XModel; } 50 namespace xsd { class XDataType; } 51 } } } 52 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> 64 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 72 73 74 75 namespace xforms 76 { 77 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) 84 * 85 * See http://www.w3.org/TR/xforms/ for more information. 86 */ 87 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; 99 100 class Binding : public Binding_t 101 { 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; 118 119 120 121 private: 122 123 /// the Model to which this Binding belongs; may be NULL 124 Model_t mxModel; 125 126 /// binding-ID. A document-wide unique ID for this binding element. 127 rtl::OUString msBindingID; 128 129 /// an XPath-expression to be instantiated on the data instance 130 PathExpression maBindingExpression; 131 132 /// an XPath-expression to determine read-only status 133 BoolExpression maReadonly; 134 135 /// an XPath-expression to determine relevance 136 BoolExpression maRelevant; 137 138 /// an XPath-expression to determine if item is required 139 BoolExpression maRequired; 140 141 /// an XPath-expression to determine if item is valid 142 BoolExpression maConstraint; 143 144 /// user-readable explanation of the constraint 145 rtl::OUString msExplainConstraint; 146 147 /// an XPath-expression to calculate values 148 ComputedExpression maCalculate; 149 150 /// the XML namespaces used for XML names/XPath-expressions in this binding 151 XNameContainer_t mxNamespaces; 152 153 /// a type name 154 rtl::OUString msTypeName; 155 156 /// modify listeners 157 ModifyListeners_t maModifyListeners; 158 159 /// list entry listener 160 XListEntryListeners_t maListEntryListeners; 161 162 /// validity listeners; 163 XValidityConstraintListeners_t maValidityListeners; 164 165 /// nodes on which we are listening for events 166 XNodes_t maEventNodes; 167 168 /// the current MIP object for the first node we are bound to 169 MIP maMIP; 170 171 /// flag to detect recursions in calculate 172 bool mbInCalculate; 173 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 179 180 181 void initializePropertySet(); 182 183 184 public: 185 Binding(); 186 virtual ~Binding() throw(); 187 188 // 189 // property methods: get/set value 190 // 191 192 Model_t getModel() const; /// get XForms model 193 void _setModel( const Model_t& ); /// set XForms model (only called by Model) 194 195 196 rtl::OUString getModelID() const; /// get ID of XForms model 197 198 rtl::OUString getBindingID() const; /// get ID for this binding 199 void setBindingID( const rtl::OUString& ); /// set ID for this binding 200 201 rtl::OUString getBindingExpression() const; /// get binding expression 202 void setBindingExpression( const rtl::OUString& ); /// set binding exp. 203 204 // MIPs (model item properties) 205 206 rtl::OUString getReadonlyExpression() const; /// get read-only MIP 207 void setReadonlyExpression( const rtl::OUString& ); /// set read-only MIP 208 209 rtl::OUString getRelevantExpression() const; /// get relevant MIP 210 void setRelevantExpression( const rtl::OUString& ); /// set relevant MIP 211 212 rtl::OUString getRequiredExpression() const; /// get required MIP 213 void setRequiredExpression( const rtl::OUString& ); /// set required MIP 214 215 rtl::OUString getConstraintExpression() const; /// get constraint MIP 216 void setConstraintExpression( const rtl::OUString& );/// set constraint MIP 217 218 rtl::OUString getCalculateExpression() const; /// get calculate MIP 219 void setCalculateExpression( const rtl::OUString& ); /// set calculate MIP 220 221 rtl::OUString getType() const; /// get type name MIP (static) 222 void setType( const rtl::OUString& ); /// set type name MIP (static) 223 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. 226 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. 231 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. 236 237 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 242 243 244 // missing binding properties: 245 // - type (static; default: xsd:string) 246 // - minOccurs/maxOccurs (computed XPath; default: 0/inf) 247 // - p3ptype (static; no default) 248 249 250 251 252 /// get this binding's context node 253 xforms::EvaluationContext getEvaluationContext() const; 254 255 /// get evalation contexts for this binding's MIPs 256 std::vector<xforms::EvaluationContext> getMIPEvaluationContexts(); 257 258 /// get nodeset the bind is bound to 259 XNodeList_t getXNodeList(); 260 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; 265 266 /// heuristically determine whether this binding's binding 267 /// expression is simple 268 bool isSimpleBindingExpression() const; 269 270 /// update this binding (e.g. called by model for refresh ) 271 void update(); 272 273 /// prevent change notifications being sent to controls 274 void deferNotifications( bool ); 275 276 /// is this binding valid? (are constraint, type and required MIPs ok?) 277 bool isValid(); 278 279 /// determine whether this binding currently performs a useful 280 /// function, r whether is may be discarded 281 bool isUseful(); 282 283 /// explain why binding is invalid 284 rtl::OUString explainInvalid(); 285 286 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>& ); 290 291 // 292 // class-scoped typedef for easy-to-read UNO interfaces 293 // 294 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; 299 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; 307 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; 319 320 321 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 ); 326 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 ); 330 331 /// determine whether object is live 332 /// live: has model, and model has been initialized 333 bool isLive() const; 334 335 /// get the model implementation 336 xforms::Model* getModelImpl() const; 337 xforms::Model* getModelImpl( const Model_t& xModel ) const; 338 339 /// get MIP evaluation contexts 340 /// (only valid if control has already been bound) 341 std::vector<xforms::EvaluationContext> _getMIPEvaluationContexts() const; 342 343 /// bind this binding, and pre-compute the affected nodes 344 void bind( bool bForceRebind = false ); 345 346 /// the binding value has been changed: 347 /// trigger a modified event on all modified listeners 348 void valueModified(); 349 350 /// the binding itself has changed: 351 /// force rebind, then call valueModified() 352 void bindingModified(); 353 354 355 /// register the event listeners for 356 void registerListeners(); 357 358 /// set MIPs defined by this binding on MIP item 359 MIP getLocalMIP() const; 360 361 /// get the data type that applies to this binding 362 XDataType_t getDataType(); 363 364 /// determine whether binding is valid according to the given data type 365 bool isValid_DataType(); 366 367 /// explain validity of binding with respect to the given data type 368 rtl::OUString explainInvalid_DataType(); 369 370 /// 'clear' this binding - remove all listeners, etc. 371 void clear(); 372 373 /// distribute MIPs from current node recursively to childs 374 void distributeMIP( const XNode_t &rxNode ); 375 376 /// implement get*Namespaces() 377 XNameContainer_t _getNamespaces() const; 378 379 /// implement set*Namespaces() 380 void _setNamespaces( const XNameContainer_t&, bool bBinding ); 381 382 /// set a useful default binding ID (if none is set) 383 void _checkBindingID(); 384 385 public: 386 /// for debugging purposes only: get the MIPs defined by this binding 387 const MIP* _getMIP(); 388 389 390 391 392 393 // 394 // XValueBinding: 395 // 396 397 public: 398 399 virtual Sequence_Type_t SAL_CALL getSupportedValueTypes() 400 throw( RuntimeException_t ); 401 402 virtual sal_Bool SAL_CALL supportsType( const Type_t& aType ) 403 throw( RuntimeException_t ); 404 405 virtual Any_t SAL_CALL getValue( const Type_t& aType ) 406 throw( IncompatibleTypesException_t, 407 RuntimeException_t ); 408 409 virtual void SAL_CALL setValue( const Any_t& aValue ) 410 throw( IncompatibleTypesException_t, 411 InvalidBindingStateException_t, 412 NoSupportException_t, 413 RuntimeException_t ); 414 415 416 417 // 418 // XListEntry Source 419 // 420 421 virtual sal_Int32 SAL_CALL getListEntryCount() 422 throw( RuntimeException_t ); 423 424 virtual rtl::OUString SAL_CALL getListEntry( sal_Int32 nPosition ) 425 throw( IndexOutOfBoundsException_t, 426 RuntimeException_t ); 427 428 virtual StringSequence_t SAL_CALL getAllListEntries() 429 throw( RuntimeException_t ); 430 431 virtual void SAL_CALL addListEntryListener( const XListEntryListener_t& ) 432 throw( NullPointerException_t, 433 RuntimeException_t ); 434 435 virtual void SAL_CALL removeListEntryListener( const XListEntryListener_t&) 436 throw( NullPointerException_t, 437 RuntimeException_t ); 438 439 440 441 // 442 // XValidator: 443 // 444 445 virtual sal_Bool SAL_CALL isValid( 446 const Any_t& ) 447 throw( RuntimeException_t ); 448 449 virtual rtl::OUString SAL_CALL explainInvalid( 450 const Any_t& ) 451 throw( RuntimeException_t ); 452 453 virtual void SAL_CALL addValidityConstraintListener( 454 const XValidityConstraintListener_t& xListener ) 455 throw( NullPointerException_t, 456 RuntimeException_t ); 457 458 virtual void SAL_CALL removeValidityConstraintListener( 459 const XValidityConstraintListener_t& xListener ) 460 throw( NullPointerException_t, 461 RuntimeException_t ); 462 463 464 // 465 // XModifyBroadcaster & friends: 466 // inform listeners about changes in our values 467 // 468 469 public: 470 471 virtual void SAL_CALL addModifyListener( 472 const XModifyListener_t& xListener ) 473 throw( RuntimeException_t ); 474 475 virtual void SAL_CALL removeModifyListener( 476 const XModifyListener_t& xListener ) 477 throw( RuntimeException_t ); 478 479 480 481 482 // 483 // XNamed: 484 // get/set name 485 // 486 487 public: 488 489 virtual rtl::OUString SAL_CALL getName() 490 throw( RuntimeException_t ); 491 492 virtual void SAL_CALL setName( const rtl::OUString& ) 493 throw( RuntimeException_t ); 494 495 496 497 // 498 // xml::dom::event::XEventListener 499 // receive an event if our node changed 500 // 501 502 virtual void SAL_CALL handleEvent( 503 const XEvent_t& xEvent ) 504 throw( RuntimeException_t ); 505 506 507 508 // 509 // XUnoTunnel 510 // 511 512 virtual sal_Int64 SAL_CALL getSomething( const IntSequence_t& ) 513 throw( RuntimeException_t ); 514 515 516 // 517 // XCloneable 518 // 519 520 virtual XCloneable_t SAL_CALL createClone() 521 throw( RuntimeException_t ); 522 }; 523 524 525 } // namespace xforms 526 527 #endif 528