Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <string.h>
21 : :
22 : : #include "rtl/alloc.h"
23 : : #include "registry/writer.hxx"
24 : :
25 : : #include "com/sun/star/beans/PropertyAttribute.hpp"
26 : : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
27 : : #include "com/sun/star/reflection/XPublished.hpp"
28 : : #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp"
29 : : #include "com/sun/star/reflection/XSingletonTypeDescription2.hpp"
30 : : #include "com/sun/star/reflection/XServiceTypeDescription2.hpp"
31 : : #include "com/sun/star/reflection/XStructTypeDescription.hpp"
32 : : #include "com/sun/star/reflection/XConstantsTypeDescription.hpp"
33 : : #include "com/sun/star/reflection/XConstantTypeDescription.hpp"
34 : : #include "com/sun/star/reflection/XModuleTypeDescription.hpp"
35 : : #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp"
36 : : #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp"
37 : : #include "com/sun/star/reflection/XMethodParameter.hpp"
38 : : #include "com/sun/star/reflection/XCompoundTypeDescription.hpp"
39 : : #include "com/sun/star/reflection/XIndirectTypeDescription.hpp"
40 : : #include "com/sun/star/reflection/XEnumTypeDescription.hpp"
41 : :
42 : : #include "codemaker/generatedtypeset.hxx"
43 : :
44 : : using namespace com::sun::star::uno;
45 : : using namespace com::sun::star::beans;
46 : : using namespace com::sun::star::container;
47 : : using namespace com::sun::star::reflection;
48 : : using namespace codemaker;
49 : :
50 : : using ::rtl::OUString;
51 : : using ::rtl::OString;
52 : : using ::rtl::OStringToOUString;
53 : : using ::rtl::OUStringToOString;
54 : :
55 : : namespace unodevtools {
56 : :
57 : 0 : void writeConstantData(typereg::Writer& rWriter, sal_uInt16 fieldIndex,
58 : : const Reference< XConstantTypeDescription >& xConstant)
59 : :
60 : : {
61 : 0 : RTConstValue constValue;
62 : 0 : OUString uConstTypeName;
63 : 0 : OUString uConstName = xConstant->getName();
64 : 0 : Any aConstantAny = xConstant->getConstantValue();
65 : :
66 : 0 : switch ( aConstantAny.getValueTypeClass() )
67 : : {
68 : : case TypeClass_BOOLEAN:
69 : : {
70 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("boolean"));
71 : 0 : constValue.m_type = RT_TYPE_BOOL;
72 : 0 : aConstantAny >>= constValue.m_value.aBool;
73 : : }
74 : 0 : break;
75 : : case TypeClass_BYTE:
76 : : {
77 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("byte"));
78 : 0 : constValue.m_type = RT_TYPE_BYTE;
79 : 0 : aConstantAny >>= constValue.m_value.aByte;
80 : : }
81 : 0 : break;
82 : : case TypeClass_SHORT:
83 : : {
84 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("short"));
85 : 0 : constValue.m_type = RT_TYPE_INT16;
86 : 0 : aConstantAny >>= constValue.m_value.aShort;
87 : : }
88 : 0 : break;
89 : : case TypeClass_UNSIGNED_SHORT:
90 : : {
91 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("unsigned short"));
92 : 0 : constValue.m_type = RT_TYPE_UINT16;
93 : 0 : aConstantAny >>= constValue.m_value.aUShort;
94 : : }
95 : 0 : break;
96 : : case TypeClass_LONG:
97 : : {
98 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("long"));
99 : 0 : constValue.m_type = RT_TYPE_INT32;
100 : 0 : aConstantAny >>= constValue.m_value.aLong;
101 : : }
102 : 0 : break;
103 : : case TypeClass_UNSIGNED_LONG:
104 : : {
105 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("unsigned long"));
106 : 0 : constValue.m_type = RT_TYPE_UINT32;
107 : 0 : aConstantAny >>= constValue.m_value.aULong;
108 : : }
109 : 0 : break;
110 : : case TypeClass_FLOAT:
111 : : {
112 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("float"));
113 : 0 : constValue.m_type = RT_TYPE_FLOAT;
114 : 0 : aConstantAny >>= constValue.m_value.aFloat;
115 : : }
116 : 0 : break;
117 : : case TypeClass_DOUBLE:
118 : : {
119 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("double"));
120 : 0 : constValue.m_type = RT_TYPE_DOUBLE;
121 : 0 : aConstantAny >>= constValue.m_value.aDouble;
122 : : }
123 : 0 : break;
124 : : case TypeClass_STRING:
125 : : {
126 : 0 : uConstTypeName = OUString(RTL_CONSTASCII_USTRINGPARAM("string"));
127 : 0 : constValue.m_type = RT_TYPE_STRING;
128 : 0 : constValue.m_value.aString = ((OUString*)aConstantAny.getValue())->getStr();
129 : : }
130 : 0 : break;
131 : : default:
132 : : OSL_FAIL( "unsupported constant type" );
133 : 0 : break;
134 : : }
135 : :
136 : : rWriter.setFieldData(fieldIndex, OUString(), OUString(), RT_ACCESS_CONST,
137 : 0 : uConstName, uConstTypeName, constValue);
138 : 0 : }
139 : :
140 : 0 : sal_uInt32 getInheritedMemberCount(
141 : : GeneratedTypeSet& checkedTypes,
142 : : Sequence< Reference< XTypeDescription > >& superTypes)
143 : : {
144 : 0 : sal_uInt32 memberCount = 0;
145 : :
146 : 0 : sal_uInt16 count = (sal_uInt16)superTypes.getLength();
147 : 0 : OString name;
148 : 0 : for (sal_uInt16 i=0; i < count; i++) {
149 : 0 : name = OString(OUStringToOString(superTypes[i]->getName(),
150 : 0 : RTL_TEXTENCODING_UTF8));
151 : 0 : if (!checkedTypes.contains(name)) {
152 : 0 : checkedTypes.add(name);
153 : :
154 : : Reference< XInterfaceTypeDescription2 > xIFace(
155 : 0 : superTypes[i], UNO_QUERY);
156 : :
157 : : Sequence< Reference< XTypeDescription> > baseTypes =
158 : 0 : xIFace->getBaseTypes();
159 : 0 : if ( baseTypes.getLength() > 0)
160 : 0 : memberCount += getInheritedMemberCount(checkedTypes, baseTypes);
161 : :
162 : 0 : memberCount += xIFace->getMembers().getLength();
163 : : }
164 : : }
165 : :
166 : 0 : return memberCount;
167 : : }
168 : :
169 : 0 : void writeMethodData( typereg::Writer& rWriter, sal_uInt32 calculatedMemberOffset,
170 : : const Reference< XInterfaceMethodTypeDescription >& xMethod )
171 : : {
172 : 0 : RTMethodMode methodMode = RT_MODE_TWOWAY;
173 : 0 : if ( xMethod->isOneway() )
174 : 0 : methodMode = RT_MODE_ONEWAY;
175 : :
176 : 0 : Sequence< Reference< XMethodParameter > > parameters(xMethod->getParameters());
177 : 0 : Sequence< Reference< XTypeDescription > > exceptions(xMethod->getExceptions());
178 : :
179 : 0 : OUString name(xMethod->getMemberName());
180 : 0 : sal_uInt16 methodIndex = (sal_uInt16)(xMethod->getPosition()
181 : 0 : - calculatedMemberOffset);
182 : 0 : sal_uInt16 paramCount = (sal_uInt16)parameters.getLength();
183 : 0 : sal_uInt16 exceptionCount = (sal_uInt16)exceptions.getLength();
184 : :
185 : : rWriter.setMethodData(methodIndex, OUString(), methodMode,
186 : 0 : xMethod->getMemberName(),
187 : 0 : xMethod->getReturnType()->getName().replace('.', '/'),
188 : 0 : paramCount, exceptionCount);
189 : :
190 : 0 : RTParamMode paramMode = RT_PARAM_IN;
191 : : sal_uInt16 i;
192 : :
193 : 0 : for ( i=0; i < paramCount; i++) {
194 : 0 : Reference< XMethodParameter > xParam = parameters[i];
195 : 0 : if ( xParam->isIn() && xParam->isOut())
196 : 0 : paramMode = RT_PARAM_INOUT;
197 : 0 : else if ( xParam->isIn() )
198 : 0 : paramMode = RT_PARAM_IN;
199 : 0 : else if ( xParam->isOut() )
200 : 0 : paramMode = RT_PARAM_OUT;
201 : :
202 : : rWriter.setMethodParameterData(methodIndex,
203 : 0 : (sal_uInt16)xParam->getPosition(),
204 : 0 : paramMode, xParam->getName(),
205 : 0 : xParam->getType()->
206 : 0 : getName().replace('.', '/'));
207 : 0 : }
208 : :
209 : 0 : for (i=0; i < exceptionCount; i++) {
210 : : rWriter.setMethodExceptionTypeName(
211 : 0 : methodIndex, i, exceptions[i]->getName().replace('.', '/'));
212 : 0 : }
213 : 0 : }
214 : :
215 : 0 : void writeAttributeMethodData(
216 : : typereg::Writer& rWriter, sal_uInt16& methodindex, RTMethodMode methodmode,
217 : : const Reference<XInterfaceAttributeTypeDescription2>& xAttr)
218 : : {
219 : 0 : Sequence<Reference<XCompoundTypeDescription> > seqExcp;
220 : 0 : if (methodmode == RT_MODE_ATTRIBUTE_GET)
221 : 0 : seqExcp = xAttr->getGetExceptions();
222 : : else
223 : 0 : seqExcp = xAttr->getSetExceptions();
224 : :
225 : 0 : if (seqExcp.getLength() > 0) {
226 : : rWriter.setMethodData(methodindex, OUString(), methodmode,
227 : 0 : xAttr->getMemberName(),
228 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")),
229 : 0 : 0, (sal_uInt16)seqExcp.getLength());
230 : :
231 : 0 : for (sal_Int32 i=0; i < seqExcp.getLength(); i++) {
232 : : rWriter.setMethodExceptionTypeName(
233 : : methodindex, (sal_uInt16)i,
234 : 0 : seqExcp[i]->getName().replace('.', '/'));
235 : : }
236 : 0 : ++methodindex;
237 : 0 : }
238 : 0 : }
239 : :
240 : 0 : RTFieldAccess checkParameterizedTypeFlag(const Sequence< OUString >& typeParams,
241 : : const OUString & memberType)
242 : : {
243 : 0 : for (sal_uInt16 i=0; i < typeParams.getLength(); i++) {
244 : 0 : if (typeParams[i].equals(memberType))
245 : 0 : return RT_ACCESS_PARAMETERIZED_TYPE;
246 : : }
247 : :
248 : 0 : return RT_ACCESS_READWRITE;
249 : : }
250 : :
251 : 0 : RTFieldAccess checkPropertyFlags(short flags) {
252 : 0 : RTFieldAccess propertyFlags=RT_ACCESS_INVALID;
253 : 0 : switch(flags) {
254 : : case PropertyAttribute::MAYBEVOID:
255 : 0 : propertyFlags |= RT_ACCESS_MAYBEVOID;
256 : : case PropertyAttribute::BOUND:
257 : 0 : propertyFlags |= RT_ACCESS_BOUND;
258 : : case PropertyAttribute::CONSTRAINED:
259 : 0 : propertyFlags |= RT_ACCESS_CONSTRAINED;
260 : : case PropertyAttribute::TRANSIENT:
261 : 0 : propertyFlags |= RT_ACCESS_TRANSIENT;
262 : : case PropertyAttribute::READONLY :
263 : 0 : propertyFlags |= RT_ACCESS_READONLY;
264 : : case PropertyAttribute::MAYBEAMBIGUOUS:
265 : 0 : propertyFlags |= RT_ACCESS_MAYBEAMBIGUOUS;
266 : : case PropertyAttribute::MAYBEDEFAULT:
267 : 0 : propertyFlags |= RT_ACCESS_MAYBEDEFAULT;
268 : : case PropertyAttribute::REMOVEABLE:
269 : 0 : propertyFlags |= RT_ACCESS_REMOVEABLE;
270 : : case PropertyAttribute::OPTIONAL:
271 : 0 : propertyFlags |= RT_ACCESS_OPTIONAL;
272 : : }
273 : 0 : return propertyFlags;
274 : : }
275 : :
276 : 0 : void* getTypeBlob(Reference< XHierarchicalNameAccess > xTDmgr,
277 : : const OString& typeName, sal_uInt32* blobsize)
278 : : {
279 : 0 : if ( typeName.isEmpty() )
280 : 0 : return NULL;
281 : :
282 : : OUString uTypeName(OStringToOUString(typeName, RTL_TEXTENCODING_UTF8)
283 : 0 : .replace('/', '.'));
284 : :
285 : 0 : Any aTypeAny( xTDmgr->getByHierarchicalName( uTypeName ) );
286 : :
287 : 0 : if ( !aTypeAny.hasValue() )
288 : 0 : return NULL;
289 : :
290 : 0 : Reference< XTypeDescription > xType;
291 : 0 : aTypeAny >>= xType;
292 : :
293 : 0 : if ( !xType.is() )
294 : 0 : return NULL;
295 : :
296 : 0 : Reference< XPublished > xPublished(xType, UNO_QUERY);
297 : 0 : void* pBlob = NULL;
298 : 0 : switch (xType->getTypeClass())
299 : : {
300 : : case TypeClass_CONSTANTS:
301 : : {
302 : 0 : Reference< XConstantsTypeDescription > xCFace(xType, UNO_QUERY);
303 : :
304 : 0 : if ( !xCFace.is() )
305 : 0 : return NULL;
306 : :
307 : : Sequence< Reference< XConstantTypeDescription > > constTypes(
308 : 0 : xCFace->getConstants());
309 : 0 : sal_uInt16 constCount = (sal_uInt16)constTypes.getLength();
310 : :
311 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
312 : 0 : RT_TYPE_CONSTANTS, xPublished->isPublished(),
313 : : uTypeName.replace('.', '/'),
314 : 0 : 0, constCount, 0, 0);
315 : :
316 : 0 : for (sal_uInt16 i=0; i < constCount; i++)
317 : 0 : writeConstantData(writer, i, constTypes[i]);
318 : :
319 : 0 : const void* p = writer.getBlob(blobsize);
320 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
321 : 0 : memcpy(pBlob, p, *blobsize);
322 : : }
323 : 0 : break;
324 : : case TypeClass_MODULE:
325 : : {
326 : 0 : Reference< XModuleTypeDescription > xMFace(xType, UNO_QUERY);
327 : :
328 : 0 : if ( !xMFace.is() )
329 : 0 : return NULL;
330 : :
331 : : Sequence< Reference< XTypeDescription > > memberTypes(
332 : 0 : xMFace->getMembers());
333 : :
334 : 0 : sal_uInt16 memberCount = (sal_uInt16)memberTypes.getLength();
335 : 0 : sal_uInt16 constCount = 0;
336 : : sal_Int16 i;
337 : :
338 : 0 : for ( i=0; i < memberCount; i++) {
339 : 0 : if ( TypeClass_CONSTANT == memberTypes[i]->getTypeClass() )
340 : 0 : constCount++;
341 : : }
342 : :
343 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
344 : 0 : RT_TYPE_MODULE, xPublished->isPublished(),
345 : : uTypeName.replace('.', '/'),
346 : 0 : 0, constCount, 0, 0);
347 : :
348 : 0 : if ( 0 < constCount ) {
349 : 0 : Reference< XConstantTypeDescription > xConst;
350 : 0 : sal_uInt16 fieldIndex = 0;
351 : 0 : for (i=0; i < memberCount; i++) {
352 : 0 : if ( TypeClass_CONSTANT == memberTypes[i]->getTypeClass() ) {
353 : : xConst = Reference< XConstantTypeDescription >(
354 : 0 : memberTypes[i], UNO_QUERY);
355 : :
356 : 0 : writeConstantData(writer, ++fieldIndex, xConst);
357 : : }
358 : 0 : }
359 : : }
360 : :
361 : 0 : const void* p = writer.getBlob(blobsize);
362 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
363 : 0 : memcpy(pBlob, p, *blobsize);
364 : : }
365 : 0 : break;
366 : : case TypeClass_INTERFACE:
367 : : {
368 : 0 : Reference< XInterfaceTypeDescription2 > xIFace(xType, UNO_QUERY);
369 : :
370 : 0 : if ( !xIFace.is() )
371 : 0 : return NULL;
372 : :
373 : 0 : Reference< XInterfaceAttributeTypeDescription2 > xAttr;
374 : 0 : Reference< XInterfaceMethodTypeDescription > xMethod;
375 : : Sequence< Reference< XInterfaceMemberTypeDescription > > memberTypes(
376 : 0 : xIFace->getMembers());
377 : : Sequence< Reference< XTypeDescription > > baseTypes =
378 : 0 : xIFace->getBaseTypes();
379 : : Sequence< Reference< XTypeDescription > > optBaseTypes =
380 : 0 : xIFace->getOptionalBaseTypes();
381 : :
382 : 0 : sal_uInt16 baseCount = (sal_uInt16)baseTypes.getLength();
383 : 0 : sal_uInt16 optBaseCount = (sal_uInt16)optBaseTypes.getLength();
384 : 0 : sal_uInt16 memberCount = (sal_uInt16)memberTypes.getLength();
385 : 0 : sal_uInt16 attrCount = 0, attrmethods = 0;
386 : 0 : sal_uInt16 inheritedMemberCount = 0;
387 : : sal_uInt16 i;
388 : :
389 : 0 : for (i=0; i < memberCount; i++) {
390 : : xAttr = Reference< XInterfaceAttributeTypeDescription2 >(
391 : 0 : memberTypes[i], UNO_QUERY);
392 : 0 : if ( xAttr.is() ) {
393 : 0 : attrCount++;
394 : :
395 : 0 : if (xAttr->getGetExceptions().getLength() > 0)
396 : 0 : attrmethods++;
397 : :
398 : 0 : if (xAttr->getSetExceptions().getLength() > 0)
399 : 0 : attrmethods++;
400 : : }
401 : : }
402 : :
403 : : // check inherited members count
404 : 0 : if (baseCount > 0) {
405 : 0 : GeneratedTypeSet checkedTypes;
406 : : inheritedMemberCount = (sal_uInt16)getInheritedMemberCount(
407 : 0 : checkedTypes, baseTypes );
408 : : }
409 : :
410 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
411 : 0 : RT_TYPE_INTERFACE, xPublished->isPublished(),
412 : : uTypeName.replace('.', '/'),
413 : : baseCount, attrCount, memberCount-attrCount+attrmethods,
414 : 0 : (sal_uInt16)optBaseTypes.getLength());
415 : :
416 : : // set super types
417 : 0 : for (i=0; i < baseCount; i++) {
418 : 0 : writer.setSuperTypeName(i, baseTypes[i]->
419 : 0 : getName().replace('.', '/'));
420 : : }
421 : :
422 : : // set optional super types
423 : 0 : RTReferenceType referenceType = RT_REF_SUPPORTS;
424 : 0 : RTFieldAccess fieldAccess = RT_ACCESS_OPTIONAL;
425 : 0 : for (i=0; i < optBaseCount; i++) {
426 : : writer.setReferenceData(i, OUString(), referenceType,
427 : 0 : fieldAccess, optBaseTypes[i]->
428 : 0 : getName().replace('.', '/'));
429 : : }
430 : :
431 : 0 : fieldAccess = RT_ACCESS_READWRITE;
432 : : // reset attrCount, used for method index calculation
433 : 0 : attrCount = 0;
434 : 0 : attrmethods = 0;
435 : 0 : for (i=0; i < memberCount; i++) {
436 : : xAttr = Reference< XInterfaceAttributeTypeDescription2 >(
437 : 0 : memberTypes[i], UNO_QUERY);
438 : 0 : if ( xAttr.is() ) {
439 : 0 : ++attrCount;
440 : 0 : if (xAttr->isReadOnly())
441 : 0 : fieldAccess = RT_ACCESS_READONLY;
442 : : else
443 : 0 : fieldAccess = RT_ACCESS_READWRITE;
444 : :
445 : 0 : if (xAttr->isBound())
446 : 0 : fieldAccess |= RT_ACCESS_BOUND;
447 : :
448 : 0 : writer.setFieldData((sal_uInt16)memberTypes[i]->getPosition()
449 : : - inheritedMemberCount,
450 : : OUString(), OUString(), fieldAccess,
451 : 0 : memberTypes[i]->getMemberName(),
452 : 0 : xAttr->getType()->getName().replace('.','/'),
453 : 0 : RTConstValue());
454 : :
455 : : writeAttributeMethodData(writer, attrmethods,
456 : 0 : RT_MODE_ATTRIBUTE_GET, xAttr);
457 : 0 : if (!xAttr->isReadOnly()) {
458 : : writeAttributeMethodData(writer, attrmethods,
459 : 0 : RT_MODE_ATTRIBUTE_SET, xAttr);
460 : : }
461 : :
462 : 0 : continue;
463 : : }
464 : :
465 : : xMethod = Reference< XInterfaceMethodTypeDescription >(
466 : 0 : memberTypes[i], UNO_QUERY);
467 : 0 : if ( xMethod.is() ) {
468 : : writeMethodData(writer, attrCount+inheritedMemberCount-attrmethods,
469 : 0 : xMethod);
470 : : }
471 : : }
472 : :
473 : 0 : const void* p = writer.getBlob(blobsize);
474 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
475 : 0 : memcpy(pBlob, p, *blobsize);
476 : : }
477 : 0 : break;
478 : : case TypeClass_STRUCT:
479 : : {
480 : 0 : Reference< XStructTypeDescription > xStruct(xType, UNO_QUERY);
481 : :
482 : 0 : if ( !xStruct.is() )
483 : 0 : return NULL;
484 : :
485 : 0 : if ( xStruct->getTypeArguments().getLength() > 0)
486 : 0 : return NULL;
487 : :
488 : :
489 : 0 : Sequence< OUString > typeParams( xStruct->getTypeParameters());
490 : 0 : Sequence< OUString > memberNames( xStruct->getMemberNames());
491 : : Sequence< Reference< XTypeDescription > > memberTypes(
492 : 0 : xStruct->getMemberTypes());
493 : 0 : sal_uInt16 memberCount = (sal_uInt16)memberNames.getLength();
494 : :
495 : 0 : OUString uSuperType;
496 : 0 : sal_uInt16 superCount=0;
497 : 0 : if ( typeParams.getLength() == 0) {
498 : 0 : Reference< XTypeDescription > xSuperType = xStruct->getBaseType();
499 : 0 : if ( xSuperType.is() ) {
500 : 0 : ++superCount;
501 : 0 : uSuperType = xSuperType->getName().replace('.','/');
502 : 0 : }
503 : : }
504 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
505 : 0 : RT_TYPE_STRUCT, xPublished->isPublished(),
506 : : uTypeName.replace('.', '/'),
507 : : superCount, memberCount, 0,
508 : 0 : (sal_uInt16)typeParams.getLength());
509 : :
510 : : // set super type
511 : 0 : if (superCount > 0) {
512 : 0 : writer.setSuperTypeName(0, uSuperType);
513 : : }
514 : :
515 : 0 : sal_uInt16 i=0;
516 : 0 : for (i=0; i < memberCount; i++) {
517 : 0 : RTFieldAccess fieldAccess = RT_ACCESS_READWRITE;
518 : 0 : if (typeParams.getLength() > 0)
519 : : fieldAccess |= checkParameterizedTypeFlag(
520 : 0 : typeParams, memberTypes[i]->getName());
521 : :
522 : : writer.setFieldData(i, OUString(), OUString(), fieldAccess,
523 : 0 : memberNames[i],
524 : 0 : memberTypes[i]->getName().replace('.', '/'),
525 : 0 : RTConstValue());
526 : : }
527 : :
528 : 0 : for (i=0; i < typeParams.getLength(); i++) {
529 : : writer.setReferenceData(i, OUString(), RT_REF_TYPE_PARAMETER,
530 : 0 : RT_ACCESS_INVALID, typeParams[i]);
531 : : }
532 : :
533 : 0 : const void* p = writer.getBlob(blobsize);
534 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
535 : 0 : memcpy(pBlob, p, *blobsize);
536 : : }
537 : 0 : break;
538 : : case TypeClass_EXCEPTION:
539 : : {
540 : 0 : Reference< XCompoundTypeDescription > xComp(xType, UNO_QUERY);
541 : :
542 : 0 : if ( !xComp.is() )
543 : 0 : return NULL;
544 : :
545 : 0 : Sequence< OUString > memberNames( xComp->getMemberNames());
546 : : Sequence< Reference< XTypeDescription > > memberTypes(
547 : 0 : xComp->getMemberTypes());
548 : 0 : sal_uInt16 memberCount = (sal_uInt16)memberNames.getLength();
549 : :
550 : 0 : OUString uSuperType;
551 : 0 : sal_uInt16 superCount=0;
552 : 0 : Reference< XTypeDescription > xSuperType = xComp->getBaseType();
553 : 0 : if ( xSuperType.is() ) {
554 : 0 : ++superCount;
555 : 0 : uSuperType = xSuperType->getName().replace('.','/');
556 : : }
557 : :
558 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
559 : 0 : RT_TYPE_EXCEPTION, xPublished->isPublished(),
560 : : uTypeName.replace('.', '/'),
561 : 0 : superCount, memberCount, 0, 0);
562 : :
563 : : // set super type
564 : 0 : if (superCount > 0) {
565 : 0 : writer.setSuperTypeName(0, uSuperType);
566 : : }
567 : :
568 : 0 : for (sal_Int16 i=0; i < memberCount; i++) {
569 : : writer.setFieldData(i, OUString(), OUString(), RT_ACCESS_READWRITE,
570 : 0 : memberNames[i],
571 : 0 : memberTypes[i]->getName().replace('.', '/'),
572 : 0 : RTConstValue());
573 : : }
574 : :
575 : 0 : const void* p = writer.getBlob(blobsize);
576 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
577 : 0 : memcpy(pBlob, p, *blobsize);
578 : : }
579 : 0 : break;
580 : : case TypeClass_ENUM:
581 : : {
582 : 0 : Reference< XEnumTypeDescription > xEnum(xType, UNO_QUERY);
583 : :
584 : 0 : if ( !xEnum.is() )
585 : 0 : return NULL;
586 : :
587 : 0 : Sequence< OUString > enumNames( xEnum->getEnumNames());
588 : 0 : Sequence< sal_Int32 > enumValues( xEnum->getEnumValues());
589 : 0 : sal_uInt16 enumCount = (sal_uInt16)enumNames.getLength();
590 : :
591 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
592 : 0 : RT_TYPE_ENUM, xPublished->isPublished(),
593 : : uTypeName.replace('.', '/'),
594 : 0 : 0, enumCount, 0, 0);
595 : :
596 : 0 : RTConstValue constValue;
597 : 0 : for (sal_Int16 i=0; i < enumCount; i++) {
598 : 0 : constValue.m_type = RT_TYPE_INT32;
599 : 0 : constValue.m_value.aLong = enumValues[i];
600 : :
601 : : writer.setFieldData(i, OUString(), OUString(),
602 : 0 : RT_ACCESS_CONST, enumNames[i],
603 : 0 : OUString(), constValue);
604 : : }
605 : :
606 : 0 : const void* p = writer.getBlob(blobsize);
607 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
608 : 0 : memcpy(pBlob, p, *blobsize);
609 : : }
610 : 0 : break;
611 : : case TypeClass_TYPEDEF:
612 : : {
613 : 0 : Reference< XIndirectTypeDescription > xTD(xType, UNO_QUERY);
614 : :
615 : 0 : if ( !xTD.is() )
616 : 0 : return NULL;
617 : :
618 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
619 : 0 : RT_TYPE_TYPEDEF, xPublished->isPublished(),
620 : : uTypeName.replace('.', '/'),
621 : 0 : 1, 0, 0, 0);
622 : :
623 : 0 : writer.setSuperTypeName(0, xTD->getReferencedType()
624 : 0 : ->getName().replace('.','/'));
625 : :
626 : 0 : const void* p = writer.getBlob(blobsize);
627 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
628 : 0 : memcpy(pBlob, p, *blobsize);
629 : : }
630 : 0 : break;
631 : : case TypeClass_SERVICE:
632 : : {
633 : 0 : Reference< XServiceTypeDescription2 > xService(xType, UNO_QUERY);
634 : :
635 : 0 : if ( !xService.is() )
636 : 0 : return NULL;
637 : :
638 : : Sequence<Reference<XServiceConstructorDescription> > constructors(
639 : 0 : xService->getConstructors());
640 : 0 : Sequence<Reference<XPropertyTypeDescription> > properties;
641 : 0 : Sequence<Reference<XServiceTypeDescription> > mandatoryServices;
642 : 0 : Sequence<Reference<XServiceTypeDescription> > optionalServices;
643 : 0 : Sequence<Reference<XInterfaceTypeDescription> > mandatoryInterfaces;
644 : 0 : Sequence<Reference<XInterfaceTypeDescription> > optionalInterfaces;
645 : 0 : sal_uInt16 methodCount = (sal_uInt16)constructors.getLength();
646 : 0 : sal_uInt16 referenceCount = 0;
647 : 0 : sal_uInt16 propertyCount = 0;
648 : :
649 : 0 : if ( !xService->isSingleInterfaceBased() ) {
650 : 0 : mandatoryServices = xService->getMandatoryServices();
651 : 0 : optionalServices = xService->getOptionalServices();
652 : 0 : mandatoryInterfaces = xService->getMandatoryInterfaces();
653 : 0 : optionalInterfaces = xService->getOptionalInterfaces();
654 : 0 : properties = xService->getProperties();
655 : : referenceCount = (sal_uInt16)(
656 : 0 : mandatoryServices.getLength()+
657 : 0 : optionalServices.getLength()+
658 : 0 : mandatoryInterfaces.getLength()+
659 : 0 : optionalInterfaces.getLength());
660 : 0 : propertyCount = (sal_uInt16)properties.getLength();
661 : : }
662 : :
663 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
664 : 0 : RT_TYPE_SERVICE, xPublished->isPublished(),
665 : : uTypeName.replace('.', '/'),
666 : 0 : (xService->isSingleInterfaceBased() ? 1 : 0),
667 : 0 : propertyCount, methodCount, referenceCount);
668 : :
669 : 0 : sal_uInt16 i=0;
670 : 0 : if ( xService->isSingleInterfaceBased() ) {
671 : 0 : writer.setSuperTypeName(0, xService->getInterface()
672 : 0 : ->getName().replace('.','/'));
673 : :
674 : 0 : sal_uInt16 j=0;
675 : 0 : for ( i=0; i<methodCount; i++ ) {
676 : : Reference<XServiceConstructorDescription> xConstructor(
677 : 0 : constructors[i], UNO_QUERY);
678 : 0 : Sequence<Reference<XParameter> > parameters;
679 : 0 : Sequence<Reference<XCompoundTypeDescription> > exceptions;
680 : 0 : sal_uInt16 parameterCount=0;
681 : 0 : sal_uInt16 exceptionCount=0;
682 : 0 : if ( !xConstructor->isDefaultConstructor() ) {
683 : 0 : parameters = xConstructor->getParameters();
684 : 0 : parameterCount = (sal_uInt16)parameters.getLength();
685 : : }
686 : :
687 : : writer.setMethodData(i, OUString(), RT_MODE_TWOWAY,
688 : 0 : xConstructor->getName(),
689 : : OUString(
690 : : RTL_CONSTASCII_USTRINGPARAM("void")),
691 : 0 : parameterCount, exceptionCount);
692 : :
693 : 0 : if ( !xConstructor->isDefaultConstructor() ) {
694 : 0 : for ( j=0; j<parameterCount; j++ ) {
695 : 0 : Reference<XParameter> xParam(parameters[j], UNO_QUERY);
696 : 0 : RTParamMode paramMode = RT_PARAM_IN;
697 : 0 : if (xParam->isRestParameter())
698 : 0 : paramMode = RT_PARAM_REST;
699 : :
700 : : writer.setMethodParameterData(
701 : 0 : i, (sal_uInt16)xParam->getPosition(),
702 : 0 : paramMode, xParam->getName(),
703 : 0 : xParam->getType()->getName().replace('.', '/'));
704 : 0 : }
705 : :
706 : 0 : for (j=0; j<exceptionCount; j++) {
707 : : Reference<XCompoundTypeDescription> xExcp(
708 : 0 : exceptions[j], UNO_QUERY);
709 : :
710 : : writer.setMethodExceptionTypeName(
711 : 0 : i, j, xExcp->getName().replace('.', '/'));
712 : 0 : }
713 : : }
714 : 0 : }
715 : : } else
716 : : {
717 : 0 : for (i=0; i<propertyCount; i++) {
718 : : Reference<XPropertyTypeDescription> xProp(
719 : 0 : properties[i], UNO_QUERY);
720 : :
721 : : RTFieldAccess propertyFlags = checkPropertyFlags(
722 : 0 : xProp->getPropertyFlags());
723 : :
724 : : writer.setFieldData(i, OUString(), OUString(),
725 : : propertyFlags,
726 : 0 : xProp->getName().copy(xProp->getName().lastIndexOf('.')+1),
727 : 0 : xProp->getPropertyTypeDescription()
728 : 0 : ->getName().replace('.', '/'),
729 : 0 : RTConstValue());
730 : 0 : }
731 : :
732 : 0 : sal_uInt16 refIndex = 0;
733 : 0 : sal_uInt16 length = (sal_uInt16)mandatoryServices.getLength();
734 : 0 : for (i=0; i < length; i++) {
735 : : writer.setReferenceData(refIndex++, OUString(),
736 : : RT_REF_EXPORTS, RT_ACCESS_INVALID,
737 : 0 : mandatoryServices[i]->getName()
738 : 0 : .replace('.', '/'));
739 : : }
740 : 0 : length = (sal_uInt16)optionalServices.getLength();
741 : 0 : for (i=0; i < length; i++) {
742 : : writer.setReferenceData(refIndex++, OUString(),
743 : : RT_REF_EXPORTS, RT_ACCESS_OPTIONAL,
744 : 0 : optionalServices[i]->getName()
745 : 0 : .replace('.', '/'));
746 : : }
747 : 0 : length = (sal_uInt16)mandatoryInterfaces.getLength();
748 : 0 : for (i=0; i < length; i++) {
749 : : writer.setReferenceData(refIndex++, OUString(),
750 : : RT_REF_SUPPORTS, RT_ACCESS_INVALID,
751 : 0 : mandatoryInterfaces[i]->getName()
752 : 0 : .replace('.', '/'));
753 : : }
754 : 0 : length = (sal_uInt16)optionalInterfaces.getLength();
755 : 0 : for (i=0; i < length; i++) {
756 : : writer.setReferenceData(refIndex++, OUString(),
757 : : RT_REF_SUPPORTS, RT_ACCESS_OPTIONAL,
758 : 0 : optionalInterfaces[i]->getName()
759 : 0 : .replace('.', '/'));
760 : : }
761 : : }
762 : :
763 : 0 : const void* p = writer.getBlob(blobsize);
764 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
765 : 0 : memcpy(pBlob, p, *blobsize);
766 : : }
767 : 0 : break;
768 : : case TypeClass_SINGLETON:
769 : : {
770 : 0 : Reference<XSingletonTypeDescription2> xSingleton(xType, UNO_QUERY);
771 : :
772 : 0 : if ( !xSingleton.is() )
773 : 0 : return NULL;
774 : :
775 : : typereg::Writer writer(TYPEREG_VERSION_1, OUString(), OUString(),
776 : 0 : RT_TYPE_SINGLETON, xPublished->isPublished(),
777 : : uTypeName.replace('.', '/'),
778 : 0 : 1, 0, 0, 0);
779 : :
780 : 0 : if (xSingleton->isInterfaceBased()) {
781 : 0 : writer.setSuperTypeName(0, xSingleton->getInterface()
782 : 0 : ->getName().replace('.','/'));
783 : : } else {
784 : 0 : writer.setSuperTypeName(0, xSingleton->getService()
785 : 0 : ->getName().replace('.','/'));
786 : : }
787 : :
788 : 0 : const void* p = writer.getBlob(blobsize);
789 : 0 : pBlob = (sal_uInt8*)rtl_allocateMemory(*blobsize);
790 : 0 : memcpy(pBlob, p, *blobsize);
791 : : }
792 : 0 : break;
793 : : default:
794 : : OSL_FAIL( "unsupported type" );
795 : 0 : break;
796 : : }
797 : :
798 : 0 : return pBlob;
799 : : }
800 : :
801 : : } // end of namespace unodevtools
802 : :
803 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|