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 #include "base.hxx"
31 
32 #include "registry/reader.hxx"
33 #include "registry/version.h"
34 
35 namespace stoc_rdbtdp
36 {
37 
38 //__________________________________________________________________________________________________
39 CompoundTypeDescriptionImpl::~CompoundTypeDescriptionImpl()
40 {
41 	delete _pMembers;
42 	delete _pMemberNames;
43 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
44 }
45 
46 // XTypeDescription
47 //__________________________________________________________________________________________________
48 TypeClass CompoundTypeDescriptionImpl::getTypeClass()
49 	throw(::com::sun::star::uno::RuntimeException)
50 {
51 	return _eTypeClass;
52 }
53 //__________________________________________________________________________________________________
54 OUString CompoundTypeDescriptionImpl::getName()
55 	throw(::com::sun::star::uno::RuntimeException)
56 {
57 	return _aName;
58 }
59 
60 // XCompoundTypeDescription
61 //__________________________________________________________________________________________________
62 Reference< XTypeDescription > CompoundTypeDescriptionImpl::getBaseType()
63 	throw(::com::sun::star::uno::RuntimeException)
64 {
65 	if (!_xBaseTD.is() && _aBaseType.getLength())
66 	{
67         try
68         {
69             Reference< XTypeDescription > xBaseTD;
70             if (_xTDMgr->getByHierarchicalName( _aBaseType ) >>= xBaseTD)
71             {
72                 MutexGuard aGuard( getMutex() );
73                 if (! _xBaseTD.is())
74                     _xBaseTD = xBaseTD;
75                 return _xBaseTD;
76             }
77         }
78         catch (NoSuchElementException &)
79         {
80         }
81         // never try again, if no base td was found
82         _aBaseType = OUString();
83 	}
84 	return _xBaseTD;
85 }
86 //__________________________________________________________________________________________________
87 
88 namespace {
89 
90 class TypeParameter: public WeakImplHelper1< XTypeDescription > {
91 public:
92     explicit TypeParameter(OUString const & name): m_name(name) {}
93 
94     virtual TypeClass SAL_CALL getTypeClass() throw (RuntimeException)
95     { return TypeClass_UNKNOWN; }
96 
97     virtual OUString SAL_CALL getName() throw (RuntimeException)
98     { return m_name; }
99 
100 private:
101     OUString m_name;
102 };
103 
104 }
105 
106 Sequence< Reference< XTypeDescription > > CompoundTypeDescriptionImpl::getMemberTypes()
107 	throw(::com::sun::star::uno::RuntimeException)
108 {
109 	if (! _pMembers)
110 	{
111         typereg::Reader aReader(
112             _aBytes.getConstArray(), _aBytes.getLength(), false,
113             TYPEREG_VERSION_1);
114 
115         sal_uInt16 nFields = aReader.getFieldCount();
116         Sequence< Reference< XTypeDescription > > * pTempMembers =
117             new Sequence< Reference< XTypeDescription > >( nFields );
118         Reference< XTypeDescription > * pMembers = pTempMembers->getArray();
119 
120         while (nFields--)
121         {
122             if ((aReader.getFieldFlags(nFields) & RT_ACCESS_PARAMETERIZED_TYPE)
123                 != 0)
124             {
125                 pMembers[nFields] = new TypeParameter(
126                     aReader.getFieldTypeName(nFields));
127             } else {
128                 try {
129                     _xTDMgr->getByHierarchicalName(
130                         aReader.getFieldTypeName(nFields).replace('/', '.'))
131                             >>= pMembers[nFields];
132                 } catch (NoSuchElementException &) {}
133                 OSL_ENSURE(
134                     pMembers[nFields].is(), "### compound member unknown!");
135             }
136         }
137 
138 		ClearableMutexGuard aGuard( getMutex() );
139 		if (_pMembers)
140         {
141             aGuard.clear();
142             delete pTempMembers;
143         }
144         else
145 		{
146 			_pMembers = pTempMembers;
147 		}
148 	}
149 
150 	return *_pMembers;
151 }
152 //__________________________________________________________________________________________________
153 Sequence< OUString > CompoundTypeDescriptionImpl::getMemberNames()
154 	throw(::com::sun::star::uno::RuntimeException)
155 {
156 	if (! _pMemberNames)
157 	{
158         typereg::Reader aReader(
159             _aBytes.getConstArray(), _aBytes.getLength(), false,
160             TYPEREG_VERSION_1);
161 
162         sal_uInt16 nFields = aReader.getFieldCount();
163         Sequence< OUString > * pTempMemberNames = new Sequence< OUString >( nFields );
164         OUString * pMemberNames = pTempMemberNames->getArray();
165 
166         while (nFields--)
167         {
168             pMemberNames[nFields] = aReader.getFieldName( nFields );
169         }
170 
171 		ClearableMutexGuard aGuard( getMutex() );
172 		if (_pMemberNames)
173 		{
174             aGuard.clear();
175             delete pTempMemberNames;
176         }
177         else
178         {
179 			_pMemberNames = pTempMemberNames;
180 		}
181 	}
182 	return *_pMemberNames;
183 }
184 
185 }
186 
187 
188