1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/diagnose.h>
21 #include <rtl/ustrbuf.hxx>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include "com/sun/star/uno/RuntimeException.hpp"
25 #include "registry/reader.hxx"
26 #include "registry/version.h"
28 #include "methoddescription.hxx"
32 using namespace com::sun::star
;
37 public cppu::WeakImplHelper1
< XServiceConstructorDescription
>
41 Reference
< XHierarchicalNameAccess
> const & manager
,
42 OUString
const & name
, Sequence
< sal_Int8
> const & bytes
,
44 m_desc(manager
, name
, bytes
, index
) {}
46 virtual ~Constructor() {}
48 virtual sal_Bool SAL_CALL
isDefaultConstructor() throw (RuntimeException
)
49 { return m_desc
.getName().isEmpty(); }
51 virtual OUString SAL_CALL
getName() throw (RuntimeException
)
52 { return m_desc
.getName(); }
54 virtual Sequence
< Reference
< XParameter
> > SAL_CALL
getParameters()
55 throw (RuntimeException
)
56 { return m_desc
.getParameters(); }
58 virtual Sequence
< Reference
<XCompoundTypeDescription
> > SAL_CALL
59 getExceptions() throw (RuntimeException
)
60 { return m_desc
.getExceptions(); }
63 Constructor(Constructor
&); // not implemented
64 void operator =(Constructor
); // not implemented
66 stoc::registry_tdprovider::MethodDescription m_desc
;
74 // PropertyTypeDescriptionImpl
76 class PropertyTypeDescriptionImpl
: public WeakImplHelper1
< XPropertyTypeDescription
>
79 Reference
< XTypeDescription
> _xTD
;
83 PropertyTypeDescriptionImpl( const OUString
& rName
,
84 const Reference
< XTypeDescription
> & xTD
,
86 : _aName( rName
), _xTD( xTD
), _nFlags( nFlags
)
88 virtual ~PropertyTypeDescriptionImpl();
91 virtual TypeClass SAL_CALL
getTypeClass()
92 throw( RuntimeException
);
93 virtual OUString SAL_CALL
getName()
94 throw( RuntimeException
);
96 // XPropertyTypeDescription
97 virtual sal_Int16 SAL_CALL
getPropertyFlags()
98 throw ( RuntimeException
);
99 virtual Reference
< XTypeDescription
> SAL_CALL
getPropertyTypeDescription()
100 throw ( RuntimeException
);
104 PropertyTypeDescriptionImpl::~PropertyTypeDescriptionImpl() {}
109 TypeClass
PropertyTypeDescriptionImpl::getTypeClass()
110 throw ( RuntimeException
)
112 return TypeClass_PROPERTY
;
116 OUString
PropertyTypeDescriptionImpl::getName()
117 throw ( RuntimeException
)
122 // XPropertyTypeDescription
125 sal_Int16 SAL_CALL
PropertyTypeDescriptionImpl::getPropertyFlags()
126 throw ( RuntimeException
)
132 Reference
< XTypeDescription
> SAL_CALL
133 PropertyTypeDescriptionImpl::getPropertyTypeDescription()
134 throw ( RuntimeException
)
139 // ServiceTypeDescriptionImpl
142 ServiceTypeDescriptionImpl::~ServiceTypeDescriptionImpl() {}
147 TypeClass
ServiceTypeDescriptionImpl::getTypeClass()
148 throw(::com::sun::star::uno::RuntimeException
)
150 return TypeClass_SERVICE
;
154 OUString
ServiceTypeDescriptionImpl::getName()
155 throw(::com::sun::star::uno::RuntimeException
)
160 // XServiceTypeDescription
163 Sequence
< Reference
< XServiceTypeDescription
> > SAL_CALL
164 ServiceTypeDescriptionImpl::getMandatoryServices()
165 throw ( RuntimeException
)
168 return _aMandatoryServices
;
172 Sequence
< Reference
< XServiceTypeDescription
> > SAL_CALL
173 ServiceTypeDescriptionImpl::getOptionalServices()
174 throw ( RuntimeException
)
177 return _aOptionalServices
;
181 Sequence
< Reference
< XInterfaceTypeDescription
> > SAL_CALL
182 ServiceTypeDescriptionImpl::getMandatoryInterfaces()
183 throw ( RuntimeException
)
186 return _aMandatoryInterfaces
;
190 Sequence
< Reference
< XInterfaceTypeDescription
> > SAL_CALL
191 ServiceTypeDescriptionImpl::getOptionalInterfaces()
192 throw ( RuntimeException
)
195 return _aOptionalInterfaces
;
199 Sequence
< Reference
< XPropertyTypeDescription
> > SAL_CALL
200 ServiceTypeDescriptionImpl::getProperties()
201 throw ( RuntimeException
)
204 MutexGuard
guard(getMutex());
205 if (_pProps
.get() != 0) {
210 typereg::Reader
aReader(
211 _aBytes
.getConstArray(), _aBytes
.getLength(), false, TYPEREG_VERSION_1
);
213 sal_uInt16 nFields
= (sal_uInt16
)aReader
.getFieldCount();
214 SAL_WNODEPRECATED_DECLARATIONS_PUSH
215 std::auto_ptr
< Sequence
< Reference
< XPropertyTypeDescription
> > >
217 new Sequence
< Reference
< XPropertyTypeDescription
> >(nFields
));
218 SAL_WNODEPRECATED_DECLARATIONS_POP
219 Reference
< XPropertyTypeDescription
> * pProps
= pTempProps
->getArray();
224 OUStringBuffer
aName( _aName
);
225 aName
.appendAscii( "." );
226 aName
.append( aReader
.getFieldName( nFields
) );
229 Reference
< XTypeDescription
> xTD
;
232 _xTDMgr
->getByHierarchicalName(
233 aReader
.getFieldTypeName( nFields
).replace( '/', '.' ) )
236 catch ( NoSuchElementException
const & )
239 OSL_ENSURE( xTD
.is(), "### no type description for property!" );
242 RTFieldAccess nFlags
= aReader
.getFieldFlags( nFields
);
244 sal_Int16 nAttribs
= 0;
245 if ( nFlags
& RT_ACCESS_READONLY
)
246 nAttribs
|= beans::PropertyAttribute::READONLY
;
247 if ( nFlags
& RT_ACCESS_OPTIONAL
)
248 nAttribs
|= beans::PropertyAttribute::OPTIONAL
;
249 if ( nFlags
& RT_ACCESS_MAYBEVOID
)
250 nAttribs
|= beans::PropertyAttribute::MAYBEVOID
;
251 if ( nFlags
& RT_ACCESS_BOUND
)
252 nAttribs
|= beans::PropertyAttribute::BOUND
;
253 if ( nFlags
& RT_ACCESS_CONSTRAINED
)
254 nAttribs
|= beans::PropertyAttribute::CONSTRAINED
;
255 if ( nFlags
& RT_ACCESS_TRANSIENT
)
256 nAttribs
|= beans::PropertyAttribute::TRANSIENT
;
257 if ( nFlags
& RT_ACCESS_MAYBEAMBIGUOUS
)
258 nAttribs
|= beans::PropertyAttribute::MAYBEAMBIGUOUS
;
259 if ( nFlags
& RT_ACCESS_MAYBEDEFAULT
)
260 nAttribs
|= beans::PropertyAttribute::MAYBEDEFAULT
;
261 if ( nFlags
& RT_ACCESS_REMOVEABLE
)
262 nAttribs
|= beans::PropertyAttribute::REMOVABLE
;
264 OSL_ENSURE( !(nFlags
& RT_ACCESS_PROPERTY
),
265 "### RT_ACCESS_PROPERTY is unexpected here!" );
266 OSL_ENSURE( !(nFlags
& RT_ACCESS_ATTRIBUTE
),
267 "### RT_ACCESS_ATTRIBUTE is unexpected here!" );
268 OSL_ENSURE( !(nFlags
& RT_ACCESS_CONST
),
269 "### RT_ACCESS_CONST is unexpected here!" );
270 // always set, unless RT_ACCESS_READONLY is set.
271 //OSL_ENSURE( !(nFlags & RT_ACCESS_READWRITE),
272 // "### RT_ACCESS_READWRITE is unexpected here" );
273 OSL_ENSURE( !(nFlags
& RT_ACCESS_DEFAULT
),
274 "### RT_ACCESS_DEAFAULT is unexpected here" );
277 = new PropertyTypeDescriptionImpl( aName
.makeStringAndClear(),
282 MutexGuard
guard(getMutex());
283 if (_pProps
.get() == 0) {
284 _pProps
= pTempProps
;
289 sal_Bool
ServiceTypeDescriptionImpl::isSingleInterfaceBased()
290 throw (RuntimeException
)
293 return _xInterfaceTD
.is();
296 Reference
< XTypeDescription
> ServiceTypeDescriptionImpl::getInterface()
297 throw (RuntimeException
)
300 return _xInterfaceTD
;
303 Sequence
< Reference
< XServiceConstructorDescription
> >
304 ServiceTypeDescriptionImpl::getConstructors() throw (RuntimeException
) {
305 MutexGuard
guard(getMutex());
306 if (_pCtors
.get() == 0) {
307 typereg::Reader
reader(
308 _aBytes
.getConstArray(), _aBytes
.getLength(), false,
310 sal_uInt16 ctorCount
= reader
.getMethodCount();
311 SAL_WNODEPRECATED_DECLARATIONS_PUSH
312 std::auto_ptr
< Sequence
< Reference
< XServiceConstructorDescription
> > >
314 new Sequence
< Reference
< XServiceConstructorDescription
> >(
316 SAL_WNODEPRECATED_DECLARATIONS_POP
317 for (sal_uInt16 i
= 0; i
< ctorCount
; ++i
) {
318 OUString
name(reader
.getMethodName(i
));
319 if (reader
.getMethodFlags(i
) != RT_MODE_TWOWAY
320 || (reader
.getMethodReturnTypeName(i
) != "void")
322 && (ctorCount
!= 1 || reader
.getMethodParameterCount(i
) != 0
323 || reader
.getMethodExceptionCount(i
) != 0)))
325 throw RuntimeException(
326 OUString("Service has bad constructors"),
327 static_cast< OWeakObject
* >(this));
329 (*ctors
)[i
] = new Constructor(
330 _xTDMgr
, reader
.getMethodName(i
), _aBytes
, i
);
337 void ServiceTypeDescriptionImpl::getReferences()
338 throw ( RuntimeException
)
341 MutexGuard
guard(getMutex());
342 if (_bInitReferences
) {
346 typereg::Reader
aReader(
347 _aBytes
.getConstArray(), _aBytes
.getLength(), false, TYPEREG_VERSION_1
);
348 sal_uInt16 superTypes
= aReader
.getSuperTypeCount();
349 if (superTypes
> 1) {
350 throw RuntimeException(
351 OUString("Service has more than one supertype"),
352 static_cast< OWeakObject
* >(this));
354 if (superTypes
== 1) {
355 OUString
aBaseName( aReader
.getSuperTypeName(0).replace( '/', '.' ) );
356 if ( aReader
.getReferenceCount() != 0
357 || aReader
.getFieldCount() != 0 )
358 throw RuntimeException(
359 OUString("Service is single-interface--based but also has"
360 " references and/or properties" ),
361 static_cast< OWeakObject
* >( this ) );
362 Reference
< XTypeDescription
> ifc
;
365 _xTDMgr
->getByHierarchicalName( aBaseName
) >>= ifc
;
367 catch ( NoSuchElementException
const & e
)
369 throw RuntimeException(
370 OUString("com.sun.star.container.NoSuchElementException: " )
372 static_cast< OWeakObject
* >( this ) );
374 OSL_ASSERT(ifc
.is());
375 if (resolveTypedefs(ifc
)->getTypeClass() != TypeClass_INTERFACE
) {
376 throw RuntimeException(
377 OUString("Single-interface--based service is not based on"
379 static_cast< OWeakObject
* >( this ) );
381 MutexGuard
guard(getMutex());
382 if (!_bInitReferences
) {
384 _bInitReferences
= true;
389 sal_uInt16 nRefs
= aReader
.getReferenceCount();
390 Sequence
< Reference
< XServiceTypeDescription
> > aMandatoryServices(
392 Sequence
< Reference
< XServiceTypeDescription
> > aOptionalServices(
394 Sequence
< Reference
< XInterfaceTypeDescription
> > aMandatoryInterfaces(
396 Sequence
< Reference
< XInterfaceTypeDescription
> > aOptionalInterfaces(
403 for ( sal_uInt16 nPos
= 0; nPos
< nRefs
; ++nPos
)
405 RTReferenceType eType
= aReader
.getReferenceSort( nPos
);
408 case RT_REF_EXPORTS
: // service
413 aTypeDesc
= _xTDMgr
->getByHierarchicalName(
414 aReader
.getReferenceTypeName( nPos
).replace(
417 catch ( NoSuchElementException
const & e
)
419 throw RuntimeException(
420 OUString("com.sun.star.container.NoSuchElementException: " )
422 static_cast< OWeakObject
* >( this ) );
425 RTFieldAccess nAccess
= aReader
.getReferenceFlags( nPos
);
426 if ( nAccess
& RT_ACCESS_OPTIONAL
)
429 if ( !( aTypeDesc
>>= aOptionalServices
[ nOS
] ) )
430 throw RuntimeException(
431 OUString("Service 'export' is not a service" ),
432 static_cast< OWeakObject
* >( this ) );
438 if ( !( aTypeDesc
>>= aMandatoryServices
[ nMS
] ) )
439 throw RuntimeException(
440 OUString("Service 'export' is not a service" ),
441 static_cast< OWeakObject
* >( this ) );
446 case RT_REF_SUPPORTS
: // interface
451 aTypeDesc
= _xTDMgr
->getByHierarchicalName(
452 aReader
.getReferenceTypeName( nPos
).replace(
455 catch ( NoSuchElementException
const & e
)
457 throw RuntimeException(
458 OUString("com.sun.star.container.NoSuchElementException: " )
460 static_cast< OWeakObject
* >( this ) );
463 RTFieldAccess nAccess
= aReader
.getReferenceFlags( nPos
);
464 if ( nAccess
& RT_ACCESS_OPTIONAL
)
466 // optional interface
467 if ( !( aTypeDesc
>>= aOptionalInterfaces
[ nOI
] ) )
468 throw RuntimeException(
469 OUString("Service 'supports' is not an"
471 static_cast< OWeakObject
* >( this ) );
476 // mandatory interface
477 if ( !( aTypeDesc
>>= aMandatoryInterfaces
[ nMI
] ) )
478 throw RuntimeException(
479 OUString("Service 'supports' is not an"
481 static_cast< OWeakObject
* >( this ) );
486 case RT_REF_OBSERVES
:
490 OSL_FAIL( "### unsupported reference type!" );
494 aMandatoryServices
.realloc( nMS
);
495 aOptionalServices
.realloc( nOS
);
496 aMandatoryInterfaces
.realloc( nMI
);
497 aOptionalInterfaces
.realloc( nOI
);
499 MutexGuard
guard(getMutex());
500 if (!_bInitReferences
) {
501 _aMandatoryServices
= aMandatoryServices
;
502 _aOptionalServices
= aOptionalServices
;
503 _aMandatoryInterfaces
= aMandatoryInterfaces
;
504 _aOptionalInterfaces
= aOptionalInterfaces
;
505 _bInitReferences
= true;
513 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */