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>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <rtl/ref.hxx>
36 // forward declaractions
37 namespace com::sun::star
39 namespace xml::dom
{ class XDocument
; }
40 namespace xml::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
<
72 css::xforms::XFormsUIHelper1
,
73 css::util::XUpdatable
,
74 css::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 css::uno::Reference
<css::xml::dom::XNode
> XNode_t
;
81 typedef css::uno::Reference
<css::beans::XPropertySet
> XPropertySet_t
;
83 typedef std::multimap
<XNode_t
,std::pair
<void*,MIP
> > MIPs_t
;
88 OUString msID
; /// the model ID
89 rtl::Reference
<BindingCollection
> mxBindings
; /// the bindings
90 rtl::Reference
<SubmissionCollection
> mxSubmissions
; /// the submissions
91 rtl::Reference
<InstanceCollection
> mxInstances
; /// the instance(s)
93 css::uno::Reference
<css::xforms::XDataTypeRepository
> mxDataTypes
; /// the XSD data-types used
94 css::uno::Reference
<css::xml::dom::XDocument
> mxForeignSchema
; /// the XSD-schema part we cannot
95 /// map onto data types
96 OUString msSchemaRef
; /// xforms:model/@schema attribute
98 css::uno::Reference
<css::container::XNameContainer
> mxNamespaces
; /// namespaces for entire model
100 MIPs_t maMIPs
; /// map nodes to their MIPs
102 bool mbInitialized
; /// has model been initialized ?
103 bool mbExternalData
; /// is the data of this model to be considered an integral part of the document?
105 void initializePropertySet();
107 void ensureAtLeastOneInstance();
112 /// create a new model with an empty, default instance
114 virtual ~Model() throw() override
;
116 xforms::EvaluationContext
getEvaluationContext();
119 static css::uno::Sequence
<sal_Int8
> getUnoTunnelId();
122 // get/set that part of the schema, that we can't interpret as data types
123 css::uno::Reference
<css::xml::dom::XDocument
> getForeignSchema() const { return mxForeignSchema
;}
124 void setForeignSchema( const css::uno::Reference
<css::xml::dom::XDocument
>& );
126 // get/set the xforms:model/@schema attribute
127 OUString
getSchemaRef() const { return msSchemaRef
;}
128 void setSchemaRef( const OUString
& );
130 // get/set namespaces for entire model
131 css::uno::Reference
<css::container::XNameContainer
> getNamespaces() const { return mxNamespaces
;}
132 void setNamespaces( const css::uno::Reference
<css::container::XNameContainer
>& );
134 // get/set the ExternalData property
135 bool getExternalData() const { return mbExternalData
;}
136 void setExternalData( bool _bData
);
139 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
140 void dbg_assertInvariant() const;
144 // MIP (model item property) management
147 // register MIPs which apply to a given node; only to be called by bindings
148 // (The pTag parameter serves only to be able to remove the MIPs
149 // that were added using the same tag. No functions will be
150 // performed on it; hence the void* type.)
151 void addMIP( void* pTag
, const XNode_t
&, const MIP
& );
152 void removeMIPs( void const * pTag
);
154 /// query which MIPs apply to the given node
155 MIP
queryMIP( const XNode_t
& xNode
) const;
157 /// re-bind all bindings
160 /// call defer notifications on all bindings
161 void deferNotifications( bool );
163 /// set a data value in the instance
164 /// (also defers notifications)
165 bool setSimpleContent( const XNode_t
&, const OUString
& );
167 /// load instance data
168 void loadInstance( sal_Int32 nInstance
);
169 void loadInstances();
171 /// has model been initialized?
172 bool isInitialized() const { return mbInitialized
;}
174 /// is model currently valid (for submission)?
175 bool isValid() const;
179 // implement the xforms::XModel implementation
182 virtual OUString SAL_CALL
getID() override
;
184 virtual void SAL_CALL
setID( const OUString
& sID
) override
;
186 virtual void SAL_CALL
initialize() override
;
188 virtual void SAL_CALL
rebuild() override
;
190 virtual void SAL_CALL
recalculate() override
;
192 virtual void SAL_CALL
revalidate() override
;
194 virtual void SAL_CALL
refresh() override
;
196 virtual void SAL_CALL
submit( const OUString
& sID
) override
;
198 virtual void SAL_CALL
submitWithInteraction( const OUString
& id
, const css::uno::Reference
<css::task::XInteractionHandler
>& _rxHandler
) override
;
200 virtual css::uno::Reference
<css::xforms::XDataTypeRepository
> SAL_CALL
getDataTypeRepository( ) override
;
203 // XModel: instance management
205 virtual css::uno::Reference
<css::container::XSet
> SAL_CALL
getInstances() override
;
207 virtual css::uno::Reference
<css::xml::dom::XDocument
> SAL_CALL
getInstanceDocument( const OUString
& ) override
;
209 virtual css::uno::Reference
<css::xml::dom::XDocument
> SAL_CALL
getDefaultInstance() override
;
212 // XModel: binding management
214 virtual css::uno::Reference
<css::beans::XPropertySet
> SAL_CALL
createBinding() override
;
216 virtual css::uno::Reference
<css::beans::XPropertySet
> SAL_CALL
cloneBinding( const css::uno::Reference
<css::beans::XPropertySet
>& ) override
;
218 virtual css::uno::Reference
<css::beans::XPropertySet
> SAL_CALL
getBinding( const OUString
& ) override
;
220 virtual css::uno::Reference
<css::container::XSet
> SAL_CALL
getBindings() override
;
223 // XModel: submission management
225 virtual css::uno::Reference
<css::xforms::XSubmission
> SAL_CALL
createSubmission() override
;
227 virtual css::uno::Reference
<css::xforms::XSubmission
> SAL_CALL
cloneSubmission( const css::uno::Reference
<css::beans::XPropertySet
>& ) override
;
229 virtual css::uno::Reference
<css::xforms::XSubmission
> SAL_CALL
getSubmission( const OUString
& ) override
;
231 virtual css::uno::Reference
<css::container::XSet
> SAL_CALL
getSubmissions() override
;
235 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& p
) override
236 { return PropertySetBase::getPropertyValue(p
); }
238 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& p2
) override
239 { PropertySetBase::addPropertyChangeListener(p1
, p2
); }
241 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XPropertyChangeListener
>& p2
) override
242 { PropertySetBase::removePropertyChangeListener(p1
, p2
); }
244 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& p2
) override
245 { PropertySetBase::addVetoableChangeListener(p1
, p2
); }
247 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& p1
, const css::uno::Reference
<css::beans::XVetoableChangeListener
>& p2
) override
248 { PropertySetBase::removeVetoableChangeListener(p1
, p2
); }
250 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
251 { return PropertySetBase::getPropertySetInfo(); }
253 virtual void SAL_CALL
setPropertyValue(const OUString
& p1
, const css::uno::Any
& p2
) override
254 { PropertySetBase::setPropertyValue(p1
, p2
); }
257 // XFormsUIHelper1 & friends:
258 // (implementation in model_ui.cxx)
261 /// determine a reasonable control service for a given node
262 /// (based on data type MIP assigned to the node)
263 virtual OUString SAL_CALL
getDefaultServiceNameForNode( const css::uno::Reference
<css::xml::dom::XNode
>& xNode
) override
;
265 /// call getDefaultBindingExpressionForNode with default evaluation context
266 virtual OUString SAL_CALL
getDefaultBindingExpressionForNode( const css::uno::Reference
<css::xml::dom::XNode
>& xNode
) override
;
268 /// determine a reasonable default binding expression for a given node
269 /// and a given evaluation context
270 /// @returns expression, or empty string if no expression could be derived
271 OUString
getDefaultBindingExpressionForNode(
273 const EvaluationContext
& );
275 virtual OUString SAL_CALL
getNodeDisplayName( const css::uno::Reference
<css::xml::dom::XNode
>&,
276 sal_Bool bDetail
) override
;
278 virtual OUString SAL_CALL
getNodeName( const css::uno::Reference
<css::xml::dom::XNode
>& ) override
;
280 virtual OUString SAL_CALL
getBindingName( const css::uno::Reference
< ::css::beans::XPropertySet
>&,
281 sal_Bool bDetail
) override
;
283 virtual OUString SAL_CALL
getSubmissionName( const css::uno::Reference
< ::css::beans::XPropertySet
>&,
284 sal_Bool bDetail
) override
;
286 virtual css::uno::Reference
< ::css::beans::XPropertySet
> SAL_CALL
cloneBindingAsGhost( const css::uno::Reference
< ::css::beans::XPropertySet
>& ) override
;
288 virtual void SAL_CALL
removeBindingIfUseless( const css::uno::Reference
< ::css::beans::XPropertySet
>& ) override
;
290 virtual css::uno::Reference
<css::xml::dom::XDocument
> SAL_CALL
newInstance( const OUString
& sName
,
291 const OUString
& sURL
,
292 sal_Bool bURLOnce
) override
;
294 virtual void SAL_CALL
renameInstance( const OUString
& sFrom
,
296 const OUString
& sURL
,
297 sal_Bool bURLOnce
) override
;
299 virtual void SAL_CALL
removeInstance( const OUString
& sName
) override
;
302 virtual css::uno::Reference
<css::xforms::XModel
> SAL_CALL
newModel( const css::uno::Reference
<css::frame::XModel
>& xComponent
,
303 const OUString
& sName
) override
;
304 virtual void SAL_CALL
renameModel( const css::uno::Reference
<css::frame::XModel
>& xComponent
,
305 const OUString
& sFrom
,
306 const OUString
& sTo
) override
;
308 virtual void SAL_CALL
removeModel( const css::uno::Reference
<css::frame::XModel
>& xComponent
,
309 const OUString
& sName
) override
;
312 virtual css::uno::Reference
< css::xml::dom::XNode
> SAL_CALL
createElement(
313 const css::uno::Reference
< ::css::xml::dom::XNode
>& xParent
,
314 const OUString
& sName
) override
;
316 virtual css::uno::Reference
< css::xml::dom::XNode
> SAL_CALL
createAttribute(
317 const css::uno::Reference
< ::css::xml::dom::XNode
>& xParent
,
318 const OUString
& sName
) override
;
320 virtual css::uno::Reference
< css::xml::dom::XNode
> SAL_CALL
renameNode(
321 const css::uno::Reference
< ::css::xml::dom::XNode
>& xNode
,
322 const OUString
& sName
) override
;
324 virtual css::uno::Reference
< css::beans::XPropertySet
> SAL_CALL
getBindingForNode( const
325 css::uno::Reference
<css::xml::dom::XNode
>&,
326 sal_Bool bCreate
) override
;
328 virtual void SAL_CALL
removeBindingForNode( const css::uno::Reference
< ::css::xml::dom::XNode
>& ) override
;
330 virtual OUString SAL_CALL
getResultForExpression(
331 const css::uno::Reference
< css::beans::XPropertySet
>& xBinding
,
332 sal_Bool bIsBindingExpression
,
333 const OUString
& sExpression
) override
;
335 virtual sal_Bool SAL_CALL
isValidXMLName( const OUString
& sName
) override
;
337 virtual sal_Bool SAL_CALL
isValidPrefixName( const OUString
& sName
) override
;
339 virtual void SAL_CALL
setNodeValue(
340 const css::uno::Reference
< ::css::xml::dom::XNode
>& xNode
,
341 const OUString
& sValue
) override
;
348 virtual void SAL_CALL
update() override
;
355 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
<sal_Int8
>& ) override
;
358 // XTypeProvider::getImplementationId
362 virtual css::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId() override
;
364 OUString SAL_CALL
getImplementationName() override
;
366 sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
;
368 css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */