merge the formfield patch from ooo-build
[ooovba.git] / stoc / source / corereflection / crbase.cxx
blob9d4b4bffa2a0b09bc7b7f400642341ec0d8ebc00
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: crbase.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
33 #include <cppuhelper/queryinterface.hxx>
34 #include <uno/any2.h>
36 #include "base.hxx"
38 namespace stoc_corefl
41 #ifdef TEST_LIST_CLASSES
42 ClassNameList g_aClassNames;
43 #endif
45 //--------------------------------------------------------------------------------------------------
46 Mutex & getMutexAccess()
48 static Mutex * s_pMutex = 0;
49 if (! s_pMutex)
51 MutexGuard aGuard( Mutex::getGlobalMutex() );
52 if (! s_pMutex)
54 static Mutex s_aMutex;
55 s_pMutex = &s_aMutex;
58 return *s_pMutex;
61 //__________________________________________________________________________________________________
62 IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl * pReflection,
63 const OUString & rName, typelib_TypeClass eTypeClass,
64 typelib_TypeDescription * pTypeDescr )
65 : _pReflection( pReflection )
66 , _aName( rName )
67 , _eTypeClass( (TypeClass)eTypeClass )
68 , _pTypeDescr( pTypeDescr )
70 if (_pReflection)
71 _pReflection->acquire();
72 if (_pTypeDescr)
74 typelib_typedescription_acquire( _pTypeDescr );
75 if (! _pTypeDescr->bComplete)
76 typelib_typedescription_complete( &_pTypeDescr );
79 #ifdef TEST_LIST_CLASSES
80 ClassNameList::const_iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
81 OSL_ENSURE( iFind == g_aClassNames.end(), "### idl class already exists!" );
82 g_aClassNames.push_front( _aName );
83 #endif
85 //__________________________________________________________________________________________________
86 IdlClassImpl::~IdlClassImpl()
88 if (_pTypeDescr)
89 typelib_typedescription_release( _pTypeDescr );
90 if (_pReflection)
91 _pReflection->release();
93 #ifdef TEST_LIST_CLASSES
94 ClassNameList::iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
95 OSL_ENSURE( iFind != g_aClassNames.end(), "### idl class does not exist!" );
96 g_aClassNames.erase( iFind );
97 #endif
100 // XIdlClassImpl default implementation
101 //__________________________________________________________________________________________________
102 TypeClass IdlClassImpl::getTypeClass()
103 throw(::com::sun::star::uno::RuntimeException)
105 return _eTypeClass;
107 //__________________________________________________________________________________________________
108 OUString IdlClassImpl::getName()
109 throw(::com::sun::star::uno::RuntimeException)
111 return _aName;
113 //__________________________________________________________________________________________________
114 sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
115 throw(::com::sun::star::uno::RuntimeException)
117 return (xType.is() &&
118 (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
121 static sal_Bool s_aAssignableFromTab[11][11] =
123 /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */
124 /* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
125 /* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
126 /* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
127 /* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
128 /* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
129 /* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
130 /* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
131 /* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
132 /* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
133 /* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
134 /* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
136 //__________________________________________________________________________________________________
137 sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
138 throw(::com::sun::star::uno::RuntimeException)
140 TypeClass eAssign = getTypeClass();
141 if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
143 return sal_True;
145 else
147 TypeClass eFrom = xType->getTypeClass();
148 if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
149 eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
151 return s_aAssignableFromTab[eAssign-1][eFrom-1];
154 return sal_False;
156 //__________________________________________________________________________________________________
157 void IdlClassImpl::createObject( Any & rObj )
158 throw(::com::sun::star::uno::RuntimeException)
160 rObj.clear();
161 uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
162 uno_any_construct( &rObj, 0, getTypeDescr(), 0 );
165 // what TODO ????
166 //__________________________________________________________________________________________________
167 Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
168 throw(::com::sun::star::uno::RuntimeException)
170 OSL_ENSURE( sal_False, "### unexpected use!" );
171 return Sequence< Reference< XIdlClass > >();
173 //__________________________________________________________________________________________________
174 Reference< XIdlClass > IdlClassImpl::getClass( const OUString & )
175 throw(::com::sun::star::uno::RuntimeException)
177 OSL_ENSURE( sal_False, "### unexpected use!" );
178 return Reference< XIdlClass >();
180 //__________________________________________________________________________________________________
181 Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
182 throw(::com::sun::star::uno::RuntimeException)
184 // OSL_ENSURE( sal_False, "### unexpected use!" );
185 return Sequence< Reference< XIdlClass > >();
188 // structs, interfaces
189 //__________________________________________________________________________________________________
190 Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(::com::sun::star::uno::RuntimeException)
192 return Sequence< Reference< XIdlClass > >();
194 // structs
195 //__________________________________________________________________________________________________
196 Reference< XIdlField > IdlClassImpl::getField( const OUString & )
197 throw(::com::sun::star::uno::RuntimeException)
199 return Reference< XIdlField >();
201 //__________________________________________________________________________________________________
202 Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
203 throw(::com::sun::star::uno::RuntimeException)
205 return Sequence< Reference< XIdlField > >();
207 // interfaces
208 //__________________________________________________________________________________________________
209 Uik IdlClassImpl::getUik()
210 throw(::com::sun::star::uno::RuntimeException)
212 return Uik();
214 //__________________________________________________________________________________________________
215 Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
216 throw(::com::sun::star::uno::RuntimeException)
218 return Reference< XIdlMethod >();
220 //__________________________________________________________________________________________________
221 Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
222 throw(::com::sun::star::uno::RuntimeException)
224 return Sequence< Reference< XIdlMethod > >();
226 // array
227 //__________________________________________________________________________________________________
228 Reference< XIdlClass > IdlClassImpl::getComponentType()
229 throw(::com::sun::star::uno::RuntimeException)
231 return Reference< XIdlClass >();
233 //__________________________________________________________________________________________________
234 Reference< XIdlArray > IdlClassImpl::getArray()
235 throw(::com::sun::star::uno::RuntimeException)
237 return Reference< XIdlArray >();
241 //##################################################################################################
242 //##################################################################################################
243 //##################################################################################################
246 //__________________________________________________________________________________________________
247 IdlMemberImpl::IdlMemberImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
248 typelib_TypeDescription * pTypeDescr,
249 typelib_TypeDescription * pDeclTypeDescr )
250 : _pReflection( pReflection )
251 , _aName( rName )
252 , _pTypeDescr( pTypeDescr )
253 , _pDeclTypeDescr( pDeclTypeDescr )
255 _pReflection->acquire();
256 typelib_typedescription_acquire( _pTypeDescr );
257 if (! _pTypeDescr->bComplete)
258 typelib_typedescription_complete( &_pTypeDescr );
259 typelib_typedescription_acquire( _pDeclTypeDescr );
260 if (! _pDeclTypeDescr->bComplete)
261 typelib_typedescription_complete( &_pDeclTypeDescr );
263 //__________________________________________________________________________________________________
264 IdlMemberImpl::~IdlMemberImpl()
266 typelib_typedescription_release( _pDeclTypeDescr );
267 typelib_typedescription_release( _pTypeDescr );
268 _pReflection->release();
271 // XIdlMember
272 //__________________________________________________________________________________________________
273 Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
274 throw(::com::sun::star::uno::RuntimeException)
276 if (! _xDeclClass.is())
278 Reference< XIdlClass > xDeclClass( getReflection()->forType( getDeclTypeDescr() ) );
279 MutexGuard aGuard( getMutexAccess() );
280 if (! _xDeclClass.is())
281 _xDeclClass = xDeclClass;
283 return _xDeclClass;
285 //__________________________________________________________________________________________________
286 OUString IdlMemberImpl::getName()
287 throw(::com::sun::star::uno::RuntimeException)
289 return _aName;