Update ooo320-m1
[ooovba.git] / stoc / source / registry_tdprovider / tdcomp.cxx
blob13ca7734154f1a26033738e3a5e5d6114e866132
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdcomp.cxx,v $
10 * $Revision: 1.12 $
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 "base.hxx"
35 #include "registry/reader.hxx"
36 #include "registry/version.h"
38 namespace stoc_rdbtdp
41 //__________________________________________________________________________________________________
42 CompoundTypeDescriptionImpl::~CompoundTypeDescriptionImpl()
44 delete _pMembers;
45 delete _pMemberNames;
46 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
49 // XTypeDescription
50 //__________________________________________________________________________________________________
51 TypeClass CompoundTypeDescriptionImpl::getTypeClass()
52 throw(::com::sun::star::uno::RuntimeException)
54 return _eTypeClass;
56 //__________________________________________________________________________________________________
57 OUString CompoundTypeDescriptionImpl::getName()
58 throw(::com::sun::star::uno::RuntimeException)
60 return _aName;
63 // XCompoundTypeDescription
64 //__________________________________________________________________________________________________
65 Reference< XTypeDescription > CompoundTypeDescriptionImpl::getBaseType()
66 throw(::com::sun::star::uno::RuntimeException)
68 if (!_xBaseTD.is() && _aBaseType.getLength())
70 try
72 Reference< XTypeDescription > xBaseTD;
73 if (_xTDMgr->getByHierarchicalName( _aBaseType ) >>= xBaseTD)
75 MutexGuard aGuard( getMutex() );
76 if (! _xBaseTD.is())
77 _xBaseTD = xBaseTD;
78 return _xBaseTD;
81 catch (NoSuchElementException &)
84 // never try again, if no base td was found
85 _aBaseType = OUString();
87 return _xBaseTD;
89 //__________________________________________________________________________________________________
91 namespace {
93 class TypeParameter: public WeakImplHelper1< XTypeDescription > {
94 public:
95 explicit TypeParameter(OUString const & name): m_name(name) {}
97 virtual TypeClass SAL_CALL getTypeClass() throw (RuntimeException)
98 { return TypeClass_UNKNOWN; }
100 virtual OUString SAL_CALL getName() throw (RuntimeException)
101 { return m_name; }
103 private:
104 OUString m_name;
109 Sequence< Reference< XTypeDescription > > CompoundTypeDescriptionImpl::getMemberTypes()
110 throw(::com::sun::star::uno::RuntimeException)
112 if (! _pMembers)
114 typereg::Reader aReader(
115 _aBytes.getConstArray(), _aBytes.getLength(), false,
116 TYPEREG_VERSION_1);
118 sal_uInt16 nFields = aReader.getFieldCount();
119 Sequence< Reference< XTypeDescription > > * pTempMembers =
120 new Sequence< Reference< XTypeDescription > >( nFields );
121 Reference< XTypeDescription > * pMembers = pTempMembers->getArray();
123 while (nFields--)
125 if ((aReader.getFieldFlags(nFields) & RT_ACCESS_PARAMETERIZED_TYPE)
126 != 0)
128 pMembers[nFields] = new TypeParameter(
129 aReader.getFieldTypeName(nFields));
130 } else {
131 try {
132 _xTDMgr->getByHierarchicalName(
133 aReader.getFieldTypeName(nFields).replace('/', '.'))
134 >>= pMembers[nFields];
135 } catch (NoSuchElementException &) {}
136 OSL_ENSURE(
137 pMembers[nFields].is(), "### compound member unknown!");
141 ClearableMutexGuard aGuard( getMutex() );
142 if (_pMembers)
144 aGuard.clear();
145 delete pTempMembers;
147 else
149 _pMembers = pTempMembers;
153 return *_pMembers;
155 //__________________________________________________________________________________________________
156 Sequence< OUString > CompoundTypeDescriptionImpl::getMemberNames()
157 throw(::com::sun::star::uno::RuntimeException)
159 if (! _pMemberNames)
161 typereg::Reader aReader(
162 _aBytes.getConstArray(), _aBytes.getLength(), false,
163 TYPEREG_VERSION_1);
165 sal_uInt16 nFields = aReader.getFieldCount();
166 Sequence< OUString > * pTempMemberNames = new Sequence< OUString >( nFields );
167 OUString * pMemberNames = pTempMemberNames->getArray();
169 while (nFields--)
171 pMemberNames[nFields] = aReader.getFieldName( nFields );
174 ClearableMutexGuard aGuard( getMutex() );
175 if (_pMemberNames)
177 aGuard.clear();
178 delete pTempMemberNames;
180 else
182 _pMemberNames = pTempMemberNames;
185 return *_pMemberNames;