1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: crbase.cxx,v $
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>
41 #ifdef TEST_LIST_CLASSES
42 ClassNameList g_aClassNames
;
45 //--------------------------------------------------------------------------------------------------
46 Mutex
& getMutexAccess()
48 static Mutex
* s_pMutex
= 0;
51 MutexGuard
aGuard( Mutex::getGlobalMutex() );
54 static Mutex s_aMutex
;
61 //__________________________________________________________________________________________________
62 IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl
* pReflection
,
63 const OUString
& rName
, typelib_TypeClass eTypeClass
,
64 typelib_TypeDescription
* pTypeDescr
)
65 : _pReflection( pReflection
)
67 , _eTypeClass( (TypeClass
)eTypeClass
)
68 , _pTypeDescr( pTypeDescr
)
71 _pReflection
->acquire();
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
);
85 //__________________________________________________________________________________________________
86 IdlClassImpl::~IdlClassImpl()
89 typelib_typedescription_release( _pTypeDescr
);
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
);
100 // XIdlClassImpl default implementation
101 //__________________________________________________________________________________________________
102 TypeClass
IdlClassImpl::getTypeClass()
103 throw(::com::sun::star::uno::RuntimeException
)
107 //__________________________________________________________________________________________________
108 OUString
IdlClassImpl::getName()
109 throw(::com::sun::star::uno::RuntimeException
)
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
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];
156 //__________________________________________________________________________________________________
157 void IdlClassImpl::createObject( Any
& rObj
)
158 throw(::com::sun::star::uno::RuntimeException
)
161 uno_any_destruct( &rObj
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
162 uno_any_construct( &rObj
, 0, getTypeDescr(), 0 );
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
> >();
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
> >();
208 //__________________________________________________________________________________________________
209 Uik
IdlClassImpl::getUik()
210 throw(::com::sun::star::uno::RuntimeException
)
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
> >();
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
)
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();
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
;
285 //__________________________________________________________________________________________________
286 OUString
IdlMemberImpl::getName()
287 throw(::com::sun::star::uno::RuntimeException
)