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