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 #ifndef _MODEL_HXX 25 #define _MODEL_HXX 26 27 28 // include for parent class(es) 29 #include <cppuhelper/implbase4.hxx> 30 #include <propertysetbase.hxx> 31 #include <com/sun/star/xforms/XModel.hpp> 32 #include <com/sun/star/xforms/XFormsUIHelper1.hpp> 33 #include <com/sun/star/util/XUpdatable.hpp> 34 #include <com/sun/star/lang/XUnoTunnel.hpp> 35 36 37 // includes for member variables 38 #include <com/sun/star/uno/Reference.hxx> 39 #include <map> 40 41 42 // forward declaractions 43 namespace com { namespace sun { namespace star 44 { 45 namespace xml { namespace dom { class XDocument; } } 46 namespace xml { namespace dom { class XNode; } } 47 namespace uno { template<typename T> class Sequence; } 48 namespace lang { class IndexOutOfBoundsException; } 49 namespace lang { class IllegalArgumentException; } 50 namespace beans { class XPropertySet; } 51 namespace container { class XSet; } 52 namespace container { class XNameContainer; } 53 namespace frame { class XModel; } 54 } } } 55 namespace rtl { class OUString; } 56 namespace xforms 57 { 58 class Binding; 59 class MIP; 60 class BindingCollection; 61 class SubmissionCollection; 62 class InstanceCollection; 63 class EvaluationContext; 64 } 65 66 67 namespace xforms 68 { 69 70 /** An XForms Model. Contains: 71 * # (set of) instance data (XML DOM tree) 72 * # (set of) bindings 73 * # (set of) submissions 74 * # (NOT YET IMPLEMENTED) actions (set of) 75 * 76 * See http://www.w3.org/TR/xforms/ for more information. 77 */ 78 typedef cppu::ImplInheritanceHelper4< 79 PropertySetBase, 80 com::sun::star::xforms::XModel, 81 com::sun::star::xforms::XFormsUIHelper1, 82 com::sun::star::util::XUpdatable, 83 com::sun::star::lang::XUnoTunnel 84 > Model_t; 85 class Model : public Model_t 86 { 87 // a number of local typedefs, to make the remaining header readable 88 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument> XDocument_t; 89 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode> XNode_t; 90 typedef com::sun::star::lang::IndexOutOfBoundsException IndexOutOfBoundsException_t; 91 typedef com::sun::star::lang::IllegalArgumentException IllegalArgumentException_t; 92 typedef com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> XPropertySet_t; 93 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XDataTypeRepository> XDataTypeRepository_t; 94 typedef com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> XNameContainer_t; 95 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XSubmission> XSubmission_t; 96 typedef com::sun::star::uno::Reference<com::sun::star::frame::XModel> Frame_XModel_t; 97 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XModel> XModel_t; 98 typedef com::sun::star::uno::Reference<com::sun::star::task::XInteractionHandler> XInteractionHandler_t; 99 100 typedef com::sun::star::uno::Reference<com::sun::star::container::XSet> XSet_t; 101 typedef com::sun::star::beans::PropertyVetoException PropertyVetoException_t; 102 typedef com::sun::star::beans::UnknownPropertyException UnknownPropertyException_t; 103 typedef com::sun::star::util::VetoException VetoException_t; 104 typedef com::sun::star::lang::WrappedTargetException WrappedTargetException_t; 105 typedef com::sun::star::uno::RuntimeException RuntimeException_t; 106 typedef com::sun::star::uno::Any Any_t; 107 typedef com::sun::star::uno::Sequence<sal_Int8> IntSequence_t; 108 typedef std::multimap<XNode_t,std::pair<void*,MIP> > MIPs_t; 109 110 111 private: 112 113 rtl::OUString msID; /// the model ID 114 BindingCollection* mpBindings; /// the bindings 115 SubmissionCollection* mpSubmissions; /// the submissions 116 InstanceCollection* mpInstances; /// the instance(s) 117 118 XDataTypeRepository_t mxDataTypes; /// the XSD data-types used 119 XDocument_t mxForeignSchema; /// the XSD-schema part we cannot 120 /// map onto data types 121 rtl::OUString msSchemaRef; /// xforms:model/@schema attribute 122 123 XNameContainer_t mxNamespaces; /// namespaces for entire model 124 125 126 // references to mpBindings/mpSubmissions, for UNO reference counting 127 XSet_t mxBindings; 128 XSet_t mxSubmissions; 129 XSet_t mxInstances; 130 131 MIPs_t maMIPs; /// map nodes to their MIPs 132 133 bool mbInitialized; /// has model been initialized ? 134 bool mbExternalData; /// is the data of this model to be considered an ingegral part of the document? 135 136 void initializePropertySet(); 137 138 void ensureAtLeastOneInstance(); 139 140 141 public: 142 143 /// create a new model with an empty, default instance 144 Model(); 145 virtual ~Model() throw(); 146 147 // get Model implementation from API object 148 static Model* getModel( const com::sun::star::uno::Reference<com::sun::star::xforms::XModel>& ); 149 150 xforms::EvaluationContext getEvaluationContext(); 151 152 153 static IntSequence_t getUnoTunnelID(); 154 155 156 // get/set that part of the schema, that we can't interpret as data types 157 XDocument_t getForeignSchema() const; 158 void setForeignSchema( const XDocument_t& ); 159 160 // get/set the xforms:model/@schema attribute 161 rtl::OUString getSchemaRef() const; 162 void setSchemaRef( const rtl::OUString& ); 163 164 // get/set namespaces for entire model 165 XNameContainer_t getNamespaces() const; 166 void setNamespaces( const XNameContainer_t& ); 167 168 // get/set the ExternalData property 169 bool getExternalData() const; 170 void setExternalData( bool _bData ); 171 172 173 #if OSL_DEBUG_LEVEL > 1 174 void dbg_assertInvariant() const; 175 #endif 176 177 178 // 179 // MIP (model item property) management 180 // 181 182 // register MIPs which apply to a given node; only to be called by bindings 183 // (The pTag parameter serves only to be able to remove the MIPs 184 // that were added using the same tag. No functions will be 185 // performed on it; hence the void* type.) 186 void addMIP( void* pTag, const XNode_t&, const MIP& ); 187 void removeMIPs( void* pTag ); 188 189 /// query which MIPs appy to the given node 190 MIP queryMIP( const XNode_t& xNode ) const; 191 192 /// re-bind all bindings 193 void rebind(); 194 195 /// call defer notifications on all bindings 196 void deferNotifications( bool ); 197 198 /// set a data value in the instance 199 /// (also defers notifications) 200 bool setSimpleContent( const XNode_t&, const rtl::OUString& ); 201 202 /// load instance data 203 void loadInstance( sal_Int32 nInstance ); 204 void loadInstances(); 205 206 /// has model been initialized? 207 bool isInitialized() const; 208 209 /// is model currently valid (for submission)? 210 bool isValid() const; 211 212 213 214 // 215 // XModel 216 // implement the xforms::XModel implementation 217 // 218 219 220 virtual rtl::OUString SAL_CALL getID() 221 throw( RuntimeException_t ); 222 223 virtual void SAL_CALL setID( const rtl::OUString& sID ) 224 throw( RuntimeException_t ); 225 226 virtual void SAL_CALL initialize() 227 throw( RuntimeException_t ); 228 229 virtual void SAL_CALL rebuild() 230 throw( RuntimeException_t ); 231 232 virtual void SAL_CALL recalculate() 233 throw( RuntimeException_t ); 234 235 virtual void SAL_CALL revalidate() 236 throw( RuntimeException_t ); 237 238 virtual void SAL_CALL refresh() 239 throw( RuntimeException_t ); 240 241 virtual void SAL_CALL submit( const rtl::OUString& sID ) 242 throw( VetoException_t, WrappedTargetException_t, RuntimeException_t ); 243 244 virtual void SAL_CALL submitWithInteraction( const ::rtl::OUString& id, const XInteractionHandler_t& _rxHandler ) 245 throw( VetoException_t, WrappedTargetException_t, RuntimeException_t ); 246 247 virtual XDataTypeRepository_t SAL_CALL getDataTypeRepository( ) 248 throw( RuntimeException_t ); 249 250 251 // XModel: instance management 252 253 virtual XSet_t SAL_CALL getInstances() 254 throw( RuntimeException_t ); 255 256 virtual XDocument_t SAL_CALL getInstanceDocument( const rtl::OUString& ) 257 throw( RuntimeException_t ); 258 259 virtual XDocument_t SAL_CALL getDefaultInstance() 260 throw( RuntimeException_t ); 261 262 263 264 // XModel: binding management 265 266 virtual XPropertySet_t SAL_CALL createBinding() 267 throw( RuntimeException_t ); 268 269 virtual XPropertySet_t SAL_CALL cloneBinding( const XPropertySet_t& ) 270 throw( RuntimeException_t ); 271 272 virtual XPropertySet_t SAL_CALL getBinding( const rtl::OUString& ) 273 throw( RuntimeException_t ); 274 275 virtual XSet_t SAL_CALL getBindings() 276 throw( RuntimeException_t ); 277 278 279 // XModel: submission management 280 281 virtual XSubmission_t SAL_CALL createSubmission() 282 throw( RuntimeException_t ); 283 284 virtual XSubmission_t SAL_CALL cloneSubmission( const XPropertySet_t& ) 285 throw( RuntimeException_t ); 286 287 virtual XSubmission_t SAL_CALL getSubmission( const rtl::OUString& ) 288 throw( RuntimeException_t ); 289 290 virtual XSet_t SAL_CALL getSubmissions() 291 throw( RuntimeException_t ); 292 293 294 295 // 296 // XFormsUIHelper1 & friends: 297 // (implementation in model_ui.cxx) 298 // 299 300 /// determine a reasonable control service for a given node 301 /// (based on data type MIP assigned to the node) 302 virtual rtl::OUString SAL_CALL getDefaultServiceNameForNode( const XNode_t& xNode ) throw (RuntimeException_t); 303 304 /// call getDefaultBindingExpressionForNode with default evaluation context 305 virtual rtl::OUString SAL_CALL getDefaultBindingExpressionForNode( const XNode_t& xNode ) throw (RuntimeException_t); 306 307 /// determine a reasonable default binding expression for a given node 308 /// and a given evaluation context 309 /// @returns expression, or empty string if no expression could be derived 310 rtl::OUString getDefaultBindingExpressionForNode( 311 const XNode_t&, 312 const EvaluationContext& ); 313 314 virtual rtl::OUString SAL_CALL getNodeDisplayName( const XNode_t&, 315 sal_Bool bDetail ) 316 throw( RuntimeException_t ); 317 318 virtual rtl::OUString SAL_CALL getNodeName( const XNode_t& ) 319 throw( RuntimeException_t ); 320 321 virtual rtl::OUString SAL_CALL getBindingName( const XPropertySet_t&, 322 sal_Bool bDetail ) 323 throw( RuntimeException_t ); 324 325 virtual rtl::OUString SAL_CALL getSubmissionName( const XPropertySet_t&, 326 sal_Bool bDetail ) 327 throw( RuntimeException_t ); 328 329 virtual XPropertySet_t SAL_CALL cloneBindingAsGhost( const XPropertySet_t& ) 330 throw( RuntimeException_t ); 331 332 virtual void SAL_CALL removeBindingIfUseless( const XPropertySet_t& ) 333 throw( RuntimeException_t ); 334 335 virtual XDocument_t SAL_CALL newInstance( const rtl::OUString& sName, 336 const rtl::OUString& sURL, 337 sal_Bool bURLOnce ) 338 throw( RuntimeException_t ); 339 340 virtual void SAL_CALL renameInstance( const rtl::OUString& sFrom, 341 const rtl::OUString& sTo, 342 const rtl::OUString& sURL, 343 sal_Bool bURLOnce ) 344 throw( RuntimeException_t ); 345 346 virtual void SAL_CALL removeInstance( const rtl::OUString& sName ) 347 throw( RuntimeException_t ); 348 349 350 virtual XModel_t SAL_CALL newModel( const Frame_XModel_t& xComponent, 351 const rtl::OUString& sName ) 352 throw( RuntimeException_t ); 353 virtual void SAL_CALL renameModel( const Frame_XModel_t& xComponent, 354 const rtl::OUString& sFrom, 355 const rtl::OUString& sTo ) 356 throw( RuntimeException_t ); 357 358 virtual void SAL_CALL removeModel( const Frame_XModel_t& xComponent, 359 const rtl::OUString& sName ) 360 throw( RuntimeException_t ); 361 362 363 virtual XNode_t SAL_CALL createElement( const XNode_t& xParent, 364 const rtl::OUString& sName ) 365 throw( RuntimeException_t ); 366 367 virtual XNode_t SAL_CALL createAttribute( const XNode_t& xParent, 368 const rtl::OUString& sName ) 369 throw( RuntimeException_t ); 370 371 virtual XNode_t SAL_CALL renameNode( const XNode_t& xNode, 372 const rtl::OUString& sName ) 373 throw( RuntimeException_t ); 374 375 virtual XPropertySet_t SAL_CALL getBindingForNode( const XNode_t&, 376 sal_Bool bCreate ) 377 throw( RuntimeException_t ); 378 379 virtual void SAL_CALL removeBindingForNode( const XNode_t& ) 380 throw( RuntimeException_t ); 381 382 virtual rtl::OUString SAL_CALL getResultForExpression( 383 const XPropertySet_t& xBinding, 384 sal_Bool bIsBindingExpression, 385 const rtl::OUString& sExpression ) 386 throw( RuntimeException_t ); 387 388 virtual sal_Bool SAL_CALL isValidXMLName( const rtl::OUString& sName ) 389 throw( RuntimeException_t ); 390 391 virtual sal_Bool SAL_CALL isValidPrefixName( const rtl::OUString& sName ) 392 throw( RuntimeException_t ); 393 394 virtual void SAL_CALL setNodeValue( 395 const XNode_t& xNode, 396 const rtl::OUString& sValue ) 397 throw( RuntimeException_t ); 398 399 400 // 401 // XUpdatable 402 // 403 404 public: 405 virtual void SAL_CALL update() 406 throw( RuntimeException_t ); 407 408 // 409 // XUnoTunnel 410 // 411 412 public: 413 virtual sal_Int64 SAL_CALL getSomething( const IntSequence_t& ) 414 throw( RuntimeException_t ); 415 416 // 417 // XTypeProvider::getImplementationId 418 // 419 420 public: 421 virtual IntSequence_t SAL_CALL getImplementationId() 422 throw( RuntimeException_t ); 423 424 }; 425 426 // finally, allow 'shifting' of Model objects into/out of Any 427 void operator <<= ( com::sun::star::uno::Any&, const xforms::Model* ); 428 bool operator >>= ( xforms::Model*, const com::sun::star::uno::Any& ); 429 430 } // namespace 431 #endif 432