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