1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_stoc.hxx"
30 
31 #include <vector>
32 #include <osl/diagnose.h>
33 #include "base.hxx"
34 
35 namespace stoc_rdbtdp
36 {
37 
38 //__________________________________________________________________________________________________
39 // virtual
40 ModuleTypeDescriptionImpl::~ModuleTypeDescriptionImpl()
41 {
42     delete _pMembers;
43 
44 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
45 }
46 
47 // XTypeDescription
48 //__________________________________________________________________________________________________
49 // virtual
50 TypeClass ModuleTypeDescriptionImpl::getTypeClass()
51     throw( RuntimeException )
52 {
53     return TypeClass_MODULE;
54 }
55 //__________________________________________________________________________________________________
56 // virtual
57 OUString ModuleTypeDescriptionImpl::getName()
58     throw( RuntimeException )
59 {
60 	return _aName;
61 }
62 
63 // XModuleTypeDescription
64 //__________________________________________________________________________________________________
65 // virtual
66 Sequence< Reference< XTypeDescription > > SAL_CALL
67 ModuleTypeDescriptionImpl::getMembers()
68     throw ( RuntimeException )
69 {
70     if ( !_pMembers )
71     {
72         Reference< XTypeDescriptionEnumeration > xEnum;
73         try
74         {
75             xEnum = _xTDMgr->createTypeDescriptionEnumeration(
76                         _aName,
77                         Sequence< TypeClass >(),
78                         TypeDescriptionSearchDepth_ONE );
79         }
80         catch ( NoSuchTypeNameException const & )
81         {
82         }
83         catch ( InvalidTypeNameException const & )
84         {
85         }
86 
87         OSL_ENSURE( xEnum.is(),
88                     "ModuleTypeDescriptionImpl::getMembers - No enumeration!" );
89 
90         std::vector< Reference< XTypeDescription > > aTDs;
91         while ( xEnum->hasMoreElements() )
92         {
93             try
94             {
95                 Reference< XTypeDescription > xTD(
96                     xEnum->nextTypeDescription() );
97                 aTDs.push_back( xTD );
98             }
99             catch ( NoSuchElementException const & )
100             {
101                 OSL_ENSURE( sal_False,
102                     "ModuleTypeDescriptionImpl::getMembers - "
103                     " Caught NoSuchElementException!" );
104             }
105         }
106 
107         Sequence< Reference< XTypeDescription > > * pMembers
108             = new Sequence< Reference< XTypeDescription > >( aTDs.size() );
109         for ( sal_Int32 n = 0; n < pMembers->getLength(); n++ )
110             (*pMembers)[ n ] = aTDs[ n ];
111 
112         ClearableMutexGuard aGuard( getMutex() );
113         if ( _pMembers )
114         {
115             aGuard.clear();
116             delete pMembers;
117         }
118         else
119         {
120             _pMembers = pMembers;
121         }
122     }
123     return *_pMembers;
124 }
125 
126 }
127