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_stoc.hxx"
30*cdf0e10cSrcweir #include <typelib/typedescription.h>
31*cdf0e10cSrcweir #include <uno/data.h>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "base.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir namespace stoc_corefl
37*cdf0e10cSrcweir {
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir // XInterface
40*cdf0e10cSrcweir //__________________________________________________________________________________________________
41*cdf0e10cSrcweir Any ArrayIdlClassImpl::queryInterface( const Type & rType )
42*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir 	Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlArray * >( this ) ) );
45*cdf0e10cSrcweir 	return (aRet.hasValue() ? aRet : IdlClassImpl::queryInterface( rType ));
46*cdf0e10cSrcweir }
47*cdf0e10cSrcweir //__________________________________________________________________________________________________
48*cdf0e10cSrcweir void ArrayIdlClassImpl::acquire() throw()
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 	IdlClassImpl::acquire();
51*cdf0e10cSrcweir }
52*cdf0e10cSrcweir //__________________________________________________________________________________________________
53*cdf0e10cSrcweir void ArrayIdlClassImpl::release() throw()
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir 	IdlClassImpl::release();
56*cdf0e10cSrcweir }
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir // XTypeProvider
59*cdf0e10cSrcweir //__________________________________________________________________________________________________
60*cdf0e10cSrcweir Sequence< Type > ArrayIdlClassImpl::getTypes()
61*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 	static OTypeCollection * s_pTypes = 0;
64*cdf0e10cSrcweir 	if (! s_pTypes)
65*cdf0e10cSrcweir 	{
66*cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
67*cdf0e10cSrcweir 		if (! s_pTypes)
68*cdf0e10cSrcweir 		{
69*cdf0e10cSrcweir 			static OTypeCollection s_aTypes(
70*cdf0e10cSrcweir 				::getCppuType( (const Reference< XIdlArray > *)0 ),
71*cdf0e10cSrcweir 				IdlClassImpl::getTypes() );
72*cdf0e10cSrcweir 			s_pTypes = &s_aTypes;
73*cdf0e10cSrcweir 		}
74*cdf0e10cSrcweir 	}
75*cdf0e10cSrcweir 	return s_pTypes->getTypes();
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir //__________________________________________________________________________________________________
78*cdf0e10cSrcweir Sequence< sal_Int8 > ArrayIdlClassImpl::getImplementationId()
79*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	static OImplementationId * s_pId = 0;
82*cdf0e10cSrcweir 	if (! s_pId)
83*cdf0e10cSrcweir 	{
84*cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
85*cdf0e10cSrcweir 		if (! s_pId)
86*cdf0e10cSrcweir 		{
87*cdf0e10cSrcweir 			static OImplementationId s_aId;
88*cdf0e10cSrcweir 			s_pId = &s_aId;
89*cdf0e10cSrcweir 		}
90*cdf0e10cSrcweir 	}
91*cdf0e10cSrcweir 	return s_pId->getImplementationId();
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir // XIdlArray
95*cdf0e10cSrcweir //__________________________________________________________________________________________________
96*cdf0e10cSrcweir void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen )
97*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir 	TypeClass eTC = rArray.getValueTypeClass();
100*cdf0e10cSrcweir 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
101*cdf0e10cSrcweir 	{
102*cdf0e10cSrcweir 		throw IllegalArgumentException(
103*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
104*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 0 );
105*cdf0e10cSrcweir 	}
106*cdf0e10cSrcweir 	if (nLen < 0)
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir 		throw IllegalArgumentException(
109*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal length given!") ),
110*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 1 );
111*cdf0e10cSrcweir 	}
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
114*cdf0e10cSrcweir 	uno_sequence_realloc( ppSeq, (typelib_TypeDescription *)getTypeDescr(),
115*cdf0e10cSrcweir 						  nLen,
116*cdf0e10cSrcweir                           reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
117*cdf0e10cSrcweir                           reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
118*cdf0e10cSrcweir 	rArray.pData = ppSeq;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir //__________________________________________________________________________________________________
121*cdf0e10cSrcweir sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray )
122*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	TypeClass eTC = rArray.getValueTypeClass();
125*cdf0e10cSrcweir 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir 		throw IllegalArgumentException(
128*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
129*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 0 );
130*cdf0e10cSrcweir 	}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	return (*(uno_Sequence **)rArray.getValue())->nElements;
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir //__________________________________________________________________________________________________
135*cdf0e10cSrcweir Any ArrayIdlClassImpl::get( const Any & rArray, sal_Int32 nIndex )
136*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	TypeClass eTC = rArray.getValueTypeClass();
139*cdf0e10cSrcweir 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
140*cdf0e10cSrcweir 	{
141*cdf0e10cSrcweir 		throw IllegalArgumentException(
142*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
143*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 0 );
144*cdf0e10cSrcweir 	}
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
147*cdf0e10cSrcweir 	if (pSeq->nElements <= nIndex)
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		throw ArrayIndexOutOfBoundsException(
150*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
151*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this );
152*cdf0e10cSrcweir 	}
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	Any aRet;
155*cdf0e10cSrcweir 	typelib_TypeDescription * pElemTypeDescr = 0;
156*cdf0e10cSrcweir 	TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
157*cdf0e10cSrcweir 	uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
158*cdf0e10cSrcweir 	uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize],
159*cdf0e10cSrcweir 					   pElemTypeDescr,
160*cdf0e10cSrcweir                        reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
161*cdf0e10cSrcweir 	TYPELIB_DANGER_RELEASE( pElemTypeDescr );
162*cdf0e10cSrcweir 	return aRet;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //__________________________________________________________________________________________________
166*cdf0e10cSrcweir void ArrayIdlClassImpl::set( Any & rArray, sal_Int32 nIndex, const Any & rNewValue )
167*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir 	TypeClass eTC = rArray.getValueTypeClass();
170*cdf0e10cSrcweir 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
171*cdf0e10cSrcweir 	{
172*cdf0e10cSrcweir 		throw IllegalArgumentException(
173*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
174*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 0 );
175*cdf0e10cSrcweir 	}
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
178*cdf0e10cSrcweir 	if (pSeq->nElements <= nIndex)
179*cdf0e10cSrcweir 	{
180*cdf0e10cSrcweir 		throw ArrayIndexOutOfBoundsException(
181*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
182*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this );
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
186*cdf0e10cSrcweir 	uno_sequence_reference2One(
187*cdf0e10cSrcweir         ppSeq, (typelib_TypeDescription *)getTypeDescr(),
188*cdf0e10cSrcweir         reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
189*cdf0e10cSrcweir         reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
190*cdf0e10cSrcweir 	rArray.pData = ppSeq;
191*cdf0e10cSrcweir 	pSeq = *ppSeq;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	typelib_TypeDescription * pElemTypeDescr = 0;
194*cdf0e10cSrcweir 	TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 	if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize],
197*cdf0e10cSrcweir 						 pElemTypeDescr, rNewValue, getReflection() ))
198*cdf0e10cSrcweir 	{
199*cdf0e10cSrcweir 		TYPELIB_DANGER_RELEASE( pElemTypeDescr );
200*cdf0e10cSrcweir 		throw IllegalArgumentException(
201*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("sequence element is not assignable by given value!") ),
202*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 2 );
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir 	TYPELIB_DANGER_RELEASE( pElemTypeDescr );
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir // ArrayIdlClassImpl
208*cdf0e10cSrcweir //__________________________________________________________________________________________________
209*cdf0e10cSrcweir sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
210*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir 	return (xType.is() &&
213*cdf0e10cSrcweir 			(equals( xType ) ||
214*cdf0e10cSrcweir 			 (xType->getTypeClass() == getTypeClass() && // must be sequence|array
215*cdf0e10cSrcweir 			  getComponentType()->isAssignableFrom( xType->getComponentType() ))));
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir //__________________________________________________________________________________________________
218*cdf0e10cSrcweir Reference< XIdlClass > ArrayIdlClassImpl::getComponentType()
219*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir 	return getReflection()->forType( getTypeDescr()->pType );
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir //__________________________________________________________________________________________________
224*cdf0e10cSrcweir Reference< XIdlArray > ArrayIdlClassImpl::getArray()
225*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	return this;
228*cdf0e10cSrcweir }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 
233