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