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_helper.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 ************************************************************************/
30 #ifndef _MODEL_HELPER_HXX
31 #define _MODEL_HELPER_HXX
34 // some helper definitions that must be available for model.cxx and
38 #include "namedcollection.hxx"
39 #include "binding.hxx"
40 #include "submission.hxx"
41 #include "unohelper.hxx"
43 #include <com/sun/star/uno/Reference.hxx>
44 #include <com/sun/star/uno/Sequence.hxx>
45 #include <com/sun/star/lang/XUnoTunnel.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/PropertyValue.hpp>
61 class BindingCollection
: public NamedCollection
<com::sun::star::uno::Reference
<com::sun::star::beans::XPropertySet
> >
66 BindingCollection( Model
* pModel
) : mpModel( pModel
) {}
67 virtual ~BindingCollection() {}
69 virtual bool isValid( const T
& t
) const
71 return Binding::getBinding( t
) != NULL
;
75 virtual void _insert( const T
& t
)
77 OSL_ENSURE( Binding::getBinding( t
) != NULL
, "invalid item?" );
78 Binding::getBinding( t
)->_setModel( Binding::Model_t( mpModel
) );
81 virtual void _remove( const T
& t
)
83 OSL_ENSURE( Binding::getBinding( t
) != NULL
, "invalid item?" );
84 Binding::getBinding( t
)->_setModel( Binding::Model_t() );
91 // SubmissionCollection
94 class SubmissionCollection
: public NamedCollection
<com::sun::star::uno::Reference
<com::sun::star::beans::XPropertySet
> >
99 SubmissionCollection( Model
* pModel
) : mpModel( pModel
) {}
100 virtual ~SubmissionCollection() {}
103 virtual bool isValid( const T
& t
) const
105 return Submission::getSubmission( t
) != NULL
;
109 virtual void _insert( const T
& t
)
111 OSL_ENSURE( Submission::getSubmission( t
) != NULL
, "invalid item?" );
112 Submission::getSubmission( t
)->setModel( com::sun::star::uno::Reference
<com::sun::star::xforms::XModel
>( mpModel
) );
115 virtual void _remove( const T
& t
)
117 OSL_ENSURE( Submission::getSubmission( t
) != NULL
, "invalid item?" );
118 Submission::getSubmission( t
)->setModel( com::sun::star::uno::Reference
<com::sun::star::xforms::XModel
>( ) );
124 // InstanceCollection
127 class InstanceCollection
: public Collection
<com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
> >
130 virtual bool isValid( const T
& t
) const
132 const com::sun::star::beans::PropertyValue
* pValues
= t
.getConstArray();
133 rtl::OUString
sInstance( OUSTRING("Instance") );
134 sal_Bool bFound
= sal_False
;
135 for( sal_Int32 i
= 0; ( ! bFound
) && ( i
< t
.getLength() ); i
++ )
137 bFound
|= ( pValues
[i
].Name
== sInstance
);
139 return bFound
? true : false;
148 sal_Int32
lcl_findInstance( const InstanceCollection
*,
149 const rtl::OUString
& );
152 // get values from Sequence<PropertyValue> describing an Instance
153 void getInstanceData(
154 const com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>&,
156 com::sun::star::uno::Reference
<com::sun::star::xml::dom::XDocument
>*,
160 // set values on Sequence<PropertyValue> for an Instance
161 void setInstanceData(
162 com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>&,
163 const rtl::OUString
* pID
,
164 const com::sun::star::uno::Reference
<com::sun::star::xml::dom::XDocument
>*,
165 const rtl::OUString
* pURL
,
166 const bool* pURLOnce
);
168 } // namespace xforms