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