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