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 "mip.hxx" 40 #include <map> 41 42 43 // forward declaractions 44 namespace com { namespace sun { namespace star 45 { 46 namespace xml { namespace dom { class XDocument; } } 47 namespace xml { namespace dom { class XNode; } } 48 namespace uno { template<typename T> class Sequence; } 49 namespace lang { class IndexOutOfBoundsException; } 50 namespace lang { class IllegalArgumentException; } 51 namespace beans { class XPropertySet; } 52 namespace container { class XSet; } 53 namespace container { class XNameContainer; } 54 namespace frame { class XModel; } 55 } } } 56 namespace rtl { class OUString; } 57 namespace xforms 58 { 59 class Binding; 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 integral 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 222 virtual void SAL_CALL setID( const rtl::OUString& sID ); 223 224 virtual void SAL_CALL initialize(); 225 226 virtual void SAL_CALL rebuild(); 227 228 virtual void SAL_CALL recalculate(); 229 230 virtual void SAL_CALL revalidate(); 231 232 virtual void SAL_CALL refresh(); 233 234 virtual void SAL_CALL submit( const rtl::OUString& sID ); 235 236 virtual void SAL_CALL submitWithInteraction( const ::rtl::OUString& id, const XInteractionHandler_t& _rxHandler ); 237 238 virtual XDataTypeRepository_t SAL_CALL getDataTypeRepository( ); 239 240 241 // XModel: instance management 242 243 virtual XSet_t SAL_CALL getInstances(); 244 245 virtual XDocument_t SAL_CALL getInstanceDocument( const rtl::OUString& ); 246 247 virtual XDocument_t SAL_CALL getDefaultInstance(); 248 249 250 251 // XModel: binding management 252 253 virtual XPropertySet_t SAL_CALL createBinding(); 254 255 virtual XPropertySet_t SAL_CALL cloneBinding( const XPropertySet_t& ); 256 257 virtual XPropertySet_t SAL_CALL getBinding( const rtl::OUString& ); 258 259 virtual XSet_t SAL_CALL getBindings(); 260 261 262 // XModel: submission management 263 264 virtual XSubmission_t SAL_CALL createSubmission(); 265 266 virtual XSubmission_t SAL_CALL cloneSubmission( const XPropertySet_t& ); 267 268 virtual XSubmission_t SAL_CALL getSubmission( const rtl::OUString& ); 269 270 virtual XSet_t SAL_CALL getSubmissions(); 271 272 273 274 // 275 // XFormsUIHelper1 & friends: 276 // (implementation in model_ui.cxx) 277 // 278 279 /// determine a reasonable control service for a given node 280 /// (based on data type MIP assigned to the node) 281 virtual rtl::OUString SAL_CALL getDefaultServiceNameForNode( const XNode_t& xNode ); 282 283 /// call getDefaultBindingExpressionForNode with default evaluation context 284 virtual rtl::OUString SAL_CALL getDefaultBindingExpressionForNode( const XNode_t& xNode ); 285 286 /// determine a reasonable default binding expression for a given node 287 /// and a given evaluation context 288 /// @returns expression, or empty string if no expression could be derived 289 rtl::OUString getDefaultBindingExpressionForNode( 290 const XNode_t&, 291 const EvaluationContext& ); 292 293 virtual rtl::OUString SAL_CALL getNodeDisplayName( const XNode_t&, 294 sal_Bool bDetail ); 295 296 virtual rtl::OUString SAL_CALL getNodeName( const XNode_t& ); 297 298 virtual rtl::OUString SAL_CALL getBindingName( const XPropertySet_t&, 299 sal_Bool bDetail ); 300 301 virtual rtl::OUString SAL_CALL getSubmissionName( const XPropertySet_t&, 302 sal_Bool bDetail ); 303 304 virtual XPropertySet_t SAL_CALL cloneBindingAsGhost( const XPropertySet_t& ); 305 306 virtual void SAL_CALL removeBindingIfUseless( const XPropertySet_t& ); 307 308 virtual XDocument_t SAL_CALL newInstance( const rtl::OUString& sName, 309 const rtl::OUString& sURL, 310 sal_Bool bURLOnce ); 311 312 virtual void SAL_CALL renameInstance( const rtl::OUString& sFrom, 313 const rtl::OUString& sTo, 314 const rtl::OUString& sURL, 315 sal_Bool bURLOnce ); 316 317 virtual void SAL_CALL removeInstance( const rtl::OUString& sName ); 318 319 320 virtual XModel_t SAL_CALL newModel( const Frame_XModel_t& xComponent, 321 const rtl::OUString& sName ); 322 virtual void SAL_CALL renameModel( const Frame_XModel_t& xComponent, 323 const rtl::OUString& sFrom, 324 const rtl::OUString& sTo ); 325 326 virtual void SAL_CALL removeModel( const Frame_XModel_t& xComponent, 327 const rtl::OUString& sName ); 328 329 330 virtual XNode_t SAL_CALL createElement( const XNode_t& xParent, 331 const rtl::OUString& sName ); 332 333 virtual XNode_t SAL_CALL createAttribute( const XNode_t& xParent, 334 const rtl::OUString& sName ); 335 336 virtual XNode_t SAL_CALL renameNode( const XNode_t& xNode, 337 const rtl::OUString& sName ); 338 339 virtual XPropertySet_t SAL_CALL getBindingForNode( const XNode_t&, 340 sal_Bool bCreate ); 341 342 virtual void SAL_CALL removeBindingForNode( const XNode_t& ); 343 344 virtual rtl::OUString SAL_CALL getResultForExpression( 345 const XPropertySet_t& xBinding, 346 sal_Bool bIsBindingExpression, 347 const rtl::OUString& sExpression ); 348 349 virtual sal_Bool SAL_CALL isValidXMLName( const rtl::OUString& sName ); 350 351 virtual sal_Bool SAL_CALL isValidPrefixName( const rtl::OUString& sName ); 352 353 virtual void SAL_CALL setNodeValue( 354 const XNode_t& xNode, 355 const rtl::OUString& sValue ); 356 357 358 // 359 // XUpdatable 360 // 361 362 public: 363 virtual void SAL_CALL update(); 364 365 // 366 // XUnoTunnel 367 // 368 369 public: 370 virtual sal_Int64 SAL_CALL getSomething( const IntSequence_t& ); 371 372 // 373 // XTypeProvider::getImplementationId 374 // 375 376 public: 377 virtual IntSequence_t SAL_CALL getImplementationId(); 378 379 }; 380 381 // finally, allow 'shifting' of Model objects into/out of Any 382 void operator <<= ( com::sun::star::uno::Any&, const xforms::Model* ); 383 bool operator >>= ( xforms::Model*, const com::sun::star::uno::Any& ); 384 385 } // namespace 386 #endif 387