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_cli_ure.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #pragma warning(push, 1)
32*cdf0e10cSrcweir #include "windows.h"
33*cdf0e10cSrcweir #pragma warning(pop)
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <memory>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "rtl/ustring.hxx"
39*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
40*cdf0e10cSrcweir #include "uno/sequence2.h"
41*cdf0e10cSrcweir #include "typelib/typedescription.hxx"
42*cdf0e10cSrcweir #include "cli_proxy.h"
43*cdf0e10cSrcweir #include "cli_base.h"
44*cdf0e10cSrcweir #include "cli_bridge.h"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #using <cli_uretypes.dll>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #undef VOID
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir namespace css = com::sun::star;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace sri = System::Runtime::InteropServices;
54*cdf0e10cSrcweir namespace sr = System::Reflection;
55*cdf0e10cSrcweir namespace st = System::Text;
56*cdf0e10cSrcweir namespace ucss = unoidl::com::sun::star;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace rtl;
59*cdf0e10cSrcweir using namespace std;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir namespace cli_uno
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir System::String* mapUnoPolymorphicName(System::String* unoName);
65*cdf0e10cSrcweir OUString mapCliTypeName(System::String* typeName);
66*cdf0e10cSrcweir System::String* mapCliPolymorphicName(System::String* unoName);
67*cdf0e10cSrcweir System::String* mapPolymorphicName(System::String* unoName, bool bCliToUno);
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir inline auto_ptr< rtl_mem > seq_allocate( sal_Int32 nElements, sal_Int32 nSize )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir     auto_ptr< rtl_mem > seq(
72*cdf0e10cSrcweir         rtl_mem::allocate( SAL_SEQUENCE_HEADER_SIZE + (nElements * nSize) ) );
73*cdf0e10cSrcweir     uno_Sequence * p = (uno_Sequence *)seq.get();
74*cdf0e10cSrcweir     p->nRefCount = 1;
75*cdf0e10cSrcweir     p->nElements = nElements;
76*cdf0e10cSrcweir     return seq;
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir System::Object* Bridge::map_uno2cli(uno_Interface * pUnoI, typelib_InterfaceTypeDescription *pTD) const
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir     System::Object* retVal= NULL;
83*cdf0e10cSrcweir // get oid
84*cdf0e10cSrcweir     rtl_uString * pOid = 0;
85*cdf0e10cSrcweir     (*m_uno_env->getObjectIdentifier)( m_uno_env, &pOid, pUnoI );
86*cdf0e10cSrcweir     OSL_ASSERT( 0 != pOid );
87*cdf0e10cSrcweir     OUString oid(pOid, SAL_NO_ACQUIRE);
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	//see if the interface was already mapped
90*cdf0e10cSrcweir     System::Type* ifaceType= mapUnoType(reinterpret_cast<typelib_TypeDescription*>(pTD));
91*cdf0e10cSrcweir     System::String* sOid= mapUnoString(oid.pData);
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	System::Threading::Monitor::Enter( CliEnvHolder::g_cli_env );
94*cdf0e10cSrcweir     try
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir 		retVal = CliEnvHolder::g_cli_env->getRegisteredInterface(sOid, ifaceType);
97*cdf0e10cSrcweir         if (retVal)
98*cdf0e10cSrcweir         {
99*cdf0e10cSrcweir             // There is already an registered object. It can either be a proxy
100*cdf0e10cSrcweir             // for the UNO object or a real cli object. In the first case we
101*cdf0e10cSrcweir             // tell the proxy that it shall also represent the current UNO
102*cdf0e10cSrcweir             // interface. If it already does that, then it does nothing
103*cdf0e10cSrcweir             if (srr::RemotingServices::IsTransparentProxy(retVal))
104*cdf0e10cSrcweir             {
105*cdf0e10cSrcweir                 UnoInterfaceProxy* p = static_cast<UnoInterfaceProxy*>(
106*cdf0e10cSrcweir                     srr::RemotingServices::GetRealProxy(retVal));
107*cdf0e10cSrcweir                 p->addUnoInterface(pUnoI, pTD);
108*cdf0e10cSrcweir             }
109*cdf0e10cSrcweir         }
110*cdf0e10cSrcweir         else
111*cdf0e10cSrcweir         {
112*cdf0e10cSrcweir             retVal = UnoInterfaceProxy::create(
113*cdf0e10cSrcweir                 (Bridge *) this, pUnoI, pTD, oid );
114*cdf0e10cSrcweir         }
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir     __finally
117*cdf0e10cSrcweir     {
118*cdf0e10cSrcweir 		System::Threading::Monitor::Exit( CliEnvHolder::g_cli_env );
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     return retVal;
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir uno_Interface* Bridge::map_cli2uno(System::Object* cliObj, typelib_TypeDescription *pTD) const
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     uno_Interface* retIface = NULL;
127*cdf0e10cSrcweir     // get oid from dot net environment
128*cdf0e10cSrcweir 	System::String* ds_oid = CliEnvHolder::g_cli_env->getObjectIdentifier( cliObj);
129*cdf0e10cSrcweir     OUString ousOid = mapCliString(ds_oid);
130*cdf0e10cSrcweir     // look if interface is already mapped
131*cdf0e10cSrcweir     m_uno_env->getRegisteredInterface(m_uno_env, (void**) &retIface, ousOid.pData,
132*cdf0e10cSrcweir                                       (typelib_InterfaceTypeDescription*) pTD);
133*cdf0e10cSrcweir     if ( ! retIface)
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir         System::Threading::Monitor::Enter(__typeof(Cli_environment));
136*cdf0e10cSrcweir         try
137*cdf0e10cSrcweir         {
138*cdf0e10cSrcweir             m_uno_env->getRegisteredInterface(m_uno_env, (void**) &retIface, ousOid.pData,
139*cdf0e10cSrcweir                                                (typelib_InterfaceTypeDescription*) pTD);
140*cdf0e10cSrcweir             if ( ! retIface)
141*cdf0e10cSrcweir             {
142*cdf0e10cSrcweir                 retIface = CliProxy::create((Bridge*)this, cliObj, pTD, ousOid);
143*cdf0e10cSrcweir             }
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir         __finally
146*cdf0e10cSrcweir         {
147*cdf0e10cSrcweir             System::Threading::Monitor::Exit(__typeof(Cli_environment));
148*cdf0e10cSrcweir         }
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir     return retIface;
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir inline System::Type* loadCliType(rtl_uString * unoName)
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir      return loadCliType(mapUnoTypeName(unoName));
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir System::Type* loadCliType(System::String * unoName)
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     System::Type* retVal= NULL;
161*cdf0e10cSrcweir     try
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         //If unoName denotes a polymorphic type, e.g com.sun.star.beans.Defaulted<System.Char>
164*cdf0e10cSrcweir         //then we remove the type list, otherwise the type could not be loaded.
165*cdf0e10cSrcweir         bool bIsPolymorphic = false;
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir         System::String * loadName = unoName;
168*cdf0e10cSrcweir         int index = unoName->IndexOf('<');
169*cdf0e10cSrcweir         if (index != -1)
170*cdf0e10cSrcweir         {
171*cdf0e10cSrcweir             loadName = unoName->Substring(0, index);
172*cdf0e10cSrcweir             bIsPolymorphic = true;
173*cdf0e10cSrcweir         }
174*cdf0e10cSrcweir         System::AppDomain*  currentDomain = System::AppDomain::CurrentDomain;
175*cdf0e10cSrcweir         sr::Assembly*  assems[] = currentDomain->GetAssemblies();
176*cdf0e10cSrcweir         for (int i = 0; i < assems->Length; i++)
177*cdf0e10cSrcweir         {
178*cdf0e10cSrcweir             retVal = assems[i]->GetType(loadName, false);
179*cdf0e10cSrcweir             if (retVal)
180*cdf0e10cSrcweir                 break;
181*cdf0e10cSrcweir         }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 		if (retVal == NULL)
184*cdf0e10cSrcweir 		{
185*cdf0e10cSrcweir             System::String * msg = new System::String(S"A type could not be loaded: ");
186*cdf0e10cSrcweir             msg = System::String::Concat(msg, loadName);
187*cdf0e10cSrcweir 			throw BridgeRuntimeError(mapCliString(msg));
188*cdf0e10cSrcweir 		}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         if (bIsPolymorphic)
191*cdf0e10cSrcweir         {
192*cdf0e10cSrcweir             retVal = uno::PolymorphicType::GetType(retVal, unoName);
193*cdf0e10cSrcweir         }
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir     catch( System::Exception * e)
196*cdf0e10cSrcweir     {
197*cdf0e10cSrcweir         rtl::OUString ouMessage(mapCliString(e->get_Message()));
198*cdf0e10cSrcweir         throw BridgeRuntimeError(ouMessage);
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir     return retVal;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescription const * pTD)
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir     return mapUnoType(pTD->pWeakRef);
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir System::Type* mapUnoType(typelib_TypeDescriptionReference const * pTD)
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     System::Type * retVal = 0;
212*cdf0e10cSrcweir     switch (pTD->eTypeClass)
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir     case typelib_TypeClass_VOID:
215*cdf0e10cSrcweir         retVal= __typeof(void); break;
216*cdf0e10cSrcweir     case typelib_TypeClass_CHAR:
217*cdf0e10cSrcweir         retVal= __typeof(System::Char); break;
218*cdf0e10cSrcweir     case typelib_TypeClass_BOOLEAN:
219*cdf0e10cSrcweir         retVal= __typeof(System::Boolean); break;
220*cdf0e10cSrcweir     case typelib_TypeClass_BYTE:
221*cdf0e10cSrcweir         retVal= __typeof(System::Byte); break;
222*cdf0e10cSrcweir     case typelib_TypeClass_SHORT:
223*cdf0e10cSrcweir         retVal= __typeof(System::Int16); break;
224*cdf0e10cSrcweir     case typelib_TypeClass_UNSIGNED_SHORT:
225*cdf0e10cSrcweir         retVal= __typeof(System::UInt16); break;
226*cdf0e10cSrcweir     case typelib_TypeClass_LONG:
227*cdf0e10cSrcweir         retVal= __typeof(System::Int32); break;
228*cdf0e10cSrcweir     case typelib_TypeClass_UNSIGNED_LONG:
229*cdf0e10cSrcweir         retVal= __typeof(System::UInt32); break;
230*cdf0e10cSrcweir     case typelib_TypeClass_HYPER:
231*cdf0e10cSrcweir         retVal= __typeof(System::Int64); break;
232*cdf0e10cSrcweir     case typelib_TypeClass_UNSIGNED_HYPER:
233*cdf0e10cSrcweir         retVal= __typeof(System::UInt64); break;
234*cdf0e10cSrcweir     case typelib_TypeClass_FLOAT:
235*cdf0e10cSrcweir         retVal= __typeof(System::Single); break;
236*cdf0e10cSrcweir     case typelib_TypeClass_DOUBLE:
237*cdf0e10cSrcweir         retVal= __typeof(System::Double); break;
238*cdf0e10cSrcweir     case typelib_TypeClass_STRING:
239*cdf0e10cSrcweir         retVal= __typeof(System::String); break;
240*cdf0e10cSrcweir     case typelib_TypeClass_TYPE:
241*cdf0e10cSrcweir         retVal= __typeof(System::Type); break;
242*cdf0e10cSrcweir     case typelib_TypeClass_ANY:
243*cdf0e10cSrcweir         retVal= __typeof(uno::Any); break;
244*cdf0e10cSrcweir     case typelib_TypeClass_ENUM:
245*cdf0e10cSrcweir     case typelib_TypeClass_STRUCT:
246*cdf0e10cSrcweir     case typelib_TypeClass_EXCEPTION:
247*cdf0e10cSrcweir         retVal= loadCliType(pTD->pTypeName); break;
248*cdf0e10cSrcweir     case typelib_TypeClass_INTERFACE:
249*cdf0e10cSrcweir     {
250*cdf0e10cSrcweir         //special handling for XInterface, since it does not exist in cli.
251*cdf0e10cSrcweir 		rtl::OUString usXInterface(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface"));
252*cdf0e10cSrcweir 		if (usXInterface.equals(pTD->pTypeName))
253*cdf0e10cSrcweir 			retVal= __typeof(System::Object);
254*cdf0e10cSrcweir 		else
255*cdf0e10cSrcweir             retVal= loadCliType(pTD->pTypeName);
256*cdf0e10cSrcweir         break;
257*cdf0e10cSrcweir     }
258*cdf0e10cSrcweir     case typelib_TypeClass_SEQUENCE:
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         css::uno::TypeDescription seqType(
261*cdf0e10cSrcweir             const_cast<typelib_TypeDescriptionReference*>(pTD));
262*cdf0e10cSrcweir         typelib_TypeDescriptionReference* pElementTDRef=
263*cdf0e10cSrcweir             reinterpret_cast<typelib_IndirectTypeDescription*>(seqType.get())->pType;
264*cdf0e10cSrcweir         switch (pElementTDRef->eTypeClass)
265*cdf0e10cSrcweir         {
266*cdf0e10cSrcweir         case typelib_TypeClass_CHAR:
267*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArChar)); break;
268*cdf0e10cSrcweir         case typelib_TypeClass_BOOLEAN:
269*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArBoolean));
270*cdf0e10cSrcweir             break;
271*cdf0e10cSrcweir         case typelib_TypeClass_BYTE:
272*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArByte));
273*cdf0e10cSrcweir             break;
274*cdf0e10cSrcweir         case typelib_TypeClass_SHORT:
275*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArInt16));
276*cdf0e10cSrcweir             break;
277*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_SHORT:
278*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArUInt16));
279*cdf0e10cSrcweir             break;
280*cdf0e10cSrcweir         case typelib_TypeClass_LONG:
281*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArInt32));
282*cdf0e10cSrcweir             break;
283*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_LONG:
284*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArUInt32));
285*cdf0e10cSrcweir             break;
286*cdf0e10cSrcweir         case typelib_TypeClass_HYPER:
287*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArInt64));
288*cdf0e10cSrcweir             break;
289*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_HYPER:
290*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArUInt64));
291*cdf0e10cSrcweir             break;
292*cdf0e10cSrcweir         case typelib_TypeClass_FLOAT:
293*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArSingle));
294*cdf0e10cSrcweir             break;
295*cdf0e10cSrcweir         case typelib_TypeClass_DOUBLE:
296*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArDouble));
297*cdf0e10cSrcweir             break;
298*cdf0e10cSrcweir         case typelib_TypeClass_STRING:
299*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArString));
300*cdf0e10cSrcweir             break;
301*cdf0e10cSrcweir         case typelib_TypeClass_TYPE:
302*cdf0e10cSrcweir             retVal= System::Type::GetType(const_cast<System::String*>(Constants::sArType));
303*cdf0e10cSrcweir             break;
304*cdf0e10cSrcweir         case typelib_TypeClass_ANY:
305*cdf0e10cSrcweir         case typelib_TypeClass_ENUM:
306*cdf0e10cSrcweir         case typelib_TypeClass_EXCEPTION:
307*cdf0e10cSrcweir         case typelib_TypeClass_STRUCT:
308*cdf0e10cSrcweir         case typelib_TypeClass_INTERFACE:
309*cdf0e10cSrcweir         case typelib_TypeClass_SEQUENCE:
310*cdf0e10cSrcweir         {
311*cdf0e10cSrcweir             retVal= loadCliType(pTD->pTypeName);
312*cdf0e10cSrcweir             break;
313*cdf0e10cSrcweir         }
314*cdf0e10cSrcweir         default:
315*cdf0e10cSrcweir             //All cases should be handled by the case statements above
316*cdf0e10cSrcweir             OSL_ASSERT(0);
317*cdf0e10cSrcweir             break;
318*cdf0e10cSrcweir         }
319*cdf0e10cSrcweir         break;
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir     default:
322*cdf0e10cSrcweir         OSL_ASSERT(false);
323*cdf0e10cSrcweir         break;
324*cdf0e10cSrcweir     }
325*cdf0e10cSrcweir     return retVal;
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir /** Returns an acquired td.
329*cdf0e10cSrcweir  */
330*cdf0e10cSrcweir typelib_TypeDescriptionReference* mapCliType(System::Type* cliType)
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir     typelib_TypeDescriptionReference* retVal= NULL;
333*cdf0e10cSrcweir     if (cliType == NULL)
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         retVal = * typelib_static_type_getByTypeClass(
336*cdf0e10cSrcweir             typelib_TypeClass_VOID );
337*cdf0e10cSrcweir         typelib_typedescriptionreference_acquire( retVal );
338*cdf0e10cSrcweir         return retVal;
339*cdf0e10cSrcweir     }
340*cdf0e10cSrcweir     //check for Enum first,
341*cdf0e10cSrcweir     //because otherwise case System::TypeCode::Int32 applies
342*cdf0e10cSrcweir     if (cliType->get_IsEnum())
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         OUString usTypeName= mapCliTypeName(cliType->get_FullName());
345*cdf0e10cSrcweir         css::uno::Type unoType(css::uno::TypeClass_ENUM, usTypeName);
346*cdf0e10cSrcweir         retVal= unoType.getTypeLibType();
347*cdf0e10cSrcweir         typelib_typedescriptionreference_acquire(retVal);
348*cdf0e10cSrcweir     }
349*cdf0e10cSrcweir     else
350*cdf0e10cSrcweir     {
351*cdf0e10cSrcweir         switch (System::Type::GetTypeCode(cliType))
352*cdf0e10cSrcweir         {
353*cdf0e10cSrcweir         case System::TypeCode::Boolean:
354*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
355*cdf0e10cSrcweir                 typelib_TypeClass_BOOLEAN );
356*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
357*cdf0e10cSrcweir             break;
358*cdf0e10cSrcweir         case System::TypeCode::Char:
359*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
360*cdf0e10cSrcweir                 typelib_TypeClass_CHAR );
361*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
362*cdf0e10cSrcweir             break;
363*cdf0e10cSrcweir         case System::TypeCode::Byte:
364*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
365*cdf0e10cSrcweir                 typelib_TypeClass_BYTE );
366*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
367*cdf0e10cSrcweir             break;
368*cdf0e10cSrcweir         case System::TypeCode::Int16:
369*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
370*cdf0e10cSrcweir                 typelib_TypeClass_SHORT );
371*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
372*cdf0e10cSrcweir             break;
373*cdf0e10cSrcweir         case System::TypeCode::Int32:
374*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
375*cdf0e10cSrcweir                 typelib_TypeClass_LONG );
376*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
377*cdf0e10cSrcweir             break;
378*cdf0e10cSrcweir         case System::TypeCode::Int64:
379*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
380*cdf0e10cSrcweir                 typelib_TypeClass_HYPER );
381*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
382*cdf0e10cSrcweir             break;
383*cdf0e10cSrcweir         case System::TypeCode::UInt16:
384*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
385*cdf0e10cSrcweir                 typelib_TypeClass_UNSIGNED_SHORT );
386*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
387*cdf0e10cSrcweir             break;
388*cdf0e10cSrcweir         case System::TypeCode::UInt32:
389*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
390*cdf0e10cSrcweir                 typelib_TypeClass_UNSIGNED_LONG );
391*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
392*cdf0e10cSrcweir             break;
393*cdf0e10cSrcweir         case System::TypeCode::UInt64:
394*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
395*cdf0e10cSrcweir                 typelib_TypeClass_UNSIGNED_HYPER );
396*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
397*cdf0e10cSrcweir             break;
398*cdf0e10cSrcweir         case System::TypeCode::Single:
399*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
400*cdf0e10cSrcweir                 typelib_TypeClass_FLOAT );
401*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
402*cdf0e10cSrcweir             break;
403*cdf0e10cSrcweir         case System::TypeCode::Double:
404*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
405*cdf0e10cSrcweir                 typelib_TypeClass_DOUBLE );
406*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
407*cdf0e10cSrcweir             break;
408*cdf0e10cSrcweir         case System::TypeCode::String:
409*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
410*cdf0e10cSrcweir                 typelib_TypeClass_STRING );
411*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
412*cdf0e10cSrcweir             break;
413*cdf0e10cSrcweir         default:
414*cdf0e10cSrcweir             break;
415*cdf0e10cSrcweir         }
416*cdf0e10cSrcweir     }
417*cdf0e10cSrcweir     if (retVal == NULL)
418*cdf0e10cSrcweir     {
419*cdf0e10cSrcweir         System::String* cliTypeName= cliType->get_FullName();
420*cdf0e10cSrcweir         // Void
421*cdf0e10cSrcweir         if (const_cast<System::String*>(Constants::sVoid)->Equals(
422*cdf0e10cSrcweir                 cliTypeName))
423*cdf0e10cSrcweir         {
424*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
425*cdf0e10cSrcweir                 typelib_TypeClass_VOID );
426*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
427*cdf0e10cSrcweir         }
428*cdf0e10cSrcweir         // Type
429*cdf0e10cSrcweir         else if (const_cast<System::String*>(Constants::sType)->Equals(
430*cdf0e10cSrcweir                      cliTypeName))
431*cdf0e10cSrcweir         {
432*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
433*cdf0e10cSrcweir                 typelib_TypeClass_TYPE );
434*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir         // Any
437*cdf0e10cSrcweir         else if (const_cast<System::String*>(Constants::sAny)->Equals(
438*cdf0e10cSrcweir                      cliTypeName))
439*cdf0e10cSrcweir         {
440*cdf0e10cSrcweir             retVal = * typelib_static_type_getByTypeClass(
441*cdf0e10cSrcweir                 typelib_TypeClass_ANY );
442*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire( retVal );
443*cdf0e10cSrcweir         }
444*cdf0e10cSrcweir         //struct, interfaces, sequences
445*cdf0e10cSrcweir         else
446*cdf0e10cSrcweir         {
447*cdf0e10cSrcweir             OUString usTypeName;
448*cdf0e10cSrcweir             uno::PolymorphicType * poly = dynamic_cast<uno::PolymorphicType*>(cliType);
449*cdf0e10cSrcweir             if (poly != NULL)
450*cdf0e10cSrcweir                 usTypeName = mapCliTypeName( poly->PolymorphicName);
451*cdf0e10cSrcweir             else
452*cdf0e10cSrcweir                 usTypeName = mapCliTypeName(cliTypeName);
453*cdf0e10cSrcweir             typelib_TypeDescription* td = NULL;
454*cdf0e10cSrcweir             typelib_typedescription_getByName(&td, usTypeName.pData);
455*cdf0e10cSrcweir             if (td)
456*cdf0e10cSrcweir             {
457*cdf0e10cSrcweir                 retVal = td->pWeakRef;
458*cdf0e10cSrcweir                 typelib_typedescriptionreference_acquire(retVal);
459*cdf0e10cSrcweir                 typelib_typedescription_release(td);
460*cdf0e10cSrcweir             }
461*cdf0e10cSrcweir         }
462*cdf0e10cSrcweir     }
463*cdf0e10cSrcweir     if (retVal == NULL)
464*cdf0e10cSrcweir     {
465*cdf0e10cSrcweir         OUStringBuffer buf( 128 );
466*cdf0e10cSrcweir         buf.appendAscii(
467*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("[cli_uno bridge] mapCliType():"
468*cdf0e10cSrcweir                                        "could not map type: ") );
469*cdf0e10cSrcweir         buf.append(mapCliString(cliType->get_FullName()));
470*cdf0e10cSrcweir         throw BridgeRuntimeError( buf.makeStringAndClear() );
471*cdf0e10cSrcweir     }
472*cdf0e10cSrcweir     return retVal;
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir /**
476*cdf0e10cSrcweir     Otherwise a leading "unoidl." is removed.
477*cdf0e10cSrcweir  */
478*cdf0e10cSrcweir System::String* mapUnoTypeName(rtl_uString const * typeName)
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir     OUString usUnoName( const_cast< rtl_uString * >( typeName ) );
481*cdf0e10cSrcweir     st::StringBuilder* buf= new st::StringBuilder();
482*cdf0e10cSrcweir     //determine if the type is a sequence and its dimensions
483*cdf0e10cSrcweir     int dims= 0;
484*cdf0e10cSrcweir     if (usUnoName[0] == '[')
485*cdf0e10cSrcweir     {
486*cdf0e10cSrcweir         sal_Int32 index= 1;
487*cdf0e10cSrcweir         while (true)
488*cdf0e10cSrcweir         {
489*cdf0e10cSrcweir             if (usUnoName[index++] == ']')
490*cdf0e10cSrcweir                 dims++;
491*cdf0e10cSrcweir             if (usUnoName[index++] != '[')
492*cdf0e10cSrcweir                 break;
493*cdf0e10cSrcweir         }
494*cdf0e10cSrcweir         usUnoName = usUnoName.copy(index - 1);
495*cdf0e10cSrcweir     }
496*cdf0e10cSrcweir 	System::String * sUnoName = mapUnoString(usUnoName.pData);
497*cdf0e10cSrcweir 	if (sUnoName->Equals(const_cast<System::String*>(Constants::usBool)))
498*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sBoolean));
499*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usChar)))
500*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sChar));
501*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usByte)))
502*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sByte));
503*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usShort)))
504*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sInt16));
505*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usUShort)))
506*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUInt16));
507*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usLong)))
508*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sInt32));
509*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usULong)))
510*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUInt32));
511*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usHyper)))
512*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sInt64));
513*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usUHyper)))
514*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUInt64));
515*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usFloat)))
516*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sSingle));
517*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usDouble)))
518*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sDouble));
519*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usString)))
520*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sString));
521*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usVoid)))
522*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sVoid));
523*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usType)))
524*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sType));
525*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usXInterface)))
526*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sObject));
527*cdf0e10cSrcweir     else if (sUnoName->Equals(const_cast<System::String*>(Constants::usAny)))
528*cdf0e10cSrcweir     {
529*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sAny));
530*cdf0e10cSrcweir     }
531*cdf0e10cSrcweir     else
532*cdf0e10cSrcweir     {
533*cdf0e10cSrcweir         //put "unoidl." at the beginning
534*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sUnoidl));
535*cdf0e10cSrcweir         //for polymorphic struct types remove the brackets, e.g mystruct<bool> -> mystruct
536*cdf0e10cSrcweir 		System::String * sName = mapUnoPolymorphicName(sUnoName);
537*cdf0e10cSrcweir         buf->Append(sName);
538*cdf0e10cSrcweir     }
539*cdf0e10cSrcweir     // apend []
540*cdf0e10cSrcweir     for (;dims--;)
541*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::sBrackets));
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     return buf->ToString();
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir /** For example, there is a uno type
550*cdf0e10cSrcweir     com.sun.star.Foo<char, long>.
551*cdf0e10cSrcweir     The values in the type list
552*cdf0e10cSrcweir     are uno types and are replaced by cli types, such as System.Char,
553*cdf0e10cSrcweir     System.Int32, etc.
554*cdf0e10cSrcweir     The pr�fix unoidl is not added.
555*cdf0e10cSrcweir  */
556*cdf0e10cSrcweir inline System::String* mapUnoPolymorphicName(System::String* unoName)
557*cdf0e10cSrcweir {
558*cdf0e10cSrcweir        return mapPolymorphicName(unoName, false);
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir /** For example, there is a type name such as
561*cdf0e10cSrcweir     com.sun.star.Foo<System.Char, System.Int32>.
562*cdf0e10cSrcweir     The values in the type list
563*cdf0e10cSrcweir     are CLI types and are replaced by uno types, such as char,
564*cdf0e10cSrcweir     long, etc.
565*cdf0e10cSrcweir     The pr�fix unoidl remains.
566*cdf0e10cSrcweir  */
567*cdf0e10cSrcweir inline System::String* mapCliPolymorphicName(System::String* unoName)
568*cdf0e10cSrcweir {
569*cdf0e10cSrcweir     return mapPolymorphicName(unoName, true);
570*cdf0e10cSrcweir }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir System::String* mapPolymorphicName(System::String* unoName, bool bCliToUno)
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir     int index = unoName->IndexOf('<');
575*cdf0e10cSrcweir     if (index == -1)
576*cdf0e10cSrcweir         return unoName;
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir     System::Text::StringBuilder * builder = new System::Text::StringBuilder(256);
579*cdf0e10cSrcweir     builder->Append(unoName->Substring(0, index +1 ));
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir 	//Find the first occurrence of ','
582*cdf0e10cSrcweir 	//If the parameter is a polymorphic struct then we neede to ignore everything
583*cdf0e10cSrcweir 	//between the brackets because it can also contain commas
584*cdf0e10cSrcweir     //get the type list within < and >
585*cdf0e10cSrcweir 	int endIndex = unoName->Length - 1;
586*cdf0e10cSrcweir 	index++;
587*cdf0e10cSrcweir 	int cur = index;
588*cdf0e10cSrcweir 	int countParams = 0;
589*cdf0e10cSrcweir 	while (cur <= endIndex)
590*cdf0e10cSrcweir 	{
591*cdf0e10cSrcweir 		System::Char c = unoName->Chars[cur];
592*cdf0e10cSrcweir 		if (c == ',' || c == '>')
593*cdf0e10cSrcweir 		{
594*cdf0e10cSrcweir 			//insert a comma if needed
595*cdf0e10cSrcweir 			if (countParams != 0)
596*cdf0e10cSrcweir 				builder->Append(S",");
597*cdf0e10cSrcweir 			countParams++;
598*cdf0e10cSrcweir 			System::String * sParam = unoName->Substring(index, cur - index);
599*cdf0e10cSrcweir 			//skip the comma
600*cdf0e10cSrcweir 			cur++;
601*cdf0e10cSrcweir 			//the the index to the beginning of the next param
602*cdf0e10cSrcweir 			index = cur;
603*cdf0e10cSrcweir             if (bCliToUno)
604*cdf0e10cSrcweir             {
605*cdf0e10cSrcweir                 builder->Append(mapCliTypeName(sParam));
606*cdf0e10cSrcweir             }
607*cdf0e10cSrcweir             else
608*cdf0e10cSrcweir             {
609*cdf0e10cSrcweir                 OUString s = mapCliString(sParam);
610*cdf0e10cSrcweir                 builder->Append(mapUnoTypeName(s.pData));
611*cdf0e10cSrcweir             }
612*cdf0e10cSrcweir 		}
613*cdf0e10cSrcweir 		else if (c == '<')
614*cdf0e10cSrcweir 		{
615*cdf0e10cSrcweir 			cur++;
616*cdf0e10cSrcweir 			//continue until the matching '>'
617*cdf0e10cSrcweir 			int numNested = 0;
618*cdf0e10cSrcweir 			for (;;cur++)
619*cdf0e10cSrcweir 			{
620*cdf0e10cSrcweir 				System::Char curChar = unoName->Chars[cur];
621*cdf0e10cSrcweir 				if (curChar == '<')
622*cdf0e10cSrcweir 				{
623*cdf0e10cSrcweir 					numNested ++;
624*cdf0e10cSrcweir 				}
625*cdf0e10cSrcweir 				else if (curChar == '>')
626*cdf0e10cSrcweir 				{
627*cdf0e10cSrcweir 					if (numNested > 0)
628*cdf0e10cSrcweir 						numNested--;
629*cdf0e10cSrcweir 					else
630*cdf0e10cSrcweir 						break;
631*cdf0e10cSrcweir 				}
632*cdf0e10cSrcweir 			}
633*cdf0e10cSrcweir 		}
634*cdf0e10cSrcweir 		cur++;
635*cdf0e10cSrcweir 	}
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir     builder->Append((System::Char) '>');
638*cdf0e10cSrcweir     return builder->ToString();
639*cdf0e10cSrcweir }
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir OUString mapCliTypeName(System::String* typeName)
642*cdf0e10cSrcweir {
643*cdf0e10cSrcweir     int dims= 0;
644*cdf0e10cSrcweir     // Array? determine the "rank" (number of "[]")
645*cdf0e10cSrcweir     // move from the rightmost end to the left, for example
646*cdf0e10cSrcweir     // unoidl.PolymorphicStruct<System.Char[]>[]
647*cdf0e10cSrcweir     // has only a "dimension" of 1
648*cdf0e10cSrcweir 	int cur = typeName->Length - 1;
649*cdf0e10cSrcweir     bool bRightBracket = false;
650*cdf0e10cSrcweir 	while (cur >= 0)
651*cdf0e10cSrcweir 	{
652*cdf0e10cSrcweir 		System::Char c = typeName->Chars[cur];
653*cdf0e10cSrcweir 		if (c == ']')
654*cdf0e10cSrcweir 		{
655*cdf0e10cSrcweir             bRightBracket = true;
656*cdf0e10cSrcweir 		}
657*cdf0e10cSrcweir         else if (c == '[')
658*cdf0e10cSrcweir         {
659*cdf0e10cSrcweir             if (!bRightBracket)
660*cdf0e10cSrcweir                 throw BridgeRuntimeError(
661*cdf0e10cSrcweir                     OUSTR("Typename is wrong. No matching brackets for sequence. Name is: ") +
662*cdf0e10cSrcweir                     mapCliString(typeName));
663*cdf0e10cSrcweir             bRightBracket = false;
664*cdf0e10cSrcweir             dims ++;
665*cdf0e10cSrcweir         }
666*cdf0e10cSrcweir         else
667*cdf0e10cSrcweir         {
668*cdf0e10cSrcweir             if (bRightBracket)
669*cdf0e10cSrcweir                 throw BridgeRuntimeError(
670*cdf0e10cSrcweir                     OUSTR("Typename is wrong. No matching brackets for sequence. Name is: ") +
671*cdf0e10cSrcweir                     mapCliString(typeName));
672*cdf0e10cSrcweir             break;
673*cdf0e10cSrcweir         }
674*cdf0e10cSrcweir         cur--;
675*cdf0e10cSrcweir 	}
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir     if (bRightBracket || cur < 0)
678*cdf0e10cSrcweir         throw BridgeRuntimeError(
679*cdf0e10cSrcweir             OUSTR("Typename is wrong. ") +
680*cdf0e10cSrcweir             mapCliString(typeName));
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir     typeName = typeName->Substring(0, cur + 1);
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir 	System::Text::StringBuilder * buf = new System::Text::StringBuilder(512);
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir     //Put the "[]" at the beginning of the uno type name
687*cdf0e10cSrcweir     for (;dims--;)
688*cdf0e10cSrcweir 		buf->Append(const_cast<System::String*>(Constants::usBrackets));
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir     if (typeName->Equals(const_cast<System::String*>(Constants::sBoolean)))
691*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usBool));
692*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sChar)))
693*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usChar));
694*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sByte)))
695*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usByte));
696*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sInt16)))
697*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usShort));
698*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sUInt16)))
699*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usUShort));
700*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sInt32)))
701*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usLong));
702*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sUInt32)))
703*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usULong));
704*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sInt64)))
705*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usHyper));
706*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sUInt64)))
707*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usUHyper));
708*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sSingle)))
709*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usFloat));
710*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sDouble)))
711*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usDouble));
712*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sString)))
713*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usString));
714*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sVoid)))
715*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usVoid));
716*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sType)))
717*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usType));
718*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sObject)))
719*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usXInterface));
720*cdf0e10cSrcweir     else if (typeName->Equals(const_cast<System::String*>(Constants::sAny)))
721*cdf0e10cSrcweir         buf->Append(const_cast<System::String*>(Constants::usAny));
722*cdf0e10cSrcweir     else
723*cdf0e10cSrcweir     {
724*cdf0e10cSrcweir         System::String * sName = mapCliPolymorphicName(typeName);
725*cdf0e10cSrcweir         int i= sName->IndexOf(L'.');
726*cdf0e10cSrcweir         buf->Append(sName->Substring(i + 1));
727*cdf0e10cSrcweir     }
728*cdf0e10cSrcweir     return mapCliString(buf->ToString());
729*cdf0e10cSrcweir }
730*cdf0e10cSrcweir /** Maps uno types to dot net types.
731*cdf0e10cSrcweir  *  If uno_data is null then the type description is converted to System::Type
732*cdf0e10cSrcweir  */
733*cdf0e10cSrcweir inline System::String* mapUnoString( rtl_uString const * data)
734*cdf0e10cSrcweir {
735*cdf0e10cSrcweir     OSL_ASSERT(data);
736*cdf0e10cSrcweir     return new System::String((__wchar_t*) data->buffer, 0, data->length);
737*cdf0e10cSrcweir }
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir OUString mapCliString(System::String const * data)
740*cdf0e10cSrcweir {
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir     if (data != NULL)
743*cdf0e10cSrcweir     {
744*cdf0e10cSrcweir         OSL_ASSERT(sizeof(wchar_t) == sizeof(sal_Unicode));
745*cdf0e10cSrcweir         wchar_t const __pin * pdata= PtrToStringChars(data);
746*cdf0e10cSrcweir         return OUString(pdata, const_cast<System::String*>(data)->get_Length());
747*cdf0e10cSrcweir     }
748*cdf0e10cSrcweir     else
749*cdf0e10cSrcweir     {
750*cdf0e10cSrcweir         return OUString();
751*cdf0e10cSrcweir     }
752*cdf0e10cSrcweir }
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir // ToDo convert cli types to expected types, e.g a long to a short where the uno type
755*cdf0e10cSrcweir // is a sal_Int16. This could be necessary if a scripting language (typeless) is used
756*cdf0e10cSrcweir // @param assign the uno_data has to be destructed (in/out args)
757*cdf0e10cSrcweir void Bridge::map_to_uno(void * uno_data, System::Object* cli_data,
758*cdf0e10cSrcweir                         typelib_TypeDescriptionReference * type,
759*cdf0e10cSrcweir                         bool assign) const
760*cdf0e10cSrcweir {
761*cdf0e10cSrcweir     try{
762*cdf0e10cSrcweir         switch (type->eTypeClass)
763*cdf0e10cSrcweir         {
764*cdf0e10cSrcweir         case typelib_TypeClass_VOID:
765*cdf0e10cSrcweir             break;
766*cdf0e10cSrcweir         case typelib_TypeClass_CHAR:
767*cdf0e10cSrcweir         {
768*cdf0e10cSrcweir             System::Char aChar= *__try_cast<System::Char*>(cli_data);
769*cdf0e10cSrcweir             *(sal_Unicode*) uno_data= aChar;
770*cdf0e10cSrcweir             break;
771*cdf0e10cSrcweir         }
772*cdf0e10cSrcweir         case typelib_TypeClass_BOOLEAN:
773*cdf0e10cSrcweir         {
774*cdf0e10cSrcweir             System::Boolean aBool= *__try_cast<System::Boolean*>(cli_data);
775*cdf0e10cSrcweir             *(sal_Bool*)uno_data= aBool == true ? sal_True : sal_False;
776*cdf0e10cSrcweir             break;
777*cdf0e10cSrcweir         }
778*cdf0e10cSrcweir         case typelib_TypeClass_BYTE:
779*cdf0e10cSrcweir         {
780*cdf0e10cSrcweir             System::Byte aByte= *__try_cast<System::Byte*>(cli_data);
781*cdf0e10cSrcweir             *(sal_Int8*) uno_data= aByte;
782*cdf0e10cSrcweir             break;
783*cdf0e10cSrcweir         }
784*cdf0e10cSrcweir         case typelib_TypeClass_SHORT:
785*cdf0e10cSrcweir         {
786*cdf0e10cSrcweir             System::Int16 aShort= *__try_cast<System::Int16*>(cli_data);
787*cdf0e10cSrcweir             *(sal_Int16*) uno_data= aShort;
788*cdf0e10cSrcweir             break;
789*cdf0e10cSrcweir         }
790*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_SHORT:
791*cdf0e10cSrcweir         {
792*cdf0e10cSrcweir             System::UInt16 aUShort= *__try_cast<System::UInt16*>(cli_data);
793*cdf0e10cSrcweir             *(sal_uInt16*) uno_data= aUShort;
794*cdf0e10cSrcweir             break;
795*cdf0e10cSrcweir         }
796*cdf0e10cSrcweir         case typelib_TypeClass_LONG:
797*cdf0e10cSrcweir         {
798*cdf0e10cSrcweir             System::Int32 aLong= *__try_cast<System::Int32*>(cli_data);
799*cdf0e10cSrcweir             *(sal_Int32*) uno_data= aLong;
800*cdf0e10cSrcweir             break;
801*cdf0e10cSrcweir         }
802*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_LONG:
803*cdf0e10cSrcweir         {
804*cdf0e10cSrcweir             System::UInt32 aULong= *__try_cast<System::UInt32*>(cli_data);
805*cdf0e10cSrcweir             *(sal_uInt32*) uno_data= aULong;
806*cdf0e10cSrcweir             break;
807*cdf0e10cSrcweir         }
808*cdf0e10cSrcweir         case typelib_TypeClass_HYPER:
809*cdf0e10cSrcweir         {
810*cdf0e10cSrcweir             System::Int64 aHyper= *__try_cast<System::Int64*>(cli_data);
811*cdf0e10cSrcweir             *(sal_Int64*) uno_data= aHyper;
812*cdf0e10cSrcweir             break;
813*cdf0e10cSrcweir         }
814*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_HYPER:
815*cdf0e10cSrcweir         {
816*cdf0e10cSrcweir             System::UInt64 aLong= *__try_cast<System::UInt64*>(cli_data);
817*cdf0e10cSrcweir             *(sal_uInt64*) uno_data= aLong;
818*cdf0e10cSrcweir             break;
819*cdf0e10cSrcweir         }
820*cdf0e10cSrcweir         case typelib_TypeClass_FLOAT:
821*cdf0e10cSrcweir         {
822*cdf0e10cSrcweir             System::Single aFloat= *__try_cast<System::Single*>(cli_data);
823*cdf0e10cSrcweir             *(float*) uno_data= aFloat;
824*cdf0e10cSrcweir             break;
825*cdf0e10cSrcweir         }
826*cdf0e10cSrcweir         case typelib_TypeClass_DOUBLE:
827*cdf0e10cSrcweir         {
828*cdf0e10cSrcweir             System::Double aDouble= *__try_cast<System::Double*>(cli_data);
829*cdf0e10cSrcweir             *(double*) uno_data= aDouble;
830*cdf0e10cSrcweir             break;
831*cdf0e10cSrcweir         }
832*cdf0e10cSrcweir         case typelib_TypeClass_STRING:
833*cdf0e10cSrcweir         {
834*cdf0e10cSrcweir             if (assign && *(rtl_uString**) uno_data)
835*cdf0e10cSrcweir                 rtl_uString_release(*(rtl_uString**) uno_data);
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir             *(rtl_uString **)uno_data = 0;
838*cdf0e10cSrcweir             if (cli_data == NULL)
839*cdf0e10cSrcweir             {
840*cdf0e10cSrcweir                  rtl_uString_new((rtl_uString**) uno_data);
841*cdf0e10cSrcweir             }
842*cdf0e10cSrcweir             else
843*cdf0e10cSrcweir             {
844*cdf0e10cSrcweir                 System::String *s= __try_cast<System::String*>(cli_data);
845*cdf0e10cSrcweir                 wchar_t const __pin * pdata= PtrToStringChars(s);
846*cdf0e10cSrcweir                 rtl_uString_newFromStr_WithLength( (rtl_uString**) uno_data,
847*cdf0e10cSrcweir                                                   pdata, s->get_Length() );
848*cdf0e10cSrcweir             }
849*cdf0e10cSrcweir             break;
850*cdf0e10cSrcweir         }
851*cdf0e10cSrcweir         case typelib_TypeClass_TYPE:
852*cdf0e10cSrcweir         {
853*cdf0e10cSrcweir             typelib_TypeDescriptionReference* td= mapCliType(__try_cast<System::Type*>(
854*cdf0e10cSrcweir                                                                     cli_data));
855*cdf0e10cSrcweir             if (assign)
856*cdf0e10cSrcweir             {
857*cdf0e10cSrcweir                 typelib_typedescriptionreference_release(
858*cdf0e10cSrcweir                     *(typelib_TypeDescriptionReference **)uno_data );
859*cdf0e10cSrcweir             }
860*cdf0e10cSrcweir             *(typelib_TypeDescriptionReference **)uno_data = td;
861*cdf0e10cSrcweir             break;
862*cdf0e10cSrcweir         }
863*cdf0e10cSrcweir         case typelib_TypeClass_ANY:
864*cdf0e10cSrcweir         {
865*cdf0e10cSrcweir             uno_Any * pAny = (uno_Any *)uno_data;
866*cdf0e10cSrcweir             if (cli_data == NULL) // null-ref or uninitialized any maps to empty any
867*cdf0e10cSrcweir             {
868*cdf0e10cSrcweir                 if (assign)
869*cdf0e10cSrcweir                     uno_any_destruct( pAny, 0 );
870*cdf0e10cSrcweir                 uno_any_construct( pAny, 0, 0, 0 );
871*cdf0e10cSrcweir                 break;
872*cdf0e10cSrcweir             }
873*cdf0e10cSrcweir             uno::Any aAny= *__try_cast<uno::Any*>(cli_data);
874*cdf0e10cSrcweir             css::uno::Type  value_td( mapCliType(aAny.Type), SAL_NO_ACQUIRE);
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir             if (assign)
877*cdf0e10cSrcweir                 uno_any_destruct( pAny, 0 );
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir             try
880*cdf0e10cSrcweir             {
881*cdf0e10cSrcweir                 switch (value_td.getTypeClass())
882*cdf0e10cSrcweir                 {
883*cdf0e10cSrcweir                 case typelib_TypeClass_VOID:
884*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
885*cdf0e10cSrcweir                     break;
886*cdf0e10cSrcweir                 case typelib_TypeClass_CHAR:
887*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
888*cdf0e10cSrcweir                     *(sal_Unicode*) &pAny->pReserved = *__try_cast<System::Char*>(aAny.Value);
889*cdf0e10cSrcweir                     break;
890*cdf0e10cSrcweir                 case typelib_TypeClass_BOOLEAN:
891*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
892*cdf0e10cSrcweir                     *(sal_Bool *) &pAny->pReserved = *__try_cast<System::Boolean*>(aAny.Value);
893*cdf0e10cSrcweir                     break;
894*cdf0e10cSrcweir                 case typelib_TypeClass_BYTE:
895*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
896*cdf0e10cSrcweir                     *(sal_Int8*) &pAny->pReserved =  *__try_cast<System::Byte*>(aAny.Value);
897*cdf0e10cSrcweir                     break;
898*cdf0e10cSrcweir                 case typelib_TypeClass_SHORT:
899*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
900*cdf0e10cSrcweir                     *(sal_Int16*) &pAny->pReserved =  *__try_cast<System::Int16*>(aAny.Value);
901*cdf0e10cSrcweir                     break;
902*cdf0e10cSrcweir                 case typelib_TypeClass_UNSIGNED_SHORT:
903*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
904*cdf0e10cSrcweir                     *(sal_uInt16*) &pAny->pReserved =  *__try_cast<System::UInt16*>(aAny.Value);
905*cdf0e10cSrcweir                     break;
906*cdf0e10cSrcweir                 case typelib_TypeClass_LONG:
907*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
908*cdf0e10cSrcweir                     *(sal_Int32*) &pAny->pReserved =  *__try_cast<System::Int32*>(aAny.Value);
909*cdf0e10cSrcweir                     break;
910*cdf0e10cSrcweir                 case typelib_TypeClass_UNSIGNED_LONG:
911*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
912*cdf0e10cSrcweir                     *(sal_uInt32*) &pAny->pReserved =  *__try_cast<System::UInt32*>(aAny.Value);
913*cdf0e10cSrcweir                     break;
914*cdf0e10cSrcweir                 case typelib_TypeClass_HYPER:
915*cdf0e10cSrcweir                     if (sizeof (sal_Int64) <= sizeof (void *))
916*cdf0e10cSrcweir                     {
917*cdf0e10cSrcweir                         pAny->pData = &pAny->pReserved;
918*cdf0e10cSrcweir                         *(sal_Int64*) &pAny->pReserved = *__try_cast<System::Int64*>(aAny.Value);
919*cdf0e10cSrcweir                     }
920*cdf0e10cSrcweir                     else
921*cdf0e10cSrcweir                     {
922*cdf0e10cSrcweir                         auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (sal_Int64) ) );
923*cdf0e10cSrcweir                         *(sal_Int64 *) mem.get()=  *__try_cast<System::Int64*>(aAny.Value);
924*cdf0e10cSrcweir                         pAny->pData = mem.release();
925*cdf0e10cSrcweir                     }
926*cdf0e10cSrcweir                     break;
927*cdf0e10cSrcweir                 case typelib_TypeClass_UNSIGNED_HYPER:
928*cdf0e10cSrcweir                     if (sizeof (sal_uInt64) <= sizeof (void *))
929*cdf0e10cSrcweir                     {
930*cdf0e10cSrcweir                         pAny->pData = &pAny->pReserved;
931*cdf0e10cSrcweir                         *(sal_uInt64*) &pAny->pReserved = *__try_cast<System::UInt64*>(aAny.Value);
932*cdf0e10cSrcweir                     }
933*cdf0e10cSrcweir                     else
934*cdf0e10cSrcweir                     {
935*cdf0e10cSrcweir                         auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (sal_uInt64) ) );
936*cdf0e10cSrcweir                         *(sal_uInt64 *) mem.get()=  *__try_cast<System::UInt64*>(aAny.Value);
937*cdf0e10cSrcweir                         pAny->pData = mem.release();
938*cdf0e10cSrcweir                     }
939*cdf0e10cSrcweir                     break;
940*cdf0e10cSrcweir                 case typelib_TypeClass_FLOAT:
941*cdf0e10cSrcweir                     if (sizeof (float) <= sizeof (void *))
942*cdf0e10cSrcweir                     {
943*cdf0e10cSrcweir                         pAny->pData = &pAny->pReserved;
944*cdf0e10cSrcweir                         *(float*) &pAny->pReserved = *__try_cast<System::Single*>(aAny.Value);
945*cdf0e10cSrcweir                     }
946*cdf0e10cSrcweir                     else
947*cdf0e10cSrcweir                     {
948*cdf0e10cSrcweir                         auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (float) ) );
949*cdf0e10cSrcweir                         *(float*) mem.get() = *__try_cast<System::Single*>(aAny.Value);
950*cdf0e10cSrcweir                         pAny->pData = mem.release();
951*cdf0e10cSrcweir                     }
952*cdf0e10cSrcweir                     break;
953*cdf0e10cSrcweir                 case typelib_TypeClass_DOUBLE:
954*cdf0e10cSrcweir                     if (sizeof (double) <= sizeof (void *))
955*cdf0e10cSrcweir                     {
956*cdf0e10cSrcweir                         pAny->pData = &pAny->pReserved;
957*cdf0e10cSrcweir                         *(double*) &pAny->pReserved= *__try_cast<System::Double*>(aAny.Value);
958*cdf0e10cSrcweir                     }
959*cdf0e10cSrcweir                     else
960*cdf0e10cSrcweir                     {
961*cdf0e10cSrcweir                         auto_ptr< rtl_mem > mem( rtl_mem::allocate( sizeof (double) ) );
962*cdf0e10cSrcweir                         *(double*) mem.get()= *__try_cast<System::Double*>(aAny.Value);
963*cdf0e10cSrcweir                         pAny->pData= mem.release();
964*cdf0e10cSrcweir                     }
965*cdf0e10cSrcweir                     break;
966*cdf0e10cSrcweir                 case typelib_TypeClass_STRING: // anies often contain strings; copy string directly
967*cdf0e10cSrcweir                 {
968*cdf0e10cSrcweir                     pAny->pData= &pAny->pReserved;
969*cdf0e10cSrcweir                     OUString _s = mapCliString(static_cast<System::String*>(aAny.Value));
970*cdf0e10cSrcweir                     pAny->pReserved= _s.pData;
971*cdf0e10cSrcweir                     rtl_uString_acquire(_s.pData);
972*cdf0e10cSrcweir                     break;
973*cdf0e10cSrcweir                 }
974*cdf0e10cSrcweir                 case typelib_TypeClass_TYPE:
975*cdf0e10cSrcweir                 case typelib_TypeClass_ENUM:  //ToDo copy enum direct
976*cdf0e10cSrcweir                 case typelib_TypeClass_SEQUENCE:
977*cdf0e10cSrcweir                 case typelib_TypeClass_INTERFACE:
978*cdf0e10cSrcweir                     pAny->pData = &pAny->pReserved;
979*cdf0e10cSrcweir                     pAny->pReserved = 0;
980*cdf0e10cSrcweir                     map_to_uno(
981*cdf0e10cSrcweir                         &pAny->pReserved, aAny.Value, value_td.getTypeLibType(),
982*cdf0e10cSrcweir                                                   false /* no assign */);
983*cdf0e10cSrcweir                     break;
984*cdf0e10cSrcweir                 case typelib_TypeClass_STRUCT:
985*cdf0e10cSrcweir                 case typelib_TypeClass_EXCEPTION:
986*cdf0e10cSrcweir                 {
987*cdf0e10cSrcweir                     css::uno::Type anyType(value_td);
988*cdf0e10cSrcweir                     typelib_TypeDescription* td= NULL;
989*cdf0e10cSrcweir                     anyType.getDescription(&td);
990*cdf0e10cSrcweir                     auto_ptr< rtl_mem > mem(rtl_mem::allocate(td->nSize));
991*cdf0e10cSrcweir                     typelib_typedescription_release(td);
992*cdf0e10cSrcweir                     map_to_uno(
993*cdf0e10cSrcweir                         mem.get(), aAny.Value, value_td.getTypeLibType(),
994*cdf0e10cSrcweir                         false /* no assign */);
995*cdf0e10cSrcweir                     pAny->pData = mem.release();
996*cdf0e10cSrcweir                     break;
997*cdf0e10cSrcweir                 }
998*cdf0e10cSrcweir                 default:
999*cdf0e10cSrcweir                 {
1000*cdf0e10cSrcweir                     OUStringBuffer buf( 128 );
1001*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1002*cdf0e10cSrcweir                     buf.append(value_td.getTypeName());
1003*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported value type of any!") );
1004*cdf0e10cSrcweir                     throw BridgeRuntimeError( buf.makeStringAndClear() );
1005*cdf0e10cSrcweir                 }
1006*cdf0e10cSrcweir                 }
1007*cdf0e10cSrcweir             }
1008*cdf0e10cSrcweir             catch(System::InvalidCastException* )
1009*cdf0e10cSrcweir             {
1010*cdf0e10cSrcweir // ToDo check this
1011*cdf0e10cSrcweir                 if (assign)
1012*cdf0e10cSrcweir                     uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
1013*cdf0e10cSrcweir                 OUStringBuffer buf( 256 );
1014*cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():Any") );
1015*cdf0e10cSrcweir                 buf.append(value_td.getTypeName());
1016*cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("]The Any type "));
1017*cdf0e10cSrcweir                 buf.append(value_td.getTypeName());
1018*cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" does not correspont  "
1019*cdf0e10cSrcweir                                                             "to its value type: ") );
1020*cdf0e10cSrcweir                 if(aAny.Value != NULL)
1021*cdf0e10cSrcweir                 {
1022*cdf0e10cSrcweir                     css::uno::Type td(mapCliType(aAny.Value->GetType()), SAL_NO_ACQUIRE);
1023*cdf0e10cSrcweir                     buf.append(td.getTypeName());
1024*cdf0e10cSrcweir                 }
1025*cdf0e10cSrcweir                 if (assign)
1026*cdf0e10cSrcweir                     uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
1027*cdf0e10cSrcweir                 throw BridgeRuntimeError( buf.makeStringAndClear() );
1028*cdf0e10cSrcweir             }
1029*cdf0e10cSrcweir             catch (BridgeRuntimeError& )
1030*cdf0e10cSrcweir             {
1031*cdf0e10cSrcweir                 if (assign)
1032*cdf0e10cSrcweir                     uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
1033*cdf0e10cSrcweir                 throw;
1034*cdf0e10cSrcweir             }
1035*cdf0e10cSrcweir             catch (...)
1036*cdf0e10cSrcweir             {
1037*cdf0e10cSrcweir                 if (assign)
1038*cdf0e10cSrcweir                     uno_any_construct( pAny, 0, 0, 0 ); // restore some valid any
1039*cdf0e10cSrcweir                 throw;
1040*cdf0e10cSrcweir             }
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir             pAny->pType = value_td.getTypeLibType();
1043*cdf0e10cSrcweir             typelib_typedescriptionreference_acquire(pAny->pType);
1044*cdf0e10cSrcweir             break;
1045*cdf0e10cSrcweir         }
1046*cdf0e10cSrcweir         case typelib_TypeClass_ENUM:
1047*cdf0e10cSrcweir         {
1048*cdf0e10cSrcweir             // InvalidCastException is caught at the end of this method
1049*cdf0e10cSrcweir             System::Int32 aEnum= System::Convert::ToInt32((cli_data));
1050*cdf0e10cSrcweir             *(sal_Int32*) uno_data = aEnum;
1051*cdf0e10cSrcweir             break;
1052*cdf0e10cSrcweir         }
1053*cdf0e10cSrcweir         case typelib_TypeClass_STRUCT:
1054*cdf0e10cSrcweir         case typelib_TypeClass_EXCEPTION:
1055*cdf0e10cSrcweir         {
1056*cdf0e10cSrcweir             css::uno::TypeDescription td(type);
1057*cdf0e10cSrcweir             typelib_CompoundTypeDescription * comp_td =
1058*cdf0e10cSrcweir                 (typelib_CompoundTypeDescription*) td.get();
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir             typelib_StructTypeDescription * struct_td = NULL;
1061*cdf0e10cSrcweir             if (type->eTypeClass == typelib_TypeClass_STRUCT)
1062*cdf0e10cSrcweir                 struct_td = (typelib_StructTypeDescription*) td.get();
1063*cdf0e10cSrcweir 
1064*cdf0e10cSrcweir             if ( ! ((typelib_TypeDescription*) comp_td)->bComplete)
1065*cdf0e10cSrcweir                 ::typelib_typedescription_complete(
1066*cdf0e10cSrcweir                     (typelib_TypeDescription**) & comp_td );
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir             sal_Int32 nMembers = comp_td->nMembers;
1069*cdf0e10cSrcweir             boolean bException= false;
1070*cdf0e10cSrcweir             System::Type* cliType = NULL;
1071*cdf0e10cSrcweir             if (cli_data)
1072*cdf0e10cSrcweir                 cliType = cli_data->GetType();
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir             if (0 != comp_td->pBaseTypeDescription)
1075*cdf0e10cSrcweir             {
1076*cdf0e10cSrcweir                 map_to_uno(
1077*cdf0e10cSrcweir                     uno_data, cli_data,
1078*cdf0e10cSrcweir                     ((typelib_TypeDescription *)comp_td->pBaseTypeDescription)->pWeakRef,
1079*cdf0e10cSrcweir                     assign);
1080*cdf0e10cSrcweir             }
1081*cdf0e10cSrcweir             sal_Int32 nPos = 0;
1082*cdf0e10cSrcweir             try
1083*cdf0e10cSrcweir             {
1084*cdf0e10cSrcweir                 typelib_TypeDescriptionReference * member_type= NULL;
1085*cdf0e10cSrcweir 
1086*cdf0e10cSrcweir 				rtl::OUString usUnoException(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception"));
1087*cdf0e10cSrcweir                 for (; nPos < nMembers; ++nPos)
1088*cdf0e10cSrcweir                 {
1089*cdf0e10cSrcweir                     member_type= comp_td->ppTypeRefs[nPos];
1090*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 2
1091*cdf0e10cSrcweir                     System::String* __s;
1092*cdf0e10cSrcweir                     sr::FieldInfo* arFields[];
1093*cdf0e10cSrcweir                     __s = mapUnoString(comp_td->ppMemberNames[nPos]);
1094*cdf0e10cSrcweir                     arFields = cliType != NULL ? cliType->GetFields() : NULL;
1095*cdf0e10cSrcweir #endif
1096*cdf0e10cSrcweir                     System::Object* val= NULL;
1097*cdf0e10cSrcweir                     if (cli_data != NULL)
1098*cdf0e10cSrcweir                     {
1099*cdf0e10cSrcweir                         sr::FieldInfo* aField= cliType->GetField(
1100*cdf0e10cSrcweir                             mapUnoString(comp_td->ppMemberNames[nPos]));
1101*cdf0e10cSrcweir                         // special case for Exception.Message property
1102*cdf0e10cSrcweir                         // The com.sun.star.uno.Exception.Message field is mapped to the
1103*cdf0e10cSrcweir                         // System.Exception property. Type.GetField("Message") returns null
1104*cdf0e10cSrcweir                         if ( ! aField && usUnoException.equals(td.get()->pTypeName))
1105*cdf0e10cSrcweir                         {// get Exception.Message property
1106*cdf0e10cSrcweir 							rtl::OUString usMessageMember(RTL_CONSTASCII_USTRINGPARAM("Message"));
1107*cdf0e10cSrcweir                             if (usMessageMember.equals(comp_td->ppMemberNames[nPos]))
1108*cdf0e10cSrcweir                             {
1109*cdf0e10cSrcweir                                 sr::PropertyInfo* pi= cliType->GetProperty(
1110*cdf0e10cSrcweir                                     mapUnoString(comp_td->ppMemberNames[nPos]));
1111*cdf0e10cSrcweir                                 val= pi->GetValue(cli_data, NULL);
1112*cdf0e10cSrcweir                             }
1113*cdf0e10cSrcweir                             else
1114*cdf0e10cSrcweir                             {
1115*cdf0e10cSrcweir                                 OUStringBuffer buf(512);
1116*cdf0e10cSrcweir                                 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("[map_to_uno(): Member: "));
1117*cdf0e10cSrcweir                                 buf.append(comp_td->ppMemberNames[nPos]);
1118*cdf0e10cSrcweir                                 throw BridgeRuntimeError(buf.makeStringAndClear());
1119*cdf0e10cSrcweir                             }
1120*cdf0e10cSrcweir                         }
1121*cdf0e10cSrcweir                         else
1122*cdf0e10cSrcweir                         {
1123*cdf0e10cSrcweir                             val= aField->GetValue(cli_data);
1124*cdf0e10cSrcweir                         }
1125*cdf0e10cSrcweir                     }
1126*cdf0e10cSrcweir                     void * p = (char *) uno_data + comp_td->pMemberOffsets[ nPos ];
1127*cdf0e10cSrcweir                     //When using polymorphic structs then the parameterized members can be null.
1128*cdf0e10cSrcweir                     //Then we set a default value.
1129*cdf0e10cSrcweir                     bool bDefault = ((struct_td != NULL
1130*cdf0e10cSrcweir                                      && struct_td->pParameterizedTypes != NULL
1131*cdf0e10cSrcweir                                      && struct_td->pParameterizedTypes[nPos] == sal_True
1132*cdf0e10cSrcweir                                       && val == NULL)
1133*cdf0e10cSrcweir                                      || cli_data == NULL) ? true : false;
1134*cdf0e10cSrcweir                     switch (member_type->eTypeClass)
1135*cdf0e10cSrcweir                     {
1136*cdf0e10cSrcweir                     case typelib_TypeClass_CHAR:
1137*cdf0e10cSrcweir                         if (bDefault)
1138*cdf0e10cSrcweir                             *(sal_Unicode*) p = 0;
1139*cdf0e10cSrcweir                         else
1140*cdf0e10cSrcweir                             *(sal_Unicode*) p = *__try_cast<System::Char*>(val);
1141*cdf0e10cSrcweir                         break;
1142*cdf0e10cSrcweir                     case typelib_TypeClass_BOOLEAN:
1143*cdf0e10cSrcweir                         if (bDefault)
1144*cdf0e10cSrcweir                             *(sal_Bool*) p = sal_False;
1145*cdf0e10cSrcweir                         else
1146*cdf0e10cSrcweir                             *(sal_Bool*) p = *__try_cast<System::Boolean*>(val);
1147*cdf0e10cSrcweir                         break;
1148*cdf0e10cSrcweir                     case typelib_TypeClass_BYTE:
1149*cdf0e10cSrcweir                         if (bDefault)
1150*cdf0e10cSrcweir                             *(sal_Int8*) p = 0;
1151*cdf0e10cSrcweir                         else
1152*cdf0e10cSrcweir                             *(sal_Int8*) p = *__try_cast<System::Byte*>(val);
1153*cdf0e10cSrcweir                         break;
1154*cdf0e10cSrcweir                     case typelib_TypeClass_SHORT:
1155*cdf0e10cSrcweir                         if (bDefault)
1156*cdf0e10cSrcweir                             *(sal_Int16*) p = 0;
1157*cdf0e10cSrcweir                         else
1158*cdf0e10cSrcweir                             *(sal_Int16*) p = *__try_cast<System::Int16*>(val);
1159*cdf0e10cSrcweir                         break;
1160*cdf0e10cSrcweir                     case typelib_TypeClass_UNSIGNED_SHORT:
1161*cdf0e10cSrcweir                         if (bDefault)
1162*cdf0e10cSrcweir                             *(sal_uInt16*) p = 0;
1163*cdf0e10cSrcweir                         else
1164*cdf0e10cSrcweir                             *(sal_uInt16*) p = *__try_cast<System::UInt16*>(val);
1165*cdf0e10cSrcweir                         break;
1166*cdf0e10cSrcweir                     case typelib_TypeClass_LONG:
1167*cdf0e10cSrcweir                         if (bDefault)
1168*cdf0e10cSrcweir                             *(sal_Int32*) p = 0;
1169*cdf0e10cSrcweir                         else
1170*cdf0e10cSrcweir                             *(sal_Int32*) p = *__try_cast<System::Int32*>(val);
1171*cdf0e10cSrcweir                         break;
1172*cdf0e10cSrcweir                     case typelib_TypeClass_UNSIGNED_LONG:
1173*cdf0e10cSrcweir                         if (bDefault)
1174*cdf0e10cSrcweir                             *(sal_uInt32*) p = 0;
1175*cdf0e10cSrcweir                         else
1176*cdf0e10cSrcweir                             *(sal_uInt32*) p = *__try_cast<System::UInt32*>(val);
1177*cdf0e10cSrcweir                         break;
1178*cdf0e10cSrcweir                     case typelib_TypeClass_HYPER:
1179*cdf0e10cSrcweir                         if (bDefault)
1180*cdf0e10cSrcweir                             *(sal_Int64*) p = 0;
1181*cdf0e10cSrcweir                         else
1182*cdf0e10cSrcweir                             *(sal_Int64*) p = *__try_cast<System::Int64*>(val);
1183*cdf0e10cSrcweir                         break;
1184*cdf0e10cSrcweir                     case typelib_TypeClass_UNSIGNED_HYPER:
1185*cdf0e10cSrcweir                         if (bDefault)
1186*cdf0e10cSrcweir                             *(sal_uInt64*) p = 0;
1187*cdf0e10cSrcweir                         else
1188*cdf0e10cSrcweir                             *(sal_uInt64*) p= *__try_cast<System::UInt64*>(val);
1189*cdf0e10cSrcweir                         break;
1190*cdf0e10cSrcweir                     case typelib_TypeClass_FLOAT:
1191*cdf0e10cSrcweir                         if (bDefault)
1192*cdf0e10cSrcweir                             *(float*) p = 0.;
1193*cdf0e10cSrcweir                         else
1194*cdf0e10cSrcweir                             *(float*) p = *__try_cast<System::Single*>(val);
1195*cdf0e10cSrcweir                         break;
1196*cdf0e10cSrcweir                     case typelib_TypeClass_DOUBLE:
1197*cdf0e10cSrcweir                         if (bDefault)
1198*cdf0e10cSrcweir                             *(double*) p = 0.;
1199*cdf0e10cSrcweir                         else
1200*cdf0e10cSrcweir                             *(double*) p = *__try_cast<System::Double*>(val);
1201*cdf0e10cSrcweir                         break;
1202*cdf0e10cSrcweir                     default:
1203*cdf0e10cSrcweir                     {   // ToDo enum, should be converted here
1204*cdf0e10cSrcweir                          map_to_uno(p, val, member_type, assign);
1205*cdf0e10cSrcweir                         break;
1206*cdf0e10cSrcweir                     }
1207*cdf0e10cSrcweir                     }
1208*cdf0e10cSrcweir                 }
1209*cdf0e10cSrcweir             }
1210*cdf0e10cSrcweir             catch (BridgeRuntimeError& e)
1211*cdf0e10cSrcweir             {
1212*cdf0e10cSrcweir                 bException= true;
1213*cdf0e10cSrcweir                 OUStringBuffer buf(512);
1214*cdf0e10cSrcweir                 buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("[map_to_uno():"));
1215*cdf0e10cSrcweir                 if (cliType)
1216*cdf0e10cSrcweir                 {
1217*cdf0e10cSrcweir                     buf.append(mapCliString(cliType->get_FullName()));
1218*cdf0e10cSrcweir                     buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("."));
1219*cdf0e10cSrcweir                     buf.append(comp_td->ppMemberNames[nPos]);
1220*cdf0e10cSrcweir                     buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(" "));
1221*cdf0e10cSrcweir                 }
1222*cdf0e10cSrcweir                 buf.append(e.m_message);
1223*cdf0e10cSrcweir                 throw BridgeRuntimeError(buf.makeStringAndClear());
1224*cdf0e10cSrcweir             }
1225*cdf0e10cSrcweir             catch (System::InvalidCastException* )
1226*cdf0e10cSrcweir             {
1227*cdf0e10cSrcweir                 bException= true;
1228*cdf0e10cSrcweir                 OUStringBuffer buf( 256 );
1229*cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1230*cdf0e10cSrcweir                 if (cliType)
1231*cdf0e10cSrcweir                 {
1232*cdf0e10cSrcweir                     buf.append(mapCliString(cliType->get_FullName()));
1233*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("."));
1234*cdf0e10cSrcweir                     buf.append(comp_td->ppMemberNames[nPos]);
1235*cdf0e10cSrcweir                 }
1236*cdf0e10cSrcweir                 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] Value has not the required type."));
1237*cdf0e10cSrcweir                 throw BridgeRuntimeError(buf.makeStringAndClear());
1238*cdf0e10cSrcweir             }
1239*cdf0e10cSrcweir             catch (...)
1240*cdf0e10cSrcweir             {
1241*cdf0e10cSrcweir                 OSL_ASSERT(0);
1242*cdf0e10cSrcweir                 bException= true;
1243*cdf0e10cSrcweir                 throw;
1244*cdf0e10cSrcweir             }
1245*cdf0e10cSrcweir             __finally
1246*cdf0e10cSrcweir             {
1247*cdf0e10cSrcweir                 if (bException && !assign) // if assign then caller cleans up
1248*cdf0e10cSrcweir                 {
1249*cdf0e10cSrcweir                     // cleanup the members which we have converted so far
1250*cdf0e10cSrcweir                     for ( sal_Int32 nCleanup = 0; nCleanup < nPos; ++nCleanup )
1251*cdf0e10cSrcweir                     {
1252*cdf0e10cSrcweir                         uno_type_destructData(
1253*cdf0e10cSrcweir                             uno_data, comp_td->ppTypeRefs[ nCleanup ], 0 );
1254*cdf0e10cSrcweir                     }
1255*cdf0e10cSrcweir                     if (0 != comp_td->pBaseTypeDescription)
1256*cdf0e10cSrcweir                     {
1257*cdf0e10cSrcweir                         uno_destructData(
1258*cdf0e10cSrcweir                             uno_data, (typelib_TypeDescription *)comp_td->pBaseTypeDescription, 0 );
1259*cdf0e10cSrcweir                     }
1260*cdf0e10cSrcweir                 }
1261*cdf0e10cSrcweir             }
1262*cdf0e10cSrcweir             break;
1263*cdf0e10cSrcweir         }
1264*cdf0e10cSrcweir         case typelib_TypeClass_SEQUENCE:
1265*cdf0e10cSrcweir         {
1266*cdf0e10cSrcweir             TypeDescr td( type );
1267*cdf0e10cSrcweir             typelib_TypeDescriptionReference * element_type =
1268*cdf0e10cSrcweir                 ((typelib_IndirectTypeDescription *)td.get())->pType;
1269*cdf0e10cSrcweir 
1270*cdf0e10cSrcweir             auto_ptr< rtl_mem > seq;
1271*cdf0e10cSrcweir 
1272*cdf0e10cSrcweir             System::Array* ar = NULL;
1273*cdf0e10cSrcweir             if (cli_data != NULL)
1274*cdf0e10cSrcweir             {
1275*cdf0e10cSrcweir                 ar = __try_cast<System::Array*>(cli_data);
1276*cdf0e10cSrcweir                 sal_Int32 nElements = ar->GetLength(0);
1277*cdf0e10cSrcweir 
1278*cdf0e10cSrcweir                 try
1279*cdf0e10cSrcweir                 {
1280*cdf0e10cSrcweir                     switch (element_type->eTypeClass)
1281*cdf0e10cSrcweir                     {
1282*cdf0e10cSrcweir                     case typelib_TypeClass_CHAR:
1283*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (sal_Unicode));
1284*cdf0e10cSrcweir                         sri::Marshal::Copy(__try_cast<System::Char[]>(cli_data), 0,
1285*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1286*cdf0e10cSrcweir                         break;
1287*cdf0e10cSrcweir                     case typelib_TypeClass_BOOLEAN:
1288*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (sal_Bool));
1289*cdf0e10cSrcweir                         sri::Marshal::Copy(__try_cast<System::Boolean[]>(cli_data), 0,
1290*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1291*cdf0e10cSrcweir                         break;
1292*cdf0e10cSrcweir                     case typelib_TypeClass_BYTE:
1293*cdf0e10cSrcweir                         seq = seq_allocate( nElements, sizeof (sal_Int8) );
1294*cdf0e10cSrcweir                     sri::Marshal::Copy(__try_cast<System::Byte[]>(cli_data), 0,
1295*cdf0e10cSrcweir                                        & ((uno_Sequence*) seq.get())->elements, nElements);
1296*cdf0e10cSrcweir                     break;
1297*cdf0e10cSrcweir                     case typelib_TypeClass_SHORT:
1298*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (sal_Int16));
1299*cdf0e10cSrcweir                         sri::Marshal::Copy(__try_cast<System::Int16[]>(cli_data), 0,
1300*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1301*cdf0e10cSrcweir                         break;
1302*cdf0e10cSrcweir                     case typelib_TypeClass_UNSIGNED_SHORT:
1303*cdf0e10cSrcweir                         seq = seq_allocate( nElements, sizeof (sal_uInt16) );
1304*cdf0e10cSrcweir                         sri::Marshal::Copy(static_cast<System::Int16[]>(
1305*cdf0e10cSrcweir                                                __try_cast<System::UInt16[]>(cli_data)), 0,
1306*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1307*cdf0e10cSrcweir                         break;
1308*cdf0e10cSrcweir                     case typelib_TypeClass_LONG:
1309*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (sal_Int32));
1310*cdf0e10cSrcweir                         sri::Marshal::Copy(__try_cast<System::Int32[]>(cli_data), 0,
1311*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1312*cdf0e10cSrcweir                         break;
1313*cdf0e10cSrcweir                     case typelib_TypeClass_UNSIGNED_LONG:
1314*cdf0e10cSrcweir                         seq = seq_allocate( nElements, sizeof (sal_uInt32) );
1315*cdf0e10cSrcweir                         sri::Marshal::Copy(static_cast<System::Int32[]>(
1316*cdf0e10cSrcweir                                                __try_cast<System::UInt32[]>(cli_data)), 0,
1317*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1318*cdf0e10cSrcweir                         break;
1319*cdf0e10cSrcweir                     case typelib_TypeClass_HYPER:
1320*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (sal_Int64));
1321*cdf0e10cSrcweir                         sri::Marshal::Copy(__try_cast<System::Int64[]>(cli_data), 0,
1322*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1323*cdf0e10cSrcweir                         break;
1324*cdf0e10cSrcweir                     case typelib_TypeClass_UNSIGNED_HYPER:
1325*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (sal_uInt64));
1326*cdf0e10cSrcweir                         sri::Marshal::Copy(static_cast<System::Int64[]>(
1327*cdf0e10cSrcweir                                                __try_cast<System::UInt64[]>(cli_data)), 0,
1328*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1329*cdf0e10cSrcweir                         break;
1330*cdf0e10cSrcweir                     case typelib_TypeClass_FLOAT:
1331*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (float));
1332*cdf0e10cSrcweir                         sri::Marshal::Copy(__try_cast<System::Single[]>(cli_data), 0,
1333*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1334*cdf0e10cSrcweir                         break;
1335*cdf0e10cSrcweir                     case typelib_TypeClass_DOUBLE:
1336*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (double));
1337*cdf0e10cSrcweir                         sri::Marshal::Copy(__try_cast<System::Double[]>(cli_data), 0,
1338*cdf0e10cSrcweir                                            & ((uno_Sequence*) seq.get())->elements, nElements);
1339*cdf0e10cSrcweir                         break;
1340*cdf0e10cSrcweir                     case typelib_TypeClass_STRING:
1341*cdf0e10cSrcweir                     {
1342*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (rtl_uString*));
1343*cdf0e10cSrcweir                         System::String* arStr[]= __try_cast<System::String*[]>(cli_data);
1344*cdf0e10cSrcweir                         for (int i= 0; i < nElements; i++)
1345*cdf0e10cSrcweir                         {
1346*cdf0e10cSrcweir                             wchar_t const __pin * pdata= PtrToStringChars(arStr[i]);
1347*cdf0e10cSrcweir                             rtl_uString** pStr=  & ((rtl_uString**) &
1348*cdf0e10cSrcweir                                                     ((uno_Sequence*) seq.get())->elements)[i];
1349*cdf0e10cSrcweir                             *pStr= NULL;
1350*cdf0e10cSrcweir                             rtl_uString_newFromStr_WithLength( pStr, pdata,
1351*cdf0e10cSrcweir                                                                arStr[i]->get_Length());
1352*cdf0e10cSrcweir                         }
1353*cdf0e10cSrcweir                         break;
1354*cdf0e10cSrcweir                     }
1355*cdf0e10cSrcweir                     case typelib_TypeClass_ENUM:
1356*cdf0e10cSrcweir                         seq = seq_allocate(nElements, sizeof (sal_Int32));
1357*cdf0e10cSrcweir                         for (int i= 0; i < nElements; i++)
1358*cdf0e10cSrcweir                         {
1359*cdf0e10cSrcweir                             ((sal_Int32*) &((uno_Sequence*) seq.get())->elements)[i]=
1360*cdf0e10cSrcweir                                 System::Convert::ToInt32(ar->GetValue(i));
1361*cdf0e10cSrcweir                         }
1362*cdf0e10cSrcweir                         break;
1363*cdf0e10cSrcweir                     case typelib_TypeClass_TYPE:
1364*cdf0e10cSrcweir                     case typelib_TypeClass_ANY:
1365*cdf0e10cSrcweir                     case typelib_TypeClass_STRUCT:
1366*cdf0e10cSrcweir                     case typelib_TypeClass_EXCEPTION:
1367*cdf0e10cSrcweir                     case typelib_TypeClass_SEQUENCE:
1368*cdf0e10cSrcweir                     case typelib_TypeClass_INTERFACE:
1369*cdf0e10cSrcweir                     {
1370*cdf0e10cSrcweir                         TypeDescr element_td( element_type );
1371*cdf0e10cSrcweir                         seq = seq_allocate( nElements, element_td.get()->nSize );
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir                         for (sal_Int32 nPos = 0; nPos < nElements; ++nPos)
1374*cdf0e10cSrcweir                         {
1375*cdf0e10cSrcweir                             try
1376*cdf0e10cSrcweir                             {
1377*cdf0e10cSrcweir                                 void * p= ((uno_Sequence *) seq.get())->elements +
1378*cdf0e10cSrcweir                                     (nPos * element_td.get()->nSize);
1379*cdf0e10cSrcweir                                 System::Object* elemData= dynamic_cast<System::Array*>(cli_data)->GetValue(nPos);
1380*cdf0e10cSrcweir                                 map_to_uno(
1381*cdf0e10cSrcweir                                     p, elemData, element_td.get()->pWeakRef,
1382*cdf0e10cSrcweir                                     false /* no assign */);
1383*cdf0e10cSrcweir                             }
1384*cdf0e10cSrcweir                             catch (...)
1385*cdf0e10cSrcweir                             {
1386*cdf0e10cSrcweir                                 // cleanup
1387*cdf0e10cSrcweir                                 for ( sal_Int32 nCleanPos = 0; nCleanPos < nPos; ++nCleanPos )
1388*cdf0e10cSrcweir                                 {
1389*cdf0e10cSrcweir                                     void * p =
1390*cdf0e10cSrcweir                                         ((uno_Sequence *)seq.get())->elements +
1391*cdf0e10cSrcweir                                         (nCleanPos * element_td.get()->nSize);
1392*cdf0e10cSrcweir                                     uno_destructData( p, element_td.get(), 0 );
1393*cdf0e10cSrcweir                                 }
1394*cdf0e10cSrcweir                                 throw;
1395*cdf0e10cSrcweir                             }
1396*cdf0e10cSrcweir                         }
1397*cdf0e10cSrcweir                         break;
1398*cdf0e10cSrcweir                     }
1399*cdf0e10cSrcweir                     default:
1400*cdf0e10cSrcweir                     {
1401*cdf0e10cSrcweir                         OUStringBuffer buf( 128 );
1402*cdf0e10cSrcweir                         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1403*cdf0e10cSrcweir                         buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) );
1404*cdf0e10cSrcweir                         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported sequence element type: ") );
1405*cdf0e10cSrcweir                         buf.append( *reinterpret_cast< OUString const * >( &element_type->pTypeName ) );
1406*cdf0e10cSrcweir                         throw BridgeRuntimeError( buf.makeStringAndClear() );
1407*cdf0e10cSrcweir                     }
1408*cdf0e10cSrcweir                     }
1409*cdf0e10cSrcweir                 }
1410*cdf0e10cSrcweir                 catch (BridgeRuntimeError& e)
1411*cdf0e10cSrcweir                 {
1412*cdf0e10cSrcweir                     OUStringBuffer buf( 128 );
1413*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1414*cdf0e10cSrcweir                     buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ));
1415*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] conversion failed\n "));
1416*cdf0e10cSrcweir                     buf.append(e.m_message);
1417*cdf0e10cSrcweir                     throw BridgeRuntimeError(buf.makeStringAndClear());
1418*cdf0e10cSrcweir                 }
1419*cdf0e10cSrcweir                 catch (System::InvalidCastException* )
1420*cdf0e10cSrcweir                 {
1421*cdf0e10cSrcweir                     // Ok, checked
1422*cdf0e10cSrcweir                     OUStringBuffer buf( 128 );
1423*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1424*cdf0e10cSrcweir                     buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName) );
1425*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] could not convert sequence element type: ") );
1426*cdf0e10cSrcweir                     buf.append( *reinterpret_cast< OUString const * >( &element_type->pTypeName ) );
1427*cdf0e10cSrcweir                     throw BridgeRuntimeError( buf.makeStringAndClear() );
1428*cdf0e10cSrcweir                 }
1429*cdf0e10cSrcweir                 catch (...)
1430*cdf0e10cSrcweir                 {
1431*cdf0e10cSrcweir                     OSL_ASSERT(0);
1432*cdf0e10cSrcweir                     throw;
1433*cdf0e10cSrcweir                 }
1434*cdf0e10cSrcweir                 __finally
1435*cdf0e10cSrcweir                     {
1436*cdf0e10cSrcweir                         if (assign)
1437*cdf0e10cSrcweir                             uno_destructData( uno_data, td.get(), 0 );
1438*cdf0e10cSrcweir                     }
1439*cdf0e10cSrcweir             }
1440*cdf0e10cSrcweir             else
1441*cdf0e10cSrcweir             {
1442*cdf0e10cSrcweir                 seq = seq_allocate(0, sizeof (sal_Int32));
1443*cdf0e10cSrcweir             }
1444*cdf0e10cSrcweir             *(uno_Sequence **)uno_data = (uno_Sequence *)seq.release();
1445*cdf0e10cSrcweir             break;
1446*cdf0e10cSrcweir         }
1447*cdf0e10cSrcweir         case typelib_TypeClass_INTERFACE:
1448*cdf0e10cSrcweir         {
1449*cdf0e10cSrcweir             if (assign)
1450*cdf0e10cSrcweir             {
1451*cdf0e10cSrcweir                 uno_Interface * p = *(uno_Interface **)uno_data;
1452*cdf0e10cSrcweir                 if (0 != p)
1453*cdf0e10cSrcweir                     (*p->release)( p );
1454*cdf0e10cSrcweir             }
1455*cdf0e10cSrcweir             if (0 == cli_data) // null-ref
1456*cdf0e10cSrcweir             {
1457*cdf0e10cSrcweir                 *(uno_Interface **)uno_data = 0;
1458*cdf0e10cSrcweir             }
1459*cdf0e10cSrcweir             else
1460*cdf0e10cSrcweir             {
1461*cdf0e10cSrcweir                 TypeDescr td( type );
1462*cdf0e10cSrcweir                 uno_Interface * pUnoI = map_cli2uno(cli_data, td.get());
1463*cdf0e10cSrcweir                 *(uno_Interface **)uno_data = pUnoI;
1464*cdf0e10cSrcweir             }
1465*cdf0e10cSrcweir             break;
1466*cdf0e10cSrcweir         }
1467*cdf0e10cSrcweir         default:
1468*cdf0e10cSrcweir         {
1469*cdf0e10cSrcweir             //ToDo check
1470*cdf0e10cSrcweir             OUStringBuffer buf( 128 );
1471*cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1472*cdf0e10cSrcweir             buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) );
1473*cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") );
1474*cdf0e10cSrcweir             throw BridgeRuntimeError( buf.makeStringAndClear() );
1475*cdf0e10cSrcweir         }
1476*cdf0e10cSrcweir         }
1477*cdf0e10cSrcweir     }
1478*cdf0e10cSrcweir     // BridgeRuntimeError are allowed to be thrown
1479*cdf0e10cSrcweir     catch (System::InvalidCastException* )
1480*cdf0e10cSrcweir     {
1481*cdf0e10cSrcweir         //ToDo check
1482*cdf0e10cSrcweir         OUStringBuffer buf( 128 );
1483*cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_uno():") );
1484*cdf0e10cSrcweir         buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) );
1485*cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] could not convert type!") );
1486*cdf0e10cSrcweir         throw BridgeRuntimeError( buf.makeStringAndClear() );
1487*cdf0e10cSrcweir     }
1488*cdf0e10cSrcweir     catch (System::NullReferenceException * e)
1489*cdf0e10cSrcweir     {
1490*cdf0e10cSrcweir         OUStringBuffer buf(512);
1491*cdf0e10cSrcweir         buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(
1492*cdf0e10cSrcweir                              "[map_to_uno()] Illegal null reference passed!\n"));
1493*cdf0e10cSrcweir         buf.append(mapCliString(e->get_StackTrace()));
1494*cdf0e10cSrcweir         throw BridgeRuntimeError( buf.makeStringAndClear() );
1495*cdf0e10cSrcweir     }
1496*cdf0e10cSrcweir     catch (BridgeRuntimeError& )
1497*cdf0e10cSrcweir     {
1498*cdf0e10cSrcweir         throw;
1499*cdf0e10cSrcweir     }
1500*cdf0e10cSrcweir     catch (...)
1501*cdf0e10cSrcweir     {
1502*cdf0e10cSrcweir         OSL_ASSERT(0);
1503*cdf0e10cSrcweir         throw;
1504*cdf0e10cSrcweir     }
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir }
1507*cdf0e10cSrcweir 
1508*cdf0e10cSrcweir /**
1509*cdf0e10cSrcweir    @param info
1510*cdf0e10cSrcweir        The expected target type. Currently info is provdided when this method is called
1511*cdf0e10cSrcweir        to convert the in/out and out parameters of a call from cli to uno. Then info
1512*cdf0e10cSrcweir        is always a byref type, e.g. "System.String&". info is used for Any and Enum conversion.
1513*cdf0e10cSrcweir    @param bDontCreateObj
1514*cdf0e10cSrcweir        false - a new object is created which holds the mapped uno value and is assigned to
1515*cdf0e10cSrcweir        cli_data.
1516*cdf0e10cSrcweir        true - cli_data already contains the newly constructed object. This is the case if
1517*cdf0e10cSrcweir        a struct is converted then on the first call to map_to_cli the new object is created.
1518*cdf0e10cSrcweir        If the struct inherits another struct then this function is called recursivly while the
1519*cdf0e10cSrcweir        newly created object is passed in cli_data.
1520*cdf0e10cSrcweir  */
1521*cdf0e10cSrcweir void Bridge::map_to_cli(
1522*cdf0e10cSrcweir     System::Object* *cli_data, void const * uno_data,
1523*cdf0e10cSrcweir     typelib_TypeDescriptionReference * type, System::Type* info,
1524*cdf0e10cSrcweir     bool bDontCreateObj) const
1525*cdf0e10cSrcweir {
1526*cdf0e10cSrcweir     switch (type->eTypeClass)
1527*cdf0e10cSrcweir     {
1528*cdf0e10cSrcweir     case typelib_TypeClass_CHAR:
1529*cdf0e10cSrcweir         *cli_data= __box(*(__wchar_t const*)uno_data);
1530*cdf0e10cSrcweir         break;
1531*cdf0e10cSrcweir     case typelib_TypeClass_BOOLEAN:
1532*cdf0e10cSrcweir         *cli_data = __box((*(bool const*)uno_data) == sal_True ? true : false);
1533*cdf0e10cSrcweir         break;
1534*cdf0e10cSrcweir     case typelib_TypeClass_BYTE:
1535*cdf0e10cSrcweir         *cli_data = __box(*(unsigned char const*) uno_data);
1536*cdf0e10cSrcweir         break;
1537*cdf0e10cSrcweir     case typelib_TypeClass_SHORT:
1538*cdf0e10cSrcweir         *cli_data= __box(*(short const*) uno_data);
1539*cdf0e10cSrcweir         break;
1540*cdf0e10cSrcweir     case typelib_TypeClass_UNSIGNED_SHORT:
1541*cdf0e10cSrcweir         *cli_data= __box(*(unsigned short const*) uno_data);
1542*cdf0e10cSrcweir         break;
1543*cdf0e10cSrcweir     case typelib_TypeClass_LONG:
1544*cdf0e10cSrcweir         *cli_data= __box(*(int const*) uno_data);
1545*cdf0e10cSrcweir         break;
1546*cdf0e10cSrcweir     case typelib_TypeClass_UNSIGNED_LONG:
1547*cdf0e10cSrcweir         *cli_data= __box(*(unsigned int const*) uno_data);
1548*cdf0e10cSrcweir         break;
1549*cdf0e10cSrcweir     case typelib_TypeClass_HYPER:
1550*cdf0e10cSrcweir         *cli_data= __box(*(__int64 const*) uno_data);
1551*cdf0e10cSrcweir         break;
1552*cdf0e10cSrcweir     case typelib_TypeClass_UNSIGNED_HYPER:
1553*cdf0e10cSrcweir         *cli_data= __box(*(unsigned __int64 const*) uno_data);
1554*cdf0e10cSrcweir         break;
1555*cdf0e10cSrcweir     case typelib_TypeClass_FLOAT:
1556*cdf0e10cSrcweir         *cli_data= __box(*(float const*) uno_data);
1557*cdf0e10cSrcweir         break;
1558*cdf0e10cSrcweir     case typelib_TypeClass_DOUBLE:
1559*cdf0e10cSrcweir         *cli_data= __box(*(double const*) uno_data);
1560*cdf0e10cSrcweir         break;
1561*cdf0e10cSrcweir     case typelib_TypeClass_STRING:
1562*cdf0e10cSrcweir     {
1563*cdf0e10cSrcweir         rtl_uString const* sVal= NULL;
1564*cdf0e10cSrcweir         sVal= *(rtl_uString* const*) uno_data;
1565*cdf0e10cSrcweir         *cli_data= new System::String((__wchar_t*) sVal->buffer,0, sVal->length);
1566*cdf0e10cSrcweir         break;
1567*cdf0e10cSrcweir     }
1568*cdf0e10cSrcweir     case typelib_TypeClass_TYPE:
1569*cdf0e10cSrcweir      {
1570*cdf0e10cSrcweir          *cli_data= mapUnoType( *(typelib_TypeDescriptionReference * const *)uno_data );
1571*cdf0e10cSrcweir          break;
1572*cdf0e10cSrcweir      }
1573*cdf0e10cSrcweir     case typelib_TypeClass_ANY:
1574*cdf0e10cSrcweir     {
1575*cdf0e10cSrcweir         uno_Any const * pAny = (uno_Any const *)uno_data;
1576*cdf0e10cSrcweir         if (typelib_TypeClass_VOID != pAny->pType->eTypeClass)
1577*cdf0e10cSrcweir         {
1578*cdf0e10cSrcweir             System::Object* objCli= NULL;
1579*cdf0e10cSrcweir             map_to_cli(
1580*cdf0e10cSrcweir                 &objCli, pAny->pData, pAny->pType, 0,
1581*cdf0e10cSrcweir                 false);
1582*cdf0e10cSrcweir 
1583*cdf0e10cSrcweir             uno::Any anyVal(mapUnoType(pAny->pType), objCli);
1584*cdf0e10cSrcweir             *cli_data= __box(anyVal);
1585*cdf0e10cSrcweir         }
1586*cdf0e10cSrcweir         else
1587*cdf0e10cSrcweir         { // void any
1588*cdf0e10cSrcweir             *cli_data= __box(uno::Any::VOID);
1589*cdf0e10cSrcweir         }
1590*cdf0e10cSrcweir         break;
1591*cdf0e10cSrcweir     }
1592*cdf0e10cSrcweir     case typelib_TypeClass_ENUM:
1593*cdf0e10cSrcweir      {
1594*cdf0e10cSrcweir          if (info != NULL)
1595*cdf0e10cSrcweir          {
1596*cdf0e10cSrcweir              OSL_ASSERT(info->get_IsByRef());
1597*cdf0e10cSrcweir              info= info->GetElementType();
1598*cdf0e10cSrcweir              *cli_data= System::Enum::ToObject(info, *(System::Int32*) uno_data);
1599*cdf0e10cSrcweir          }
1600*cdf0e10cSrcweir          else
1601*cdf0e10cSrcweir              *cli_data= System::Enum::ToObject(
1602*cdf0e10cSrcweir                  mapUnoType(type), *(System::Int32*) uno_data);
1603*cdf0e10cSrcweir         break;
1604*cdf0e10cSrcweir     }
1605*cdf0e10cSrcweir     case typelib_TypeClass_STRUCT:
1606*cdf0e10cSrcweir     case typelib_TypeClass_EXCEPTION:
1607*cdf0e10cSrcweir     {
1608*cdf0e10cSrcweir         TypeDescr td( type );
1609*cdf0e10cSrcweir         typelib_CompoundTypeDescription * comp_td =
1610*cdf0e10cSrcweir             (typelib_CompoundTypeDescription *) td.get();
1611*cdf0e10cSrcweir         if ( ! ((typelib_TypeDescription*) comp_td)->bComplete)
1612*cdf0e10cSrcweir                 ::typelib_typedescription_complete(
1613*cdf0e10cSrcweir                     (typelib_TypeDescription**) & comp_td );
1614*cdf0e10cSrcweir 
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir         //create the type
1617*cdf0e10cSrcweir         System::Type* cliType= loadCliType(td.get()->pTypeName);
1618*cdf0e10cSrcweir         //detect if we recursivly convert inherited structures
1619*cdf0e10cSrcweir         //If this point is reached because of a recursive call during convering a
1620*cdf0e10cSrcweir         //struct then we must not create a new object rather we use the one in
1621*cdf0e10cSrcweir         // cli_data argument.
1622*cdf0e10cSrcweir         System::Object* cliObj;
1623*cdf0e10cSrcweir         if (bDontCreateObj)
1624*cdf0e10cSrcweir             cliObj = *cli_data; // recursive call
1625*cdf0e10cSrcweir         else
1626*cdf0e10cSrcweir         {
1627*cdf0e10cSrcweir             //Special handling for Exception conversion. We must call constructor System::Exception
1628*cdf0e10cSrcweir             //to pass the message string
1629*cdf0e10cSrcweir             if (__typeof(ucss::uno::Exception)->IsAssignableFrom(cliType))
1630*cdf0e10cSrcweir             {
1631*cdf0e10cSrcweir                 //We need to get the Message field. Therefore we must obtain the offset from
1632*cdf0e10cSrcweir                 //the typedescription. The base interface of all exceptions is
1633*cdf0e10cSrcweir                 //com::sun::star::uno::Exception which contains the message
1634*cdf0e10cSrcweir                 typelib_CompoundTypeDescription* pCTD = comp_td;
1635*cdf0e10cSrcweir                 while (pCTD->pBaseTypeDescription)
1636*cdf0e10cSrcweir                     pCTD = pCTD->pBaseTypeDescription;
1637*cdf0e10cSrcweir                 int nPos = -1;
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir 				rtl::OUString usMessageMember(RTL_CONSTASCII_USTRINGPARAM("Message"));
1640*cdf0e10cSrcweir                 for (int i = 0; i < pCTD->nMembers; i ++)
1641*cdf0e10cSrcweir                 {
1642*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >= 2
1643*cdf0e10cSrcweir                     System::String* sMember;
1644*cdf0e10cSrcweir                     sMember = mapUnoString(pCTD->ppMemberNames[i]);
1645*cdf0e10cSrcweir #endif
1646*cdf0e10cSrcweir                     if (usMessageMember.equals(pCTD->ppMemberNames[i]))
1647*cdf0e10cSrcweir                     {
1648*cdf0e10cSrcweir                         nPos = i;
1649*cdf0e10cSrcweir                         break;
1650*cdf0e10cSrcweir                     }
1651*cdf0e10cSrcweir                 }
1652*cdf0e10cSrcweir                 OSL_ASSERT (nPos != -1);
1653*cdf0e10cSrcweir                 int offset = pCTD->pMemberOffsets[nPos];
1654*cdf0e10cSrcweir                 //Whith the offset within the exception we can get the message string
1655*cdf0e10cSrcweir                 System::String* sMessage = mapUnoString(*(rtl_uString**)
1656*cdf0e10cSrcweir                                                         ((char*) uno_data + offset));
1657*cdf0e10cSrcweir                 //We need to find a constructor for the exception that takes the message string
1658*cdf0e10cSrcweir                 //We assume that the first argument is the message string
1659*cdf0e10cSrcweir                 sr::ConstructorInfo* arCtorInfo[] = cliType->GetConstructors();
1660*cdf0e10cSrcweir                 sr::ConstructorInfo* ctorInfo = NULL;
1661*cdf0e10cSrcweir                 int numCtors = arCtorInfo->get_Length();
1662*cdf0e10cSrcweir                 //Constructor must at least have 2 params for the base
1663*cdf0e10cSrcweir                 //unoidl.com.sun.star.uno.Exception (String, Object);
1664*cdf0e10cSrcweir                 sr::ParameterInfo * arParamInfo[];
1665*cdf0e10cSrcweir                 for (int i = 0; i < numCtors; i++)
1666*cdf0e10cSrcweir                 {
1667*cdf0e10cSrcweir                     arParamInfo = arCtorInfo[i]->GetParameters();
1668*cdf0e10cSrcweir                     if (arParamInfo->get_Length() < 2)
1669*cdf0e10cSrcweir                         continue;
1670*cdf0e10cSrcweir                     ctorInfo = arCtorInfo[i];
1671*cdf0e10cSrcweir                     break;
1672*cdf0e10cSrcweir                 }
1673*cdf0e10cSrcweir                 OSL_ASSERT(arParamInfo[0]->get_ParameterType()->Equals(__typeof(System::String))
1674*cdf0e10cSrcweir                     && arParamInfo[1]->get_ParameterType()->Equals(__typeof(System::Object))
1675*cdf0e10cSrcweir                     && arParamInfo[0]->get_Position() == 0
1676*cdf0e10cSrcweir                     && arParamInfo[1]->get_Position() == 1);
1677*cdf0e10cSrcweir                 //Prepare parameters for constructor
1678*cdf0e10cSrcweir                 int numArgs = arParamInfo->get_Length();
1679*cdf0e10cSrcweir                 System::Object * args[] = new System::Object*[numArgs];
1680*cdf0e10cSrcweir                 //only initialize the first argument with the message
1681*cdf0e10cSrcweir                 args[0] = sMessage;
1682*cdf0e10cSrcweir                 cliObj = ctorInfo->Invoke(args);
1683*cdf0e10cSrcweir             }
1684*cdf0e10cSrcweir             else
1685*cdf0e10cSrcweir                 cliObj = System::Activator::CreateInstance(cliType);
1686*cdf0e10cSrcweir         }
1687*cdf0e10cSrcweir         sal_Int32 * pMemberOffsets = comp_td->pMemberOffsets;
1688*cdf0e10cSrcweir 
1689*cdf0e10cSrcweir         if (comp_td->pBaseTypeDescription)
1690*cdf0e10cSrcweir         {
1691*cdf0e10cSrcweir             //convert inherited struct
1692*cdf0e10cSrcweir             //cliObj is passed inout (args in_param, out_param are true), hence the passed
1693*cdf0e10cSrcweir             // cliObj is used by the callee instead of a newly created struct
1694*cdf0e10cSrcweir             map_to_cli(
1695*cdf0e10cSrcweir                 &cliObj, uno_data,
1696*cdf0e10cSrcweir                 ((typelib_TypeDescription *)comp_td->pBaseTypeDescription)->pWeakRef, 0,
1697*cdf0e10cSrcweir                 true);
1698*cdf0e10cSrcweir         }
1699*cdf0e10cSrcweir 		rtl::OUString usUnoException(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception"));
1700*cdf0e10cSrcweir         for (sal_Int32 nPos = comp_td->nMembers; nPos--; )
1701*cdf0e10cSrcweir         {
1702*cdf0e10cSrcweir             typelib_TypeDescriptionReference * member_type = comp_td->ppTypeRefs[ nPos ];
1703*cdf0e10cSrcweir             System::String* sMemberName= mapUnoString(comp_td->ppMemberNames[nPos]);
1704*cdf0e10cSrcweir             sr::FieldInfo* aField= cliType->GetField(sMemberName);
1705*cdf0e10cSrcweir             // special case for Exception.Message. The field has already been
1706*cdf0e10cSrcweir             // set while constructing cli object
1707*cdf0e10cSrcweir             if ( ! aField && usUnoException.equals(td.get()->pTypeName))
1708*cdf0e10cSrcweir             {
1709*cdf0e10cSrcweir                 continue;
1710*cdf0e10cSrcweir             }
1711*cdf0e10cSrcweir             void const * p = (char const *)uno_data + pMemberOffsets[ nPos ];
1712*cdf0e10cSrcweir             switch (member_type->eTypeClass)
1713*cdf0e10cSrcweir             {
1714*cdf0e10cSrcweir             case typelib_TypeClass_CHAR:
1715*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Char*) p));
1716*cdf0e10cSrcweir                 break;
1717*cdf0e10cSrcweir             case typelib_TypeClass_BOOLEAN:
1718*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Boolean*) p));
1719*cdf0e10cSrcweir                 break;
1720*cdf0e10cSrcweir             case typelib_TypeClass_BYTE:
1721*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Byte*) p));
1722*cdf0e10cSrcweir                 break;
1723*cdf0e10cSrcweir             case typelib_TypeClass_SHORT:
1724*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Int16*) p));
1725*cdf0e10cSrcweir                 break;
1726*cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_SHORT:
1727*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::UInt16*) p));
1728*cdf0e10cSrcweir                 break;
1729*cdf0e10cSrcweir             case typelib_TypeClass_LONG:
1730*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Int32*) p));
1731*cdf0e10cSrcweir                 break;
1732*cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_LONG:
1733*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::UInt32*) p));
1734*cdf0e10cSrcweir                 break;
1735*cdf0e10cSrcweir             case typelib_TypeClass_HYPER:
1736*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Int64*) p));
1737*cdf0e10cSrcweir                 break;
1738*cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_HYPER:
1739*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::UInt64*) p));
1740*cdf0e10cSrcweir                 break;
1741*cdf0e10cSrcweir             case typelib_TypeClass_FLOAT:
1742*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Single*) p));
1743*cdf0e10cSrcweir                 break;
1744*cdf0e10cSrcweir             case typelib_TypeClass_DOUBLE:
1745*cdf0e10cSrcweir                 aField->SetValue(cliObj, __box(*(System::Double*) p));
1746*cdf0e10cSrcweir                 break;
1747*cdf0e10cSrcweir             default:
1748*cdf0e10cSrcweir             {
1749*cdf0e10cSrcweir                 System::Object* cli_val;
1750*cdf0e10cSrcweir                 map_to_cli(
1751*cdf0e10cSrcweir                     &cli_val, p, member_type, 0,
1752*cdf0e10cSrcweir                     false);
1753*cdf0e10cSrcweir                 aField->SetValue(cliObj, cli_val);
1754*cdf0e10cSrcweir                 break;
1755*cdf0e10cSrcweir             }
1756*cdf0e10cSrcweir             }
1757*cdf0e10cSrcweir         }
1758*cdf0e10cSrcweir         *cli_data= cliObj;
1759*cdf0e10cSrcweir         break;
1760*cdf0e10cSrcweir     }
1761*cdf0e10cSrcweir     case typelib_TypeClass_SEQUENCE:
1762*cdf0e10cSrcweir     {
1763*cdf0e10cSrcweir         sal_Int32 nElements;
1764*cdf0e10cSrcweir         uno_Sequence const * seq = 0;
1765*cdf0e10cSrcweir         seq = *(uno_Sequence * const *)uno_data;
1766*cdf0e10cSrcweir         nElements = seq->nElements;
1767*cdf0e10cSrcweir 
1768*cdf0e10cSrcweir         TypeDescr td( type );
1769*cdf0e10cSrcweir         typelib_TypeDescriptionReference * element_type =
1770*cdf0e10cSrcweir             ((typelib_IndirectTypeDescription *)td.get())->pType;
1771*cdf0e10cSrcweir 
1772*cdf0e10cSrcweir         switch (element_type->eTypeClass)
1773*cdf0e10cSrcweir         {
1774*cdf0e10cSrcweir         case typelib_TypeClass_CHAR:
1775*cdf0e10cSrcweir         {
1776*cdf0e10cSrcweir             System::Char arChar[]= new System::Char[nElements];
1777*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arChar, 0, nElements);
1778*cdf0e10cSrcweir             *cli_data= arChar;
1779*cdf0e10cSrcweir             break;
1780*cdf0e10cSrcweir         }
1781*cdf0e10cSrcweir         case typelib_TypeClass_BOOLEAN:
1782*cdf0e10cSrcweir         {
1783*cdf0e10cSrcweir             System::Boolean arBool[]= new System::Boolean[nElements];
1784*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arBool, 0, nElements);
1785*cdf0e10cSrcweir             *cli_data= arBool;
1786*cdf0e10cSrcweir             break;
1787*cdf0e10cSrcweir         }
1788*cdf0e10cSrcweir         case typelib_TypeClass_BYTE:
1789*cdf0e10cSrcweir         {
1790*cdf0e10cSrcweir             System::Byte arByte[]= new System::Byte[nElements];
1791*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arByte, 0, nElements);
1792*cdf0e10cSrcweir             *cli_data= arByte;
1793*cdf0e10cSrcweir             break;
1794*cdf0e10cSrcweir         }
1795*cdf0e10cSrcweir         case typelib_TypeClass_SHORT:
1796*cdf0e10cSrcweir         {
1797*cdf0e10cSrcweir             System::Int16 arShort[]= new System::Int16[nElements];
1798*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arShort, 0, nElements);
1799*cdf0e10cSrcweir             *cli_data= arShort;
1800*cdf0e10cSrcweir             break;
1801*cdf0e10cSrcweir         }
1802*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_SHORT:
1803*cdf0e10cSrcweir         {
1804*cdf0e10cSrcweir             System::UInt16 arUInt16[]= new System::UInt16[nElements];
1805*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, static_cast<System::Int16[]>(arUInt16),
1806*cdf0e10cSrcweir                                 0, nElements);
1807*cdf0e10cSrcweir             *cli_data= arUInt16;
1808*cdf0e10cSrcweir             break;
1809*cdf0e10cSrcweir         }
1810*cdf0e10cSrcweir         case typelib_TypeClass_LONG:
1811*cdf0e10cSrcweir         {
1812*cdf0e10cSrcweir             System::Int32 arInt32[]= new System::Int32[nElements];
1813*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arInt32, 0, nElements);
1814*cdf0e10cSrcweir             *cli_data= arInt32;
1815*cdf0e10cSrcweir             break;
1816*cdf0e10cSrcweir         }
1817*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_LONG:
1818*cdf0e10cSrcweir         {
1819*cdf0e10cSrcweir             System::UInt32 arUInt32[]= new System::UInt32[nElements];
1820*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, static_cast<System::Int32[]>(arUInt32),
1821*cdf0e10cSrcweir                                 0, nElements);
1822*cdf0e10cSrcweir             *cli_data= arUInt32;
1823*cdf0e10cSrcweir             break;
1824*cdf0e10cSrcweir         }
1825*cdf0e10cSrcweir         case typelib_TypeClass_HYPER:
1826*cdf0e10cSrcweir         {
1827*cdf0e10cSrcweir             System::Int64 arInt64[]= new System::Int64[nElements];
1828*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arInt64, 0, nElements);
1829*cdf0e10cSrcweir             *cli_data= arInt64;
1830*cdf0e10cSrcweir             break;
1831*cdf0e10cSrcweir         }
1832*cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_HYPER:
1833*cdf0e10cSrcweir         {
1834*cdf0e10cSrcweir             System::UInt64 arUInt64[]= new System::UInt64[nElements];
1835*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arUInt64, 0, nElements);
1836*cdf0e10cSrcweir             *cli_data= arUInt64;
1837*cdf0e10cSrcweir             break;
1838*cdf0e10cSrcweir         }
1839*cdf0e10cSrcweir         case typelib_TypeClass_FLOAT:
1840*cdf0e10cSrcweir         {
1841*cdf0e10cSrcweir             System::Single arSingle[]= new System::Single[nElements];
1842*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arSingle, 0, nElements);
1843*cdf0e10cSrcweir             *cli_data= arSingle;
1844*cdf0e10cSrcweir             break;
1845*cdf0e10cSrcweir         }
1846*cdf0e10cSrcweir         case typelib_TypeClass_DOUBLE:
1847*cdf0e10cSrcweir         {
1848*cdf0e10cSrcweir             System::Double arDouble[]= new System::Double[nElements];
1849*cdf0e10cSrcweir             sri::Marshal::Copy( (void*) &seq->elements, arDouble, 0, nElements);
1850*cdf0e10cSrcweir             *cli_data= arDouble;
1851*cdf0e10cSrcweir             break;
1852*cdf0e10cSrcweir         }
1853*cdf0e10cSrcweir         case typelib_TypeClass_STRING:
1854*cdf0e10cSrcweir         {
1855*cdf0e10cSrcweir             System::String* arString[]= new System::String*[nElements];
1856*cdf0e10cSrcweir             for (int i= 0; i < nElements; i++)
1857*cdf0e10cSrcweir             {
1858*cdf0e10cSrcweir                 rtl_uString *aStr= ((rtl_uString**)(&seq->elements))[i];
1859*cdf0e10cSrcweir                 arString[i]= new System::String( (__wchar_t *) &aStr->buffer, 0, aStr->length);
1860*cdf0e10cSrcweir             }
1861*cdf0e10cSrcweir             *cli_data= arString;
1862*cdf0e10cSrcweir             break;
1863*cdf0e10cSrcweir         }
1864*cdf0e10cSrcweir         case typelib_TypeClass_TYPE:
1865*cdf0e10cSrcweir         {
1866*cdf0e10cSrcweir             System::Type* arType[]= new System::Type*[nElements];
1867*cdf0e10cSrcweir             for (int i= 0; i < nElements; i++)
1868*cdf0e10cSrcweir             {
1869*cdf0e10cSrcweir                 arType[i]=
1870*cdf0e10cSrcweir                     mapUnoType( ((typelib_TypeDescriptionReference**) seq->elements)[i]);
1871*cdf0e10cSrcweir             }
1872*cdf0e10cSrcweir             *cli_data= arType;
1873*cdf0e10cSrcweir             break;
1874*cdf0e10cSrcweir         }
1875*cdf0e10cSrcweir         case typelib_TypeClass_ANY:
1876*cdf0e10cSrcweir         {
1877*cdf0e10cSrcweir             uno::Any arCli[]= new uno::Any[nElements];
1878*cdf0e10cSrcweir             uno_Any const * p = (uno_Any const *)seq->elements;
1879*cdf0e10cSrcweir             for (sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1880*cdf0e10cSrcweir             {
1881*cdf0e10cSrcweir 				System::Object* cli_obj = NULL;
1882*cdf0e10cSrcweir                 map_to_cli(
1883*cdf0e10cSrcweir                     &cli_obj, &p[ nPos ], element_type, 0, false);
1884*cdf0e10cSrcweir                 arCli[nPos]= *__try_cast<__box uno::Any*>(cli_obj);
1885*cdf0e10cSrcweir             }
1886*cdf0e10cSrcweir             *cli_data= arCli;
1887*cdf0e10cSrcweir             break;
1888*cdf0e10cSrcweir         }
1889*cdf0e10cSrcweir         case typelib_TypeClass_ENUM:
1890*cdf0e10cSrcweir         {
1891*cdf0e10cSrcweir             //get the Enum type
1892*cdf0e10cSrcweir             System::Type* enumType= NULL;
1893*cdf0e10cSrcweir             if (info != NULL)
1894*cdf0e10cSrcweir             {
1895*cdf0e10cSrcweir                 //info is EnumType[]&, remove &
1896*cdf0e10cSrcweir                 OSL_ASSERT(info->IsByRef);
1897*cdf0e10cSrcweir                 enumType = info->GetElementType();
1898*cdf0e10cSrcweir                 //enumType is EnumType[], remove []
1899*cdf0e10cSrcweir                 enumType = enumType->GetElementType();
1900*cdf0e10cSrcweir             }
1901*cdf0e10cSrcweir             else
1902*cdf0e10cSrcweir                 enumType= mapUnoType(element_type);
1903*cdf0e10cSrcweir 
1904*cdf0e10cSrcweir             System::Array* arEnum = System::Array::CreateInstance(
1905*cdf0e10cSrcweir                 enumType, nElements);
1906*cdf0e10cSrcweir             for (int i= 0; i < nElements; i++)
1907*cdf0e10cSrcweir             {
1908*cdf0e10cSrcweir                 arEnum->SetValue(System::Enum::ToObject(enumType,
1909*cdf0e10cSrcweir                    ((sal_Int32*) seq->elements)[i]), i);
1910*cdf0e10cSrcweir             }
1911*cdf0e10cSrcweir             *cli_data = arEnum;
1912*cdf0e10cSrcweir             break;
1913*cdf0e10cSrcweir         }
1914*cdf0e10cSrcweir         case typelib_TypeClass_STRUCT:
1915*cdf0e10cSrcweir         case typelib_TypeClass_EXCEPTION:
1916*cdf0e10cSrcweir         {
1917*cdf0e10cSrcweir             TypeDescr element_td( element_type );
1918*cdf0e10cSrcweir             System::Array* ar= System::Array::CreateInstance(
1919*cdf0e10cSrcweir                 mapUnoType(element_type),nElements);
1920*cdf0e10cSrcweir             if (0 < nElements)
1921*cdf0e10cSrcweir             {
1922*cdf0e10cSrcweir                 // ToDo check this
1923*cdf0e10cSrcweir                 char * p = (char *) &seq->elements;
1924*cdf0e10cSrcweir                 sal_Int32 nSize = element_td.get()->nSize;
1925*cdf0e10cSrcweir                 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1926*cdf0e10cSrcweir                 {
1927*cdf0e10cSrcweir                     System::Object* val;
1928*cdf0e10cSrcweir                     map_to_cli(
1929*cdf0e10cSrcweir                         &val, p + (nSize * nPos), element_type, 0, false);
1930*cdf0e10cSrcweir                     ar->SetValue(val, nPos);
1931*cdf0e10cSrcweir                 }
1932*cdf0e10cSrcweir             }
1933*cdf0e10cSrcweir 			*cli_data = ar;
1934*cdf0e10cSrcweir             break;
1935*cdf0e10cSrcweir         }
1936*cdf0e10cSrcweir // ToDo, verify
1937*cdf0e10cSrcweir         case typelib_TypeClass_SEQUENCE:
1938*cdf0e10cSrcweir         {
1939*cdf0e10cSrcweir             System::Array *ar= System::Array::CreateInstance(
1940*cdf0e10cSrcweir                 mapUnoType(element_type), nElements);
1941*cdf0e10cSrcweir             if (0 < nElements)
1942*cdf0e10cSrcweir             {
1943*cdf0e10cSrcweir                 TypeDescr element_td( element_type );
1944*cdf0e10cSrcweir                 uno_Sequence ** elements = (uno_Sequence**) seq->elements;
1945*cdf0e10cSrcweir                 for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1946*cdf0e10cSrcweir                 {
1947*cdf0e10cSrcweir                     System::Object* val;
1948*cdf0e10cSrcweir                     map_to_cli(
1949*cdf0e10cSrcweir                         &val, &elements[nPos], element_type, 0, false);
1950*cdf0e10cSrcweir                     ar->SetValue(val, nPos);
1951*cdf0e10cSrcweir                 }
1952*cdf0e10cSrcweir             }
1953*cdf0e10cSrcweir             *cli_data = ar;
1954*cdf0e10cSrcweir             break;
1955*cdf0e10cSrcweir         }
1956*cdf0e10cSrcweir         case typelib_TypeClass_INTERFACE:
1957*cdf0e10cSrcweir         {
1958*cdf0e10cSrcweir             TypeDescr element_td( element_type );
1959*cdf0e10cSrcweir             System::Type * ifaceType= mapUnoType(element_type);
1960*cdf0e10cSrcweir             System::Array* ar= System::Array::CreateInstance(ifaceType, nElements);
1961*cdf0e10cSrcweir 
1962*cdf0e10cSrcweir             char * p = (char *)seq->elements;
1963*cdf0e10cSrcweir             sal_Int32 nSize = element_td.get()->nSize;
1964*cdf0e10cSrcweir             for ( sal_Int32 nPos = 0; nPos < nElements; ++nPos )
1965*cdf0e10cSrcweir             {
1966*cdf0e10cSrcweir                 System::Object* val;
1967*cdf0e10cSrcweir                 map_to_cli(
1968*cdf0e10cSrcweir                     &val, p + (nSize * nPos), element_type, NULL, false);
1969*cdf0e10cSrcweir 
1970*cdf0e10cSrcweir                 ar->SetValue(val, nPos);
1971*cdf0e10cSrcweir             }
1972*cdf0e10cSrcweir             *cli_data= ar;
1973*cdf0e10cSrcweir             break;
1974*cdf0e10cSrcweir         }
1975*cdf0e10cSrcweir         default:
1976*cdf0e10cSrcweir         {
1977*cdf0e10cSrcweir             OUStringBuffer buf( 128 );
1978*cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_cli():") );
1979*cdf0e10cSrcweir             buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) );
1980*cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported element type: ") );
1981*cdf0e10cSrcweir             buf.append( *reinterpret_cast< OUString const * >( &element_type->pTypeName ) );
1982*cdf0e10cSrcweir             throw BridgeRuntimeError( buf.makeStringAndClear() );
1983*cdf0e10cSrcweir         }
1984*cdf0e10cSrcweir         }
1985*cdf0e10cSrcweir         break;
1986*cdf0e10cSrcweir     }
1987*cdf0e10cSrcweir     case typelib_TypeClass_INTERFACE:
1988*cdf0e10cSrcweir     {
1989*cdf0e10cSrcweir         uno_Interface * pUnoI = *(uno_Interface * const *)uno_data;
1990*cdf0e10cSrcweir         if (0 != pUnoI)
1991*cdf0e10cSrcweir         {
1992*cdf0e10cSrcweir             TypeDescr td( type );
1993*cdf0e10cSrcweir             *cli_data= map_uno2cli( pUnoI, reinterpret_cast<
1994*cdf0e10cSrcweir                                           typelib_InterfaceTypeDescription*>(td.get())) ;
1995*cdf0e10cSrcweir         }
1996*cdf0e10cSrcweir 		else
1997*cdf0e10cSrcweir 			*cli_data= NULL;
1998*cdf0e10cSrcweir         break;
1999*cdf0e10cSrcweir     }
2000*cdf0e10cSrcweir     default:
2001*cdf0e10cSrcweir     {
2002*cdf0e10cSrcweir         //ToDo check this exception. The String is probably crippled
2003*cdf0e10cSrcweir         OUStringBuffer buf( 128 );
2004*cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[map_to_cli():") );
2005*cdf0e10cSrcweir         buf.append( *reinterpret_cast< OUString const * >( &type->pTypeName ) );
2006*cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] unsupported type!") );
2007*cdf0e10cSrcweir         throw BridgeRuntimeError( buf.makeStringAndClear() );
2008*cdf0e10cSrcweir     }
2009*cdf0e10cSrcweir     }
2010*cdf0e10cSrcweir }
2011*cdf0e10cSrcweir }
2012