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: tdservice.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 <osl/diagnose.h>
34 #include <rtl/ustrbuf.hxx>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include "com/sun/star/uno/RuntimeException.hpp"
38 #include "registry/reader.hxx"
39 #include "registry/version.h"
41 #include "methoddescription.hxx"
45 using namespace com::sun::star
;
50 public cppu::WeakImplHelper1
< XServiceConstructorDescription
>
54 Reference
< XHierarchicalNameAccess
> const & manager
,
55 rtl::OUString
const & name
, Sequence
< sal_Int8
> const & bytes
,
57 m_desc(manager
, name
, bytes
, index
) {}
59 virtual ~Constructor() {}
61 virtual sal_Bool SAL_CALL
isDefaultConstructor() throw (RuntimeException
)
62 { return m_desc
.getName().getLength() == 0; }
64 virtual rtl::OUString SAL_CALL
getName() throw (RuntimeException
)
65 { return m_desc
.getName(); }
67 virtual Sequence
< Reference
< XParameter
> > SAL_CALL
getParameters()
68 throw (RuntimeException
)
69 { return m_desc
.getParameters(); }
71 virtual Sequence
< Reference
<XCompoundTypeDescription
> > SAL_CALL
72 getExceptions() throw (RuntimeException
)
73 { return m_desc
.getExceptions(); }
76 Constructor(Constructor
&); // not implemented
77 void operator =(Constructor
); // not implemented
79 stoc::registry_tdprovider::MethodDescription m_desc
;
87 //==================================================================================================
89 // class PropertyTypeDescriptionImpl
91 //==================================================================================================
92 class PropertyTypeDescriptionImpl
: public WeakImplHelper1
< XPropertyTypeDescription
>
95 Reference
< XTypeDescription
> _xTD
;
99 PropertyTypeDescriptionImpl( const OUString
& rName
,
100 const Reference
< XTypeDescription
> & xTD
,
102 : _aName( rName
), _xTD( xTD
), _nFlags( nFlags
)
104 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
106 virtual ~PropertyTypeDescriptionImpl();
109 virtual TypeClass SAL_CALL
getTypeClass()
110 throw( RuntimeException
);
111 virtual OUString SAL_CALL
getName()
112 throw( RuntimeException
);
114 // XPropertyTypeDescription
115 virtual sal_Int16 SAL_CALL
getPropertyFlags()
116 throw ( RuntimeException
);
117 virtual Reference
< XTypeDescription
> SAL_CALL
getPropertyTypeDescription()
118 throw ( RuntimeException
);
121 //__________________________________________________________________________________________________
123 PropertyTypeDescriptionImpl::~PropertyTypeDescriptionImpl()
125 g_moduleCount
.modCnt
.release( &g_moduleCount
.modCnt
);
129 //__________________________________________________________________________________________________
131 TypeClass
PropertyTypeDescriptionImpl::getTypeClass()
132 throw ( RuntimeException
)
134 return TypeClass_PROPERTY
;
136 //__________________________________________________________________________________________________
138 OUString
PropertyTypeDescriptionImpl::getName()
139 throw ( RuntimeException
)
144 // XPropertyTypeDescription
145 //__________________________________________________________________________________________________
147 sal_Int16 SAL_CALL
PropertyTypeDescriptionImpl::getPropertyFlags()
148 throw ( RuntimeException
)
153 //__________________________________________________________________________________________________
155 Reference
< XTypeDescription
> SAL_CALL
156 PropertyTypeDescriptionImpl::getPropertyTypeDescription()
157 throw ( RuntimeException
)
162 //==================================================================================================
164 // ServiceTypeDescriptionImpl implementation
166 //==================================================================================================
168 //__________________________________________________________________________________________________
170 ServiceTypeDescriptionImpl::~ServiceTypeDescriptionImpl()
172 g_moduleCount
.modCnt
.release( &g_moduleCount
.modCnt
);
176 //__________________________________________________________________________________________________
178 TypeClass
ServiceTypeDescriptionImpl::getTypeClass()
179 throw(::com::sun::star::uno::RuntimeException
)
181 return TypeClass_SERVICE
;
183 //__________________________________________________________________________________________________
185 OUString
ServiceTypeDescriptionImpl::getName()
186 throw(::com::sun::star::uno::RuntimeException
)
191 // XServiceTypeDescription
192 //__________________________________________________________________________________________________
194 Sequence
< Reference
< XServiceTypeDescription
> > SAL_CALL
195 ServiceTypeDescriptionImpl::getMandatoryServices()
196 throw ( RuntimeException
)
199 return _aMandatoryServices
;
202 //__________________________________________________________________________________________________
204 Sequence
< Reference
< XServiceTypeDescription
> > SAL_CALL
205 ServiceTypeDescriptionImpl::getOptionalServices()
206 throw ( RuntimeException
)
209 return _aOptionalServices
;
212 //__________________________________________________________________________________________________
214 Sequence
< Reference
< XInterfaceTypeDescription
> > SAL_CALL
215 ServiceTypeDescriptionImpl::getMandatoryInterfaces()
216 throw ( RuntimeException
)
219 return _aMandatoryInterfaces
;
222 //__________________________________________________________________________________________________
224 Sequence
< Reference
< XInterfaceTypeDescription
> > SAL_CALL
225 ServiceTypeDescriptionImpl::getOptionalInterfaces()
226 throw ( RuntimeException
)
229 return _aOptionalInterfaces
;
232 //__________________________________________________________________________________________________
234 Sequence
< Reference
< XPropertyTypeDescription
> > SAL_CALL
235 ServiceTypeDescriptionImpl::getProperties()
236 throw ( RuntimeException
)
239 MutexGuard
guard(getMutex());
240 if (_pProps
.get() != 0) {
245 typereg::Reader
aReader(
246 _aBytes
.getConstArray(), _aBytes
.getLength(), false, TYPEREG_VERSION_1
);
248 sal_uInt16 nFields
= (sal_uInt16
)aReader
.getFieldCount();
249 std::auto_ptr
< Sequence
< Reference
< XPropertyTypeDescription
> > >
251 new Sequence
< Reference
< XPropertyTypeDescription
> >(nFields
));
252 Reference
< XPropertyTypeDescription
> * pProps
= pTempProps
->getArray();
257 OUStringBuffer
aName( _aName
);
258 aName
.appendAscii( "." );
259 aName
.append( aReader
.getFieldName( nFields
) );
262 Reference
< XTypeDescription
> xTD
;
265 _xTDMgr
->getByHierarchicalName(
266 aReader
.getFieldTypeName( nFields
).replace( '/', '.' ) )
269 catch ( NoSuchElementException
const & )
272 OSL_ENSURE( xTD
.is(), "### no type description for property!" );
275 RTFieldAccess nFlags
= aReader
.getFieldFlags( nFields
);
277 sal_Int16 nAttribs
= 0;
278 if ( nFlags
& RT_ACCESS_READONLY
)
279 nAttribs
|= beans::PropertyAttribute::READONLY
;
280 if ( nFlags
& RT_ACCESS_OPTIONAL
)
281 nAttribs
|= beans::PropertyAttribute::OPTIONAL
;
282 if ( nFlags
& RT_ACCESS_MAYBEVOID
)
283 nAttribs
|= beans::PropertyAttribute::MAYBEVOID
;
284 if ( nFlags
& RT_ACCESS_BOUND
)
285 nAttribs
|= beans::PropertyAttribute::BOUND
;
286 if ( nFlags
& RT_ACCESS_CONSTRAINED
)
287 nAttribs
|= beans::PropertyAttribute::CONSTRAINED
;
288 if ( nFlags
& RT_ACCESS_TRANSIENT
)
289 nAttribs
|= beans::PropertyAttribute::TRANSIENT
;
290 if ( nFlags
& RT_ACCESS_MAYBEAMBIGUOUS
)
291 nAttribs
|= beans::PropertyAttribute::MAYBEAMBIGUOUS
;
292 if ( nFlags
& RT_ACCESS_MAYBEDEFAULT
)
293 nAttribs
|= beans::PropertyAttribute::MAYBEDEFAULT
;
294 if ( nFlags
& RT_ACCESS_REMOVEABLE
)
295 nAttribs
|= beans::PropertyAttribute::REMOVEABLE
;
297 OSL_ENSURE( !(nFlags
& RT_ACCESS_PROPERTY
),
298 "### RT_ACCESS_PROPERTY is unexpected here!" );
299 OSL_ENSURE( !(nFlags
& RT_ACCESS_ATTRIBUTE
),
300 "### RT_ACCESS_ATTRIBUTE is unexpected here!" );
301 OSL_ENSURE( !(nFlags
& RT_ACCESS_CONST
),
302 "### RT_ACCESS_CONST is unexpected here!" );
303 // always set, unless RT_ACCESS_READONLY is set.
304 //OSL_ENSURE( !(nFlags & RT_ACCESS_READWRITE),
305 // "### RT_ACCESS_READWRITE is unexpected here" );
306 OSL_ENSURE( !(nFlags
& RT_ACCESS_DEFAULT
),
307 "### RT_ACCESS_DEAFAULT is unexpected here" );
310 = new PropertyTypeDescriptionImpl( aName
.makeStringAndClear(),
315 MutexGuard
guard(getMutex());
316 if (_pProps
.get() == 0) {
317 _pProps
= pTempProps
;
322 sal_Bool
ServiceTypeDescriptionImpl::isSingleInterfaceBased()
323 throw (RuntimeException
)
326 return _xInterfaceTD
.is();
329 Reference
< XTypeDescription
> ServiceTypeDescriptionImpl::getInterface()
330 throw (RuntimeException
)
333 return _xInterfaceTD
;
336 Sequence
< Reference
< XServiceConstructorDescription
> >
337 ServiceTypeDescriptionImpl::getConstructors() throw (RuntimeException
) {
338 MutexGuard
guard(getMutex());
339 if (_pCtors
.get() == 0) {
340 typereg::Reader
reader(
341 _aBytes
.getConstArray(), _aBytes
.getLength(), false,
343 sal_uInt16 ctorCount
= reader
.getMethodCount();
344 std::auto_ptr
< Sequence
< Reference
< XServiceConstructorDescription
> > >
346 new Sequence
< Reference
< XServiceConstructorDescription
> >(
348 for (sal_uInt16 i
= 0; i
< ctorCount
; ++i
) {
349 rtl::OUString
name(reader
.getMethodName(i
));
350 if (reader
.getMethodFlags(i
) != RT_MODE_TWOWAY
351 || (!reader
.getMethodReturnTypeName(i
).equalsAsciiL(
352 RTL_CONSTASCII_STRINGPARAM("void")))
353 || (name
.getLength() == 0
354 && (ctorCount
!= 1 || reader
.getMethodParameterCount(i
) != 0
355 || reader
.getMethodExceptionCount(i
) != 0)))
357 throw RuntimeException(
359 RTL_CONSTASCII_USTRINGPARAM(
360 "Service has bad constructors")),
361 static_cast< OWeakObject
* >(this));
363 (*ctors
)[i
] = new Constructor(
364 _xTDMgr
, reader
.getMethodName(i
), _aBytes
, i
);
371 //__________________________________________________________________________________________________
372 void ServiceTypeDescriptionImpl::getReferences()
373 throw ( RuntimeException
)
376 MutexGuard
guard(getMutex());
377 if (_bInitReferences
) {
381 typereg::Reader
aReader(
382 _aBytes
.getConstArray(), _aBytes
.getLength(), false, TYPEREG_VERSION_1
);
383 sal_uInt16 superTypes
= aReader
.getSuperTypeCount();
384 if (superTypes
> 1) {
385 throw RuntimeException(
387 RTL_CONSTASCII_USTRINGPARAM(
388 "Service has more than one supertype")),
389 static_cast< OWeakObject
* >(this));
391 if (superTypes
== 1) {
392 OUString
aBaseName( aReader
.getSuperTypeName(0).replace( '/', '.' ) );
393 if ( aReader
.getReferenceCount() != 0
394 || aReader
.getFieldCount() != 0 )
395 throw RuntimeException(
397 RTL_CONSTASCII_USTRINGPARAM(
398 "Service is single-interface--based but also has"
399 " references and/or properties" ) ),
400 static_cast< OWeakObject
* >( this ) );
401 Reference
< XTypeDescription
> ifc
;
404 _xTDMgr
->getByHierarchicalName( aBaseName
) >>= ifc
;
406 catch ( NoSuchElementException
const & e
)
408 throw RuntimeException(
410 RTL_CONSTASCII_USTRINGPARAM(
411 "com.sun.star.container.NoSuchElementException: " ) )
413 static_cast< OWeakObject
* >( this ) );
415 OSL_ASSERT(ifc
.is());
416 if (resolveTypedefs(ifc
)->getTypeClass() != TypeClass_INTERFACE
) {
417 throw RuntimeException(
419 RTL_CONSTASCII_USTRINGPARAM(
420 "Single-interface--based service is not based on"
421 " interface type" ) ),
422 static_cast< OWeakObject
* >( this ) );
424 MutexGuard
guard(getMutex());
425 if (!_bInitReferences
) {
427 _bInitReferences
= true;
432 sal_uInt16 nRefs
= aReader
.getReferenceCount();
433 Sequence
< Reference
< XServiceTypeDescription
> > aMandatoryServices(
435 Sequence
< Reference
< XServiceTypeDescription
> > aOptionalServices(
437 Sequence
< Reference
< XInterfaceTypeDescription
> > aMandatoryInterfaces(
439 Sequence
< Reference
< XInterfaceTypeDescription
> > aOptionalInterfaces(
446 for ( sal_uInt16 nPos
= 0; nPos
< nRefs
; ++nPos
)
448 RTReferenceType eType
= aReader
.getReferenceSort( nPos
);
451 case RT_REF_EXPORTS
: // service
456 aTypeDesc
= _xTDMgr
->getByHierarchicalName(
457 aReader
.getReferenceTypeName( nPos
).replace(
460 catch ( NoSuchElementException
const & e
)
462 throw RuntimeException(
464 RTL_CONSTASCII_USTRINGPARAM(
465 "com.sun.star.container."
466 "NoSuchElementException: " ) )
468 static_cast< OWeakObject
* >( this ) );
471 RTFieldAccess nAccess
= aReader
.getReferenceFlags( nPos
);
472 if ( nAccess
& RT_ACCESS_OPTIONAL
)
475 if ( !( aTypeDesc
>>= aOptionalServices
[ nOS
] ) )
476 throw RuntimeException(
478 RTL_CONSTASCII_USTRINGPARAM(
479 "Service 'export' is not a service" ) ),
480 static_cast< OWeakObject
* >( this ) );
486 if ( !( aTypeDesc
>>= aMandatoryServices
[ nMS
] ) )
487 throw RuntimeException(
489 RTL_CONSTASCII_USTRINGPARAM(
490 "Service 'export' is not a service" ) ),
491 static_cast< OWeakObject
* >( this ) );
496 case RT_REF_SUPPORTS
: // interface
501 aTypeDesc
= _xTDMgr
->getByHierarchicalName(
502 aReader
.getReferenceTypeName( nPos
).replace(
505 catch ( NoSuchElementException
const & e
)
507 throw RuntimeException(
509 RTL_CONSTASCII_USTRINGPARAM(
510 "com.sun.star.container."
511 "NoSuchElementException: " ) )
513 static_cast< OWeakObject
* >( this ) );
516 RTFieldAccess nAccess
= aReader
.getReferenceFlags( nPos
);
517 if ( nAccess
& RT_ACCESS_OPTIONAL
)
519 // optional interface
520 if ( !( aTypeDesc
>>= aOptionalInterfaces
[ nOI
] ) )
521 throw RuntimeException(
523 RTL_CONSTASCII_USTRINGPARAM(
524 "Service 'supports' is not an"
526 static_cast< OWeakObject
* >( this ) );
531 // mandatory interface
532 if ( !( aTypeDesc
>>= aMandatoryInterfaces
[ nMI
] ) )
533 throw RuntimeException(
535 RTL_CONSTASCII_USTRINGPARAM(
536 "Service 'supports' is not an"
538 static_cast< OWeakObject
* >( this ) );
543 case RT_REF_OBSERVES
:
547 OSL_ENSURE( sal_False
, "### unsupported reference type!" );
551 aMandatoryServices
.realloc( nMS
);
552 aOptionalServices
.realloc( nOS
);
553 aMandatoryInterfaces
.realloc( nMI
);
554 aOptionalInterfaces
.realloc( nOI
);
556 MutexGuard
guard(getMutex());
557 if (!_bInitReferences
) {
558 _aMandatoryServices
= aMandatoryServices
;
559 _aOptionalServices
= aOptionalServices
;
560 _aMandatoryInterfaces
= aMandatoryInterfaces
;
561 _aOptionalInterfaces
= aOptionalInterfaces
;
562 _bInitReferences
= true;