bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / xforms / model.hxx
bloba2d83b61f94b11389bb8f8fbfbe7c9ad81c09280
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _MODEL_HXX
21 #define _MODEL_HXX
23 #include <cppuhelper/implbase4.hxx>
24 #include <propertysetbase.hxx>
25 #include <com/sun/star/xforms/XModel2.hpp>
26 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
27 #include <com/sun/star/util/XUpdatable.hpp>
28 #include <com/sun/star/lang/XUnoTunnel.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <map>
34 // forward declaractions
35 namespace com { namespace sun { namespace star
37 namespace xml { namespace dom { class XDocument; } }
38 namespace xml { namespace dom { class XNode; } }
39 namespace uno { template<typename T> class Sequence; }
40 namespace lang { class IndexOutOfBoundsException; }
41 namespace lang { class IllegalArgumentException; }
42 namespace beans { class XPropertySet; }
43 namespace container { class XSet; }
44 namespace container { class XNameContainer; }
45 namespace frame { class XModel; }
46 } } }
47 namespace xforms
49 class MIP;
50 class BindingCollection;
51 class SubmissionCollection;
52 class InstanceCollection;
53 class EvaluationContext;
57 namespace xforms
60 /** An XForms Model. Contains:
61 * # (set of) instance data (XML DOM tree)
62 * # (set of) bindings
63 * # (set of) submissions
64 * # (NOT YET IMPLEMENTED) actions (set of)
66 * See http://www.w3.org/TR/xforms/ for more information.
68 typedef cppu::ImplInheritanceHelper4<
69 PropertySetBase,
70 com::sun::star::xforms::XModel2,
71 com::sun::star::xforms::XFormsUIHelper1,
72 com::sun::star::util::XUpdatable,
73 com::sun::star::lang::XUnoTunnel
74 > Model_t;
75 class Model : public Model_t
77 // a number of local typedefs, to make the remaining header readable
78 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XDocument> XDocument_t;
79 typedef com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode> XNode_t;
80 typedef com::sun::star::lang::IndexOutOfBoundsException IndexOutOfBoundsException_t;
81 typedef com::sun::star::lang::IllegalArgumentException IllegalArgumentException_t;
82 typedef com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> XPropertySet_t;
83 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XDataTypeRepository> XDataTypeRepository_t;
84 typedef com::sun::star::uno::Reference<com::sun::star::container::XNameContainer> XNameContainer_t;
85 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XSubmission> XSubmission_t;
86 typedef com::sun::star::uno::Reference<com::sun::star::frame::XModel> Frame_XModel_t;
87 typedef com::sun::star::uno::Reference<com::sun::star::xforms::XModel> XModel_t;
88 typedef com::sun::star::uno::Reference<com::sun::star::task::XInteractionHandler> XInteractionHandler_t;
90 typedef com::sun::star::uno::Reference<com::sun::star::container::XSet> XSet_t;
91 typedef com::sun::star::beans::PropertyVetoException PropertyVetoException_t;
92 typedef com::sun::star::beans::UnknownPropertyException UnknownPropertyException_t;
93 typedef com::sun::star::util::VetoException VetoException_t;
94 typedef com::sun::star::lang::WrappedTargetException WrappedTargetException_t;
95 typedef com::sun::star::uno::RuntimeException RuntimeException_t;
96 typedef com::sun::star::uno::Any Any_t;
97 typedef com::sun::star::uno::Sequence<sal_Int8> IntSequence_t;
98 typedef std::multimap<XNode_t,std::pair<void*,MIP> > MIPs_t;
101 private:
103 OUString msID; /// the model ID
104 BindingCollection* mpBindings; /// the bindings
105 SubmissionCollection* mpSubmissions; /// the submissions
106 InstanceCollection* mpInstances; /// the instance(s)
108 XDataTypeRepository_t mxDataTypes; /// the XSD data-types used
109 XDocument_t mxForeignSchema; /// the XSD-schema part we cannot
110 /// map onto data types
111 OUString msSchemaRef; /// xforms:model/@schema attribute
113 XNameContainer_t mxNamespaces; /// namespaces for entire model
116 // references to mpBindings/mpSubmissions, for UNO reference counting
117 XSet_t mxBindings;
118 XSet_t mxSubmissions;
119 XSet_t mxInstances;
121 MIPs_t maMIPs; /// map nodes to their MIPs
123 bool mbInitialized; /// has model been initialized ?
124 bool mbExternalData; /// is the data of this model to be considered an ingegral part of the document?
126 void initializePropertySet();
128 void ensureAtLeastOneInstance();
131 public:
133 /// create a new model with an empty, default instance
134 Model();
135 virtual ~Model() throw();
137 // get Model implementation from API object
138 static Model* getModel( const com::sun::star::uno::Reference<com::sun::star::xforms::XModel>& );
140 xforms::EvaluationContext getEvaluationContext();
143 static IntSequence_t getUnoTunnelID();
146 // get/set that part of the schema, that we can't interpret as data types
147 XDocument_t getForeignSchema() const;
148 void setForeignSchema( const XDocument_t& );
150 // get/set the xforms:model/@schema attribute
151 OUString getSchemaRef() const;
152 void setSchemaRef( const OUString& );
154 // get/set namespaces for entire model
155 XNameContainer_t getNamespaces() const;
156 void setNamespaces( const XNameContainer_t& );
158 // get/set the ExternalData property
159 bool getExternalData() const;
160 void setExternalData( bool _bData );
163 #if OSL_DEBUG_LEVEL > 1
164 void dbg_assertInvariant() const;
165 #endif
169 // MIP (model item property) management
172 // register MIPs which apply to a given node; only to be called by bindings
173 // (The pTag parameter serves only to be able to remove the MIPs
174 // that were added using the same tag. No functions will be
175 // performed on it; hence the void* type.)
176 void addMIP( void* pTag, const XNode_t&, const MIP& );
177 void removeMIPs( void* pTag );
179 /// query which MIPs appy to the given node
180 MIP queryMIP( const XNode_t& xNode ) const;
182 /// re-bind all bindings
183 void rebind();
185 /// call defer notifications on all bindings
186 void deferNotifications( bool );
188 /// set a data value in the instance
189 /// (also defers notifications)
190 bool setSimpleContent( const XNode_t&, const OUString& );
192 /// load instance data
193 void loadInstance( sal_Int32 nInstance );
194 void loadInstances();
196 /// has model been initialized?
197 bool isInitialized() const;
199 /// is model currently valid (for submission)?
200 bool isValid() const;
205 // XModel
206 // implement the xforms::XModel implementation
210 virtual OUString SAL_CALL getID()
211 throw( RuntimeException_t );
213 virtual void SAL_CALL setID( const OUString& sID )
214 throw( RuntimeException_t );
216 virtual void SAL_CALL initialize()
217 throw( RuntimeException_t );
219 virtual void SAL_CALL rebuild()
220 throw( RuntimeException_t );
222 virtual void SAL_CALL recalculate()
223 throw( RuntimeException_t );
225 virtual void SAL_CALL revalidate()
226 throw( RuntimeException_t );
228 virtual void SAL_CALL refresh()
229 throw( RuntimeException_t );
231 virtual void SAL_CALL submit( const OUString& sID )
232 throw( VetoException_t, WrappedTargetException_t, RuntimeException_t );
234 virtual void SAL_CALL submitWithInteraction( const OUString& id, const XInteractionHandler_t& _rxHandler )
235 throw( VetoException_t, WrappedTargetException_t, RuntimeException_t );
237 virtual XDataTypeRepository_t SAL_CALL getDataTypeRepository( )
238 throw( RuntimeException_t );
241 // XModel: instance management
243 virtual XSet_t SAL_CALL getInstances()
244 throw( RuntimeException_t );
246 virtual XDocument_t SAL_CALL getInstanceDocument( const OUString& )
247 throw( RuntimeException_t );
249 virtual XDocument_t SAL_CALL getDefaultInstance()
250 throw( RuntimeException_t );
254 // XModel: binding management
256 virtual XPropertySet_t SAL_CALL createBinding()
257 throw( RuntimeException_t );
259 virtual XPropertySet_t SAL_CALL cloneBinding( const XPropertySet_t& )
260 throw( RuntimeException_t );
262 virtual XPropertySet_t SAL_CALL getBinding( const OUString& )
263 throw( RuntimeException_t );
265 virtual XSet_t SAL_CALL getBindings()
266 throw( RuntimeException_t );
269 // XModel: submission management
271 virtual XSubmission_t SAL_CALL createSubmission()
272 throw( RuntimeException_t );
274 virtual XSubmission_t SAL_CALL cloneSubmission( const XPropertySet_t& )
275 throw( RuntimeException_t );
277 virtual XSubmission_t SAL_CALL getSubmission( const OUString& )
278 throw( RuntimeException_t );
280 virtual XSet_t SAL_CALL getSubmissions()
281 throw( RuntimeException_t );
283 // XPropertySet
285 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& p)
286 throw( css::uno::RuntimeException )
287 { return PropertySetBase::getPropertyValue(p); }
289 virtual void SAL_CALL addPropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2)
290 throw( css::uno::RuntimeException )
291 { PropertySetBase::addPropertyChangeListener(p1, p2); }
293 virtual void SAL_CALL removePropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2)
294 throw( css::uno::RuntimeException )
295 { PropertySetBase::removePropertyChangeListener(p1, p2); }
297 virtual void SAL_CALL addVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2)
298 throw( css::uno::RuntimeException )
299 { PropertySetBase::addVetoableChangeListener(p1, p2); }
301 virtual void SAL_CALL removeVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2)
302 throw( css::uno::RuntimeException )
303 { PropertySetBase::removeVetoableChangeListener(p1, p2); }
305 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo()
306 throw( css::uno::RuntimeException )
307 { return PropertySetBase::getPropertySetInfo(); }
309 virtual void SAL_CALL setPropertyValue(const OUString& p1, const com::sun::star::uno::Any& p2)
310 throw( css::uno::RuntimeException )
311 { PropertySetBase::setPropertyValue(p1, p2); }
314 // XFormsUIHelper1 & friends:
315 // (implementation in model_ui.cxx)
318 /// determine a reasonable control service for a given node
319 /// (based on data type MIP assigned to the node)
320 virtual OUString SAL_CALL getDefaultServiceNameForNode( const XNode_t& xNode ) throw (RuntimeException_t);
322 /// call getDefaultBindingExpressionForNode with default evaluation context
323 virtual OUString SAL_CALL getDefaultBindingExpressionForNode( const XNode_t& xNode ) throw (RuntimeException_t);
325 /// determine a reasonable default binding expression for a given node
326 /// and a given evaluation context
327 /// @returns expression, or empty string if no expression could be derived
328 OUString getDefaultBindingExpressionForNode(
329 const XNode_t&,
330 const EvaluationContext& );
332 virtual OUString SAL_CALL getNodeDisplayName( const XNode_t&,
333 sal_Bool bDetail )
334 throw( RuntimeException_t );
336 virtual OUString SAL_CALL getNodeName( const XNode_t& )
337 throw( RuntimeException_t );
339 virtual OUString SAL_CALL getBindingName( const XPropertySet_t&,
340 sal_Bool bDetail )
341 throw( RuntimeException_t );
343 virtual OUString SAL_CALL getSubmissionName( const XPropertySet_t&,
344 sal_Bool bDetail )
345 throw( RuntimeException_t );
347 virtual XPropertySet_t SAL_CALL cloneBindingAsGhost( const XPropertySet_t& )
348 throw( RuntimeException_t );
350 virtual void SAL_CALL removeBindingIfUseless( const XPropertySet_t& )
351 throw( RuntimeException_t );
353 virtual XDocument_t SAL_CALL newInstance( const OUString& sName,
354 const OUString& sURL,
355 sal_Bool bURLOnce )
356 throw( RuntimeException_t );
358 virtual void SAL_CALL renameInstance( const OUString& sFrom,
359 const OUString& sTo,
360 const OUString& sURL,
361 sal_Bool bURLOnce )
362 throw( RuntimeException_t );
364 virtual void SAL_CALL removeInstance( const OUString& sName )
365 throw( RuntimeException_t );
368 virtual XModel_t SAL_CALL newModel( const Frame_XModel_t& xComponent,
369 const OUString& sName )
370 throw( RuntimeException_t );
371 virtual void SAL_CALL renameModel( const Frame_XModel_t& xComponent,
372 const OUString& sFrom,
373 const OUString& sTo )
374 throw( RuntimeException_t );
376 virtual void SAL_CALL removeModel( const Frame_XModel_t& xComponent,
377 const OUString& sName )
378 throw( RuntimeException_t );
381 virtual XNode_t SAL_CALL createElement( const XNode_t& xParent,
382 const OUString& sName )
383 throw( RuntimeException_t );
385 virtual XNode_t SAL_CALL createAttribute( const XNode_t& xParent,
386 const OUString& sName )
387 throw( RuntimeException_t );
389 virtual XNode_t SAL_CALL renameNode( const XNode_t& xNode,
390 const OUString& sName )
391 throw( RuntimeException_t );
393 virtual XPropertySet_t SAL_CALL getBindingForNode( const XNode_t&,
394 sal_Bool bCreate )
395 throw( RuntimeException_t );
397 virtual void SAL_CALL removeBindingForNode( const XNode_t& )
398 throw( RuntimeException_t );
400 virtual OUString SAL_CALL getResultForExpression(
401 const XPropertySet_t& xBinding,
402 sal_Bool bIsBindingExpression,
403 const OUString& sExpression )
404 throw( RuntimeException_t );
406 virtual sal_Bool SAL_CALL isValidXMLName( const OUString& sName )
407 throw( RuntimeException_t );
409 virtual sal_Bool SAL_CALL isValidPrefixName( const OUString& sName )
410 throw( RuntimeException_t );
412 virtual void SAL_CALL setNodeValue(
413 const XNode_t& xNode,
414 const OUString& sValue )
415 throw( RuntimeException_t );
419 // XUpdatable
422 public:
423 virtual void SAL_CALL update()
424 throw( RuntimeException_t );
427 // XUnoTunnel
430 public:
431 virtual sal_Int64 SAL_CALL getSomething( const IntSequence_t& )
432 throw( RuntimeException_t );
435 // XTypeProvider::getImplementationId
438 public:
439 virtual IntSequence_t SAL_CALL getImplementationId()
440 throw( RuntimeException_t );
444 } // namespace
445 #endif
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */