1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_FORMS_SOURCE_XFORMS_MODEL_HXX
21 #define INCLUDED_FORMS_SOURCE_XFORMS_MODEL_HXX
23 #include <cppuhelper/implbase.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/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <com/sun/star/uno/Reference.hxx>
36 // forward declaractions
37 namespace com
{ namespace sun
{ namespace star
39 namespace xml
{ namespace dom
{ class XDocument
; } }
40 namespace xml
{ namespace dom
{ class XNode
; } }
41 namespace uno
{ template<typename T
> class Sequence
; }
42 namespace lang
{ class IndexOutOfBoundsException
; }
43 namespace lang
{ class IllegalArgumentException
; }
44 namespace beans
{ class XPropertySet
; }
45 namespace container
{ class XSet
; }
46 namespace container
{ class XNameContainer
; }
47 namespace frame
{ class XModel
; }
51 class BindingCollection
;
52 class SubmissionCollection
;
53 class InstanceCollection
;
54 class EvaluationContext
;
61 /** An XForms Model. Contains:
62 * # (set of) instance data (XML DOM tree)
64 * # (set of) submissions
65 * # (NOT YET IMPLEMENTED) actions (set of)
67 * See http://www.w3.org/TR/xforms/ for more information.
69 typedef cppu::ImplInheritanceHelper
<
71 com::sun::star::xforms::XModel2
,
72 com::sun::star::xforms::XFormsUIHelper1
,
73 com::sun::star::util::XUpdatable
,
74 com::sun::star::lang::XUnoTunnel
,
75 css::lang::XServiceInfo
77 class Model
: public Model_t
79 // a number of local typedefs, to make the remaining header readable
80 typedef com::sun::star::uno::Reference
<com::sun::star::xml::dom::XDocument
> XDocument_t
;
81 typedef com::sun::star::uno::Reference
<com::sun::star::xml::dom::XNode
> XNode_t
;
82 typedef com::sun::star::lang::IndexOutOfBoundsException IndexOutOfBoundsException_t
;
83 typedef com::sun::star::lang::IllegalArgumentException IllegalArgumentException_t
;
84 typedef com::sun::star::uno::Reference
<com::sun::star::beans::XPropertySet
> XPropertySet_t
;
85 typedef com::sun::star::uno::Reference
<com::sun::star::xforms::XDataTypeRepository
> XDataTypeRepository_t
;
86 typedef com::sun::star::uno::Reference
<com::sun::star::container::XNameContainer
> XNameContainer_t
;
87 typedef com::sun::star::uno::Reference
<com::sun::star::xforms::XSubmission
> XSubmission_t
;
88 typedef com::sun::star::uno::Reference
<com::sun::star::frame::XModel
> Frame_XModel_t
;
89 typedef com::sun::star::uno::Reference
<com::sun::star::xforms::XModel
> XModel_t
;
90 typedef com::sun::star::uno::Reference
<com::sun::star::task::XInteractionHandler
> XInteractionHandler_t
;
92 typedef com::sun::star::uno::Reference
<com::sun::star::container::XSet
> XSet_t
;
93 typedef com::sun::star::beans::PropertyVetoException PropertyVetoException_t
;
94 typedef com::sun::star::beans::UnknownPropertyException UnknownPropertyException_t
;
95 typedef com::sun::star::util::VetoException VetoException_t
;
96 typedef com::sun::star::lang::WrappedTargetException WrappedTargetException_t
;
97 typedef com::sun::star::uno::RuntimeException RuntimeException_t
;
98 typedef com::sun::star::uno::Any Any_t
;
99 typedef com::sun::star::uno::Sequence
<sal_Int8
> IntSequence_t
;
100 typedef std::multimap
<XNode_t
,std::pair
<void*,MIP
> > MIPs_t
;
105 OUString msID
; /// the model ID
106 BindingCollection
* mpBindings
; /// the bindings
107 SubmissionCollection
* mpSubmissions
; /// the submissions
108 InstanceCollection
* mpInstances
; /// the instance(s)
110 XDataTypeRepository_t mxDataTypes
; /// the XSD data-types used
111 XDocument_t mxForeignSchema
; /// the XSD-schema part we cannot
112 /// map onto data types
113 OUString msSchemaRef
; /// xforms:model/@schema attribute
115 XNameContainer_t mxNamespaces
; /// namespaces for entire model
118 // references to mpBindings/mpSubmissions, for UNO reference counting
120 XSet_t mxSubmissions
;
123 MIPs_t maMIPs
; /// map nodes to their MIPs
125 bool mbInitialized
; /// has model been initialized ?
126 bool mbExternalData
; /// is the data of this model to be considered an ingegral part of the document?
128 void initializePropertySet();
130 void ensureAtLeastOneInstance();
135 /// create a new model with an empty, default instance
137 virtual ~Model() throw();
139 // get Model implementation from API object
140 static Model
* getModel( const com::sun::star::uno::Reference
<com::sun::star::xforms::XModel
>& );
142 xforms::EvaluationContext
getEvaluationContext();
145 static IntSequence_t
getUnoTunnelID();
148 // get/set that part of the schema, that we can't interpret as data types
149 XDocument_t
getForeignSchema() const { return mxForeignSchema
;}
150 void setForeignSchema( const XDocument_t
& );
152 // get/set the xforms:model/@schema attribute
153 OUString
getSchemaRef() const { return msSchemaRef
;}
154 void setSchemaRef( const OUString
& );
156 // get/set namespaces for entire model
157 XNameContainer_t
getNamespaces() const { return mxNamespaces
;}
158 void setNamespaces( const XNameContainer_t
& );
160 // get/set the ExternalData property
161 bool getExternalData() const { return mbExternalData
;}
162 void setExternalData( bool _bData
);
165 #if OSL_DEBUG_LEVEL > 1
166 void dbg_assertInvariant() const;
171 // MIP (model item property) management
174 // register MIPs which apply to a given node; only to be called by bindings
175 // (The pTag parameter serves only to be able to remove the MIPs
176 // that were added using the same tag. No functions will be
177 // performed on it; hence the void* type.)
178 void addMIP( void* pTag
, const XNode_t
&, const MIP
& );
179 void removeMIPs( void* pTag
);
181 /// query which MIPs appy to the given node
182 MIP
queryMIP( const XNode_t
& xNode
) const;
184 /// re-bind all bindings
187 /// call defer notifications on all bindings
188 void deferNotifications( bool );
190 /// set a data value in the instance
191 /// (also defers notifications)
192 bool setSimpleContent( const XNode_t
&, const OUString
& );
194 /// load instance data
195 void loadInstance( sal_Int32 nInstance
);
196 void loadInstances();
198 /// has model been initialized?
199 bool isInitialized() const { return mbInitialized
;}
201 /// is model currently valid (for submission)?
202 bool isValid() const;
208 // implement the xforms::XModel implementation
212 virtual OUString SAL_CALL
getID()
213 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
215 virtual void SAL_CALL
setID( const OUString
& sID
)
216 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
218 virtual void SAL_CALL
initialize()
219 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
221 virtual void SAL_CALL
rebuild()
222 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
224 virtual void SAL_CALL
recalculate()
225 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
227 virtual void SAL_CALL
revalidate()
228 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
230 virtual void SAL_CALL
refresh()
231 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
233 virtual void SAL_CALL
submit( const OUString
& sID
)
234 throw( VetoException_t
, WrappedTargetException_t
, RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
236 virtual void SAL_CALL
submitWithInteraction( const OUString
& id
, const XInteractionHandler_t
& _rxHandler
)
237 throw( VetoException_t
, WrappedTargetException_t
, RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
239 virtual XDataTypeRepository_t SAL_CALL
getDataTypeRepository( )
240 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
243 // XModel: instance management
245 virtual XSet_t SAL_CALL
getInstances()
246 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
248 virtual XDocument_t SAL_CALL
getInstanceDocument( const OUString
& )
249 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
251 virtual XDocument_t SAL_CALL
getDefaultInstance()
252 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
256 // XModel: binding management
258 virtual XPropertySet_t SAL_CALL
createBinding()
259 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
261 virtual XPropertySet_t SAL_CALL
cloneBinding( const XPropertySet_t
& )
262 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
264 virtual XPropertySet_t SAL_CALL
getBinding( const OUString
& )
265 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
267 virtual XSet_t SAL_CALL
getBindings()
268 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
271 // XModel: submission management
273 virtual XSubmission_t SAL_CALL
createSubmission()
274 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
276 virtual XSubmission_t SAL_CALL
cloneSubmission( const XPropertySet_t
& )
277 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
279 virtual XSubmission_t SAL_CALL
getSubmission( const OUString
& )
280 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
282 virtual XSet_t SAL_CALL
getSubmissions()
283 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
287 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& p
)
288 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
289 { return PropertySetBase::getPropertyValue(p
); }
291 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& p2
)
292 throw (css::beans::UnknownPropertyException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
293 { PropertySetBase::addPropertyChangeListener(p1
, p2
); }
295 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& p2
)
296 throw (css::beans::UnknownPropertyException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
297 { PropertySetBase::removePropertyChangeListener(p1
, p2
); }
299 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& p2
)
300 throw (css::beans::UnknownPropertyException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
301 { PropertySetBase::addVetoableChangeListener(p1
, p2
); }
303 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& p2
)
304 throw( css::beans::UnknownPropertyException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
305 { PropertySetBase::removeVetoableChangeListener(p1
, p2
); }
307 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo()
308 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
309 { return PropertySetBase::getPropertySetInfo(); }
311 virtual void SAL_CALL
setPropertyValue(const OUString
& p1
, const com::sun::star::uno::Any
& p2
)
312 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
313 { PropertySetBase::setPropertyValue(p1
, p2
); }
316 // XFormsUIHelper1 & friends:
317 // (implementation in model_ui.cxx)
320 /// determine a reasonable control service for a given node
321 /// (based on data type MIP assigned to the node)
322 virtual OUString SAL_CALL
getDefaultServiceNameForNode( const XNode_t
& xNode
) throw (RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
324 /// call getDefaultBindingExpressionForNode with default evaluation context
325 virtual OUString SAL_CALL
getDefaultBindingExpressionForNode( const XNode_t
& xNode
) throw (RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
327 /// determine a reasonable default binding expression for a given node
328 /// and a given evaluation context
329 /// @returns expression, or empty string if no expression could be derived
330 OUString
getDefaultBindingExpressionForNode(
332 const EvaluationContext
& );
334 virtual OUString SAL_CALL
getNodeDisplayName( const XNode_t
&,
336 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
338 virtual OUString SAL_CALL
getNodeName( const XNode_t
& )
339 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
341 virtual OUString SAL_CALL
getBindingName( const XPropertySet_t
&,
343 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
345 virtual OUString SAL_CALL
getSubmissionName( const XPropertySet_t
&,
347 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
349 virtual XPropertySet_t SAL_CALL
cloneBindingAsGhost( const XPropertySet_t
& )
350 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
352 virtual void SAL_CALL
removeBindingIfUseless( const XPropertySet_t
& )
353 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
355 virtual XDocument_t SAL_CALL
newInstance( const OUString
& sName
,
356 const OUString
& sURL
,
358 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
360 virtual void SAL_CALL
renameInstance( const OUString
& sFrom
,
362 const OUString
& sURL
,
364 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
366 virtual void SAL_CALL
removeInstance( const OUString
& sName
)
367 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
370 virtual XModel_t SAL_CALL
newModel( const Frame_XModel_t
& xComponent
,
371 const OUString
& sName
)
372 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
373 virtual void SAL_CALL
renameModel( const Frame_XModel_t
& xComponent
,
374 const OUString
& sFrom
,
375 const OUString
& sTo
)
376 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
378 virtual void SAL_CALL
removeModel( const Frame_XModel_t
& xComponent
,
379 const OUString
& sName
)
380 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
383 virtual XNode_t SAL_CALL
createElement( const XNode_t
& xParent
,
384 const OUString
& sName
)
385 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
387 virtual XNode_t SAL_CALL
createAttribute( const XNode_t
& xParent
,
388 const OUString
& sName
)
389 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
391 virtual XNode_t SAL_CALL
renameNode( const XNode_t
& xNode
,
392 const OUString
& sName
)
393 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
395 virtual XPropertySet_t SAL_CALL
getBindingForNode( const XNode_t
&,
397 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
399 virtual void SAL_CALL
removeBindingForNode( const XNode_t
& )
400 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
402 virtual OUString SAL_CALL
getResultForExpression(
403 const XPropertySet_t
& xBinding
,
404 sal_Bool bIsBindingExpression
,
405 const OUString
& sExpression
)
406 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
408 virtual sal_Bool SAL_CALL
isValidXMLName( const OUString
& sName
)
409 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
411 virtual sal_Bool SAL_CALL
isValidPrefixName( const OUString
& sName
)
412 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
414 virtual void SAL_CALL
setNodeValue(
415 const XNode_t
& xNode
,
416 const OUString
& sValue
)
417 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
425 virtual void SAL_CALL
update()
426 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
433 virtual sal_Int64 SAL_CALL
getSomething( const IntSequence_t
& )
434 throw( RuntimeException_t
, std::exception
) SAL_OVERRIDE
;
437 // XTypeProvider::getImplementationId
441 virtual IntSequence_t SAL_CALL
getImplementationId()
442 throw( RuntimeException_t
) SAL_OVERRIDE
;
444 OUString SAL_CALL
getImplementationName()
445 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
447 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
)
448 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
450 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames()
451 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
457 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */