xref: /AOO41X/main/forms/source/xforms/model.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_forms.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "model.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "model_helper.hxx"
34*cdf0e10cSrcweir #include "unohelper.hxx"
35*cdf0e10cSrcweir #include "binding.hxx"
36*cdf0e10cSrcweir #include "submission.hxx"
37*cdf0e10cSrcweir #include "mip.hxx"
38*cdf0e10cSrcweir #include "evaluationcontext.hxx"
39*cdf0e10cSrcweir #include "xmlhelper.hxx"
40*cdf0e10cSrcweir #include "datatyperepository.hxx"
41*cdf0e10cSrcweir #include "NameContainer.hxx"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <rtl/ustring.hxx>
44*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
45*cdf0e10cSrcweir #include <tools/debug.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <comphelper/propertysetinfo.hxx>
48*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <algorithm>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir // UNO classes
53*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/xml/dom/XDocument.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/xml/dom/XCharacterData.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/xml/dom/NodeType.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
61*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir using com::sun::star::lang::XMultiServiceFactory;
68*cdf0e10cSrcweir using com::sun::star::lang::XUnoTunnel;
69*cdf0e10cSrcweir using com::sun::star::beans::XPropertySet;
70*cdf0e10cSrcweir using com::sun::star::beans::PropertyValue;
71*cdf0e10cSrcweir using rtl::OUString;
72*cdf0e10cSrcweir using rtl::OUStringBuffer;
73*cdf0e10cSrcweir using com::sun::star::beans::PropertyVetoException;
74*cdf0e10cSrcweir using com::sun::star::beans::UnknownPropertyException;
75*cdf0e10cSrcweir using com::sun::star::util::VetoException;
76*cdf0e10cSrcweir using com::sun::star::lang::WrappedTargetException;
77*cdf0e10cSrcweir using com::sun::star::lang::IllegalArgumentException;
78*cdf0e10cSrcweir using com::sun::star::ucb::XSimpleFileAccess;
79*cdf0e10cSrcweir using com::sun::star::io::XInputStream;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir using namespace com::sun::star::uno;
82*cdf0e10cSrcweir using namespace com::sun::star::xml::dom;
83*cdf0e10cSrcweir using namespace xforms;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
87*cdf0e10cSrcweir #define DBG_INVARIANT_TYPE(TYPE) class DBG_##TYPE { const TYPE* mpT; void check() { mpT->dbg_assertInvariant(); } public: DBG_##TYPE(const TYPE* pT) : mpT(pT) { check(); } ~DBG_##TYPE() { check(); } } _DBG_##TYPE(this);
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir #define DBG_INVARIANT() DBG_INVARIANT_TYPE(Model)
90*cdf0e10cSrcweir #else
91*cdf0e10cSrcweir #define DBG_INVARIANT_TYPE(TYPE)
92*cdf0e10cSrcweir #define DBG_INVARIANT()
93*cdf0e10cSrcweir #endif
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir //
98*cdf0e10cSrcweir // The Model
99*cdf0e10cSrcweir //
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir void Model::ensureAtLeastOneInstance()
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     if( ! mpInstances->hasItems() )
104*cdf0e10cSrcweir     {
105*cdf0e10cSrcweir         // create a default instance
106*cdf0e10cSrcweir         newInstance( OUString(), OUString(), true );
107*cdf0e10cSrcweir     }
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir /** Model default constructor; create empty model */
113*cdf0e10cSrcweir Model::Model() :
114*cdf0e10cSrcweir     msID(),
115*cdf0e10cSrcweir     mpBindings( NULL ),
116*cdf0e10cSrcweir     mpSubmissions( NULL ),
117*cdf0e10cSrcweir     mpInstances( new InstanceCollection ),
118*cdf0e10cSrcweir     mxNamespaces( new NameContainer<OUString>() ),
119*cdf0e10cSrcweir     mxBindings( mpBindings ),
120*cdf0e10cSrcweir     mxSubmissions( mpSubmissions ),
121*cdf0e10cSrcweir     mxInstances( mpInstances ),
122*cdf0e10cSrcweir     mbInitialized( false ),
123*cdf0e10cSrcweir     mbExternalData( true )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     initializePropertySet();
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     // initialize bindings collections
128*cdf0e10cSrcweir     // (not in initializer list to avoid use of incomplete 'this')
129*cdf0e10cSrcweir     mpBindings = new BindingCollection( this );
130*cdf0e10cSrcweir     mxBindings = mpBindings;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     mpSubmissions = new SubmissionCollection( this );
133*cdf0e10cSrcweir     mxSubmissions = mpSubmissions;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     // invariant only holds after construction
136*cdf0e10cSrcweir     DBG_INVARIANT();
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir Model::~Model() throw()
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     // give up bindings & submissions; the mxBindings/mxSubmissions
142*cdf0e10cSrcweir     // references will then delete them
143*cdf0e10cSrcweir     mpBindings = NULL;
144*cdf0e10cSrcweir     mpSubmissions = NULL;
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir Model* lcl_getModel( const Reference<XUnoTunnel>& xTunnel )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     Model* pModel = NULL;
150*cdf0e10cSrcweir     if( xTunnel.is() )
151*cdf0e10cSrcweir         pModel = reinterpret_cast<Model*>(
152*cdf0e10cSrcweir             xTunnel->getSomething( Model::getUnoTunnelID() ) );
153*cdf0e10cSrcweir     return pModel;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir Model* Model::getModel( const Reference<XModel>& xModel )
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir     return lcl_getModel( Reference<XUnoTunnel>( xModel, UNO_QUERY ) );
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir EvaluationContext Model::getEvaluationContext()
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     // the default context is the top-level element node. A default
164*cdf0e10cSrcweir     // node (instanceData' is inserted when there is no default node
165*cdf0e10cSrcweir     Reference<XDocument> xInstance = getDefaultInstance();
166*cdf0e10cSrcweir     Reference<XNode> xElement( xInstance->getDocumentElement(), UNO_QUERY );
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     // no element found? Then insert default element 'instanceData'
169*cdf0e10cSrcweir     if( ! xElement.is() )
170*cdf0e10cSrcweir     {
171*cdf0e10cSrcweir         xElement = Reference<XNode>(
172*cdf0e10cSrcweir                        xInstance->createElement( OUSTRING("instanceData") ),
173*cdf0e10cSrcweir                        UNO_QUERY_THROW );
174*cdf0e10cSrcweir         Reference<XNode>( xInstance, UNO_QUERY_THROW)->appendChild( xElement );
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     OSL_ENSURE( xElement.is() &&
178*cdf0e10cSrcweir                 xElement->getNodeType() == NodeType_ELEMENT_NODE,
179*cdf0e10cSrcweir                 "no element in evaluation context" );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     return EvaluationContext( xElement, this, mxNamespaces, 0, 1 );
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir Model::IntSequence_t Model::getUnoTunnelID()
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir     static cppu::OImplementationId aImplementationId;
188*cdf0e10cSrcweir     return aImplementationId.getImplementationId();
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir Model::XDocument_t Model::getForeignSchema() const
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     return mxForeignSchema;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir void Model::setForeignSchema( const XDocument_t& rDocument )
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     mxForeignSchema = rDocument;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir rtl::OUString Model::getSchemaRef() const
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     return msSchemaRef;
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir void Model::setSchemaRef( const rtl::OUString& rSchemaRef )
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir     msSchemaRef = rSchemaRef;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir Model::XNameContainer_t Model::getNamespaces() const
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     return mxNamespaces;
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir void Model::setNamespaces( const XNameContainer_t& rNamespaces )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     if( rNamespaces.is() )
219*cdf0e10cSrcweir         mxNamespaces = rNamespaces;
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir bool Model::getExternalData() const
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir     return mbExternalData;
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir void Model::setExternalData( bool _bData )
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir     mbExternalData = _bData;
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
233*cdf0e10cSrcweir void Model::dbg_assertInvariant() const
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     OSL_ENSURE( mpInstances != NULL, "no instances found" );
236*cdf0e10cSrcweir     OSL_ENSURE( mxInstances.is(), "No instance container!" );
237*cdf0e10cSrcweir     //    OSL_ENSURE( mxInstances->hasElements(), "no instance!" );
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     OSL_ENSURE( mpBindings != NULL, "no bindings element" );
240*cdf0e10cSrcweir     OSL_ENSURE( mxBindings.is(), "No Bindings container" );
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     OSL_ENSURE( mpSubmissions != NULL, "no submissions element" );
243*cdf0e10cSrcweir     OSL_ENSURE( mxSubmissions.is(), "No Submission container" );
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     /*
248*cdf0e10cSrcweir     // check bindings, and things that have to do with our binding
249*cdf0e10cSrcweir     std::vector<MIP*> aAllMIPs; // check MIP map
250*cdf0e10cSrcweir     sal_Int32 nCount = mpBindings->countItems();
251*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < nCount; i++ )
252*cdf0e10cSrcweir     {
253*cdf0e10cSrcweir         Binding* pBind = Binding::getBinding(
254*cdf0e10cSrcweir             mpBindings->Collection<XPropertySet_t>::getItem( i ) );
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         // examine and check binding
257*cdf0e10cSrcweir         OSL_ENSURE( pBind != NULL, "invalid binding found" );
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         OSL_ENSURE( Model::getModel( pBind->getModel() ) == this,
260*cdf0e10cSrcweir                     "our binding doesn't know us.");
261*cdf0e10cSrcweir         // check this binding's MIP against MIP map
262*cdf0e10cSrcweir         MIP* pMIP = const_cast<MIP*>( pBind->_getMIP() );
263*cdf0e10cSrcweir         sal_Int32 nFound = 0;
264*cdf0e10cSrcweir         if( pMIP != NULL )
265*cdf0e10cSrcweir         {
266*cdf0e10cSrcweir             aAllMIPs.push_back( pMIP );
267*cdf0e10cSrcweir             for( MIPs_t::const_iterator aIter = maMIPs.begin();
268*cdf0e10cSrcweir                  aIter != maMIPs.end();
269*cdf0e10cSrcweir                  aIter++ )
270*cdf0e10cSrcweir             {
271*cdf0e10cSrcweir                 if( pMIP == aIter->second )
272*cdf0e10cSrcweir                     nFound++;
273*cdf0e10cSrcweir             }
274*cdf0e10cSrcweir         }
275*cdf0e10cSrcweir         OSL_ENSURE( ( pMIP == NULL ) == ( nFound == 0 ), "MIP-map wrong" );
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     // check MIP map for left-over MIPs
279*cdf0e10cSrcweir     for( MIPs_t::const_iterator aIter = maMIPs.begin();
280*cdf0e10cSrcweir          aIter != maMIPs.end();
281*cdf0e10cSrcweir          aIter++ )
282*cdf0e10cSrcweir     {
283*cdf0e10cSrcweir         MIP* pMIP = aIter->second;
284*cdf0e10cSrcweir         std::vector<MIP*>::iterator aFound =
285*cdf0e10cSrcweir             std::find( aAllMIPs.begin(), aAllMIPs.end(), pMIP );
286*cdf0e10cSrcweir         if( aFound != aAllMIPs.end() )
287*cdf0e10cSrcweir             aAllMIPs.erase( aFound );
288*cdf0e10cSrcweir     }
289*cdf0e10cSrcweir     OSL_ENSURE( aAllMIPs.empty(), "lonely MIPs found!" );
290*cdf0e10cSrcweir     */
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir #endif
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir //
296*cdf0e10cSrcweir // MIP managment
297*cdf0e10cSrcweir //
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir void Model::addMIP( void* pTag, const XNode_t& xNode, const MIP& rMIP )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir     OSL_ENSURE( pTag != NULL, "empty tag?" );
302*cdf0e10cSrcweir     OSL_ENSURE( xNode.is(), "no node" );
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir     MIPs_t::value_type aValue( xNode, ::std::pair<void*,MIP>( pTag, rMIP ) );
305*cdf0e10cSrcweir     maMIPs.insert( aValue );
306*cdf0e10cSrcweir }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir void Model::removeMIPs( void* pTag )
309*cdf0e10cSrcweir {
310*cdf0e10cSrcweir     OSL_ENSURE( pTag != NULL, "empty tag?" );
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     for( MIPs_t::iterator aIter = maMIPs.begin();
313*cdf0e10cSrcweir          aIter != maMIPs.end(); )
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         if( aIter->second.first == pTag )
316*cdf0e10cSrcweir         {
317*cdf0e10cSrcweir             MIPs_t::iterator next( aIter ); ++next;
318*cdf0e10cSrcweir             maMIPs.erase( aIter );
319*cdf0e10cSrcweir             aIter = next;
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir         else
322*cdf0e10cSrcweir             ++aIter;
323*cdf0e10cSrcweir     }
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir MIP Model::queryMIP( const XNode_t& xNode ) const
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     //    OSL_ENSURE( xNode.is(), "no node" );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     // travel up inheritance chain and inherit MIPs
331*cdf0e10cSrcweir     MIP aRet;
332*cdf0e10cSrcweir     for( XNode_t xCurrent = xNode;
333*cdf0e10cSrcweir          xCurrent.is();
334*cdf0e10cSrcweir          xCurrent = xCurrent->getParentNode() )
335*cdf0e10cSrcweir     {
336*cdf0e10cSrcweir         // iterate over all MIPs for this node, and join MIPs
337*cdf0e10cSrcweir         MIP aMIP;
338*cdf0e10cSrcweir         MIPs_t::const_iterator aEnd = maMIPs.upper_bound( xCurrent );
339*cdf0e10cSrcweir         MIPs_t::const_iterator aIter = maMIPs.lower_bound( xCurrent );
340*cdf0e10cSrcweir         for( ; aIter != aEnd; aIter++ )
341*cdf0e10cSrcweir           aMIP.join( aIter->second.second );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir         // inherit from current node (or set if we are at the start node)
344*cdf0e10cSrcweir         if( xCurrent == xNode )
345*cdf0e10cSrcweir             aRet = aMIP;
346*cdf0e10cSrcweir         else
347*cdf0e10cSrcweir             aRet.inherit( aMIP );
348*cdf0e10cSrcweir     }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir     return aRet;
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir void Model::rebind()
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir     OSL_ENSURE( mpBindings != NULL, "bindings?" );
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir     // iterate over all bindings and call update
360*cdf0e10cSrcweir     sal_Int32 nCount = mpBindings->countItems();
361*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < nCount; i++ )
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir         Binding* pBind = Binding::getBinding( mpBindings->Collection<XPropertySet_t>::getItem( i ) );
364*cdf0e10cSrcweir         OSL_ENSURE( pBind != NULL, "binding?" );
365*cdf0e10cSrcweir         pBind->update();
366*cdf0e10cSrcweir     }
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir void Model::deferNotifications( bool bDefer )
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     // iterate over all bindings and defer notifications
374*cdf0e10cSrcweir     sal_Int32 nCount = mpBindings->countItems();
375*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < nCount; i++ )
376*cdf0e10cSrcweir     {
377*cdf0e10cSrcweir         Binding* pBind = Binding::getBinding( mpBindings->Collection<XPropertySet_t>::getItem( i ) );
378*cdf0e10cSrcweir         OSL_ENSURE( pBind != NULL, "binding?" );
379*cdf0e10cSrcweir         pBind->deferNotifications( bDefer );
380*cdf0e10cSrcweir     }
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir bool Model::setSimpleContent( const XNode_t& xConstNode,
385*cdf0e10cSrcweir                               const rtl::OUString& sValue )
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir     OSL_ENSURE( xConstNode.is(), "need node to set data" );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir     bool bRet = false;
390*cdf0e10cSrcweir     if( xConstNode.is() )
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         // non-const node reference so we can assign children (if necessary)
393*cdf0e10cSrcweir         XNode_t xNode( xConstNode );
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         switch( xNode->getNodeType() )
396*cdf0e10cSrcweir         {
397*cdf0e10cSrcweir         case NodeType_ELEMENT_NODE:
398*cdf0e10cSrcweir         {
399*cdf0e10cSrcweir             // find first text node child
400*cdf0e10cSrcweir             Reference<XNode> xChild;
401*cdf0e10cSrcweir             for( xChild = xNode->getFirstChild();
402*cdf0e10cSrcweir                  xChild.is() && xChild->getNodeType() != NodeType_TEXT_NODE;
403*cdf0e10cSrcweir                  xChild = xChild->getNextSibling() )
404*cdf0e10cSrcweir                 ; // empty loop; only find first text node child
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir             // create text node, if none is found
407*cdf0e10cSrcweir             if( ! xChild.is() )
408*cdf0e10cSrcweir             {
409*cdf0e10cSrcweir                 xChild = Reference<XNode>(
410*cdf0e10cSrcweir                     xNode->getOwnerDocument()->createTextNode( OUString() ),
411*cdf0e10cSrcweir                     UNO_QUERY_THROW );
412*cdf0e10cSrcweir                 xNode->appendChild( xChild );
413*cdf0e10cSrcweir             }
414*cdf0e10cSrcweir             xNode = xChild;
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir             OSL_ENSURE( xNode.is() &&
417*cdf0e10cSrcweir                         xNode->getNodeType() == NodeType_TEXT_NODE,
418*cdf0e10cSrcweir                         "text node creation failed?" );
419*cdf0e10cSrcweir         }
420*cdf0e10cSrcweir         // no break; continue as with text node:
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir         case NodeType_TEXT_NODE:
423*cdf0e10cSrcweir         case NodeType_ATTRIBUTE_NODE:
424*cdf0e10cSrcweir         {
425*cdf0e10cSrcweir             // set the node value (defer notifications)
426*cdf0e10cSrcweir             if( xNode->getNodeValue() != sValue )
427*cdf0e10cSrcweir             {
428*cdf0e10cSrcweir                 deferNotifications( true );
429*cdf0e10cSrcweir                 xNode->setNodeValue( sValue );
430*cdf0e10cSrcweir                 deferNotifications( false );
431*cdf0e10cSrcweir             }
432*cdf0e10cSrcweir             bRet = true;
433*cdf0e10cSrcweir         }
434*cdf0e10cSrcweir         break;
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir         default:
437*cdf0e10cSrcweir         {
438*cdf0e10cSrcweir             OSL_ENSURE( false, "bound to unknown node type?" );
439*cdf0e10cSrcweir         }
440*cdf0e10cSrcweir         break;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir         }
443*cdf0e10cSrcweir     }
444*cdf0e10cSrcweir     return bRet;
445*cdf0e10cSrcweir }
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir void Model::loadInstance( sal_Int32 nInstance )
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     Sequence<PropertyValue> aSequence = mpInstances->getItem( nInstance );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     // find URL from instance
452*cdf0e10cSrcweir     OUString sURL;
453*cdf0e10cSrcweir     bool bOnce = false;
454*cdf0e10cSrcweir     getInstanceData( aSequence, NULL, NULL, &sURL, &bOnce );
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     // if we have a URL, load the document and set it into the instance
457*cdf0e10cSrcweir     if( sURL.getLength() > 0 )
458*cdf0e10cSrcweir     {
459*cdf0e10cSrcweir         try
460*cdf0e10cSrcweir         {
461*cdf0e10cSrcweir             Reference<XInputStream> xInput =
462*cdf0e10cSrcweir                 Reference<XSimpleFileAccess>(
463*cdf0e10cSrcweir                     createInstance(
464*cdf0e10cSrcweir                         OUSTRING("com.sun.star.ucb.SimpleFileAccess") ),
465*cdf0e10cSrcweir                     UNO_QUERY_THROW )->openFileRead( sURL );
466*cdf0e10cSrcweir             if( xInput.is() )
467*cdf0e10cSrcweir             {
468*cdf0e10cSrcweir                 Reference<XDocument> xInstance =
469*cdf0e10cSrcweir                     getDocumentBuilder()->parse( xInput );
470*cdf0e10cSrcweir                 if( xInstance.is() )
471*cdf0e10cSrcweir                 {
472*cdf0e10cSrcweir                     OUString sEmpty;
473*cdf0e10cSrcweir                     setInstanceData( aSequence, NULL, &xInstance,
474*cdf0e10cSrcweir                                      bOnce ? &sEmpty : &sURL, NULL);
475*cdf0e10cSrcweir                     mpInstances->setItem( nInstance, aSequence );
476*cdf0e10cSrcweir                 }
477*cdf0e10cSrcweir             }
478*cdf0e10cSrcweir         }
479*cdf0e10cSrcweir         catch( const Exception& )
480*cdf0e10cSrcweir         {
481*cdf0e10cSrcweir             // couldn't load the instance -> ignore!
482*cdf0e10cSrcweir         }
483*cdf0e10cSrcweir     }
484*cdf0e10cSrcweir }
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir void Model::loadInstances()
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir     // iterate over instance array to get PropertyValue-Sequence
489*cdf0e10cSrcweir     const sal_Int32 nInstances = mpInstances->countItems();
490*cdf0e10cSrcweir     for( sal_Int32 nInstance = 0; nInstance < nInstances; nInstance++ )
491*cdf0e10cSrcweir     {
492*cdf0e10cSrcweir         loadInstance( nInstance );
493*cdf0e10cSrcweir     }
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir bool Model::isInitialized() const
497*cdf0e10cSrcweir {
498*cdf0e10cSrcweir     return mbInitialized;
499*cdf0e10cSrcweir }
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir bool Model::isValid() const
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     bool bValid = true;
504*cdf0e10cSrcweir     sal_Int32 nCount = mpBindings->countItems();
505*cdf0e10cSrcweir     for( sal_Int32 i = 0; bValid && i < nCount; i++ )
506*cdf0e10cSrcweir     {
507*cdf0e10cSrcweir         Binding* pBind = Binding::getBinding( mpBindings->Collection<XPropertySet_t>::getItem( i ) );
508*cdf0e10cSrcweir         OSL_ENSURE( pBind != NULL, "binding?" );
509*cdf0e10cSrcweir         bValid = pBind->isValid();
510*cdf0e10cSrcweir     }
511*cdf0e10cSrcweir     return bValid;
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir //
517*cdf0e10cSrcweir // implement xforms::XModel
518*cdf0e10cSrcweir //
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir rtl::OUString Model::getID()
521*cdf0e10cSrcweir     throw( RuntimeException )
522*cdf0e10cSrcweir {
523*cdf0e10cSrcweir     DBG_INVARIANT();
524*cdf0e10cSrcweir     return msID;
525*cdf0e10cSrcweir }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir void Model::setID( const rtl::OUString& sID )
528*cdf0e10cSrcweir     throw( RuntimeException )
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir     DBG_INVARIANT();
531*cdf0e10cSrcweir     msID = sID;
532*cdf0e10cSrcweir }
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir void Model::initialize()
535*cdf0e10cSrcweir     throw( RuntimeException )
536*cdf0e10cSrcweir {
537*cdf0e10cSrcweir     DBG_ASSERT( ! mbInitialized, "model already initialized" );
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir     // load instances
540*cdf0e10cSrcweir     loadInstances();
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir     // let's pretend we're initialized and rebind all bindings
543*cdf0e10cSrcweir     mbInitialized = true;
544*cdf0e10cSrcweir     rebind();
545*cdf0e10cSrcweir }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir void Model::rebuild()
548*cdf0e10cSrcweir     throw( RuntimeException )
549*cdf0e10cSrcweir {
550*cdf0e10cSrcweir     if( ! mbInitialized )
551*cdf0e10cSrcweir         initialize();
552*cdf0e10cSrcweir     else
553*cdf0e10cSrcweir         rebind();
554*cdf0e10cSrcweir }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir void Model::recalculate()
557*cdf0e10cSrcweir     throw( RuntimeException )
558*cdf0e10cSrcweir {
559*cdf0e10cSrcweir     rebind();
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir void Model::revalidate()
563*cdf0e10cSrcweir     throw( RuntimeException )
564*cdf0e10cSrcweir {
565*cdf0e10cSrcweir     // do nothing. We don't validate anyways!
566*cdf0e10cSrcweir }
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir void Model::refresh()
569*cdf0e10cSrcweir     throw( RuntimeException )
570*cdf0e10cSrcweir {
571*cdf0e10cSrcweir     rebind();
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir void SAL_CALL Model::submitWithInteraction(
576*cdf0e10cSrcweir     const rtl::OUString& sID,
577*cdf0e10cSrcweir     const XInteractionHandler_t& _rxHandler )
578*cdf0e10cSrcweir     throw( VetoException,
579*cdf0e10cSrcweir            WrappedTargetException,
580*cdf0e10cSrcweir            RuntimeException )
581*cdf0e10cSrcweir {
582*cdf0e10cSrcweir     DBG_INVARIANT();
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir     if( mpSubmissions->hasItem( sID ) )
585*cdf0e10cSrcweir     {
586*cdf0e10cSrcweir         Submission* pSubmission =
587*cdf0e10cSrcweir             Submission::getSubmission( mpSubmissions->getItem( sID ) );
588*cdf0e10cSrcweir         OSL_ENSURE( pSubmission != NULL, "no submission?" );
589*cdf0e10cSrcweir         OSL_ENSURE( pSubmission->getModel() == Reference<XModel>( this ),
590*cdf0e10cSrcweir                     "wrong model" );
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir         // submit. All exceptions are allowed to leave.
593*cdf0e10cSrcweir         pSubmission->submitWithInteraction( _rxHandler );
594*cdf0e10cSrcweir     }
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir void Model::submit( const rtl::OUString& sID )
598*cdf0e10cSrcweir     throw( VetoException, WrappedTargetException, RuntimeException )
599*cdf0e10cSrcweir {
600*cdf0e10cSrcweir     submitWithInteraction( sID, NULL );
601*cdf0e10cSrcweir }
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir Model::XDataTypeRepository_t SAL_CALL Model::getDataTypeRepository(  )
604*cdf0e10cSrcweir     throw( RuntimeException )
605*cdf0e10cSrcweir {
606*cdf0e10cSrcweir     if ( !mxDataTypes.is() )
607*cdf0e10cSrcweir         mxDataTypes = new ODataTypeRepository;
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir     return mxDataTypes;
610*cdf0e10cSrcweir }
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir //
613*cdf0e10cSrcweir // instance management
614*cdf0e10cSrcweir //
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir Model::XSet_t Model::getInstances()
617*cdf0e10cSrcweir     throw( RuntimeException )
618*cdf0e10cSrcweir {
619*cdf0e10cSrcweir     return mxInstances;
620*cdf0e10cSrcweir }
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir Model::XDocument_t Model::getInstanceDocument( const rtl::OUString& rName )
623*cdf0e10cSrcweir     throw( RuntimeException )
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir     ensureAtLeastOneInstance();
626*cdf0e10cSrcweir     Reference<XDocument> aInstance;
627*cdf0e10cSrcweir     sal_Int32 nInstance = lcl_findInstance( mpInstances, rName );
628*cdf0e10cSrcweir     if( nInstance != -1 )
629*cdf0e10cSrcweir         getInstanceData( mpInstances->getItem( nInstance ),
630*cdf0e10cSrcweir                          NULL, &aInstance, NULL, NULL );
631*cdf0e10cSrcweir     return aInstance;
632*cdf0e10cSrcweir }
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir Model::XDocument_t SAL_CALL Model::getDefaultInstance()
635*cdf0e10cSrcweir     throw( RuntimeException )
636*cdf0e10cSrcweir {
637*cdf0e10cSrcweir     ensureAtLeastOneInstance();
638*cdf0e10cSrcweir     DBG_ASSERT( mpInstances->countItems() > 0, "no instance?" );
639*cdf0e10cSrcweir     Reference<XDocument> aInstance;
640*cdf0e10cSrcweir     getInstanceData( mpInstances->getItem( 0 ), NULL, &aInstance, NULL, NULL );
641*cdf0e10cSrcweir     return aInstance;
642*cdf0e10cSrcweir }
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir //
647*cdf0e10cSrcweir // bindings management
648*cdf0e10cSrcweir //
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir Model::XPropertySet_t SAL_CALL Model::createBinding()
651*cdf0e10cSrcweir     throw( RuntimeException )
652*cdf0e10cSrcweir {
653*cdf0e10cSrcweir     DBG_INVARIANT();
654*cdf0e10cSrcweir     return new Binding();
655*cdf0e10cSrcweir }
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir Model::XPropertySet_t Model::cloneBinding( const XPropertySet_t& xBinding )
658*cdf0e10cSrcweir     throw( RuntimeException )
659*cdf0e10cSrcweir {
660*cdf0e10cSrcweir     DBG_INVARIANT();
661*cdf0e10cSrcweir     XPropertySet_t xNewBinding = createBinding();
662*cdf0e10cSrcweir     copy( xBinding, xNewBinding );
663*cdf0e10cSrcweir     return xNewBinding;
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir Model::XPropertySet_t Model::getBinding( const rtl::OUString& sId )
667*cdf0e10cSrcweir     throw( RuntimeException )
668*cdf0e10cSrcweir {
669*cdf0e10cSrcweir     DBG_INVARIANT();
670*cdf0e10cSrcweir     return mpBindings->hasItem( sId ) ? mpBindings->getItem( sId ) : NULL;
671*cdf0e10cSrcweir }
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir Model::XSet_t Model::getBindings()
674*cdf0e10cSrcweir     throw( RuntimeException )
675*cdf0e10cSrcweir {
676*cdf0e10cSrcweir     DBG_INVARIANT();
677*cdf0e10cSrcweir     return mxBindings;
678*cdf0e10cSrcweir }
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir //
683*cdf0e10cSrcweir // submission management
684*cdf0e10cSrcweir //
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir Model::XSubmission_t Model::createSubmission()
687*cdf0e10cSrcweir     throw( RuntimeException )
688*cdf0e10cSrcweir {
689*cdf0e10cSrcweir     DBG_INVARIANT();
690*cdf0e10cSrcweir     return new Submission();
691*cdf0e10cSrcweir }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir Model::XSubmission_t Model::cloneSubmission(const XPropertySet_t& xSubmission)
694*cdf0e10cSrcweir     throw( RuntimeException )
695*cdf0e10cSrcweir {
696*cdf0e10cSrcweir     DBG_INVARIANT();
697*cdf0e10cSrcweir     XSubmission_t xNewSubmission = createSubmission();
698*cdf0e10cSrcweir     XPropertySet_t xAsPropertySet( xNewSubmission.get() );
699*cdf0e10cSrcweir     copy( xSubmission.get(), xAsPropertySet );
700*cdf0e10cSrcweir     return xNewSubmission;
701*cdf0e10cSrcweir }
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir Model::XSubmission_t Model::getSubmission( const rtl::OUString& sId )
704*cdf0e10cSrcweir     throw( RuntimeException )
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir     DBG_INVARIANT();
707*cdf0e10cSrcweir     XSubmission_t xSubmission;
708*cdf0e10cSrcweir     if ( mpSubmissions->hasItem( sId ) )
709*cdf0e10cSrcweir         xSubmission = xSubmission.query( mpSubmissions->getItem( sId ) );
710*cdf0e10cSrcweir     return xSubmission;
711*cdf0e10cSrcweir }
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir Model::XSet_t Model::getSubmissions()
714*cdf0e10cSrcweir     throw( RuntimeException )
715*cdf0e10cSrcweir {
716*cdf0e10cSrcweir     DBG_INVARIANT();
717*cdf0e10cSrcweir     return mxSubmissions;
718*cdf0e10cSrcweir }
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir //
723*cdf0e10cSrcweir // implementation of XFormsUIHelper1 interface
724*cdf0e10cSrcweir //   can be found in file model_ui.cxx
725*cdf0e10cSrcweir //
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir //
730*cdf0e10cSrcweir // implement XPropertySet & friends
731*cdf0e10cSrcweir //
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir #define HANDLE_ID 0
734*cdf0e10cSrcweir #define HANDLE_Instance 1
735*cdf0e10cSrcweir #define HANDLE_InstanceURL 2
736*cdf0e10cSrcweir #define HANDLE_ForeignSchema 3
737*cdf0e10cSrcweir #define HANDLE_SchemaRef 4
738*cdf0e10cSrcweir #define HANDLE_Namespaces 5
739*cdf0e10cSrcweir #define HANDLE_ExternalData 6
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir #define REGISTER_PROPERTY( property, type )   \
742*cdf0e10cSrcweir     registerProperty( PROPERTY( property, type ), \
743*cdf0e10cSrcweir     new DirectPropertyAccessor< Model, type >( this, &Model::set##property, &Model::get##property ) );
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir #define REGISTER_PROPERTY_API( property, type )   \
746*cdf0e10cSrcweir     registerProperty( PROPERTY( property, type ), \
747*cdf0e10cSrcweir     new APIPropertyAccessor< Model, type >( this, &Model::set##property, &Model::get##property ) );
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir #define REGISTER_BOOL_PROPERTY( property )   \
750*cdf0e10cSrcweir     registerProperty( PROPERTY( property, sal_Bool ), \
751*cdf0e10cSrcweir     new BooleanPropertyAccessor< Model, bool >( this, &Model::set##property, &Model::get##property ) );
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir void Model::initializePropertySet()
754*cdf0e10cSrcweir {
755*cdf0e10cSrcweir     REGISTER_PROPERTY_API ( ID,            OUString );
756*cdf0e10cSrcweir     REGISTER_PROPERTY     ( ForeignSchema, XDocument_t );
757*cdf0e10cSrcweir     REGISTER_PROPERTY     ( SchemaRef,     OUString );
758*cdf0e10cSrcweir     REGISTER_PROPERTY     ( Namespaces,    XNameContainer_t );
759*cdf0e10cSrcweir     REGISTER_BOOL_PROPERTY( ExternalData );
760*cdf0e10cSrcweir }
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir void Model::update()
763*cdf0e10cSrcweir     throw( RuntimeException )
764*cdf0e10cSrcweir {
765*cdf0e10cSrcweir     rebuild();
766*cdf0e10cSrcweir }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir sal_Int64 Model::getSomething( const IntSequence_t& xId )
770*cdf0e10cSrcweir     throw( RuntimeException )
771*cdf0e10cSrcweir {
772*cdf0e10cSrcweir     return reinterpret_cast<sal_Int64>( ( xId == getUnoTunnelID() ) ? this : NULL );
773*cdf0e10cSrcweir }
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir Sequence<sal_Int8> Model::getImplementationId()
776*cdf0e10cSrcweir     throw( RuntimeException )
777*cdf0e10cSrcweir {
778*cdf0e10cSrcweir     return getUnoTunnelID();
779*cdf0e10cSrcweir }
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir //
783*cdf0e10cSrcweir // 'shift' operators for getting data into and out of Anys
784*cdf0e10cSrcweir //
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir void operator <<= ( com::sun::star::uno::Any& rAny,
787*cdf0e10cSrcweir                     xforms::Model* pModel)
788*cdf0e10cSrcweir {
789*cdf0e10cSrcweir     Reference<XPropertySet> xPropSet( static_cast<XPropertySet*>( pModel ) );
790*cdf0e10cSrcweir     rAny <<= xPropSet;
791*cdf0e10cSrcweir }
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir bool operator >>= ( xforms::Model* pModel,
794*cdf0e10cSrcweir                     com::sun::star::uno::Any& rAny )
795*cdf0e10cSrcweir {
796*cdf0e10cSrcweir     bool bRet = false;
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir     // acquire model pointer through XUnoTunnel
799*cdf0e10cSrcweir     Reference<XUnoTunnel> xTunnel( rAny, UNO_QUERY );
800*cdf0e10cSrcweir     if( xTunnel.is() )
801*cdf0e10cSrcweir     {
802*cdf0e10cSrcweir         pModel = reinterpret_cast<xforms::Model*>(
803*cdf0e10cSrcweir             xTunnel->getSomething( xforms::Model::getUnoTunnelID() ) );
804*cdf0e10cSrcweir         bRet = true;
805*cdf0e10cSrcweir     }
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir     return bRet;
808*cdf0e10cSrcweir }
809