xref: /AOO41X/main/stoc/source/registry_tdprovider/tdservice.cxx (revision 647a425c57429e1e89af1c7acf2de6af6f1bb730)
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
10cdf0e10cSrcweir  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 <osl/diagnose.h>
27cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
29cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "registry/reader.hxx"
32cdf0e10cSrcweir #include "registry/version.h"
33cdf0e10cSrcweir #include "base.hxx"
34cdf0e10cSrcweir #include "methoddescription.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <memory>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace com::sun::star;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace {
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class Constructor:
43cdf0e10cSrcweir     public cppu::WeakImplHelper1< XServiceConstructorDescription >
44cdf0e10cSrcweir {
45cdf0e10cSrcweir public:
Constructor(Reference<XHierarchicalNameAccess> const & manager,rtl::OUString const & name,Sequence<sal_Int8> const & bytes,sal_uInt16 index)46cdf0e10cSrcweir     Constructor(
47cdf0e10cSrcweir         Reference< XHierarchicalNameAccess > const & manager,
48cdf0e10cSrcweir         rtl::OUString const & name, Sequence< sal_Int8 > const & bytes,
49cdf0e10cSrcweir         sal_uInt16 index):
50cdf0e10cSrcweir         m_desc(manager, name, bytes, index) {}
51cdf0e10cSrcweir 
~Constructor()52cdf0e10cSrcweir     virtual ~Constructor() {}
53cdf0e10cSrcweir 
isDefaultConstructor()54cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isDefaultConstructor() throw (RuntimeException)
55cdf0e10cSrcweir     { return m_desc.getName().getLength() == 0; }
56cdf0e10cSrcweir 
getName()57cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getName() throw (RuntimeException)
58cdf0e10cSrcweir     { return m_desc.getName(); }
59cdf0e10cSrcweir 
getParameters()60cdf0e10cSrcweir     virtual Sequence< Reference< XParameter > > SAL_CALL getParameters()
61cdf0e10cSrcweir         throw (RuntimeException)
62cdf0e10cSrcweir     { return m_desc.getParameters(); }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     virtual Sequence< Reference<XCompoundTypeDescription > > SAL_CALL
getExceptions()65cdf0e10cSrcweir     getExceptions() throw (RuntimeException)
66cdf0e10cSrcweir     { return m_desc.getExceptions(); }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir private:
69cdf0e10cSrcweir     Constructor(Constructor &); // not implemented
70cdf0e10cSrcweir     void operator =(Constructor); // not implemented
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     stoc::registry_tdprovider::MethodDescription m_desc;
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir namespace stoc_rdbtdp
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //==================================================================================================
81cdf0e10cSrcweir //
82cdf0e10cSrcweir // class PropertyTypeDescriptionImpl
83cdf0e10cSrcweir //
84cdf0e10cSrcweir //==================================================================================================
85cdf0e10cSrcweir class PropertyTypeDescriptionImpl : public WeakImplHelper1< XPropertyTypeDescription >
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     OUString                      _aName;
88cdf0e10cSrcweir     Reference< XTypeDescription > _xTD;
89cdf0e10cSrcweir     sal_Int16                     _nFlags;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir public:
PropertyTypeDescriptionImpl(const OUString & rName,const Reference<XTypeDescription> & xTD,sal_Int16 nFlags)92cdf0e10cSrcweir     PropertyTypeDescriptionImpl( const OUString & rName,
93cdf0e10cSrcweir                                  const Reference< XTypeDescription > & xTD,
94cdf0e10cSrcweir                                  sal_Int16 nFlags )
95cdf0e10cSrcweir     : _aName( rName ), _xTD( xTD ), _nFlags( nFlags )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir     virtual ~PropertyTypeDescriptionImpl();
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     // XTypeDescription
102cdf0e10cSrcweir     virtual TypeClass SAL_CALL getTypeClass()
103cdf0e10cSrcweir         throw( RuntimeException );
104cdf0e10cSrcweir     virtual OUString SAL_CALL getName()
105cdf0e10cSrcweir         throw( RuntimeException );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     // XPropertyTypeDescription
108cdf0e10cSrcweir     virtual sal_Int16 SAL_CALL getPropertyFlags()
109cdf0e10cSrcweir         throw ( RuntimeException );
110cdf0e10cSrcweir     virtual Reference< XTypeDescription > SAL_CALL getPropertyTypeDescription()
111cdf0e10cSrcweir         throw ( RuntimeException );
112cdf0e10cSrcweir };
113cdf0e10cSrcweir 
114cdf0e10cSrcweir //__________________________________________________________________________________________________
115cdf0e10cSrcweir // virtual
~PropertyTypeDescriptionImpl()116cdf0e10cSrcweir PropertyTypeDescriptionImpl::~PropertyTypeDescriptionImpl()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // XTypeDescription
122cdf0e10cSrcweir //__________________________________________________________________________________________________
123cdf0e10cSrcweir // virtual
getTypeClass()124cdf0e10cSrcweir TypeClass PropertyTypeDescriptionImpl::getTypeClass()
125cdf0e10cSrcweir     throw ( RuntimeException )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     return TypeClass_PROPERTY;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir //__________________________________________________________________________________________________
130cdf0e10cSrcweir // virtual
getName()131cdf0e10cSrcweir OUString PropertyTypeDescriptionImpl::getName()
132cdf0e10cSrcweir     throw ( RuntimeException )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     return _aName;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // XPropertyTypeDescription
138cdf0e10cSrcweir //__________________________________________________________________________________________________
139cdf0e10cSrcweir // virtual
getPropertyFlags()140cdf0e10cSrcweir sal_Int16 SAL_CALL PropertyTypeDescriptionImpl::getPropertyFlags()
141cdf0e10cSrcweir     throw ( RuntimeException )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     return _nFlags;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir //__________________________________________________________________________________________________
147cdf0e10cSrcweir // virtual
148cdf0e10cSrcweir Reference< XTypeDescription > SAL_CALL
getPropertyTypeDescription()149cdf0e10cSrcweir PropertyTypeDescriptionImpl::getPropertyTypeDescription()
150cdf0e10cSrcweir     throw ( RuntimeException )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     return _xTD;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir //==================================================================================================
156cdf0e10cSrcweir //
157cdf0e10cSrcweir // ServiceTypeDescriptionImpl implementation
158cdf0e10cSrcweir //
159cdf0e10cSrcweir //==================================================================================================
160cdf0e10cSrcweir 
161cdf0e10cSrcweir //__________________________________________________________________________________________________
162cdf0e10cSrcweir // virtual
~ServiceTypeDescriptionImpl()163cdf0e10cSrcweir ServiceTypeDescriptionImpl::~ServiceTypeDescriptionImpl()
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir // XTypeDescription
169cdf0e10cSrcweir //__________________________________________________________________________________________________
170cdf0e10cSrcweir // virtual
getTypeClass()171cdf0e10cSrcweir TypeClass ServiceTypeDescriptionImpl::getTypeClass()
172cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     return TypeClass_SERVICE;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir //__________________________________________________________________________________________________
177cdf0e10cSrcweir // virtual
getName()178cdf0e10cSrcweir OUString ServiceTypeDescriptionImpl::getName()
179cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	return _aName;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // XServiceTypeDescription
185cdf0e10cSrcweir //__________________________________________________________________________________________________
186cdf0e10cSrcweir // virtual
187cdf0e10cSrcweir Sequence< Reference< XServiceTypeDescription > > SAL_CALL
getMandatoryServices()188cdf0e10cSrcweir ServiceTypeDescriptionImpl::getMandatoryServices()
189cdf0e10cSrcweir     throw ( RuntimeException )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     getReferences();
192cdf0e10cSrcweir     return _aMandatoryServices;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir //__________________________________________________________________________________________________
196cdf0e10cSrcweir // virtual
197cdf0e10cSrcweir Sequence< Reference< XServiceTypeDescription > > SAL_CALL
getOptionalServices()198cdf0e10cSrcweir ServiceTypeDescriptionImpl::getOptionalServices()
199cdf0e10cSrcweir     throw ( RuntimeException )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     getReferences();
202cdf0e10cSrcweir     return _aOptionalServices;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir //__________________________________________________________________________________________________
206cdf0e10cSrcweir // virtual
207cdf0e10cSrcweir Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL
getMandatoryInterfaces()208cdf0e10cSrcweir ServiceTypeDescriptionImpl::getMandatoryInterfaces()
209cdf0e10cSrcweir     throw ( RuntimeException )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     getReferences();
212cdf0e10cSrcweir     return _aMandatoryInterfaces;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir //__________________________________________________________________________________________________
216cdf0e10cSrcweir // virtual
217cdf0e10cSrcweir Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL
getOptionalInterfaces()218cdf0e10cSrcweir ServiceTypeDescriptionImpl::getOptionalInterfaces()
219cdf0e10cSrcweir     throw ( RuntimeException )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     getReferences();
222cdf0e10cSrcweir     return _aOptionalInterfaces;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir //__________________________________________________________________________________________________
226cdf0e10cSrcweir // virtual
227cdf0e10cSrcweir Sequence< Reference< XPropertyTypeDescription > > SAL_CALL
getProperties()228cdf0e10cSrcweir ServiceTypeDescriptionImpl::getProperties()
229cdf0e10cSrcweir     throw ( RuntimeException )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         MutexGuard guard(getMutex());
233cdf0e10cSrcweir         if (_pProps.get() != 0) {
234cdf0e10cSrcweir             return *_pProps;
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     typereg::Reader aReader(
239cdf0e10cSrcweir         _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     sal_uInt16 nFields = (sal_uInt16)aReader.getFieldCount();
242cdf0e10cSrcweir     std::auto_ptr< Sequence< Reference< XPropertyTypeDescription > > >
243cdf0e10cSrcweir         pTempProps(
244cdf0e10cSrcweir             new Sequence< Reference< XPropertyTypeDescription > >(nFields));
245cdf0e10cSrcweir     Reference< XPropertyTypeDescription > * pProps = pTempProps->getArray();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     while ( nFields-- )
248cdf0e10cSrcweir     {
249cdf0e10cSrcweir         // name
250cdf0e10cSrcweir         OUStringBuffer aName( _aName );
251cdf0e10cSrcweir         aName.appendAscii( "." );
252cdf0e10cSrcweir         aName.append( aReader.getFieldName( nFields ) );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         // type description
255cdf0e10cSrcweir         Reference< XTypeDescription > xTD;
256cdf0e10cSrcweir         try
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             _xTDMgr->getByHierarchicalName(
259cdf0e10cSrcweir                 aReader.getFieldTypeName( nFields ).replace( '/', '.' ) )
260cdf0e10cSrcweir                     >>= xTD;
261cdf0e10cSrcweir         }
262cdf0e10cSrcweir         catch ( NoSuchElementException const & )
263cdf0e10cSrcweir         {
264cdf0e10cSrcweir         }
265cdf0e10cSrcweir         OSL_ENSURE( xTD.is(), "### no type description for property!" );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         // flags
268cdf0e10cSrcweir         RTFieldAccess nFlags = aReader.getFieldFlags( nFields );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir         sal_Int16 nAttribs = 0;
271cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_READONLY )
272cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::READONLY;
273cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_OPTIONAL )
274cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::OPTIONAL;
275cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_MAYBEVOID )
276cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::MAYBEVOID;
277cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_BOUND )
278cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::BOUND;
279cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_CONSTRAINED )
280cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::CONSTRAINED;
281cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_TRANSIENT )
282cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::TRANSIENT;
283cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_MAYBEAMBIGUOUS )
284cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::MAYBEAMBIGUOUS;
285cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_MAYBEDEFAULT )
286cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::MAYBEDEFAULT;
287cdf0e10cSrcweir         if ( nFlags & RT_ACCESS_REMOVEABLE )
288cdf0e10cSrcweir             nAttribs |= beans::PropertyAttribute::REMOVEABLE;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         OSL_ENSURE( !(nFlags & RT_ACCESS_PROPERTY),
291cdf0e10cSrcweir                     "### RT_ACCESS_PROPERTY is unexpected here!" );
292cdf0e10cSrcweir         OSL_ENSURE( !(nFlags & RT_ACCESS_ATTRIBUTE),
293cdf0e10cSrcweir                     "### RT_ACCESS_ATTRIBUTE is unexpected here!" );
294cdf0e10cSrcweir         OSL_ENSURE( !(nFlags & RT_ACCESS_CONST),
295cdf0e10cSrcweir                     "### RT_ACCESS_CONST is unexpected here!" );
296cdf0e10cSrcweir         // always set, unless RT_ACCESS_READONLY is set.
297cdf0e10cSrcweir         //OSL_ENSURE( !(nFlags & RT_ACCESS_READWRITE),
298cdf0e10cSrcweir         //            "### RT_ACCESS_READWRITE is unexpected here" );
299cdf0e10cSrcweir         OSL_ENSURE( !(nFlags & RT_ACCESS_DEFAULT),
300cdf0e10cSrcweir                     "### RT_ACCESS_DEAFAULT is unexpected here" );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         pProps[ nFields ]
303cdf0e10cSrcweir             = new PropertyTypeDescriptionImpl( aName.makeStringAndClear(),
304cdf0e10cSrcweir                                                xTD,
305cdf0e10cSrcweir                                                nAttribs );
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     MutexGuard guard(getMutex());
309cdf0e10cSrcweir     if (_pProps.get() == 0) {
310cdf0e10cSrcweir         _pProps = pTempProps;
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir     return *_pProps;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
isSingleInterfaceBased()315cdf0e10cSrcweir sal_Bool ServiceTypeDescriptionImpl::isSingleInterfaceBased()
316cdf0e10cSrcweir     throw (RuntimeException)
317cdf0e10cSrcweir {
318cdf0e10cSrcweir     getReferences();
319cdf0e10cSrcweir     return _xInterfaceTD.is();
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
getInterface()322cdf0e10cSrcweir Reference< XTypeDescription > ServiceTypeDescriptionImpl::getInterface()
323cdf0e10cSrcweir     throw (RuntimeException)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     getReferences();
326cdf0e10cSrcweir     return _xInterfaceTD;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir Sequence< Reference< XServiceConstructorDescription > >
getConstructors()330cdf0e10cSrcweir ServiceTypeDescriptionImpl::getConstructors() throw (RuntimeException) {
331cdf0e10cSrcweir     MutexGuard guard(getMutex());
332cdf0e10cSrcweir     if (_pCtors.get() == 0) {
333cdf0e10cSrcweir         typereg::Reader reader(
334cdf0e10cSrcweir             _aBytes.getConstArray(), _aBytes.getLength(), false,
335cdf0e10cSrcweir             TYPEREG_VERSION_1);
336cdf0e10cSrcweir         sal_uInt16 ctorCount = reader.getMethodCount();
337cdf0e10cSrcweir         std::auto_ptr< Sequence< Reference< XServiceConstructorDescription > > >
338cdf0e10cSrcweir             ctors(
339cdf0e10cSrcweir                 new Sequence< Reference< XServiceConstructorDescription > >(
340cdf0e10cSrcweir                     ctorCount));
341cdf0e10cSrcweir         for (sal_uInt16 i = 0; i < ctorCount; ++i) {
342cdf0e10cSrcweir             rtl::OUString name(reader.getMethodName(i));
343cdf0e10cSrcweir             if (reader.getMethodFlags(i) != RT_MODE_TWOWAY
344cdf0e10cSrcweir                 || (!reader.getMethodReturnTypeName(i).equalsAsciiL(
345cdf0e10cSrcweir                         RTL_CONSTASCII_STRINGPARAM("void")))
346cdf0e10cSrcweir                 || (name.getLength() == 0
347cdf0e10cSrcweir                     && (ctorCount != 1 || reader.getMethodParameterCount(i) != 0
348cdf0e10cSrcweir                         || reader.getMethodExceptionCount(i) != 0)))
349cdf0e10cSrcweir             {
350cdf0e10cSrcweir                 throw RuntimeException(
351cdf0e10cSrcweir                     rtl::OUString(
352cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
353cdf0e10cSrcweir                             "Service has bad constructors")),
354cdf0e10cSrcweir                     static_cast< OWeakObject * >(this));
355cdf0e10cSrcweir             }
356cdf0e10cSrcweir             (*ctors)[i] = new Constructor(
357cdf0e10cSrcweir                 _xTDMgr, reader.getMethodName(i), _aBytes, i);
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir         _pCtors = ctors;
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir     return *_pCtors;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir //__________________________________________________________________________________________________
getReferences()365cdf0e10cSrcweir void ServiceTypeDescriptionImpl::getReferences()
366cdf0e10cSrcweir     throw ( RuntimeException )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir     {
369cdf0e10cSrcweir         MutexGuard guard(getMutex());
370cdf0e10cSrcweir         if (_bInitReferences) {
371cdf0e10cSrcweir             return;
372cdf0e10cSrcweir         }
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir     typereg::Reader aReader(
375cdf0e10cSrcweir         _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1);
376cdf0e10cSrcweir     sal_uInt16 superTypes = aReader.getSuperTypeCount();
377cdf0e10cSrcweir     if (superTypes > 1) {
378cdf0e10cSrcweir         throw RuntimeException(
379cdf0e10cSrcweir             rtl::OUString(
380cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
381cdf0e10cSrcweir                     "Service has more than one supertype")),
382cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
383cdf0e10cSrcweir     }
384cdf0e10cSrcweir     if (superTypes == 1) {
385cdf0e10cSrcweir         OUString aBaseName( aReader.getSuperTypeName(0).replace( '/', '.' ) );
386cdf0e10cSrcweir         if ( aReader.getReferenceCount() != 0
387cdf0e10cSrcweir              || aReader.getFieldCount() != 0 )
388cdf0e10cSrcweir             throw RuntimeException(
389cdf0e10cSrcweir                 OUString(
390cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
391cdf0e10cSrcweir                         "Service is single-interface--based but also has"
392cdf0e10cSrcweir                         " references and/or properties" ) ),
393cdf0e10cSrcweir                 static_cast< OWeakObject * >( this ) );
394cdf0e10cSrcweir         Reference< XTypeDescription > ifc;
395cdf0e10cSrcweir         try
396cdf0e10cSrcweir         {
397cdf0e10cSrcweir             _xTDMgr->getByHierarchicalName( aBaseName ) >>= ifc;
398cdf0e10cSrcweir         }
399cdf0e10cSrcweir         catch ( NoSuchElementException const & e )
400cdf0e10cSrcweir         {
401cdf0e10cSrcweir             throw RuntimeException(
402cdf0e10cSrcweir                 OUString(
403cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
404cdf0e10cSrcweir                         "com.sun.star.container.NoSuchElementException: " ) )
405cdf0e10cSrcweir                 + e.Message,
406cdf0e10cSrcweir                 static_cast< OWeakObject * >( this ) );
407cdf0e10cSrcweir         }
408cdf0e10cSrcweir         OSL_ASSERT(ifc.is());
409cdf0e10cSrcweir         if (resolveTypedefs(ifc)->getTypeClass() != TypeClass_INTERFACE) {
410cdf0e10cSrcweir             throw RuntimeException(
411cdf0e10cSrcweir                 OUString(
412cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
413cdf0e10cSrcweir                         "Single-interface--based service is not based on"
414cdf0e10cSrcweir                         " interface type" ) ),
415cdf0e10cSrcweir                 static_cast< OWeakObject * >( this ) );
416cdf0e10cSrcweir         }
417cdf0e10cSrcweir         MutexGuard guard(getMutex());
418cdf0e10cSrcweir         if (!_bInitReferences) {
419cdf0e10cSrcweir             _xInterfaceTD = ifc;
420cdf0e10cSrcweir             _bInitReferences = true;
421cdf0e10cSrcweir         }
422cdf0e10cSrcweir     }
423cdf0e10cSrcweir     else
424cdf0e10cSrcweir     {
425cdf0e10cSrcweir         sal_uInt16 nRefs = aReader.getReferenceCount();
426cdf0e10cSrcweir         Sequence< Reference< XServiceTypeDescription > > aMandatoryServices(
427cdf0e10cSrcweir             nRefs);
428cdf0e10cSrcweir         Sequence< Reference< XServiceTypeDescription > > aOptionalServices(
429cdf0e10cSrcweir             nRefs);
430cdf0e10cSrcweir         Sequence< Reference< XInterfaceTypeDescription > > aMandatoryInterfaces(
431cdf0e10cSrcweir             nRefs);
432cdf0e10cSrcweir         Sequence< Reference< XInterfaceTypeDescription > > aOptionalInterfaces(
433cdf0e10cSrcweir             nRefs);
434cdf0e10cSrcweir         sal_uInt32 nMS = 0;
435cdf0e10cSrcweir         sal_uInt32 nOS = 0;
436cdf0e10cSrcweir         sal_uInt32 nMI = 0;
437cdf0e10cSrcweir         sal_uInt32 nOI = 0;
438cdf0e10cSrcweir 
439cdf0e10cSrcweir         for ( sal_uInt16 nPos = 0; nPos < nRefs; ++nPos )
440cdf0e10cSrcweir         {
441cdf0e10cSrcweir             RTReferenceType eType = aReader.getReferenceSort( nPos );
442cdf0e10cSrcweir             switch ( eType )
443cdf0e10cSrcweir             {
444cdf0e10cSrcweir             case RT_REF_EXPORTS: // service
445cdf0e10cSrcweir                 {
446cdf0e10cSrcweir                     uno::Any aTypeDesc;
447cdf0e10cSrcweir                     try
448cdf0e10cSrcweir                     {
449cdf0e10cSrcweir                         aTypeDesc = _xTDMgr->getByHierarchicalName(
450cdf0e10cSrcweir                             aReader.getReferenceTypeName( nPos ).replace(
451cdf0e10cSrcweir                                 '/', '.' ) );
452cdf0e10cSrcweir                     }
453cdf0e10cSrcweir                     catch ( NoSuchElementException const & e )
454cdf0e10cSrcweir                     {
455cdf0e10cSrcweir                         throw RuntimeException(
456cdf0e10cSrcweir                             OUString(
457cdf0e10cSrcweir                                 RTL_CONSTASCII_USTRINGPARAM(
458cdf0e10cSrcweir                                     "com.sun.star.container."
459cdf0e10cSrcweir                                     "NoSuchElementException: " ) )
460cdf0e10cSrcweir                             + e.Message,
461cdf0e10cSrcweir                             static_cast< OWeakObject * >( this ) );
462cdf0e10cSrcweir                     }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir                     RTFieldAccess nAccess = aReader.getReferenceFlags( nPos );
465cdf0e10cSrcweir                     if ( nAccess & RT_ACCESS_OPTIONAL )
466cdf0e10cSrcweir                     {
467cdf0e10cSrcweir                         // optional service
468cdf0e10cSrcweir                         if ( !( aTypeDesc >>= aOptionalServices[ nOS ] ) )
469cdf0e10cSrcweir                             throw RuntimeException(
470cdf0e10cSrcweir                                 OUString(
471cdf0e10cSrcweir                                     RTL_CONSTASCII_USTRINGPARAM(
472cdf0e10cSrcweir                                         "Service 'export' is not a service" ) ),
473cdf0e10cSrcweir                                 static_cast< OWeakObject * >( this ) );
474cdf0e10cSrcweir                         nOS++;
475cdf0e10cSrcweir                     }
476cdf0e10cSrcweir                     else
477cdf0e10cSrcweir                     {
478cdf0e10cSrcweir                         // mandatory service
479cdf0e10cSrcweir                         if ( !( aTypeDesc >>= aMandatoryServices[ nMS ] ) )
480cdf0e10cSrcweir                             throw RuntimeException(
481cdf0e10cSrcweir                                 OUString(
482cdf0e10cSrcweir                                     RTL_CONSTASCII_USTRINGPARAM(
483cdf0e10cSrcweir                                         "Service 'export' is not a service" ) ),
484cdf0e10cSrcweir                                 static_cast< OWeakObject * >( this ) );
485cdf0e10cSrcweir                         nMS++;
486cdf0e10cSrcweir                     }
487cdf0e10cSrcweir                     break;
488cdf0e10cSrcweir                 }
489cdf0e10cSrcweir             case RT_REF_SUPPORTS: // interface
490cdf0e10cSrcweir                 {
491cdf0e10cSrcweir                     uno::Any aTypeDesc;
492cdf0e10cSrcweir                     try
493cdf0e10cSrcweir                     {
494cdf0e10cSrcweir                         aTypeDesc = _xTDMgr->getByHierarchicalName(
495cdf0e10cSrcweir                             aReader.getReferenceTypeName( nPos ).replace(
496cdf0e10cSrcweir                                 '/', '.' ) );
497cdf0e10cSrcweir                     }
498cdf0e10cSrcweir                     catch ( NoSuchElementException const & e )
499cdf0e10cSrcweir                     {
500cdf0e10cSrcweir                         throw RuntimeException(
501cdf0e10cSrcweir                             OUString(
502cdf0e10cSrcweir                                 RTL_CONSTASCII_USTRINGPARAM(
503cdf0e10cSrcweir                                     "com.sun.star.container."
504cdf0e10cSrcweir                                     "NoSuchElementException: " ) )
505cdf0e10cSrcweir                             + e.Message,
506cdf0e10cSrcweir                             static_cast< OWeakObject * >( this ) );
507cdf0e10cSrcweir                     }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir                     RTFieldAccess nAccess = aReader.getReferenceFlags( nPos );
510cdf0e10cSrcweir                     if ( nAccess & RT_ACCESS_OPTIONAL )
511cdf0e10cSrcweir                     {
512cdf0e10cSrcweir                         // optional interface
513cdf0e10cSrcweir                         if ( !( aTypeDesc >>= aOptionalInterfaces[ nOI ] ) )
514cdf0e10cSrcweir                             throw RuntimeException(
515cdf0e10cSrcweir                                 OUString(
516cdf0e10cSrcweir                                     RTL_CONSTASCII_USTRINGPARAM(
517cdf0e10cSrcweir                                         "Service 'supports' is not an"
518cdf0e10cSrcweir                                         " interface" ) ),
519cdf0e10cSrcweir                                 static_cast< OWeakObject * >( this ) );
520cdf0e10cSrcweir                         nOI++;
521cdf0e10cSrcweir                     }
522cdf0e10cSrcweir                     else
523cdf0e10cSrcweir                     {
524cdf0e10cSrcweir                         // mandatory interface
525cdf0e10cSrcweir                         if ( !( aTypeDesc >>= aMandatoryInterfaces[ nMI ] ) )
526cdf0e10cSrcweir                             throw RuntimeException(
527cdf0e10cSrcweir                                 OUString(
528cdf0e10cSrcweir                                     RTL_CONSTASCII_USTRINGPARAM(
529cdf0e10cSrcweir                                         "Service 'supports' is not an"
530cdf0e10cSrcweir                                         " interface" ) ),
531cdf0e10cSrcweir                                 static_cast< OWeakObject * >( this ) );
532cdf0e10cSrcweir                         nMI++;
533cdf0e10cSrcweir                     }
534cdf0e10cSrcweir                     break;
535cdf0e10cSrcweir                 }
536cdf0e10cSrcweir             case RT_REF_OBSERVES:
537cdf0e10cSrcweir             case RT_REF_NEEDS:
538cdf0e10cSrcweir                 break;
539cdf0e10cSrcweir             default:
540cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "### unsupported reference type!" );
541cdf0e10cSrcweir                 break;
542cdf0e10cSrcweir             }
543cdf0e10cSrcweir         }
544cdf0e10cSrcweir         aMandatoryServices.realloc( nMS );
545cdf0e10cSrcweir         aOptionalServices.realloc( nOS );
546cdf0e10cSrcweir         aMandatoryInterfaces.realloc( nMI );
547cdf0e10cSrcweir         aOptionalInterfaces.realloc( nOI );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir         MutexGuard guard(getMutex());
550cdf0e10cSrcweir         if (!_bInitReferences) {
551cdf0e10cSrcweir             _aMandatoryServices = aMandatoryServices;
552cdf0e10cSrcweir             _aOptionalServices = aOptionalServices;
553cdf0e10cSrcweir             _aMandatoryInterfaces = aMandatoryInterfaces;
554cdf0e10cSrcweir             _aOptionalInterfaces = aOptionalInterfaces;
555cdf0e10cSrcweir             _bInitReferences = true;
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir     }
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
561cdf0e10cSrcweir }
562