1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: model.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
35 // include for parent class(es)
36 #include <cppuhelper/implbase4.hxx>
37 #include <propertysetbase.hxx>
38 #include <com/sun/star/xforms/XModel.hpp>
39 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
40 #include <com/sun/star/util/XUpdatable.hpp>
41 #include <com/sun/star/lang/XUnoTunnel.hpp>
44 // includes for member variables
45 #include <com/sun/star/uno/Reference.hxx>
49 // forward declaractions
50 namespace com
{ namespace sun
{ namespace star
52 namespace xml
{ namespace dom
{ class XDocument
; } }
53 namespace xml
{ namespace dom
{ class XNode
; } }
54 namespace uno
{ template<typename T
> class Sequence
; }
55 namespace lang
{ class IndexOutOfBoundsException
; }
56 namespace lang
{ class IllegalArgumentException
; }
57 namespace beans
{ class XPropertySet
; }
58 namespace container
{ class XSet
; }
59 namespace container
{ class XNameContainer
; }
60 namespace frame
{ class XModel
; }
62 namespace rtl
{ class OUString
; }
67 class BindingCollection
;
68 class SubmissionCollection
;
69 class InstanceCollection
;
70 class EvaluationContext
;
77 /** An XForms Model. Contains:
78 * # (set of) instance data (XML DOM tree)
80 * # (set of) submissions
81 * # (NOT YET IMPLEMENTED) actions (set of)
83 * See http://www.w3.org/TR/xforms/ for more information.
85 typedef cppu::ImplInheritanceHelper4
<
87 com::sun::star::xforms::XModel
,
88 com::sun::star::xforms::XFormsUIHelper1
,
89 com::sun::star::util::XUpdatable
,
90 com::sun::star::lang::XUnoTunnel
92 class Model
: public Model_t
94 // a number of local typedefs, to make the remaining header readable
95 typedef com::sun::star::uno::Reference
<com::sun::star::xml::dom::XDocument
> XDocument_t
;
96 typedef com::sun::star::uno::Reference
<com::sun::star::xml::dom::XNode
> XNode_t
;
97 typedef com::sun::star::lang::IndexOutOfBoundsException IndexOutOfBoundsException_t
;
98 typedef com::sun::star::lang::IllegalArgumentException IllegalArgumentException_t
;
99 typedef com::sun::star::uno::Reference
<com::sun::star::beans::XPropertySet
> XPropertySet_t
;
100 typedef com::sun::star::uno::Reference
<com::sun::star::xforms::XDataTypeRepository
> XDataTypeRepository_t
;
101 typedef com::sun::star::uno::Reference
<com::sun::star::container::XNameContainer
> XNameContainer_t
;
102 typedef com::sun::star::uno::Reference
<com::sun::star::xforms::XSubmission
> XSubmission_t
;
103 typedef com::sun::star::uno::Reference
<com::sun::star::frame::XModel
> Frame_XModel_t
;
104 typedef com::sun::star::uno::Reference
<com::sun::star::xforms::XModel
> XModel_t
;
105 typedef com::sun::star::uno::Reference
<com::sun::star::task::XInteractionHandler
> XInteractionHandler_t
;
107 typedef com::sun::star::uno::Reference
<com::sun::star::container::XSet
> XSet_t
;
108 typedef com::sun::star::beans::PropertyVetoException PropertyVetoException_t
;
109 typedef com::sun::star::beans::UnknownPropertyException UnknownPropertyException_t
;
110 typedef com::sun::star::util::VetoException VetoException_t
;
111 typedef com::sun::star::lang::WrappedTargetException WrappedTargetException_t
;
112 typedef com::sun::star::uno::RuntimeException RuntimeException_t
;
113 typedef com::sun::star::uno::Any Any_t
;
114 typedef com::sun::star::uno::Sequence
<sal_Int8
> IntSequence_t
;
115 typedef std::multimap
<XNode_t
,std::pair
<void*,MIP
> > MIPs_t
;
120 rtl::OUString msID
; /// the model ID
121 BindingCollection
* mpBindings
; /// the bindings
122 SubmissionCollection
* mpSubmissions
; /// the submissions
123 InstanceCollection
* mpInstances
; /// the instance(s)
125 XDataTypeRepository_t mxDataTypes
; /// the XSD data-types used
126 XDocument_t mxForeignSchema
; /// the XSD-schema part we cannot
127 /// map onto data types
128 rtl::OUString msSchemaRef
; /// xforms:model/@schema attribute
130 XNameContainer_t mxNamespaces
; /// namespaces for entire model
133 // references to mpBindings/mpSubmissions, for UNO reference counting
135 XSet_t mxSubmissions
;
138 MIPs_t maMIPs
; /// map nodes to their MIPs
140 bool mbInitialized
; /// has model been initialized ?
141 bool mbExternalData
; /// is the data of this model to be considered an ingegral part of the document?
143 void initializePropertySet();
145 void ensureAtLeastOneInstance();
150 /// create a new model with an empty, default instance
152 virtual ~Model() throw();
154 // get Model implementation from API object
155 static Model
* getModel( const com::sun::star::uno::Reference
<com::sun::star::xforms::XModel
>& );
157 xforms::EvaluationContext
getEvaluationContext();
160 static IntSequence_t
getUnoTunnelID();
163 // get/set that part of the schema, that we can't interpret as data types
164 XDocument_t
getForeignSchema() const;
165 void setForeignSchema( const XDocument_t
& );
167 // get/set the xforms:model/@schema attribute
168 rtl::OUString
getSchemaRef() const;
169 void setSchemaRef( const rtl::OUString
& );
171 // get/set namespaces for entire model
172 XNameContainer_t
getNamespaces() const;
173 void setNamespaces( const XNameContainer_t
& );
175 // get/set the ExternalData property
176 bool getExternalData() const;
177 void setExternalData( bool _bData
);
180 #if OSL_DEBUG_LEVEL > 1
181 void dbg_assertInvariant() const;
186 // MIP (model item property) management
189 // register MIPs which apply to a given node; only to be called by bindings
190 // (The pTag parameter serves only to be able to remove the MIPs
191 // that were added using the same tag. No functions will be
192 // performed on it; hence the void* type.)
193 void addMIP( void* pTag
, const XNode_t
&, const MIP
& );
194 void removeMIPs( void* pTag
);
196 /// query which MIPs appy to the given node
197 MIP
queryMIP( const XNode_t
& xNode
) const;
199 /// re-bind all bindings
202 /// call defer notifications on all bindings
203 void deferNotifications( bool );
205 /// set a data value in the instance
206 /// (also defers notifications)
207 bool setSimpleContent( const XNode_t
&, const rtl::OUString
& );
209 /// load instance data
210 void loadInstance( sal_Int32 nInstance
);
211 void loadInstances();
213 /// has model been initialized?
214 bool isInitialized() const;
216 /// is model currently valid (for submission)?
217 bool isValid() const;
223 // implement the xforms::XModel implementation
227 virtual rtl::OUString SAL_CALL
getID()
228 throw( RuntimeException_t
);
230 virtual void SAL_CALL
setID( const rtl::OUString
& sID
)
231 throw( RuntimeException_t
);
233 virtual void SAL_CALL
initialize()
234 throw( RuntimeException_t
);
236 virtual void SAL_CALL
rebuild()
237 throw( RuntimeException_t
);
239 virtual void SAL_CALL
recalculate()
240 throw( RuntimeException_t
);
242 virtual void SAL_CALL
revalidate()
243 throw( RuntimeException_t
);
245 virtual void SAL_CALL
refresh()
246 throw( RuntimeException_t
);
248 virtual void SAL_CALL
submit( const rtl::OUString
& sID
)
249 throw( VetoException_t
, WrappedTargetException_t
, RuntimeException_t
);
251 virtual void SAL_CALL
submitWithInteraction( const ::rtl::OUString
& id
, const XInteractionHandler_t
& _rxHandler
)
252 throw( VetoException_t
, WrappedTargetException_t
, RuntimeException_t
);
254 virtual XDataTypeRepository_t SAL_CALL
getDataTypeRepository( )
255 throw( RuntimeException_t
);
258 // XModel: instance management
260 virtual XSet_t SAL_CALL
getInstances()
261 throw( RuntimeException_t
);
263 virtual XDocument_t SAL_CALL
getInstanceDocument( const rtl::OUString
& )
264 throw( RuntimeException_t
);
266 virtual XDocument_t SAL_CALL
getDefaultInstance()
267 throw( RuntimeException_t
);
271 // XModel: binding management
273 virtual XPropertySet_t SAL_CALL
createBinding()
274 throw( RuntimeException_t
);
276 virtual XPropertySet_t SAL_CALL
cloneBinding( const XPropertySet_t
& )
277 throw( RuntimeException_t
);
279 virtual XPropertySet_t SAL_CALL
getBinding( const rtl::OUString
& )
280 throw( RuntimeException_t
);
282 virtual XSet_t SAL_CALL
getBindings()
283 throw( RuntimeException_t
);
286 // XModel: submission management
288 virtual XSubmission_t SAL_CALL
createSubmission()
289 throw( RuntimeException_t
);
291 virtual XSubmission_t SAL_CALL
cloneSubmission( const XPropertySet_t
& )
292 throw( RuntimeException_t
);
294 virtual XSubmission_t SAL_CALL
getSubmission( const rtl::OUString
& )
295 throw( RuntimeException_t
);
297 virtual XSet_t SAL_CALL
getSubmissions()
298 throw( RuntimeException_t
);
303 // XFormsUIHelper1 & friends:
304 // (implementation in model_ui.cxx)
307 /// determine a reasonable control service for a given node
308 /// (based on data type MIP assigned to the node)
309 virtual rtl::OUString SAL_CALL
getDefaultServiceNameForNode( const XNode_t
& xNode
) throw (RuntimeException_t
);
311 /// call getDefaultBindingExpressionForNode with default evaluation context
312 virtual rtl::OUString SAL_CALL
getDefaultBindingExpressionForNode( const XNode_t
& xNode
) throw (RuntimeException_t
);
314 /// determine a reasonable default binding expression for a given node
315 /// and a given evaluation context
316 /// @returns expression, or empty string if no expression could be derived
317 rtl::OUString
getDefaultBindingExpressionForNode(
319 const EvaluationContext
& );
321 virtual rtl::OUString SAL_CALL
getNodeDisplayName( const XNode_t
&,
323 throw( RuntimeException_t
);
325 virtual rtl::OUString SAL_CALL
getNodeName( const XNode_t
& )
326 throw( RuntimeException_t
);
328 virtual rtl::OUString SAL_CALL
getBindingName( const XPropertySet_t
&,
330 throw( RuntimeException_t
);
332 virtual rtl::OUString SAL_CALL
getSubmissionName( const XPropertySet_t
&,
334 throw( RuntimeException_t
);
336 virtual XPropertySet_t SAL_CALL
cloneBindingAsGhost( const XPropertySet_t
& )
337 throw( RuntimeException_t
);
339 virtual void SAL_CALL
removeBindingIfUseless( const XPropertySet_t
& )
340 throw( RuntimeException_t
);
342 virtual XDocument_t SAL_CALL
newInstance( const rtl::OUString
& sName
,
343 const rtl::OUString
& sURL
,
345 throw( RuntimeException_t
);
347 virtual void SAL_CALL
renameInstance( const rtl::OUString
& sFrom
,
348 const rtl::OUString
& sTo
,
349 const rtl::OUString
& sURL
,
351 throw( RuntimeException_t
);
353 virtual void SAL_CALL
removeInstance( const rtl::OUString
& sName
)
354 throw( RuntimeException_t
);
357 virtual XModel_t SAL_CALL
newModel( const Frame_XModel_t
& xComponent
,
358 const rtl::OUString
& sName
)
359 throw( RuntimeException_t
);
360 virtual void SAL_CALL
renameModel( const Frame_XModel_t
& xComponent
,
361 const rtl::OUString
& sFrom
,
362 const rtl::OUString
& sTo
)
363 throw( RuntimeException_t
);
365 virtual void SAL_CALL
removeModel( const Frame_XModel_t
& xComponent
,
366 const rtl::OUString
& sName
)
367 throw( RuntimeException_t
);
370 virtual XNode_t SAL_CALL
createElement( const XNode_t
& xParent
,
371 const rtl::OUString
& sName
)
372 throw( RuntimeException_t
);
374 virtual XNode_t SAL_CALL
createAttribute( const XNode_t
& xParent
,
375 const rtl::OUString
& sName
)
376 throw( RuntimeException_t
);
378 virtual XNode_t SAL_CALL
renameNode( const XNode_t
& xNode
,
379 const rtl::OUString
& sName
)
380 throw( RuntimeException_t
);
382 virtual XPropertySet_t SAL_CALL
getBindingForNode( const XNode_t
&,
384 throw( RuntimeException_t
);
386 virtual void SAL_CALL
removeBindingForNode( const XNode_t
& )
387 throw( RuntimeException_t
);
389 virtual rtl::OUString SAL_CALL
getResultForExpression(
390 const XPropertySet_t
& xBinding
,
391 sal_Bool bIsBindingExpression
,
392 const rtl::OUString
& sExpression
)
393 throw( RuntimeException_t
);
395 virtual sal_Bool SAL_CALL
isValidXMLName( const rtl::OUString
& sName
)
396 throw( RuntimeException_t
);
398 virtual sal_Bool SAL_CALL
isValidPrefixName( const rtl::OUString
& sName
)
399 throw( RuntimeException_t
);
401 virtual void SAL_CALL
setNodeValue(
402 const XNode_t
& xNode
,
403 const rtl::OUString
& sValue
)
404 throw( RuntimeException_t
);
412 virtual void SAL_CALL
update()
413 throw( RuntimeException_t
);
420 virtual sal_Int64 SAL_CALL
getSomething( const IntSequence_t
& )
421 throw( RuntimeException_t
);
424 // XTypeProvider::getImplementationId
428 virtual IntSequence_t SAL_CALL
getImplementationId()
429 throw( RuntimeException_t
);
433 // finally, allow 'shifting' of Model objects into/out of Any
434 void operator <<= ( com::sun::star::uno::Any
&, const xforms::Model
* );
435 bool operator >>= ( xforms::Model
*, const com::sun::star::uno::Any
& );