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