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 "codemaker/commonjava.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "skeletoncommon.hxx"
27cdf0e10cSrcweir #include "skeletonjava.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir using namespace ::rtl;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace skeletonmaker { namespace java {
32cdf0e10cSrcweir 
33cdf0e10cSrcweir void printType(std::ostream & o,
34cdf0e10cSrcweir                ProgramOptions const & options, TypeManager const & manager,
35cdf0e10cSrcweir                OString const & type, bool referenceType,
36cdf0e10cSrcweir                bool defaultvalue);
37cdf0e10cSrcweir 
printType(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,codemaker::UnoType::Sort sort,RTTypeClass typeClass,OString const & name,sal_Int32 rank,std::vector<OString> const & arguments,bool referenceType,bool defaultvalue)38cdf0e10cSrcweir void printType(std::ostream & o,
39cdf0e10cSrcweir                ProgramOptions const & options, TypeManager const & manager,
40cdf0e10cSrcweir                codemaker::UnoType::Sort sort, RTTypeClass typeClass,
41cdf0e10cSrcweir                OString const & name, sal_Int32 rank,
42cdf0e10cSrcweir                std::vector< OString > const & arguments, bool referenceType,
43cdf0e10cSrcweir                bool defaultvalue)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     if ( defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR ) {
46cdf0e10cSrcweir         switch (sort)
47cdf0e10cSrcweir         {
48cdf0e10cSrcweir         case codemaker::UnoType::SORT_BOOLEAN:
49cdf0e10cSrcweir             o << "false";
50cdf0e10cSrcweir             return;
51cdf0e10cSrcweir         case codemaker::UnoType::SORT_CHAR:
52cdf0e10cSrcweir         case codemaker::UnoType::SORT_BYTE:
53cdf0e10cSrcweir         case codemaker::UnoType::SORT_SHORT:
54cdf0e10cSrcweir         case codemaker::UnoType::SORT_UNSIGNED_SHORT:
55cdf0e10cSrcweir         case codemaker::UnoType::SORT_LONG:
56cdf0e10cSrcweir         case codemaker::UnoType::SORT_UNSIGNED_LONG:
57cdf0e10cSrcweir         case codemaker::UnoType::SORT_HYPER:
58cdf0e10cSrcweir         case codemaker::UnoType::SORT_UNSIGNED_HYPER:
59cdf0e10cSrcweir         case codemaker::UnoType::SORT_FLOAT:
60cdf0e10cSrcweir         case codemaker::UnoType::SORT_DOUBLE:
61cdf0e10cSrcweir             o << "0";
62cdf0e10cSrcweir             return;
63cdf0e10cSrcweir         case codemaker::UnoType::SORT_VOID:
64cdf0e10cSrcweir         case codemaker::UnoType::SORT_STRING:
65cdf0e10cSrcweir         case codemaker::UnoType::SORT_TYPE:
66cdf0e10cSrcweir         case codemaker::UnoType::SORT_ANY:
67cdf0e10cSrcweir         case codemaker::UnoType::SORT_COMPLEX:
68cdf0e10cSrcweir             break;
69cdf0e10cSrcweir         }
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     if ( defaultvalue ) {
73cdf0e10cSrcweir         if ( sort == codemaker::UnoType::SORT_COMPLEX &&
74cdf0e10cSrcweir             typeClass == RT_TYPE_INTERFACE ) {
75cdf0e10cSrcweir             o << "null";
76cdf0e10cSrcweir             return;
77cdf0e10cSrcweir         } else if ( sort == codemaker::UnoType::SORT_ANY && rank==0 ) {
78cdf0e10cSrcweir             o << "com.sun.star.uno.Any.VOID";
79cdf0e10cSrcweir             return;
80cdf0e10cSrcweir         } else if ( sort == codemaker::UnoType::SORT_TYPE && rank==0 ) {
81cdf0e10cSrcweir             o << "com.sun.star.uno.Type.VOID";
82cdf0e10cSrcweir             return;
83cdf0e10cSrcweir         } else
84cdf0e10cSrcweir             if ( typeClass != RT_TYPE_ENUM || rank > 0 )
85cdf0e10cSrcweir                 o << "new ";
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     OString sType(codemaker::java::translateUnoToJavaType(
89cdf0e10cSrcweir                       sort, typeClass, name, referenceType && rank==0).replace('/', '.'));
90cdf0e10cSrcweir     if ( sType.indexOf("java.lang.") == 0 )
91cdf0e10cSrcweir         sType = sType.copy(10);
92cdf0e10cSrcweir     o << sType.getStr();
93cdf0e10cSrcweir     if ( !arguments.empty() && options.java5 ) {
94cdf0e10cSrcweir         o << '<';
95cdf0e10cSrcweir         for ( std::vector< OString >::const_iterator i(arguments.begin());
96cdf0e10cSrcweir               i != arguments.end(); ++i )
97cdf0e10cSrcweir         {
98cdf0e10cSrcweir             if ( i != arguments.begin() ) {
99cdf0e10cSrcweir                 o << ", ";
100cdf0e10cSrcweir             }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir             printType(o, options, manager, *i, true, false);
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir         o << '>';
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < rank; ++i ) {
107cdf0e10cSrcweir         if ( defaultvalue )
108cdf0e10cSrcweir             o << "[0]";
109cdf0e10cSrcweir         else
110cdf0e10cSrcweir             o << "[]";
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     if ( defaultvalue && sort > codemaker::UnoType::SORT_CHAR && rank == 0 ) {
114cdf0e10cSrcweir         if ( typeClass == RT_TYPE_ENUM )
115cdf0e10cSrcweir             o << ".getDefault()";
116cdf0e10cSrcweir         else
117cdf0e10cSrcweir             o << "()";
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
printType(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,OString const & type,bool referenceType,bool defaultvalue)121cdf0e10cSrcweir void printType(std::ostream & o,
122cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
123cdf0e10cSrcweir     OString const & type, bool referenceType, bool defaultvalue)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     RTTypeClass typeClass;
126cdf0e10cSrcweir     OString name;
127cdf0e10cSrcweir     sal_Int32 rank;
128cdf0e10cSrcweir     std::vector< OString > arguments;
129cdf0e10cSrcweir     codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
130cdf0e10cSrcweir         manager, type, true, true, true, &typeClass, &name, &rank, &arguments);
131cdf0e10cSrcweir     printType(o,
132cdf0e10cSrcweir         options, manager, sort, typeClass, name, rank, arguments,
133cdf0e10cSrcweir         referenceType, defaultvalue);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
printConstructorParameters(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,typereg::Reader const & reader,typereg::Reader const & outerReader,std::vector<OString> const & arguments)136cdf0e10cSrcweir bool printConstructorParameters(std::ostream & o,
137cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
138cdf0e10cSrcweir     typereg::Reader const & reader, typereg::Reader const & outerReader,
139cdf0e10cSrcweir     std::vector< OString > const & arguments)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     bool previous = false;
142cdf0e10cSrcweir     if ( reader.getSuperTypeCount() != 0 ) {
143cdf0e10cSrcweir         OString super(
144cdf0e10cSrcweir             codemaker::convertString(reader.getSuperTypeName(0)));
145cdf0e10cSrcweir         typereg::Reader superReader(manager.getTypeReader(super));
146cdf0e10cSrcweir         if ( !superReader.isValid() ) {
147cdf0e10cSrcweir             throw CannotDumpException("Bad type library entity " + super);
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir         previous = printConstructorParameters(o,
150cdf0e10cSrcweir             options, manager, superReader, outerReader, arguments);
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < reader.getFieldCount(); ++i ) {
153cdf0e10cSrcweir         if ( previous ) {
154cdf0e10cSrcweir             o << ", ";
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir         previous = true;
157cdf0e10cSrcweir         if ( (reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE) == 0  ) {
158cdf0e10cSrcweir             printType(o,
159cdf0e10cSrcweir                 options, manager,
160cdf0e10cSrcweir                 codemaker::convertString(reader.getFieldTypeName(i)),
161cdf0e10cSrcweir                 false);
162cdf0e10cSrcweir         } else if ( arguments.empty() ) {
163cdf0e10cSrcweir             o << "java.lang.Object";
164cdf0e10cSrcweir         } else {
165cdf0e10cSrcweir             sal_uInt16 tparam = 0;
166cdf0e10cSrcweir             while ( outerReader.getReferenceTypeName(tparam)
167cdf0e10cSrcweir                     != reader.getFieldTypeName(i) )
168cdf0e10cSrcweir             {
169cdf0e10cSrcweir                 ++tparam;
170cdf0e10cSrcweir                 OSL_ASSERT(tparam < outerReader.getReferenceCount());
171cdf0e10cSrcweir             }
172cdf0e10cSrcweir             // assume std::vector< OString >::size_type is at least as
173cdf0e10cSrcweir             // large as sal_uInt16:
174cdf0e10cSrcweir             printType(o, options, manager, arguments[tparam], true);
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir         o
177cdf0e10cSrcweir             << ' '
178cdf0e10cSrcweir             << (codemaker::java::translateUnoToJavaIdentifier(
179cdf0e10cSrcweir                     codemaker::convertString(reader.getFieldName(i)),
180cdf0e10cSrcweir                     "param").
181cdf0e10cSrcweir                 getStr());
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir     return previous;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
printConstructor(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,typereg::Reader const & reader,std::vector<OString> const & arguments)186cdf0e10cSrcweir void printConstructor(std::ostream & o,
187cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
188cdf0e10cSrcweir     typereg::Reader const & reader,
189cdf0e10cSrcweir     std::vector< OString > const & arguments)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     OString type(codemaker::convertString(reader.getTypeName()));
192cdf0e10cSrcweir     o << "public " << type.copy(type.lastIndexOf('/') + 1) << '(';
193cdf0e10cSrcweir     printConstructorParameters(o, options, manager, reader, reader, arguments);
194cdf0e10cSrcweir     o << ");\n";
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
printMethodParameters(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,typereg::Reader const & reader,sal_uInt16 method,bool previous,bool withtype,bool)197cdf0e10cSrcweir void printMethodParameters(std::ostream & o,
198cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
199cdf0e10cSrcweir     typereg::Reader const & reader, sal_uInt16 method, bool previous,
200cdf0e10cSrcweir     bool withtype, bool /*shortname*/)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < reader.getMethodParameterCount(method); ++i ) {
203cdf0e10cSrcweir         if ( previous  )
204cdf0e10cSrcweir             o << ", ";
205cdf0e10cSrcweir         else
206cdf0e10cSrcweir             previous = true;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         if ( withtype ) {
209cdf0e10cSrcweir             printType(o, options, manager,
210cdf0e10cSrcweir                       codemaker::convertString(
211cdf0e10cSrcweir                           reader.getMethodParameterTypeName(method, i)),
212cdf0e10cSrcweir                       false);
213cdf0e10cSrcweir             if ( reader.getMethodParameterFlags(method, i) == RT_PARAM_OUT
214cdf0e10cSrcweir                  || reader.getMethodParameterFlags(method, i) == RT_PARAM_INOUT )
215cdf0e10cSrcweir             {
216cdf0e10cSrcweir                 o << "[]";
217cdf0e10cSrcweir             } else if ( (reader.getMethodParameterFlags(method, i) & RT_PARAM_REST )
218cdf0e10cSrcweir                        != 0)
219cdf0e10cSrcweir             {
220cdf0e10cSrcweir                 o << (options.java5 ? "..." : "[]");
221cdf0e10cSrcweir             }
222cdf0e10cSrcweir             o << ' ';
223cdf0e10cSrcweir         }
224cdf0e10cSrcweir         o << (codemaker::java::translateUnoToJavaIdentifier(
225cdf0e10cSrcweir                   codemaker::convertString(
226cdf0e10cSrcweir                       reader.getMethodParameterName(method, i)),
227cdf0e10cSrcweir                   "param").
228cdf0e10cSrcweir               getStr());
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
printExceptionSpecification(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,typereg::Reader const & reader,sal_uInt16 method)232cdf0e10cSrcweir void printExceptionSpecification(std::ostream & o,
233cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
234cdf0e10cSrcweir     typereg::Reader const & reader, sal_uInt16 method)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     if ( reader.getMethodExceptionCount(method) > 0 ) {
237cdf0e10cSrcweir         o << " throws ";
238cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < reader.getMethodExceptionCount(method); ++i )
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir             if ( i != 0 ) {
241cdf0e10cSrcweir                 o << ", ";
242cdf0e10cSrcweir             }
243cdf0e10cSrcweir             printType(o,
244cdf0e10cSrcweir                 options, manager,
245cdf0e10cSrcweir                 codemaker::convertString(
246cdf0e10cSrcweir                     reader.getMethodExceptionTypeName(method, i)),
247cdf0e10cSrcweir                 false);
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 
printSetPropertyMixinBody(std::ostream & o,typereg::Reader const & reader,sal_uInt16 field,sal_uInt16 method,OString const & indentation)253cdf0e10cSrcweir void printSetPropertyMixinBody(std::ostream & o,
254cdf0e10cSrcweir                                typereg::Reader const & reader,
255cdf0e10cSrcweir                                sal_uInt16 field,
256cdf0e10cSrcweir                                sal_uInt16 method,
257cdf0e10cSrcweir                                OString const & indentation)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     RTFieldAccess propFlags = checkAdditionalPropertyFlags(reader, field, method);
260cdf0e10cSrcweir     OString fieldname = codemaker::convertString(reader.getFieldName(field));
261cdf0e10cSrcweir     bool bound = (reader.getFieldFlags(field) & RT_ACCESS_BOUND ? true : false);
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     o << "\n" << indentation << "{\n";
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     if ( bound ) {
266cdf0e10cSrcweir         o << indentation << "    PropertySetMixin.BoundListeners l = "
267cdf0e10cSrcweir             "new PropertySetMixin.BoundListeners();\n\n";
268cdf0e10cSrcweir     }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir     o << indentation << "    m_prophlp.prepareSet(\""
271cdf0e10cSrcweir       << fieldname << "\", ";
272cdf0e10cSrcweir     if ( propFlags & RT_ACCESS_CONSTRAINED ) {
273cdf0e10cSrcweir         OString fieldtype = codemaker::convertString(reader.getFieldTypeName(field));
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         sal_Int32 index = fieldtype.lastIndexOf('<');
276cdf0e10cSrcweir         sal_Int32 nPos=0;
277cdf0e10cSrcweir 		bool single = true;
278cdf0e10cSrcweir 		bool optional = false;
279cdf0e10cSrcweir 		OStringBuffer buffer1(64);
280cdf0e10cSrcweir 		OStringBuffer buffer2(64);
281cdf0e10cSrcweir         do
282cdf0e10cSrcweir         {
283cdf0e10cSrcweir             OString s(fieldtype.getToken(0, '<', nPos));
284cdf0e10cSrcweir 			OStringBuffer buffer(16);
285cdf0e10cSrcweir             buffer.append("((");
286cdf0e10cSrcweir             buffer.append(s.copy(s.lastIndexOf('/')+1));
287cdf0e10cSrcweir             buffer.append(')');
288cdf0e10cSrcweir 			OString t = buffer.makeStringAndClear();
289cdf0e10cSrcweir 
290cdf0e10cSrcweir             if ( t.equals("((Optional)") ) {
291cdf0e10cSrcweir                 optional=true;
292cdf0e10cSrcweir                 if (single) {
293cdf0e10cSrcweir                     single=false;
294cdf0e10cSrcweir                     buffer1.append("the_value.IsPresent");
295cdf0e10cSrcweir                     buffer2.append("the_value.Value");
296cdf0e10cSrcweir                 } else {
297cdf0e10cSrcweir                     buffer1.insert(0, t);
298cdf0e10cSrcweir                     buffer1.append(").IsPresent");
299cdf0e10cSrcweir                     buffer2.insert(0, t);
300cdf0e10cSrcweir                     buffer2.append(").Value");
301cdf0e10cSrcweir                 }
302cdf0e10cSrcweir             } else {
303cdf0e10cSrcweir                 if ( single ) {
304cdf0e10cSrcweir                     single=false;
305cdf0e10cSrcweir                     if ( !optional ) {
306cdf0e10cSrcweir                         buffer1.append("the_value.Value");
307cdf0e10cSrcweir                     }
308cdf0e10cSrcweir                     buffer2.append("the_value.Value");
309cdf0e10cSrcweir                 } else {
310cdf0e10cSrcweir                     if ( !optional ) {
311cdf0e10cSrcweir                         buffer1.insert(0, t);
312cdf0e10cSrcweir                         buffer1.append(").Value");
313cdf0e10cSrcweir                     }
314cdf0e10cSrcweir                     buffer2.insert(0, t);
315cdf0e10cSrcweir                     buffer2.append(").Value");
316cdf0e10cSrcweir                 }
317cdf0e10cSrcweir             }
318cdf0e10cSrcweir         } while( nPos <= index );
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         o << "Any.VOID,\n" << indentation << "        ";
321cdf0e10cSrcweir         if ( optional )
322cdf0e10cSrcweir             o << "(";
323cdf0e10cSrcweir         o << buffer1.makeStringAndClear();
324cdf0e10cSrcweir 		if ( optional )
325cdf0e10cSrcweir 			o << ") ? " << buffer2.makeStringAndClear() << " : Any.VOID,\n"
326cdf0e10cSrcweir               << indentation << "        ";
327cdf0e10cSrcweir         else
328cdf0e10cSrcweir             o << ", ";
329cdf0e10cSrcweir     }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     if ( bound )
332cdf0e10cSrcweir         o << "l";
333cdf0e10cSrcweir     else
334cdf0e10cSrcweir         o << "null";
335cdf0e10cSrcweir     o << ");\n";
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     o << indentation << "    synchronized (this) {\n"
338cdf0e10cSrcweir       << indentation << "        m_" << fieldname
339cdf0e10cSrcweir       << " = the_value;\n" << indentation << "    }\n";
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     if ( bound ) {
342cdf0e10cSrcweir         o << indentation << "    l.notifyListeners();\n";
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir     o  << indentation << "}\n\n";
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir void generateXPropertySetBodies(std::ostream& o);
348cdf0e10cSrcweir void generateXFastPropertySetBodies(std::ostream& o);
349cdf0e10cSrcweir void generateXPropertyAccessBodies(std::ostream& o);
350cdf0e10cSrcweir 
printMethods(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,typereg::Reader const & reader,codemaker::GeneratedTypeSet & generated,OString const & delegate,OString const & indentation,bool defaultvalue,bool usepropertymixin)351cdf0e10cSrcweir void printMethods(std::ostream & o,
352cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
353cdf0e10cSrcweir     typereg::Reader const & reader,
354cdf0e10cSrcweir     codemaker::GeneratedTypeSet & generated,
355cdf0e10cSrcweir     OString const & delegate, OString const & indentation,
356cdf0e10cSrcweir     bool defaultvalue, bool usepropertymixin)
357cdf0e10cSrcweir {
358cdf0e10cSrcweir     OString type(codemaker::convertString(reader.getTypeName()));
359cdf0e10cSrcweir     if ( generated.contains(type) || type == "com/sun/star/uno/XInterface" ||
360cdf0e10cSrcweir          ( defaultvalue &&
361cdf0e10cSrcweir            ( type.equals("com/sun/star/lang/XComponent") ||
362cdf0e10cSrcweir              type.equals("com/sun/star/lang/XTypeProvider") ||
363cdf0e10cSrcweir              type.equals("com/sun/star/uno/XWeak") ) ) ) {
364cdf0e10cSrcweir         return;
365cdf0e10cSrcweir     }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     if ( usepropertymixin ) {
368cdf0e10cSrcweir         if ( type.equals("com/sun/star/beans/XPropertySet") ) {
369cdf0e10cSrcweir             generated.add(type);
370cdf0e10cSrcweir             generateXPropertySetBodies(o);
371cdf0e10cSrcweir             return;
372cdf0e10cSrcweir         } else if ( type.equals("com/sun/star/beans/XFastPropertySet") ) {
373cdf0e10cSrcweir             generated.add(type);
374cdf0e10cSrcweir             generateXFastPropertySetBodies(o);
375cdf0e10cSrcweir             return;
376cdf0e10cSrcweir         } else if ( type.equals("com/sun/star/beans/XPropertyAccess") ) {
377cdf0e10cSrcweir             generated.add(type);
378cdf0e10cSrcweir             generateXPropertyAccessBodies(o);
379cdf0e10cSrcweir             return;
380cdf0e10cSrcweir         }
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     static OString sd(RTL_CONSTASCII_STRINGPARAM("_"));
384cdf0e10cSrcweir     bool body = ((delegate.getLength() > 0) ? true : false);
385cdf0e10cSrcweir     bool defaultbody = ((delegate.equals(sd)) ? true : false);
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     generated.add(type);
388cdf0e10cSrcweir     if ( options.all || defaultvalue ) {
389cdf0e10cSrcweir         for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
390cdf0e10cSrcweir             typereg::Reader super(
391cdf0e10cSrcweir                 manager.getTypeReader(
392cdf0e10cSrcweir                     codemaker::convertString(
393cdf0e10cSrcweir                         reader.getSuperTypeName(i))));
394cdf0e10cSrcweir             if ( !super.isValid() ) {
395cdf0e10cSrcweir                 throw CannotDumpException(
396cdf0e10cSrcweir                     "Bad type library entity "
397cdf0e10cSrcweir                     + codemaker::convertString(
398cdf0e10cSrcweir                         reader.getSuperTypeName(i)));
399cdf0e10cSrcweir             }
400cdf0e10cSrcweir             printMethods(o, options, manager, super, generated, delegate,
401cdf0e10cSrcweir                          indentation, defaultvalue, usepropertymixin);
402cdf0e10cSrcweir         }
403cdf0e10cSrcweir         if ( reader.getFieldCount() > 0 || reader.getMethodCount() > 0 ) {
404cdf0e10cSrcweir             o << indentation << "// ";
405cdf0e10cSrcweir             printType(o, options, manager, type, false);
406cdf0e10cSrcweir             o << ":\n";
407cdf0e10cSrcweir         }
408cdf0e10cSrcweir     }
409cdf0e10cSrcweir     sal_uInt16 method = 0;
410cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < reader.getFieldCount(); ++i ) {
411cdf0e10cSrcweir //         OString fieldName(
412cdf0e10cSrcweir //             codemaker::convertString(reader.getFieldName(i)).
413cdf0e10cSrcweir //             replace('/', '.'));
414cdf0e10cSrcweir //         OString fieldType(
415cdf0e10cSrcweir //             codemaker::convertString(reader.getFieldTypeName(i)).
416cdf0e10cSrcweir //             replace('/', '.'));
417cdf0e10cSrcweir //         attributes.insert(StringPairHashMap::value_type(fieldName,
418cdf0e10cSrcweir //                               std::pair<OString, sal_Int16>(
419cdf0e10cSrcweir //                                   fieldType, reader.getFieldFlags(i))));
420cdf0e10cSrcweir 
421cdf0e10cSrcweir         o << indentation << "public ";
422cdf0e10cSrcweir         printType(o,
423cdf0e10cSrcweir             options, manager,
424cdf0e10cSrcweir             codemaker::convertString(reader.getFieldTypeName(i)), false);
425cdf0e10cSrcweir         o << " get"
426cdf0e10cSrcweir           << codemaker::convertString(reader.getFieldName(i)).getStr()
427cdf0e10cSrcweir           << "()";
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         #if 0
430cdf0e10cSrcweir 		// DEBUG
431cdf0e10cSrcweir 		sal_uInt16 mc = reader.getMethodCount();
432cdf0e10cSrcweir 		RTMethodMode mm = reader.getMethodFlags(method);
433cdf0e10cSrcweir         #endif
434cdf0e10cSrcweir 		OUString mn = reader.getMethodName(method);
435cdf0e10cSrcweir 		OUString fn = reader.getFieldName(i);
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         if ( method < reader.getMethodCount()
438cdf0e10cSrcweir              && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_GET
439cdf0e10cSrcweir              && reader.getMethodName(method) == reader.getFieldName(i) )
440cdf0e10cSrcweir         {
441cdf0e10cSrcweir             printExceptionSpecification(o, options, manager, reader, method++);
442cdf0e10cSrcweir         }
443cdf0e10cSrcweir         if ( body ) {
444cdf0e10cSrcweir             if ( defaultbody ) {
445cdf0e10cSrcweir                 if ( usepropertymixin ) {
446cdf0e10cSrcweir                     o << "\n" << indentation << "{\n" << indentation
447cdf0e10cSrcweir                       << "    return m_"
448cdf0e10cSrcweir                       << codemaker::convertString(reader.getFieldName(i)).getStr()
449cdf0e10cSrcweir                       << ";\n" << indentation << "}\n\n";
450cdf0e10cSrcweir                 } else {
451cdf0e10cSrcweir                     o << "\n" << indentation << "{\n" << indentation
452cdf0e10cSrcweir                       << "    return ";
453cdf0e10cSrcweir                     printType(o,
454cdf0e10cSrcweir                               options, manager,
455cdf0e10cSrcweir                               codemaker::convertString(reader.getFieldTypeName(i)),
456cdf0e10cSrcweir                               false, true);
457cdf0e10cSrcweir                     o << ";\n" << indentation << "}\n\n";
458cdf0e10cSrcweir                 }
459cdf0e10cSrcweir             } else {
460cdf0e10cSrcweir                 o << "\n" << indentation << "{\n" << indentation <<
461cdf0e10cSrcweir                     "    return "
462cdf0e10cSrcweir                   << delegate.getStr() << "get"
463cdf0e10cSrcweir                   << codemaker::convertString(reader.getFieldName(i)).getStr()
464cdf0e10cSrcweir                   << "();\n" << indentation << "}\n\n";
465cdf0e10cSrcweir             }
466cdf0e10cSrcweir 		} else {
467cdf0e10cSrcweir             o << ";\n";
468cdf0e10cSrcweir 		}
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 		// REMOVE next line
471cdf0e10cSrcweir 		OUString tmp = reader.getFieldName(i);
472cdf0e10cSrcweir 		bool setAttrMethod = false;
473cdf0e10cSrcweir         if ( (reader.getFieldFlags(i) & RT_ACCESS_READONLY) == 0 ) {
474cdf0e10cSrcweir             o << indentation << "public void set"
475cdf0e10cSrcweir               << (codemaker::convertString(reader.getFieldName(i)).
476cdf0e10cSrcweir                   getStr())
477cdf0e10cSrcweir               << '(';
478cdf0e10cSrcweir             printType(o,
479cdf0e10cSrcweir                 options, manager,
480cdf0e10cSrcweir                 codemaker::convertString(reader.getFieldTypeName(i)),
481cdf0e10cSrcweir                 false);
482cdf0e10cSrcweir             o << " the_value)";
483cdf0e10cSrcweir             if ( method < reader.getMethodCount()
484cdf0e10cSrcweir                  && reader.getMethodFlags(method) == RT_MODE_ATTRIBUTE_SET
485cdf0e10cSrcweir                  && reader.getMethodName(method) == reader.getFieldName(i) )
486cdf0e10cSrcweir             {
487cdf0e10cSrcweir 				setAttrMethod=true;
488cdf0e10cSrcweir                 printExceptionSpecification(o, options, manager, reader, method);
489cdf0e10cSrcweir             }
490cdf0e10cSrcweir             if ( body ) {
491cdf0e10cSrcweir                 if ( defaultbody ) {
492cdf0e10cSrcweir                     if ( usepropertymixin ) {
493cdf0e10cSrcweir                         printSetPropertyMixinBody(o, reader, i, method,
494cdf0e10cSrcweir                                                   indentation);
495cdf0e10cSrcweir                     } else {
496cdf0e10cSrcweir                         o << "\n" << indentation << "{\n\n" << indentation
497cdf0e10cSrcweir                           << "}\n\n";
498cdf0e10cSrcweir                     }
499cdf0e10cSrcweir                 } else {
500cdf0e10cSrcweir                     o << "\n" << indentation << "{\n" << indentation
501cdf0e10cSrcweir                       << "    " << delegate.getStr() << "set"
502cdf0e10cSrcweir                       << codemaker::convertString(reader.getFieldName(i)).getStr()
503cdf0e10cSrcweir                       << "(the_value);\n" << indentation << "}\n\n";
504cdf0e10cSrcweir                 }
505cdf0e10cSrcweir 			} else {
506cdf0e10cSrcweir                 o << ";\n";
507cdf0e10cSrcweir 			}
508cdf0e10cSrcweir 			if (setAttrMethod) ++method;
509cdf0e10cSrcweir         }
510cdf0e10cSrcweir     }
511cdf0e10cSrcweir     for ( ; method < reader.getMethodCount(); ++method ) {
512cdf0e10cSrcweir         o << indentation << "public ";
513cdf0e10cSrcweir         printType(o,
514cdf0e10cSrcweir             options, manager,
515cdf0e10cSrcweir             codemaker::convertString(
516cdf0e10cSrcweir                 reader.getMethodReturnTypeName(method)),
517cdf0e10cSrcweir             false);
518cdf0e10cSrcweir 
519cdf0e10cSrcweir         const OString methodName(codemaker::convertString(reader.getMethodName(method)));
520cdf0e10cSrcweir 
521cdf0e10cSrcweir         o << ' ' << methodName.getStr() << '(';
522cdf0e10cSrcweir         printMethodParameters(o, options, manager, reader, method, false, true);
523cdf0e10cSrcweir         o << ')';
524cdf0e10cSrcweir         printExceptionSpecification(o, options, manager, reader, method);
525cdf0e10cSrcweir         if ( body ) {
526cdf0e10cSrcweir             static OUString s(RTL_CONSTASCII_USTRINGPARAM("void"));
527cdf0e10cSrcweir             if ( defaultbody ) {
528cdf0e10cSrcweir                 o << "\n" << indentation << "{\n";
529cdf0e10cSrcweir                 if ( !reader.getMethodReturnTypeName(method).equals(s) ) {
530cdf0e10cSrcweir                     o << indentation << "    // TODO: Exchange the default return "
531cdf0e10cSrcweir                       << "implementation for \"" << methodName << "\" !!!\n";
532cdf0e10cSrcweir                     o << indentation << "    // NOTE: "
533cdf0e10cSrcweir                         "Default initialized polymorphic structs can cause problems"
534cdf0e10cSrcweir                         "\n" << indentation << "    // because of missing default "
535cdf0e10cSrcweir                         "initialization of primitive types of\n" << indentation
536cdf0e10cSrcweir                       << "    // some C++ compilers or different Any initialization"
537cdf0e10cSrcweir                         " in Java and C++\n" << indentation
538cdf0e10cSrcweir                       << "    // polymorphic structs.\n" << indentation
539cdf0e10cSrcweir                       << "    return ";
540cdf0e10cSrcweir                     printType(o,
541cdf0e10cSrcweir                         options, manager,
542cdf0e10cSrcweir                         codemaker::convertString(
543cdf0e10cSrcweir                             reader.getMethodReturnTypeName(method)),
544cdf0e10cSrcweir                         false, true);
545cdf0e10cSrcweir                     o << ";";
546cdf0e10cSrcweir                 } else {
547cdf0e10cSrcweir                     o << indentation << "    // TODO: Insert your implementation for \""
548cdf0e10cSrcweir                       << methodName << "\" here.";
549cdf0e10cSrcweir                 }
550cdf0e10cSrcweir                 o << "\n" << indentation << "}\n\n";
551cdf0e10cSrcweir             } else {
552cdf0e10cSrcweir                 o << "\n" << indentation << "{\n" << indentation << "    ";
553cdf0e10cSrcweir                 if ( !reader.getMethodReturnTypeName(method).equals(s) )
554cdf0e10cSrcweir                     o << "return ";
555cdf0e10cSrcweir                 o << delegate.getStr()
556cdf0e10cSrcweir                   << (codemaker::convertString(
557cdf0e10cSrcweir                           reader.getMethodName(method)).getStr())
558cdf0e10cSrcweir                   << '(';
559cdf0e10cSrcweir                 printMethodParameters(o, options, manager, reader, method,
560cdf0e10cSrcweir                                          false, false);
561cdf0e10cSrcweir                 o << ");\n" << indentation << "}\n\n";
562cdf0e10cSrcweir             }
563cdf0e10cSrcweir         } else {
564cdf0e10cSrcweir             o << ";\n";
565cdf0e10cSrcweir         }
566cdf0e10cSrcweir     }
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
printConstructionMethods(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,typereg::Reader const & reader)569cdf0e10cSrcweir void printConstructionMethods(std::ostream & o,
570cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
571cdf0e10cSrcweir     typereg::Reader const & reader)
572cdf0e10cSrcweir {
573cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < reader.getMethodCount(); ++i ) {
574cdf0e10cSrcweir         o << "public static ";
575cdf0e10cSrcweir         printType(o,
576cdf0e10cSrcweir             options, manager,
577cdf0e10cSrcweir             codemaker::convertString(reader.getSuperTypeName(0)), false);
578cdf0e10cSrcweir         o << ' ';
579cdf0e10cSrcweir         if ( reader.getMethodName(i).getLength() == 0 ) {
580cdf0e10cSrcweir             o << "create";
581cdf0e10cSrcweir         } else {
582cdf0e10cSrcweir             o << (codemaker::java::translateUnoToJavaIdentifier(
583cdf0e10cSrcweir                       codemaker::convertString(reader.getMethodName(i)),
584cdf0e10cSrcweir                       "method").getStr());
585cdf0e10cSrcweir         }
586cdf0e10cSrcweir         o << "(com.sun.star.uno.XComponentContext the_context";
587cdf0e10cSrcweir         printMethodParameters(o, options, manager, reader, i, true, true);
588cdf0e10cSrcweir         o << ')';
589cdf0e10cSrcweir         printExceptionSpecification(o, options, manager, reader, i);
590cdf0e10cSrcweir         o << ";\n";
591cdf0e10cSrcweir     }
592cdf0e10cSrcweir }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir void generateDocumentation(std::ostream & o,
595cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
596cdf0e10cSrcweir     OString const & type);
597cdf0e10cSrcweir 
printServiceMembers(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,typereg::Reader const & reader,OString const & type,OString const & delegate)598cdf0e10cSrcweir void printServiceMembers(std::ostream & o,
599cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
600cdf0e10cSrcweir     typereg::Reader const & reader, OString const & type,
601cdf0e10cSrcweir     OString const & delegate)
602cdf0e10cSrcweir {
603cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i ) {
604cdf0e10cSrcweir         OString referenceType(
605cdf0e10cSrcweir             codemaker::convertString(
606cdf0e10cSrcweir                 reader.getReferenceTypeName(i)).replace('/', '.'));
607cdf0e10cSrcweir 
608cdf0e10cSrcweir         if ( reader.getReferenceSort(i) == RT_REF_SUPPORTS ) {
609cdf0e10cSrcweir             o << "\n// supported interface " << referenceType.getStr() << "\n";
610cdf0e10cSrcweir             generateDocumentation(o, options, manager, referenceType, delegate);
611cdf0e10cSrcweir         } else if ( reader.getReferenceSort(i) == RT_REF_EXPORTS ) {
612cdf0e10cSrcweir             o << "\n// exported service " << referenceType.getStr() << "\n";
613cdf0e10cSrcweir             generateDocumentation(o, options, manager, referenceType, delegate);
614cdf0e10cSrcweir         }
615cdf0e10cSrcweir     }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir     o << "\n// properties of service \""<< type.getStr() << "\"\n";
618cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < reader.getFieldCount(); ++i ) {
619cdf0e10cSrcweir         OString fieldName(
620cdf0e10cSrcweir             codemaker::convertString(reader.getFieldName(i)));
621cdf0e10cSrcweir         OString fieldType(
622cdf0e10cSrcweir             codemaker::convertString(reader.getFieldTypeName(i)));
623cdf0e10cSrcweir 
624cdf0e10cSrcweir         o << "// private ";
625cdf0e10cSrcweir         printType(o, options, manager, fieldType, false);
626cdf0e10cSrcweir         o << " "
627cdf0e10cSrcweir           << codemaker::java::translateUnoToJavaIdentifier(
628cdf0e10cSrcweir               fieldName, "property").getStr()
629cdf0e10cSrcweir           << ";\n";
630cdf0e10cSrcweir     }
631cdf0e10cSrcweir }
632cdf0e10cSrcweir 
printMapsToJavaType(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,codemaker::UnoType::Sort sort,RTTypeClass typeClass,OString const & name,sal_Int32 rank,std::vector<OString> const & arguments,const char * javaTypeSort)633cdf0e10cSrcweir void printMapsToJavaType(std::ostream & o,
634cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
635cdf0e10cSrcweir     codemaker::UnoType::Sort sort, RTTypeClass typeClass,
636cdf0e10cSrcweir     OString const & name, sal_Int32 rank,
637cdf0e10cSrcweir     std::vector< OString > const & arguments, const char * javaTypeSort)
638cdf0e10cSrcweir {
639cdf0e10cSrcweir     o << "maps to Java " << (options.java5 ? "1.5" : "1.4") << " ";
640cdf0e10cSrcweir     if ( javaTypeSort != 0 ) {
641cdf0e10cSrcweir         o << javaTypeSort << ' ';
642cdf0e10cSrcweir     }
643cdf0e10cSrcweir     o << "type \"";
644cdf0e10cSrcweir     if ( rank == 0 && name == "com/sun/star/uno/XInterface" ) {
645cdf0e10cSrcweir         o << "com.sun.star.uno.XInterface";
646cdf0e10cSrcweir     } else {
647cdf0e10cSrcweir         printType(o,
648cdf0e10cSrcweir             options, manager, sort, typeClass, name, rank, arguments, false);
649cdf0e10cSrcweir     }
650cdf0e10cSrcweir     o << '"';
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
generateDocumentation(std::ostream & o,ProgramOptions const & options,TypeManager const & manager,OString const & type,OString const & delegate)653cdf0e10cSrcweir void generateDocumentation(std::ostream & o,
654cdf0e10cSrcweir     ProgramOptions const & options, TypeManager const & manager,
655cdf0e10cSrcweir     OString const & type, OString const & delegate)
656cdf0e10cSrcweir {
657cdf0e10cSrcweir     if ( type.indexOf('/') >= 0 ) {
658cdf0e10cSrcweir         throw CannotDumpException("Illegal type name " + type);
659cdf0e10cSrcweir     }
660cdf0e10cSrcweir     OString binType(type.replace('.', '/'));
661cdf0e10cSrcweir     RTTypeClass typeClass;
662cdf0e10cSrcweir     OString name;
663cdf0e10cSrcweir     sal_Int32 rank;
664cdf0e10cSrcweir     std::vector< OString > arguments;
665cdf0e10cSrcweir     codemaker::UnoType::Sort sort = decomposeResolveAndCheck(
666cdf0e10cSrcweir         manager, binType, false, true, true, &typeClass, &name, &rank,
667cdf0e10cSrcweir         &arguments);
668cdf0e10cSrcweir 
669cdf0e10cSrcweir     bool comment=true;
670cdf0e10cSrcweir     if ( delegate.getLength() > 0 ) {
671cdf0e10cSrcweir         if ( typeClass != RT_TYPE_INTERFACE && typeClass != RT_TYPE_SERVICE )
672cdf0e10cSrcweir             return;
673cdf0e10cSrcweir 
674cdf0e10cSrcweir         comment=false;
675cdf0e10cSrcweir     }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir     if ( comment ) {
678cdf0e10cSrcweir         o << "\n// UNO";
679cdf0e10cSrcweir         if ( rank > 0 ) {
680cdf0e10cSrcweir             o << " sequence type";
681cdf0e10cSrcweir         } else if ( sort != codemaker::UnoType::SORT_COMPLEX ) {
682cdf0e10cSrcweir             o << " simple type";
683cdf0e10cSrcweir         } else {
684cdf0e10cSrcweir             typereg::Reader reader(manager.getTypeReader(name));
685cdf0e10cSrcweir             if ( !reader.isValid() ) {
686cdf0e10cSrcweir                 throw CannotDumpException("Bad type library entity " + name);
687cdf0e10cSrcweir             }
688cdf0e10cSrcweir             switch ( typeClass ) {
689cdf0e10cSrcweir             case RT_TYPE_INTERFACE:
690cdf0e10cSrcweir                 o << " interface type";
691cdf0e10cSrcweir                 break;
692cdf0e10cSrcweir 
693cdf0e10cSrcweir             case RT_TYPE_MODULE:
694cdf0e10cSrcweir                 o << "IDL module";
695cdf0e10cSrcweir                 break;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir             case RT_TYPE_STRUCT:
698cdf0e10cSrcweir                 if ( reader.getReferenceCount() == 0 ) {
699cdf0e10cSrcweir                     o << " simple struct type";
700cdf0e10cSrcweir                 } else if ( arguments.empty() ) {
701cdf0e10cSrcweir                     o << " polymorphic struct type template";
702cdf0e10cSrcweir                 } else {
703cdf0e10cSrcweir                     o << " instantiated polymorphic struct type";
704cdf0e10cSrcweir                 }
705cdf0e10cSrcweir                 break;
706cdf0e10cSrcweir 
707cdf0e10cSrcweir             case RT_TYPE_ENUM:
708cdf0e10cSrcweir                 o << " enum type";
709cdf0e10cSrcweir                 break;
710cdf0e10cSrcweir 
711cdf0e10cSrcweir             case RT_TYPE_EXCEPTION:
712cdf0e10cSrcweir                 o << " exception type";
713cdf0e10cSrcweir                 break;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir             case RT_TYPE_TYPEDEF:
716cdf0e10cSrcweir                 o << "IDL typedef";
717cdf0e10cSrcweir                 break;
718cdf0e10cSrcweir 
719cdf0e10cSrcweir             case RT_TYPE_SERVICE:
720cdf0e10cSrcweir                 if ( reader.getSuperTypeCount() > 0 ) {
721cdf0e10cSrcweir                     o << " single-inheritance--based service";
722cdf0e10cSrcweir                 } else {
723cdf0e10cSrcweir                     o << "IDL accumulation-based service";
724cdf0e10cSrcweir                 }
725cdf0e10cSrcweir                 break;
726cdf0e10cSrcweir 
727cdf0e10cSrcweir             case RT_TYPE_SINGLETON:
728cdf0e10cSrcweir                 if ( (manager.getTypeReader(
729cdf0e10cSrcweir                           codemaker::convertString(
730cdf0e10cSrcweir                               reader.getSuperTypeName(0))).getTypeClass())
731cdf0e10cSrcweir                      == RT_TYPE_INTERFACE )
732cdf0e10cSrcweir                 {
733cdf0e10cSrcweir                     o << " inheritance-based singleton";
734cdf0e10cSrcweir                 } else {
735cdf0e10cSrcweir                     o << "IDL service-based singleton";
736cdf0e10cSrcweir                 }
737cdf0e10cSrcweir                 break;
738cdf0e10cSrcweir 
739cdf0e10cSrcweir             case RT_TYPE_CONSTANTS:
740cdf0e10cSrcweir                 o << "IDL constant group";
741cdf0e10cSrcweir                 break;
742cdf0e10cSrcweir 
743cdf0e10cSrcweir             default:
744cdf0e10cSrcweir                 OSL_ASSERT(false);
745cdf0e10cSrcweir                 break;
746cdf0e10cSrcweir             }
747cdf0e10cSrcweir         }
748cdf0e10cSrcweir         o << " \"" << type.getStr() << "\" ";
749cdf0e10cSrcweir     }
750cdf0e10cSrcweir     sort = codemaker::decomposeAndResolve(
751cdf0e10cSrcweir         manager, binType, true, true, true, &typeClass, &name, &rank,
752cdf0e10cSrcweir         &arguments);
753cdf0e10cSrcweir     if ( rank > 0 ) {
754cdf0e10cSrcweir         printMapsToJavaType(o,
755cdf0e10cSrcweir             options, manager, sort, typeClass, name, rank, arguments, "array");
756cdf0e10cSrcweir         o << '\n';
757cdf0e10cSrcweir     } else if ( sort != codemaker::UnoType::SORT_COMPLEX ) {
758cdf0e10cSrcweir         printMapsToJavaType(o,
759cdf0e10cSrcweir             options, manager, sort, typeClass, name, rank, arguments, 0);
760cdf0e10cSrcweir         o << '\n';
761cdf0e10cSrcweir     } else {
762cdf0e10cSrcweir         typereg::Reader reader(manager.getTypeReader(name));
763cdf0e10cSrcweir         if ( !reader.isValid() ) {
764cdf0e10cSrcweir             throw CannotDumpException("Bad type library entity " + name);
765cdf0e10cSrcweir         }
766cdf0e10cSrcweir         switch ( typeClass ) {
767cdf0e10cSrcweir         case RT_TYPE_INTERFACE:
768cdf0e10cSrcweir             printMapsToJavaType(o,
769cdf0e10cSrcweir                 options, manager, sort, typeClass, name, rank, arguments,
770cdf0e10cSrcweir                 "interface");
771cdf0e10cSrcweir             if ( name == "com/sun/star/uno/XInterface" ) {
772cdf0e10cSrcweir                 o << '\n';
773cdf0e10cSrcweir             } else {
774cdf0e10cSrcweir                 o
775cdf0e10cSrcweir                     << "; " << (options.all ? "all" : "direct")
776cdf0e10cSrcweir                     << " methods:\n";
777cdf0e10cSrcweir                 codemaker::GeneratedTypeSet generated;
778cdf0e10cSrcweir                 printMethods(o, options, manager, reader, generated,
779cdf0e10cSrcweir                              delegate, "");
780cdf0e10cSrcweir             }
781cdf0e10cSrcweir             break;
782cdf0e10cSrcweir 
783cdf0e10cSrcweir         case RT_TYPE_MODULE:
784cdf0e10cSrcweir             printMapsToJavaType(o,
785cdf0e10cSrcweir                 options, manager, sort, typeClass, name, rank, arguments,
786cdf0e10cSrcweir                 "package");
787cdf0e10cSrcweir             o << '\n';
788cdf0e10cSrcweir             break;
789cdf0e10cSrcweir 
790cdf0e10cSrcweir         case RT_TYPE_STRUCT:
791cdf0e10cSrcweir             if ( reader.getReferenceCount() == 0 ) {
792cdf0e10cSrcweir                 printMapsToJavaType(o,
793cdf0e10cSrcweir                     options, manager, sort, typeClass, name, rank, arguments,
794cdf0e10cSrcweir                     "class");
795cdf0e10cSrcweir             } else if ( arguments.empty() ) {
796cdf0e10cSrcweir                 printMapsToJavaType(o,
797cdf0e10cSrcweir                     options, manager, sort, typeClass, name, rank, arguments,
798cdf0e10cSrcweir                     options.java5 ? "generic class" : "class");
799cdf0e10cSrcweir             } else {
800cdf0e10cSrcweir                 printMapsToJavaType(o,
801cdf0e10cSrcweir                     options, manager, sort, typeClass, name, rank, arguments,
802cdf0e10cSrcweir                     options.java5 ? "generic class instantiation" : "class");
803cdf0e10cSrcweir             }
804cdf0e10cSrcweir             o << "; full constructor:\n";
805cdf0e10cSrcweir             printConstructor(o, options, manager, reader, arguments);
806cdf0e10cSrcweir             break;
807cdf0e10cSrcweir 
808cdf0e10cSrcweir         case RT_TYPE_ENUM:
809cdf0e10cSrcweir         case RT_TYPE_CONSTANTS:
810cdf0e10cSrcweir             printMapsToJavaType(o,
811cdf0e10cSrcweir                 options, manager, sort, typeClass, name, rank, arguments,
812cdf0e10cSrcweir                 "class");
813cdf0e10cSrcweir             o << '\n';
814cdf0e10cSrcweir             break;
815cdf0e10cSrcweir 
816cdf0e10cSrcweir         case RT_TYPE_EXCEPTION:
817cdf0e10cSrcweir             printMapsToJavaType(o,
818cdf0e10cSrcweir                 options, manager, sort, typeClass, name, rank, arguments,
819cdf0e10cSrcweir                 "exception class");
820cdf0e10cSrcweir             o << "; full constructor:\n";
821cdf0e10cSrcweir             printConstructor(o, options, manager, reader, arguments);
822cdf0e10cSrcweir             break;
823cdf0e10cSrcweir 
824cdf0e10cSrcweir         case RT_TYPE_SERVICE:
825cdf0e10cSrcweir             if ( reader.getSuperTypeCount() > 0 ) {
826cdf0e10cSrcweir                 printMapsToJavaType(o,
827cdf0e10cSrcweir                     options, manager, sort, typeClass, name, rank, arguments,
828cdf0e10cSrcweir                     "class");
829cdf0e10cSrcweir                 o << "; construction methods:\n";
830cdf0e10cSrcweir                 printConstructionMethods(o, options, manager, reader);
831cdf0e10cSrcweir 
832cdf0e10cSrcweir                 OString super(
833cdf0e10cSrcweir                     codemaker::convertString(
834cdf0e10cSrcweir                         reader.getSuperTypeName(0)).replace('/', '.'));
835cdf0e10cSrcweir 
836cdf0e10cSrcweir                 generateDocumentation(o, options, manager, super, delegate);
837cdf0e10cSrcweir             } else {
838cdf0e10cSrcweir                 o << ("does not map to Java\n"
839cdf0e10cSrcweir                       "// the service members are generated instead\n");
840cdf0e10cSrcweir                 printServiceMembers(o, options, manager, reader, type, delegate);
841cdf0e10cSrcweir             }
842cdf0e10cSrcweir             break;
843cdf0e10cSrcweir 
844cdf0e10cSrcweir         case RT_TYPE_SINGLETON:
845cdf0e10cSrcweir             if ( reader.getSuperTypeCount() > 0 &&
846cdf0e10cSrcweir                  ((manager.getTypeReader(
847cdf0e10cSrcweir                        codemaker::convertString(
848cdf0e10cSrcweir                            reader.getSuperTypeName(0))).getTypeClass())
849cdf0e10cSrcweir                   == RT_TYPE_INTERFACE) ) {
850cdf0e10cSrcweir                 printMapsToJavaType(o, options, manager, sort, typeClass,
851cdf0e10cSrcweir                                     name, rank, arguments, "class");
852cdf0e10cSrcweir                 o << "; get method:\npublic static ";
853cdf0e10cSrcweir                 printType(o, options, manager,
854cdf0e10cSrcweir                           codemaker::convertString(reader.getSuperTypeName(0)),
855cdf0e10cSrcweir                           false);
856cdf0e10cSrcweir                 o
857cdf0e10cSrcweir                     << " get(com.sun.star.uno.XComponentContext context);\n";
858cdf0e10cSrcweir             } else {
859cdf0e10cSrcweir                 o << "does not map to Java\n";
860cdf0e10cSrcweir             }
861cdf0e10cSrcweir             break;
862cdf0e10cSrcweir 
863cdf0e10cSrcweir         default:
864cdf0e10cSrcweir             OSL_ASSERT(false);
865cdf0e10cSrcweir             break;
866cdf0e10cSrcweir         }
867cdf0e10cSrcweir     }
868cdf0e10cSrcweir }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir } }
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 
873