1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*647a425cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647a425cSAndrew Rist  * distributed with this work for additional information
6*647a425cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647a425cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist  * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647a425cSAndrew Rist  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist  *
13*647a425cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist  * software distributed under the License is distributed on an
15*647a425cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647a425cSAndrew Rist  * specific language governing permissions and limitations
18*647a425cSAndrew Rist  * under the License.
19*647a425cSAndrew Rist  *
20*647a425cSAndrew Rist  *************************************************************/
21*647a425cSAndrew Rist 
22*647a425cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
27cdf0e10cSrcweir #include <uno/any2.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "base.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace stoc_corefl
32cdf0e10cSrcweir {
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES
35cdf0e10cSrcweir ClassNameList g_aClassNames;
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
getMutexAccess()39cdf0e10cSrcweir Mutex & getMutexAccess()
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	static Mutex * s_pMutex = 0;
42cdf0e10cSrcweir 	if (! s_pMutex)
43cdf0e10cSrcweir 	{
44cdf0e10cSrcweir 		MutexGuard aGuard( Mutex::getGlobalMutex() );
45cdf0e10cSrcweir 		if (! s_pMutex)
46cdf0e10cSrcweir 		{
47cdf0e10cSrcweir 			static Mutex s_aMutex;
48cdf0e10cSrcweir 			s_pMutex = &s_aMutex;
49cdf0e10cSrcweir 		}
50cdf0e10cSrcweir 	}
51cdf0e10cSrcweir 	return *s_pMutex;
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //__________________________________________________________________________________________________
IdlClassImpl(IdlReflectionServiceImpl * pReflection,const OUString & rName,typelib_TypeClass eTypeClass,typelib_TypeDescription * pTypeDescr)55cdf0e10cSrcweir IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl * pReflection,
56cdf0e10cSrcweir 							const OUString & rName, typelib_TypeClass eTypeClass,
57cdf0e10cSrcweir 							typelib_TypeDescription * pTypeDescr )
58cdf0e10cSrcweir 	: _pReflection( pReflection )
59cdf0e10cSrcweir 	, _aName( rName )
60cdf0e10cSrcweir 	, _eTypeClass( (TypeClass)eTypeClass )
61cdf0e10cSrcweir 	, _pTypeDescr( pTypeDescr )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	if (_pReflection)
64cdf0e10cSrcweir 		_pReflection->acquire();
65cdf0e10cSrcweir 	if (_pTypeDescr)
66cdf0e10cSrcweir 	{
67cdf0e10cSrcweir 		typelib_typedescription_acquire( _pTypeDescr );
68cdf0e10cSrcweir 		if (! _pTypeDescr->bComplete)
69cdf0e10cSrcweir 			typelib_typedescription_complete( &_pTypeDescr );
70cdf0e10cSrcweir 	}
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES
73cdf0e10cSrcweir 	ClassNameList::const_iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
74cdf0e10cSrcweir 	OSL_ENSURE( iFind == g_aClassNames.end(), "### idl class already exists!" );
75cdf0e10cSrcweir 	g_aClassNames.push_front( _aName );
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir }
78cdf0e10cSrcweir //__________________________________________________________________________________________________
~IdlClassImpl()79cdf0e10cSrcweir IdlClassImpl::~IdlClassImpl()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	if (_pTypeDescr)
82cdf0e10cSrcweir 		typelib_typedescription_release( _pTypeDescr );
83cdf0e10cSrcweir 	if (_pReflection)
84cdf0e10cSrcweir 		_pReflection->release();
85cdf0e10cSrcweir 
86cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES
87cdf0e10cSrcweir 	ClassNameList::iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) );
88cdf0e10cSrcweir 	OSL_ENSURE( iFind != g_aClassNames.end(), "### idl class does not exist!" );
89cdf0e10cSrcweir 	g_aClassNames.erase( iFind );
90cdf0e10cSrcweir #endif
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir // XIdlClassImpl default implementation
94cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypeClass()95cdf0e10cSrcweir TypeClass IdlClassImpl::getTypeClass()
96cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	return _eTypeClass;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir //__________________________________________________________________________________________________
getName()101cdf0e10cSrcweir OUString IdlClassImpl::getName()
102cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	return _aName;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir //__________________________________________________________________________________________________
equals(const Reference<XIdlClass> & xType)107cdf0e10cSrcweir sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType )
108cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	return (xType.is() &&
111cdf0e10cSrcweir 			(xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName));
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir static sal_Bool s_aAssignableFromTab[11][11] =
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 						 /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */
117cdf0e10cSrcweir /* TypeClass_CHAR */			{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
118cdf0e10cSrcweir /* TypeClass_BOOLEAN */			{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
119cdf0e10cSrcweir /* TypeClass_BYTE */			{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
120cdf0e10cSrcweir /* TypeClass_SHORT */			{ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
121cdf0e10cSrcweir /* TypeClass_UNSIGNED_SHORT */	{ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
122cdf0e10cSrcweir /* TypeClass_LONG */			{ 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
123cdf0e10cSrcweir /* TypeClass_UNSIGNED_LONG */	{ 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
124cdf0e10cSrcweir /* TypeClass_HYPER */			{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
125cdf0e10cSrcweir /* TypeClass_UNSIGNED_HYPER */	{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
126cdf0e10cSrcweir /* TypeClass_FLOAT */			{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
127cdf0e10cSrcweir /* TypeClass_DOUBLE */			{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
128cdf0e10cSrcweir };
129cdf0e10cSrcweir //__________________________________________________________________________________________________
isAssignableFrom(const Reference<XIdlClass> & xType)130cdf0e10cSrcweir sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
131cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	TypeClass eAssign = getTypeClass();
134cdf0e10cSrcweir 	if (equals( xType ) || eAssign == TypeClass_ANY) // default shot
135cdf0e10cSrcweir 	{
136cdf0e10cSrcweir 		return sal_True;
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 	else
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 		TypeClass eFrom	  = xType->getTypeClass();
141cdf0e10cSrcweir 		if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING &&
142cdf0e10cSrcweir 			eFrom > TypeClass_VOID && eFrom < TypeClass_STRING)
143cdf0e10cSrcweir 		{
144cdf0e10cSrcweir 			return s_aAssignableFromTab[eAssign-1][eFrom-1];
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir 	return sal_False;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir //__________________________________________________________________________________________________
createObject(Any & rObj)150cdf0e10cSrcweir void IdlClassImpl::createObject( Any & rObj )
151cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	rObj.clear();
154cdf0e10cSrcweir 	uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
155cdf0e10cSrcweir 	uno_any_construct( &rObj, 0, getTypeDescr(), 0 );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir // what TODO ????
159cdf0e10cSrcweir //__________________________________________________________________________________________________
getClasses()160cdf0e10cSrcweir Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses()
161cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "### unexpected use!" );
164cdf0e10cSrcweir 	return Sequence< Reference< XIdlClass > >();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir //__________________________________________________________________________________________________
getClass(const OUString &)167cdf0e10cSrcweir Reference< XIdlClass > IdlClassImpl::getClass( const OUString & )
168cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	OSL_ENSURE( sal_False, "### unexpected use!" );
171cdf0e10cSrcweir 	return Reference< XIdlClass >();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir //__________________________________________________________________________________________________
getInterfaces()174cdf0e10cSrcweir Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces()
175cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir //  	OSL_ENSURE( sal_False, "### unexpected use!" );
178cdf0e10cSrcweir 	return Sequence< Reference< XIdlClass > >();
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir // structs, interfaces
182cdf0e10cSrcweir //__________________________________________________________________________________________________
getSuperclasses()183cdf0e10cSrcweir Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(::com::sun::star::uno::RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	return Sequence< Reference< XIdlClass > >();
186cdf0e10cSrcweir }
187cdf0e10cSrcweir // structs
188cdf0e10cSrcweir //__________________________________________________________________________________________________
getField(const OUString &)189cdf0e10cSrcweir Reference< XIdlField > IdlClassImpl::getField( const OUString & )
190cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	return Reference< XIdlField >();
193cdf0e10cSrcweir }
194cdf0e10cSrcweir //__________________________________________________________________________________________________
getFields()195cdf0e10cSrcweir Sequence< Reference< XIdlField > > IdlClassImpl::getFields()
196cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	return Sequence< Reference< XIdlField > >();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir // interfaces
201cdf0e10cSrcweir //__________________________________________________________________________________________________
getUik()202cdf0e10cSrcweir Uik IdlClassImpl::getUik()
203cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	return Uik();
206cdf0e10cSrcweir }
207cdf0e10cSrcweir //__________________________________________________________________________________________________
getMethod(const OUString &)208cdf0e10cSrcweir Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & )
209cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	return Reference< XIdlMethod >();
212cdf0e10cSrcweir }
213cdf0e10cSrcweir //__________________________________________________________________________________________________
getMethods()214cdf0e10cSrcweir Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods()
215cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	return Sequence< Reference< XIdlMethod > >();
218cdf0e10cSrcweir }
219cdf0e10cSrcweir // array
220cdf0e10cSrcweir //__________________________________________________________________________________________________
getComponentType()221cdf0e10cSrcweir Reference< XIdlClass > IdlClassImpl::getComponentType()
222cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	return Reference< XIdlClass >();
225cdf0e10cSrcweir }
226cdf0e10cSrcweir //__________________________________________________________________________________________________
getArray()227cdf0e10cSrcweir Reference< XIdlArray > IdlClassImpl::getArray()
228cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir 	return Reference< XIdlArray >();
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 
234cdf0e10cSrcweir //##################################################################################################
235cdf0e10cSrcweir //##################################################################################################
236cdf0e10cSrcweir //##################################################################################################
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 
239cdf0e10cSrcweir //__________________________________________________________________________________________________
IdlMemberImpl(IdlReflectionServiceImpl * pReflection,const OUString & rName,typelib_TypeDescription * pTypeDescr,typelib_TypeDescription * pDeclTypeDescr)240cdf0e10cSrcweir IdlMemberImpl::IdlMemberImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
241cdf0e10cSrcweir 							  typelib_TypeDescription * pTypeDescr,
242cdf0e10cSrcweir 							  typelib_TypeDescription * pDeclTypeDescr )
243cdf0e10cSrcweir 	: _pReflection( pReflection )
244cdf0e10cSrcweir 	, _aName( rName )
245cdf0e10cSrcweir 	, _pTypeDescr( pTypeDescr )
246cdf0e10cSrcweir 	, _pDeclTypeDescr( pDeclTypeDescr )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir 	_pReflection->acquire();
249cdf0e10cSrcweir 	typelib_typedescription_acquire( _pTypeDescr );
250cdf0e10cSrcweir     if (! _pTypeDescr->bComplete)
251cdf0e10cSrcweir         typelib_typedescription_complete( &_pTypeDescr );
252cdf0e10cSrcweir 	typelib_typedescription_acquire( _pDeclTypeDescr );
253cdf0e10cSrcweir     if (! _pDeclTypeDescr->bComplete)
254cdf0e10cSrcweir         typelib_typedescription_complete( &_pDeclTypeDescr );
255cdf0e10cSrcweir }
256cdf0e10cSrcweir //__________________________________________________________________________________________________
~IdlMemberImpl()257cdf0e10cSrcweir IdlMemberImpl::~IdlMemberImpl()
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	typelib_typedescription_release( _pDeclTypeDescr );
260cdf0e10cSrcweir 	typelib_typedescription_release( _pTypeDescr );
261cdf0e10cSrcweir 	_pReflection->release();
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir // XIdlMember
265cdf0e10cSrcweir //__________________________________________________________________________________________________
getDeclaringClass()266cdf0e10cSrcweir Reference< XIdlClass > IdlMemberImpl::getDeclaringClass()
267cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	if (! _xDeclClass.is())
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir 		Reference< XIdlClass > xDeclClass( getReflection()->forType( getDeclTypeDescr() ) );
272cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
273cdf0e10cSrcweir         if (! _xDeclClass.is())
274cdf0e10cSrcweir             _xDeclClass = xDeclClass;
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir 	return _xDeclClass;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir //__________________________________________________________________________________________________
getName()279cdf0e10cSrcweir OUString IdlMemberImpl::getName()
280cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir 	return _aName;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 
288