xref: /AOO42X/main/framework/source/fwi/uielement/constitemcontainer.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_framework.hxx"
30*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
31*cdf0e10cSrcweir //  my own includes
32*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
33*cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx>
34*cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx>
35*cdf0e10cSrcweir #include <uielement/itemcontainer.hxx>
36*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39*cdf0e10cSrcweir //  interface includes
40*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
41*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44*cdf0e10cSrcweir //  other includes
45*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace cppu;
49*cdf0e10cSrcweir using namespace com::sun::star::uno;
50*cdf0e10cSrcweir using namespace com::sun::star::lang;
51*cdf0e10cSrcweir using namespace com::sun::star::beans;
52*cdf0e10cSrcweir using namespace com::sun::star::container;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir const char WRONG_TYPE_EXCEPTION[] = "Type must be com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >";
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir const int PROPHANDLE_UINAME     = 1;
57*cdf0e10cSrcweir const int PROPCOUNT             = 1;
58*cdf0e10cSrcweir const rtl::OUString PROPNAME_UINAME( RTL_CONSTASCII_USTRINGPARAM( "UIName" ));
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir namespace framework
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir /**
64*cdf0e10cSrcweir  * The class which implements the PropertySetInfo interface.
65*cdf0e10cSrcweir  */
66*cdf0e10cSrcweir extern "C"
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir static int SAL_CALL compare_OUString_Property_Impl( const void *arg1, const void *arg2 ) SAL_THROW( () )
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir    return ((::rtl::OUString *)arg1)->compareTo( ((Property *)arg2)->Name );
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir class OPropertySetHelperInfo_Impl
75*cdf0e10cSrcweir     : public WeakImplHelper1< ::com::sun::star::beans::XPropertySetInfo >
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     Sequence < Property > aInfos;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir public:
80*cdf0e10cSrcweir     OPropertySetHelperInfo_Impl( IPropertyArrayHelper & rHelper_ ) SAL_THROW( () );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     // XPropertySetInfo-Methoden
83*cdf0e10cSrcweir     virtual Sequence< Property > SAL_CALL getProperties(void) throw(::com::sun::star::uno::RuntimeException);
84*cdf0e10cSrcweir     virtual Property SAL_CALL getPropertyByName(const ::rtl::OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
85*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasPropertyByName(const ::rtl::OUString& PropertyName) throw(::com::sun::star::uno::RuntimeException);
86*cdf0e10cSrcweir };
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir /**
90*cdf0e10cSrcweir  * Create an object that implements XPropertySetInfo IPropertyArrayHelper.
91*cdf0e10cSrcweir  */
92*cdf0e10cSrcweir OPropertySetHelperInfo_Impl::OPropertySetHelperInfo_Impl(
93*cdf0e10cSrcweir     IPropertyArrayHelper & rHelper_ )
94*cdf0e10cSrcweir     SAL_THROW( () )
95*cdf0e10cSrcweir     :aInfos( rHelper_.getProperties() )
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir /**
100*cdf0e10cSrcweir  * Return the sequence of properties, which are provided throug the constructor.
101*cdf0e10cSrcweir  */
102*cdf0e10cSrcweir Sequence< Property > OPropertySetHelperInfo_Impl::getProperties(void) throw(::com::sun::star::uno::RuntimeException)
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     return aInfos;
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir /**
108*cdf0e10cSrcweir  * Return the sequence of properties, which are provided throug the constructor.
109*cdf0e10cSrcweir  */
110*cdf0e10cSrcweir Property OPropertySetHelperInfo_Impl::getPropertyByName( const ::rtl::OUString & PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir     Property * pR;
113*cdf0e10cSrcweir     pR = (Property *)bsearch( &PropertyName, aInfos.getConstArray(), aInfos.getLength(),
114*cdf0e10cSrcweir                               sizeof( Property ),
115*cdf0e10cSrcweir                               compare_OUString_Property_Impl );
116*cdf0e10cSrcweir     if( !pR ) {
117*cdf0e10cSrcweir         throw UnknownPropertyException();
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     return *pR;
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir /**
124*cdf0e10cSrcweir  * Return the sequence of properties, which are provided throug the constructor.
125*cdf0e10cSrcweir  */
126*cdf0e10cSrcweir sal_Bool OPropertySetHelperInfo_Impl::hasPropertyByName( const ::rtl::OUString & PropertyName ) throw(::com::sun::star::uno::RuntimeException)
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     Property * pR;
129*cdf0e10cSrcweir     pR = (Property *)bsearch( &PropertyName, aInfos.getConstArray(), aInfos.getLength(),
130*cdf0e10cSrcweir                               sizeof( Property ),
131*cdf0e10cSrcweir                               compare_OUString_Property_Impl );
132*cdf0e10cSrcweir     return pR != NULL;
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //*****************************************************************************************************************
136*cdf0e10cSrcweir //  XInterface, XTypeProvider
137*cdf0e10cSrcweir //*****************************************************************************************************************
138*cdf0e10cSrcweir DEFINE_XINTERFACE_6     (   ConstItemContainer                                              ,
139*cdf0e10cSrcweir                             OWeakObject                                                     ,
140*cdf0e10cSrcweir                             DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider         ),
141*cdf0e10cSrcweir                             DIRECT_INTERFACE( ::com::sun::star::container::XElementAccess   ),
142*cdf0e10cSrcweir                             DIRECT_INTERFACE( ::com::sun::star::container::XIndexAccess     ),
143*cdf0e10cSrcweir                             DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet     ),
144*cdf0e10cSrcweir                             DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet         ),
145*cdf0e10cSrcweir                             DIRECT_INTERFACE( ::com::sun::star::lang::XUnoTunnel            )
146*cdf0e10cSrcweir                         )
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_6  (   ConstItemContainer                          ,
149*cdf0e10cSrcweir                             ::com::sun::star::lang::XTypeProvider       ,
150*cdf0e10cSrcweir                             ::com::sun::star::container::XIndexAccess   ,
151*cdf0e10cSrcweir                             ::com::sun::star::container::XElementAccess ,
152*cdf0e10cSrcweir                             ::com::sun::star::beans::XFastPropertySet   ,
153*cdf0e10cSrcweir                             ::com::sun::star::beans::XPropertySet       ,
154*cdf0e10cSrcweir                             ::com::sun::star::lang::XUnoTunnel
155*cdf0e10cSrcweir                         )
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir ConstItemContainer::ConstItemContainer() : ::cppu::OWeakObject()
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir ConstItemContainer::ConstItemContainer( const RootItemContainer& rRootItemContainer, sal_Bool bFastCopy )
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     ShareGuard( rRootItemContainer.m_aShareMutex );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     // If bFastCopy is set the onwer of the root item container will transfer ownership to us. So
166*cdf0e10cSrcweir     // it is possible to copy only the root part.
167*cdf0e10cSrcweir     m_aUIName = rRootItemContainer.m_aUIName;
168*cdf0e10cSrcweir     if ( bFastCopy )
169*cdf0e10cSrcweir         m_aItemVector = rRootItemContainer.m_aItemVector;
170*cdf0e10cSrcweir     else
171*cdf0e10cSrcweir         copyItemContainer( rRootItemContainer.m_aItemVector );
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir ConstItemContainer::ConstItemContainer( const ItemContainer& rItemContainer )
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir     ShareGuard( rItemContainer.m_aShareMutex );
177*cdf0e10cSrcweir     copyItemContainer( rItemContainer.m_aItemVector );
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir ConstItemContainer::ConstItemContainer( const Reference< XIndexAccess >& rSourceContainer, sal_Bool bFastCopy )
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     // We also have to copy the UIName property
183*cdf0e10cSrcweir     try
184*cdf0e10cSrcweir     {
185*cdf0e10cSrcweir         Reference< XPropertySet > xPropSet( rSourceContainer, UNO_QUERY );
186*cdf0e10cSrcweir         if ( xPropSet.is() )
187*cdf0e10cSrcweir         {
188*cdf0e10cSrcweir             rtl::OUString aUIName;
189*cdf0e10cSrcweir             xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= m_aUIName;
190*cdf0e10cSrcweir         }
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir     catch ( Exception& )
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     if ( rSourceContainer.is() )
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir         try
199*cdf0e10cSrcweir         {
200*cdf0e10cSrcweir             sal_Int32 nCount = rSourceContainer->getCount();
201*cdf0e10cSrcweir             m_aItemVector.reserve(nCount);
202*cdf0e10cSrcweir             if ( bFastCopy )
203*cdf0e10cSrcweir             {
204*cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < nCount; i++ )
205*cdf0e10cSrcweir                 {
206*cdf0e10cSrcweir                     Sequence< PropertyValue > aPropSeq;
207*cdf0e10cSrcweir                     if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
208*cdf0e10cSrcweir                         m_aItemVector.push_back( aPropSeq );
209*cdf0e10cSrcweir                 }
210*cdf0e10cSrcweir             }
211*cdf0e10cSrcweir             else
212*cdf0e10cSrcweir             {
213*cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < nCount; i++ )
214*cdf0e10cSrcweir                 {
215*cdf0e10cSrcweir                     Sequence< PropertyValue > aPropSeq;
216*cdf0e10cSrcweir                     if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
217*cdf0e10cSrcweir                     {
218*cdf0e10cSrcweir                         sal_Int32 nContainerIndex = -1;
219*cdf0e10cSrcweir                         Reference< XIndexAccess > xIndexAccess;
220*cdf0e10cSrcweir                         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
221*cdf0e10cSrcweir                         {
222*cdf0e10cSrcweir                             if ( aPropSeq[j].Name.equalsAscii( "ItemDescriptorContainer" ))
223*cdf0e10cSrcweir                             {
224*cdf0e10cSrcweir                                 aPropSeq[j].Value >>= xIndexAccess;
225*cdf0e10cSrcweir                                 nContainerIndex = j;
226*cdf0e10cSrcweir                                 break;
227*cdf0e10cSrcweir                             }
228*cdf0e10cSrcweir                         }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir                         if ( xIndexAccess.is() && nContainerIndex >= 0 )
231*cdf0e10cSrcweir                             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir                         m_aItemVector.push_back( aPropSeq );
234*cdf0e10cSrcweir                     }
235*cdf0e10cSrcweir                 }
236*cdf0e10cSrcweir             }
237*cdf0e10cSrcweir         }
238*cdf0e10cSrcweir         catch ( IndexOutOfBoundsException& )
239*cdf0e10cSrcweir         {
240*cdf0e10cSrcweir         }
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir ConstItemContainer::~ConstItemContainer()
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir // private
249*cdf0e10cSrcweir void ConstItemContainer::copyItemContainer( const std::vector< Sequence< PropertyValue > >& rSourceVector )
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir     const sal_uInt32 nCount = rSourceVector.size();
252*cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < nCount; i++ )
253*cdf0e10cSrcweir     {
254*cdf0e10cSrcweir         sal_Int32 nContainerIndex = -1;
255*cdf0e10cSrcweir         Sequence< PropertyValue > aPropSeq( rSourceVector[i] );
256*cdf0e10cSrcweir         Reference< XIndexAccess > xIndexAccess;
257*cdf0e10cSrcweir         for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
258*cdf0e10cSrcweir         {
259*cdf0e10cSrcweir             if ( aPropSeq[j].Name.equalsAscii( "ItemDescriptorContainer" ))
260*cdf0e10cSrcweir             {
261*cdf0e10cSrcweir                 aPropSeq[j].Value >>= xIndexAccess;
262*cdf0e10cSrcweir                 nContainerIndex = j;
263*cdf0e10cSrcweir                 break;
264*cdf0e10cSrcweir             }
265*cdf0e10cSrcweir         }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         if ( xIndexAccess.is() && nContainerIndex >= 0 )
268*cdf0e10cSrcweir             aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir         m_aItemVector.push_back( aPropSeq );
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir Reference< XIndexAccess > ConstItemContainer::deepCopyContainer( const Reference< XIndexAccess >& rSubContainer )
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     Reference< XIndexAccess > xReturn;
277*cdf0e10cSrcweir     if ( rSubContainer.is() )
278*cdf0e10cSrcweir     {
279*cdf0e10cSrcweir         ItemContainer*      pSource = ItemContainer::GetImplementation( rSubContainer );
280*cdf0e10cSrcweir         ConstItemContainer* pSubContainer( 0 );
281*cdf0e10cSrcweir         if ( pSource )
282*cdf0e10cSrcweir             pSubContainer = new ConstItemContainer( *pSource );
283*cdf0e10cSrcweir         else
284*cdf0e10cSrcweir             pSubContainer = new ConstItemContainer( rSubContainer );
285*cdf0e10cSrcweir         xReturn = Reference< XIndexAccess >( static_cast< OWeakObject* >( pSubContainer ), UNO_QUERY );
286*cdf0e10cSrcweir     }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     return xReturn;
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir // XUnoTunnel
292*cdf0e10cSrcweir sal_Int64 ConstItemContainer::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException)
293*cdf0e10cSrcweir {
294*cdf0e10cSrcweir     if( ( rIdentifier.getLength() == 16 ) && ( 0 == rtl_compareMemory( ConstItemContainer::GetUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) ) )
295*cdf0e10cSrcweir     {
296*cdf0e10cSrcweir         return reinterpret_cast< sal_Int64 >( this );
297*cdf0e10cSrcweir     }
298*cdf0e10cSrcweir     return 0;
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir const Sequence< sal_Int8 >& ConstItemContainer::GetUnoTunnelId() throw()
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir     static ::com::sun::star::uno::Sequence< sal_Int8 > * pSeq = NULL;
304*cdf0e10cSrcweir     if( !pSeq )
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
307*cdf0e10cSrcweir         if( !pSeq )
308*cdf0e10cSrcweir         {
309*cdf0e10cSrcweir             static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 );
310*cdf0e10cSrcweir             rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
311*cdf0e10cSrcweir             pSeq = &aSeq;
312*cdf0e10cSrcweir         }
313*cdf0e10cSrcweir     }
314*cdf0e10cSrcweir     return *pSeq;
315*cdf0e10cSrcweir }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir ConstItemContainer* ConstItemContainer::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw()
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY );
320*cdf0e10cSrcweir     return xUT.is() ? reinterpret_cast< ConstItemContainer* >(sal::static_int_cast< sal_IntPtr >(
321*cdf0e10cSrcweir                           xUT->getSomething( ConstItemContainer::GetUnoTunnelId() ))) : NULL;
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir // XElementAccess
325*cdf0e10cSrcweir sal_Bool SAL_CALL ConstItemContainer::hasElements()
326*cdf0e10cSrcweir throw ( RuntimeException )
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     return ( !m_aItemVector.empty() );
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir // XIndexAccess
332*cdf0e10cSrcweir sal_Int32 SAL_CALL ConstItemContainer::getCount()
333*cdf0e10cSrcweir throw ( RuntimeException )
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     return m_aItemVector.size();
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir Any SAL_CALL ConstItemContainer::getByIndex( sal_Int32 Index )
339*cdf0e10cSrcweir throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
340*cdf0e10cSrcweir {
341*cdf0e10cSrcweir     if ( sal_Int32( m_aItemVector.size()) > Index )
342*cdf0e10cSrcweir         return makeAny( m_aItemVector[Index] );
343*cdf0e10cSrcweir     else
344*cdf0e10cSrcweir         throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
345*cdf0e10cSrcweir }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir // XPropertySet
348*cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL ConstItemContainer::getPropertySetInfo()
349*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
350*cdf0e10cSrcweir {
351*cdf0e10cSrcweir     // Optimize this method !
352*cdf0e10cSrcweir     // We initialize a static variable only one time. And we don't must use a mutex at every call!
353*cdf0e10cSrcweir     // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
354*cdf0e10cSrcweir     static Reference< XPropertySetInfo >* pInfo = NULL;
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir     if( pInfo == NULL )
357*cdf0e10cSrcweir     {
358*cdf0e10cSrcweir         // Ready for multithreading
359*cdf0e10cSrcweir         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
360*cdf0e10cSrcweir         // Control this pointer again, another instance can be faster then these!
361*cdf0e10cSrcweir         if( pInfo == NULL )
362*cdf0e10cSrcweir         {
363*cdf0e10cSrcweir             // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
364*cdf0e10cSrcweir             // (Use method "getInfoHelper()".)
365*cdf0e10cSrcweir             static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
366*cdf0e10cSrcweir             pInfo = &xInfo;
367*cdf0e10cSrcweir         }
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir     return (*pInfo);
371*cdf0e10cSrcweir }
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir void SAL_CALL ConstItemContainer::setPropertyValue( const ::rtl::OUString&, const Any& )
374*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
375*cdf0e10cSrcweir {
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir Any SAL_CALL ConstItemContainer::getPropertyValue( const ::rtl::OUString& PropertyName )
379*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
380*cdf0e10cSrcweir {
381*cdf0e10cSrcweir     if ( PropertyName.equals( PROPNAME_UINAME ))
382*cdf0e10cSrcweir         return makeAny( m_aUIName );
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir     throw UnknownPropertyException();
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir void SAL_CALL ConstItemContainer::addPropertyChangeListener( const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& )
388*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir void SAL_CALL ConstItemContainer::removePropertyChangeListener( const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& )
393*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir     // Only read-only properties - do nothing
396*cdf0e10cSrcweir }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir void SAL_CALL ConstItemContainer::addVetoableChangeListener( const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& )
399*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
400*cdf0e10cSrcweir {
401*cdf0e10cSrcweir     // Only read-only properties - do nothing
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir void SAL_CALL ConstItemContainer::removeVetoableChangeListener( const ::rtl::OUString&, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& )
405*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
406*cdf0e10cSrcweir {
407*cdf0e10cSrcweir     // Only read-only properties - do nothing
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir // XFastPropertySet
411*cdf0e10cSrcweir void SAL_CALL ConstItemContainer::setFastPropertyValue( sal_Int32, const ::com::sun::star::uno::Any& )
412*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir Any SAL_CALL ConstItemContainer::getFastPropertyValue( sal_Int32 nHandle )
417*cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir     if ( nHandle == PROPHANDLE_UINAME )
420*cdf0e10cSrcweir         return makeAny( m_aUIName );
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir     throw UnknownPropertyException();
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& SAL_CALL ConstItemContainer::getInfoHelper()
426*cdf0e10cSrcweir {
427*cdf0e10cSrcweir     // Optimize this method !
428*cdf0e10cSrcweir     // We initialize a static variable only one time. And we don't must use a mutex at every call!
429*cdf0e10cSrcweir     // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
430*cdf0e10cSrcweir     static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir     if( pInfoHelper == NULL )
433*cdf0e10cSrcweir     {
434*cdf0e10cSrcweir         // Ready for multithreading
435*cdf0e10cSrcweir         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         // Control this pointer again, another instance can be faster then these!
438*cdf0e10cSrcweir         if( pInfoHelper == NULL )
439*cdf0e10cSrcweir         {
440*cdf0e10cSrcweir             // Define static member to give structure of properties to baseclass "OPropertySetHelper".
441*cdf0e10cSrcweir             // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
442*cdf0e10cSrcweir             // "sal_True" say: Table is sorted by name.
443*cdf0e10cSrcweir             static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
444*cdf0e10cSrcweir             pInfoHelper = &aInfoHelper;
445*cdf0e10cSrcweir         }
446*cdf0e10cSrcweir     }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir     return(*pInfoHelper);
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir const com::sun::star::uno::Sequence< com::sun::star::beans::Property > ConstItemContainer::impl_getStaticPropertyDescriptor()
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir     // Create a new static property array to initialize sequence!
454*cdf0e10cSrcweir     // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
455*cdf0e10cSrcweir     // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
456*cdf0e10cSrcweir     // It's necessary for methods of OPropertySetHelper.
457*cdf0e10cSrcweir     // ATTENTION:
458*cdf0e10cSrcweir     //      YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir     static const com::sun::star::beans::Property pProperties[] =
461*cdf0e10cSrcweir     {
462*cdf0e10cSrcweir         com::sun::star::beans::Property( PROPNAME_UINAME, PROPHANDLE_UINAME ,
463*cdf0e10cSrcweir                                          ::getCppuType((const rtl::OUString*)NULL),
464*cdf0e10cSrcweir                                          com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY  )
465*cdf0e10cSrcweir     };
466*cdf0e10cSrcweir     // Use it to initialize sequence!
467*cdf0e10cSrcweir     static const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, PROPCOUNT );
468*cdf0e10cSrcweir     // Return static "PropertyDescriptor"
469*cdf0e10cSrcweir     return lPropertyDescriptor;
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir Reference < XPropertySetInfo > ConstItemContainer::createPropertySetInfo(
473*cdf0e10cSrcweir     IPropertyArrayHelper & rProperties ) SAL_THROW( () )
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir     return static_cast< XPropertySetInfo * >( new OPropertySetHelperInfo_Impl( rProperties ) );
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir } // namespace framework
479*cdf0e10cSrcweir 
480