1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 #include <typelib/typedescription.h>
27 #include <uno/data.h>
28 
29 #include "base.hxx"
30 
31 
32 namespace stoc_corefl
33 {
34 
35 // XInterface
36 //__________________________________________________________________________________________________
queryInterface(const Type & rType)37 Any ArrayIdlClassImpl::queryInterface( const Type & rType )
38 	throw(::com::sun::star::uno::RuntimeException)
39 {
40 	Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlArray * >( this ) ) );
41 	return (aRet.hasValue() ? aRet : IdlClassImpl::queryInterface( rType ));
42 }
43 //__________________________________________________________________________________________________
acquire()44 void ArrayIdlClassImpl::acquire() throw()
45 {
46 	IdlClassImpl::acquire();
47 }
48 //__________________________________________________________________________________________________
release()49 void ArrayIdlClassImpl::release() throw()
50 {
51 	IdlClassImpl::release();
52 }
53 
54 // XTypeProvider
55 //__________________________________________________________________________________________________
getTypes()56 Sequence< Type > ArrayIdlClassImpl::getTypes()
57 	throw (::com::sun::star::uno::RuntimeException)
58 {
59 	static OTypeCollection * s_pTypes = 0;
60 	if (! s_pTypes)
61 	{
62 		MutexGuard aGuard( getMutexAccess() );
63 		if (! s_pTypes)
64 		{
65 			static OTypeCollection s_aTypes(
66 				::getCppuType( (const Reference< XIdlArray > *)0 ),
67 				IdlClassImpl::getTypes() );
68 			s_pTypes = &s_aTypes;
69 		}
70 	}
71 	return s_pTypes->getTypes();
72 }
73 //__________________________________________________________________________________________________
getImplementationId()74 Sequence< sal_Int8 > ArrayIdlClassImpl::getImplementationId()
75 	throw (::com::sun::star::uno::RuntimeException)
76 {
77 	static OImplementationId * s_pId = 0;
78 	if (! s_pId)
79 	{
80 		MutexGuard aGuard( getMutexAccess() );
81 		if (! s_pId)
82 		{
83 			static OImplementationId s_aId;
84 			s_pId = &s_aId;
85 		}
86 	}
87 	return s_pId->getImplementationId();
88 }
89 
90 // XIdlArray
91 //__________________________________________________________________________________________________
realloc(Any & rArray,sal_Int32 nLen)92 void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen )
93 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
94 {
95 	TypeClass eTC = rArray.getValueTypeClass();
96 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
97 	{
98 		throw IllegalArgumentException(
99 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
100 			(XWeak *)(OWeakObject *)this, 0 );
101 	}
102 	if (nLen < 0)
103 	{
104 		throw IllegalArgumentException(
105 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal length given!") ),
106 			(XWeak *)(OWeakObject *)this, 1 );
107 	}
108 
109 	uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
110 	uno_sequence_realloc( ppSeq, (typelib_TypeDescription *)getTypeDescr(),
111 						  nLen,
112                           reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
113                           reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
114 	rArray.pData = ppSeq;
115 }
116 //__________________________________________________________________________________________________
getLen(const Any & rArray)117 sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray )
118 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
119 {
120 	TypeClass eTC = rArray.getValueTypeClass();
121 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
122 	{
123 		throw IllegalArgumentException(
124 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
125 			(XWeak *)(OWeakObject *)this, 0 );
126 	}
127 
128 	return (*(uno_Sequence **)rArray.getValue())->nElements;
129 }
130 //__________________________________________________________________________________________________
get(const Any & rArray,sal_Int32 nIndex)131 Any ArrayIdlClassImpl::get( const Any & rArray, sal_Int32 nIndex )
132 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
133 {
134 	TypeClass eTC = rArray.getValueTypeClass();
135 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
136 	{
137 		throw IllegalArgumentException(
138 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
139 			(XWeak *)(OWeakObject *)this, 0 );
140 	}
141 
142 	uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
143 	if (pSeq->nElements <= nIndex)
144 	{
145 		throw ArrayIndexOutOfBoundsException(
146 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
147 			(XWeak *)(OWeakObject *)this );
148 	}
149 
150 	Any aRet;
151 	typelib_TypeDescription * pElemTypeDescr = 0;
152 	TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
153 	uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
154 	uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize],
155 					   pElemTypeDescr,
156                        reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
157 	TYPELIB_DANGER_RELEASE( pElemTypeDescr );
158 	return aRet;
159 }
160 
161 //__________________________________________________________________________________________________
set(Any & rArray,sal_Int32 nIndex,const Any & rNewValue)162 void ArrayIdlClassImpl::set( Any & rArray, sal_Int32 nIndex, const Any & rNewValue )
163 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
164 {
165 	TypeClass eTC = rArray.getValueTypeClass();
166 	if (eTC != TypeClass_SEQUENCE && eTC != TypeClass_ARRAY)
167 	{
168 		throw IllegalArgumentException(
169 			OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
170 			(XWeak *)(OWeakObject *)this, 0 );
171 	}
172 
173 	uno_Sequence * pSeq = *(uno_Sequence **)rArray.getValue();
174 	if (pSeq->nElements <= nIndex)
175 	{
176 		throw ArrayIndexOutOfBoundsException(
177 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
178 			(XWeak *)(OWeakObject *)this );
179 	}
180 
181 	uno_Sequence ** ppSeq = (uno_Sequence **)rArray.getValue();
182 	uno_sequence_reference2One(
183         ppSeq, (typelib_TypeDescription *)getTypeDescr(),
184         reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
185         reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
186 	rArray.pData = ppSeq;
187 	pSeq = *ppSeq;
188 
189 	typelib_TypeDescription * pElemTypeDescr = 0;
190 	TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
191 
192 	if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize],
193 						 pElemTypeDescr, rNewValue, getReflection() ))
194 	{
195 		TYPELIB_DANGER_RELEASE( pElemTypeDescr );
196 		throw IllegalArgumentException(
197 			OUString( RTL_CONSTASCII_USTRINGPARAM("sequence element is not assignable by given value!") ),
198 			(XWeak *)(OWeakObject *)this, 2 );
199 	}
200 	TYPELIB_DANGER_RELEASE( pElemTypeDescr );
201 }
202 
203 // ArrayIdlClassImpl
204 //__________________________________________________________________________________________________
isAssignableFrom(const Reference<XIdlClass> & xType)205 sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
206 	throw(::com::sun::star::uno::RuntimeException)
207 {
208 	return (xType.is() &&
209 			(equals( xType ) ||
210 			 (xType->getTypeClass() == getTypeClass() && // must be sequence|array
211 			  getComponentType()->isAssignableFrom( xType->getComponentType() ))));
212 }
213 //__________________________________________________________________________________________________
getComponentType()214 Reference< XIdlClass > ArrayIdlClassImpl::getComponentType()
215 	throw(::com::sun::star::uno::RuntimeException)
216 {
217 	return getReflection()->forType( getTypeDescr()->pType );
218 }
219 //__________________________________________________________________________________________________
getArray()220 Reference< XIdlArray > ArrayIdlClassImpl::getArray()
221 	throw(::com::sun::star::uno::RuntimeException)
222 {
223 	return this;
224 }
225 
226 }
227 
228 
229