1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 #include "base.hxx"
27
28 #include "registry/reader.hxx"
29 #include "registry/version.h"
30
31 namespace stoc_rdbtdp
32 {
33
34 //__________________________________________________________________________________________________
~CompoundTypeDescriptionImpl()35 CompoundTypeDescriptionImpl::~CompoundTypeDescriptionImpl()
36 {
37 delete _pMembers;
38 delete _pMemberNames;
39 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
40 }
41
42 // XTypeDescription
43 //__________________________________________________________________________________________________
getTypeClass()44 TypeClass CompoundTypeDescriptionImpl::getTypeClass()
45 {
46 return _eTypeClass;
47 }
48 //__________________________________________________________________________________________________
getName()49 OUString CompoundTypeDescriptionImpl::getName()
50 {
51 return _aName;
52 }
53
54 // XCompoundTypeDescription
55 //__________________________________________________________________________________________________
getBaseType()56 Reference< XTypeDescription > CompoundTypeDescriptionImpl::getBaseType()
57 {
58 if (!_xBaseTD.is() && _aBaseType.getLength())
59 {
60 try
61 {
62 Reference< XTypeDescription > xBaseTD;
63 if (_xTDMgr->getByHierarchicalName( _aBaseType ) >>= xBaseTD)
64 {
65 MutexGuard aGuard( getMutex() );
66 if (! _xBaseTD.is())
67 _xBaseTD = xBaseTD;
68 return _xBaseTD;
69 }
70 }
71 catch (NoSuchElementException &)
72 {
73 }
74 // never try again, if no base td was found
75 _aBaseType = OUString();
76 }
77 return _xBaseTD;
78 }
79 //__________________________________________________________________________________________________
80
81 namespace {
82
83 class TypeParameter: public WeakImplHelper1< XTypeDescription > {
84 public:
TypeParameter(OUString const & name)85 explicit TypeParameter(OUString const & name): m_name(name) {}
86
getTypeClass()87 virtual TypeClass SAL_CALL getTypeClass()
88 { return TypeClass_UNKNOWN; }
89
getName()90 virtual OUString SAL_CALL getName()
91 { return m_name; }
92
93 private:
94 OUString m_name;
95 };
96
97 }
98
getMemberTypes()99 Sequence< Reference< XTypeDescription > > CompoundTypeDescriptionImpl::getMemberTypes()
100 {
101 if (! _pMembers)
102 {
103 typereg::Reader aReader(
104 _aBytes.getConstArray(), _aBytes.getLength(), false,
105 TYPEREG_VERSION_1);
106
107 sal_uInt16 nFields = aReader.getFieldCount();
108 Sequence< Reference< XTypeDescription > > * pTempMembers =
109 new Sequence< Reference< XTypeDescription > >( nFields );
110 Reference< XTypeDescription > * pMembers = pTempMembers->getArray();
111
112 while (nFields--)
113 {
114 if ((aReader.getFieldFlags(nFields) & RT_ACCESS_PARAMETERIZED_TYPE)
115 != 0)
116 {
117 pMembers[nFields] = new TypeParameter(
118 aReader.getFieldTypeName(nFields));
119 } else {
120 try {
121 _xTDMgr->getByHierarchicalName(
122 aReader.getFieldTypeName(nFields).replace('/', '.'))
123 >>= pMembers[nFields];
124 } catch (NoSuchElementException &) {}
125 OSL_ENSURE(
126 pMembers[nFields].is(), "### compound member unknown!");
127 }
128 }
129
130 ClearableMutexGuard aGuard( getMutex() );
131 if (_pMembers)
132 {
133 aGuard.clear();
134 delete pTempMembers;
135 }
136 else
137 {
138 _pMembers = pTempMembers;
139 }
140 }
141
142 return *_pMembers;
143 }
144 //__________________________________________________________________________________________________
getMemberNames()145 Sequence< OUString > CompoundTypeDescriptionImpl::getMemberNames()
146 {
147 if (! _pMemberNames)
148 {
149 typereg::Reader aReader(
150 _aBytes.getConstArray(), _aBytes.getLength(), false,
151 TYPEREG_VERSION_1);
152
153 sal_uInt16 nFields = aReader.getFieldCount();
154 Sequence< OUString > * pTempMemberNames = new Sequence< OUString >( nFields );
155 OUString * pMemberNames = pTempMemberNames->getArray();
156
157 while (nFields--)
158 {
159 pMemberNames[nFields] = aReader.getFieldName( nFields );
160 }
161
162 ClearableMutexGuard aGuard( getMutex() );
163 if (_pMemberNames)
164 {
165 aGuard.clear();
166 delete pTempMemberNames;
167 }
168 else
169 {
170 _pMemberNames = pTempMemberNames;
171 }
172 }
173 return *_pMemberNames;
174 }
175
176 }
177