Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <cstring>
23 :
24 : #include "codemaker/codemaker.hxx"
25 : #include "codemaker/commonjava.hxx"
26 : #include "codemaker/global.hxx"
27 :
28 : #include "skeletoncommon.hxx"
29 : #include "skeletonjava.hxx"
30 :
31 : using namespace ::rtl;
32 :
33 : namespace skeletonmaker { namespace java {
34 :
35 0 : void printType(
36 : std::ostream & o, ProgramOptions const & options,
37 : rtl::Reference< TypeManager > const & manager,
38 : codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
39 : std::vector< OUString > const & arguments, bool referenceType,
40 : bool defaultvalue)
41 : {
42 0 : if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
43 0 : switch (sort) {
44 : case codemaker::UnoType::SORT_BOOLEAN:
45 0 : o << "false";
46 0 : return;
47 : case codemaker::UnoType::SORT_CHAR:
48 : case codemaker::UnoType::SORT_BYTE:
49 : case codemaker::UnoType::SORT_SHORT:
50 : case codemaker::UnoType::SORT_UNSIGNED_SHORT:
51 : case codemaker::UnoType::SORT_LONG:
52 : case codemaker::UnoType::SORT_UNSIGNED_LONG:
53 : case codemaker::UnoType::SORT_HYPER:
54 : case codemaker::UnoType::SORT_UNSIGNED_HYPER:
55 : case codemaker::UnoType::SORT_FLOAT:
56 : case codemaker::UnoType::SORT_DOUBLE:
57 0 : o << "0";
58 0 : return;
59 : default:
60 0 : break;
61 : }
62 : }
63 :
64 0 : if (defaultvalue) {
65 0 : if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE) {
66 0 : o << "null";
67 0 : return;
68 0 : } else if (sort == codemaker::UnoType::SORT_ANY && rank == 0) {
69 0 : o << "com.sun.star.uno.Any.VOID";
70 0 : return;
71 0 : } else if (sort == codemaker::UnoType::SORT_TYPE && rank == 0) {
72 0 : o << "com.sun.star.uno.Type.VOID";
73 0 : return;
74 0 : } else if (sort != codemaker::UnoType::SORT_ENUM_TYPE || rank != 0) {
75 0 : o << "new ";
76 : }
77 : }
78 :
79 : OString sType(
80 : codemaker::java::translateUnoToJavaType(
81 0 : sort, u2b(nucleus), referenceType && rank == 0));
82 0 : if (sType.startsWith("java.lang.")) {
83 0 : sType = sType.copy(std::strlen("java.lang."));
84 : }
85 0 : o << sType;
86 0 : if (!arguments.empty() && options.java5) {
87 0 : o << '<';
88 0 : for (std::vector< OUString >::const_iterator i(arguments.begin());
89 0 : i != arguments.end(); ++i)
90 : {
91 0 : if (i != arguments.begin()) {
92 0 : o << ", ";
93 : }
94 0 : printType(o, options, manager, *i, true, false);
95 : }
96 0 : o << '>';
97 : }
98 0 : for (sal_Int32 i = 0; i != rank; ++i) {
99 0 : if (defaultvalue)
100 0 : o << "[0]";
101 : else
102 0 : o << "[]";
103 : }
104 :
105 0 : if (defaultvalue && sort > codemaker::UnoType::SORT_CHAR && rank == 0) {
106 0 : if (sort == codemaker::UnoType::SORT_ENUM_TYPE)
107 0 : o << ".getDefault()";
108 : else
109 0 : o << "()";
110 0 : }
111 : }
112 :
113 0 : void printType(
114 : std::ostream & o, ProgramOptions const & options,
115 : rtl::Reference< TypeManager > const & manager, OUString const & name,
116 : bool referenceType, bool defaultvalue)
117 : {
118 0 : OUString nucleus;
119 : sal_Int32 rank;
120 0 : std::vector< OUString > arguments;
121 : codemaker::UnoType::Sort sort = manager->decompose(
122 0 : name, true, &nucleus, &rank, &arguments, 0);
123 : printType(
124 : o, options, manager, sort, nucleus, rank, arguments, referenceType,
125 0 : defaultvalue);
126 0 : }
127 :
128 0 : bool printConstructorParameters(
129 : std::ostream & o, ProgramOptions const & options,
130 : rtl::Reference< TypeManager > const & manager,
131 : codemaker::UnoType::Sort sort,
132 : rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
133 : std::vector< OUString > const & arguments)
134 : {
135 0 : bool previous = false;
136 0 : switch (sort) {
137 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
138 : {
139 : rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
140 0 : dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
141 : assert(ent2.is());
142 0 : if (!ent2->getDirectBase().isEmpty()) {
143 0 : rtl::Reference< unoidl::Entity > baseEnt;
144 : codemaker::UnoType::Sort baseSort = manager->getSort(
145 0 : ent2->getDirectBase(), &baseEnt);
146 : previous = printConstructorParameters(
147 : o, options, manager, baseSort, baseEnt,
148 0 : ent2->getDirectBase(), std::vector< OUString >());
149 : }
150 0 : for (std::vector< unoidl::PlainStructTypeEntity::Member >::
151 0 : const_iterator i(ent2->getDirectMembers().begin());
152 0 : i != ent2->getDirectMembers().end(); ++i)
153 : {
154 0 : if (previous) {
155 0 : o << ", ";
156 : }
157 0 : previous = true;
158 0 : printType(o, options, manager, i->type, false);
159 0 : o << ' '
160 : << codemaker::java::translateUnoToJavaIdentifier(
161 0 : u2b(i->name), "param");
162 : }
163 0 : break;
164 : }
165 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
166 : {
167 : rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
168 : dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
169 0 : entity.get()));
170 : assert(ent2.is());
171 0 : for (std::vector<
172 : unoidl::PolymorphicStructTypeTemplateEntity::Member >::
173 0 : const_iterator i(ent2->getMembers().begin());
174 0 : i != ent2->getMembers().end(); ++i)
175 : {
176 0 : if (previous) {
177 0 : o << ", ";
178 : }
179 0 : previous = true;
180 0 : if (i->parameterized) {
181 0 : o << i->type;
182 : } else {
183 0 : printType(o, options, manager, i->type, false);
184 : }
185 0 : o << ' '
186 : << codemaker::java::translateUnoToJavaIdentifier(
187 0 : u2b(i->name), "param");
188 : }
189 0 : break;
190 : }
191 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
192 : {
193 : rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
194 : dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
195 0 : entity.get()));
196 : assert(ent2.is());
197 0 : for (std::vector<
198 : unoidl::PolymorphicStructTypeTemplateEntity::Member >::
199 0 : const_iterator i(ent2->getMembers().begin());
200 0 : i != ent2->getMembers().end(); ++i)
201 : {
202 0 : if (previous) {
203 0 : o << ", ";
204 : }
205 0 : previous = true;
206 0 : if (i->parameterized) {
207 0 : for (std::vector< OUString >::const_iterator j(
208 0 : ent2->getTypeParameters().begin());
209 0 : j != ent2->getTypeParameters().end(); ++j)
210 : {
211 0 : if (i->type == *j) {
212 : o << arguments[
213 0 : j - ent2->getTypeParameters().begin()];
214 0 : break;
215 : }
216 : }
217 : } else {
218 0 : printType(o, options, manager, i->type, false);
219 : }
220 0 : o << ' '
221 : << codemaker::java::translateUnoToJavaIdentifier(
222 0 : u2b(i->name), "param");
223 : }
224 0 : break;
225 : }
226 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
227 : {
228 : rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
229 0 : dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
230 : assert(ent2.is());
231 0 : if (!ent2->getDirectBase().isEmpty()) {
232 0 : rtl::Reference< unoidl::Entity > baseEnt;
233 : codemaker::UnoType::Sort baseSort = manager->getSort(
234 0 : ent2->getDirectBase(), &baseEnt);
235 : previous = printConstructorParameters(
236 : o, options, manager, baseSort, baseEnt,
237 0 : ent2->getDirectBase(), std::vector< OUString >());
238 : }
239 0 : for (std::vector< unoidl::ExceptionTypeEntity::Member >::
240 0 : const_iterator i(ent2->getDirectMembers().begin());
241 0 : i != ent2->getDirectMembers().end(); ++i)
242 : {
243 0 : if (previous) {
244 0 : o << ", ";
245 : }
246 0 : previous = true;
247 0 : printType(o, options, manager, i->type, false);
248 0 : o << ' '
249 : << codemaker::java::translateUnoToJavaIdentifier(
250 0 : u2b(i->name), "param");
251 : }
252 0 : break;
253 : }
254 : default:
255 : throw CannotDumpException(
256 0 : "unexpected entity \"" + name
257 0 : + "\" in call to skeletonmaker::cpp::printConstructorParameters");
258 : }
259 0 : return previous;
260 : }
261 :
262 0 : void printConstructor(
263 : std::ostream & o, ProgramOptions const & options,
264 : rtl::Reference< TypeManager > const & manager,
265 : codemaker::UnoType::Sort sort,
266 : rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
267 : std::vector< OUString > const & arguments)
268 : {
269 0 : o << "public " << name.copy(name.lastIndexOf('.') + 1) << '(';
270 : printConstructorParameters(
271 0 : o, options, manager, sort, entity, name, arguments);
272 0 : o << ");\n";
273 0 : }
274 :
275 0 : void printMethodParameters(
276 : std::ostream & o, ProgramOptions const & options,
277 : rtl::Reference< TypeManager > const & manager,
278 : std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
279 : parameters,
280 : bool withType)
281 : {
282 0 : for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
283 0 : const_iterator i(parameters.begin());
284 0 : i != parameters.end(); ++i)
285 : {
286 0 : if (i != parameters.begin()) {
287 0 : o << ", ";
288 : }
289 0 : if (withType) {
290 0 : printType(o, options, manager, i->type, false);
291 0 : if (i->direction
292 0 : != unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
293 : {
294 0 : o << "[]";
295 : }
296 0 : o << ' ';
297 : }
298 : o << codemaker::java::translateUnoToJavaIdentifier(
299 0 : u2b(i->name), "param");
300 : }
301 0 : }
302 :
303 0 : void printExceptionSpecification(
304 : std::ostream & o, ProgramOptions const & options,
305 : rtl::Reference< TypeManager > const & manager,
306 : std::vector< OUString > const & exceptions)
307 : {
308 0 : if (!exceptions.empty()) {
309 0 : o << " throws ";
310 0 : for (std::vector< OUString >::const_iterator i(exceptions.begin());
311 0 : i != exceptions.end(); ++i)
312 : {
313 0 : if (i !=exceptions.begin() ) {
314 0 : o << ", ";
315 : }
316 0 : printType(o, options, manager, *i, false);
317 : }
318 : }
319 0 : }
320 :
321 :
322 0 : void printSetPropertyMixinBody(
323 : std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute,
324 : OString const & indentation)
325 : {
326 : unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
327 0 : = checkAdditionalPropertyFlags(attribute);
328 :
329 0 : o << "\n" << indentation << "{\n";
330 :
331 0 : if ( attribute.bound ) {
332 0 : o << indentation << " PropertySetMixin.BoundListeners l = "
333 0 : "new PropertySetMixin.BoundListeners();\n\n";
334 : }
335 :
336 0 : o << indentation << " m_prophlp.prepareSet(\""
337 0 : << attribute.name << "\", ";
338 0 : if ( propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED ) {
339 0 : OString fieldtype = codemaker::convertString(attribute.type);
340 :
341 0 : sal_Int32 index = fieldtype.lastIndexOf('<');
342 0 : sal_Int32 nPos=0;
343 0 : bool single = true;
344 0 : bool optional = false;
345 0 : OStringBuffer buffer1(64);
346 0 : OStringBuffer buffer2(64);
347 0 : do
348 : {
349 0 : OString s(fieldtype.getToken(0, '<', nPos));
350 0 : OStringBuffer buffer(16);
351 0 : buffer.append("((");
352 0 : buffer.append(s.copy(s.lastIndexOf('/')+1));
353 0 : buffer.append(')');
354 0 : OString t = buffer.makeStringAndClear();
355 :
356 0 : if ( t.equals("((Optional)") ) {
357 0 : optional=true;
358 0 : if (single) {
359 0 : single=false;
360 0 : buffer1.append("the_value.IsPresent");
361 0 : buffer2.append("the_value.Value");
362 : } else {
363 0 : buffer1.insert(0, t);
364 0 : buffer1.append(").IsPresent");
365 0 : buffer2.insert(0, t);
366 0 : buffer2.append(").Value");
367 : }
368 : } else {
369 0 : if ( single ) {
370 0 : single=false;
371 0 : if ( !optional ) {
372 0 : buffer1.append("the_value.Value");
373 : }
374 0 : buffer2.append("the_value.Value");
375 : } else {
376 0 : if ( !optional ) {
377 0 : buffer1.insert(0, t);
378 0 : buffer1.append(").Value");
379 : }
380 0 : buffer2.insert(0, t);
381 0 : buffer2.append(").Value");
382 : }
383 0 : }
384 0 : } while( nPos <= index );
385 :
386 0 : o << "Any.VOID,\n" << indentation << " ";
387 0 : if ( optional )
388 0 : o << "(";
389 0 : o << buffer1.makeStringAndClear();
390 0 : if ( optional )
391 0 : o << ") ? " << buffer2.makeStringAndClear() << " : Any.VOID,\n"
392 0 : << indentation << " ";
393 : else
394 0 : o << ", ";
395 : }
396 :
397 0 : if ( attribute.bound )
398 0 : o << "l";
399 : else
400 0 : o << "null";
401 0 : o << ");\n";
402 :
403 0 : o << indentation << " synchronized (this) {\n"
404 0 : << indentation << " m_" << attribute.name
405 0 : << " = the_value;\n" << indentation << " }\n";
406 :
407 0 : if ( attribute.bound ) {
408 0 : o << indentation << " l.notifyListeners();\n";
409 : }
410 0 : o << indentation << "}\n\n";
411 0 : }
412 :
413 : void generateXPropertySetBodies(std::ostream& o);
414 : void generateXFastPropertySetBodies(std::ostream& o);
415 : void generateXPropertyAccessBodies(std::ostream& o);
416 :
417 0 : void printMethods(std::ostream & o,
418 : ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
419 : OUString const & name,
420 : codemaker::GeneratedTypeSet & generated,
421 : OString const & delegate, OString const & indentation,
422 : bool defaultvalue, bool usepropertymixin)
423 : {
424 0 : if ( generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
425 0 : ( defaultvalue &&
426 0 : ( name == "com.sun.star.lang.XComponent" ||
427 0 : name == "com.sun.star.lang.XTypeProvider" ||
428 0 : name == "com.sun.star.uno.XWeak" ) ) ) {
429 0 : return;
430 : }
431 :
432 0 : if ( usepropertymixin ) {
433 0 : if (name == "com.sun.star.beans.XPropertySet") {
434 0 : generated.add(u2b(name));
435 0 : generateXPropertySetBodies(o);
436 0 : return;
437 0 : } else if (name == "com.sun.star.beans.XFastPropertySet") {
438 0 : generated.add(u2b(name));
439 0 : generateXFastPropertySetBodies(o);
440 0 : return;
441 0 : } else if (name == "com.sun.star.beans.XPropertyAccess") {
442 0 : generated.add(u2b(name));
443 0 : generateXPropertyAccessBodies(o);
444 0 : return;
445 : }
446 : }
447 :
448 0 : static OString sd("_");
449 0 : bool body = !delegate.isEmpty();
450 0 : bool defaultbody = ((delegate.equals(sd)) ? true : false);
451 :
452 0 : generated.add(u2b(name));
453 0 : rtl::Reference< unoidl::Entity > ent;
454 0 : if (manager->getSort(name, &ent) != codemaker::UnoType::SORT_INTERFACE_TYPE)
455 : {
456 : throw CannotDumpException(
457 0 : "unexpected entity \"" + name
458 0 : + "\" in call to skeletonmaker::java::printMethods");
459 : }
460 : rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
461 0 : dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
462 : assert(ent2.is());
463 0 : if ( options.all || defaultvalue ) {
464 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
465 0 : ent2->getDirectMandatoryBases().begin());
466 0 : i != ent2->getDirectMandatoryBases().end(); ++i)
467 : {
468 : printMethods(
469 0 : o, options, manager, i->name, generated, delegate, indentation,
470 0 : defaultvalue, usepropertymixin);
471 : }
472 0 : if (!(ent2->getDirectAttributes().empty()
473 0 : && ent2->getDirectMethods().empty()))
474 : {
475 0 : o << indentation << "// ";
476 0 : printType(o, options, manager, name, false);
477 0 : o << ":\n";
478 : }
479 : }
480 0 : for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
481 0 : i(ent2->getDirectAttributes().begin());
482 0 : i != ent2->getDirectAttributes().end(); ++i)
483 : {
484 0 : o << indentation << "public ";
485 0 : printType(o, options, manager, i->type, false);
486 0 : o << " get" << i->name << "()";
487 0 : printExceptionSpecification(o, options, manager, i->getExceptions);
488 0 : if ( body ) {
489 0 : if ( defaultbody ) {
490 0 : if ( usepropertymixin ) {
491 0 : o << "\n" << indentation << "{\n" << indentation
492 0 : << " return m_" << i->name << ";\n" << indentation
493 0 : << "}\n\n";
494 : } else {
495 0 : o << "\n" << indentation << "{\n" << indentation
496 0 : << " return ";
497 0 : printType(o, options, manager, i->type, false, true);
498 0 : o << ";\n" << indentation << "}\n\n";
499 : }
500 : } else {
501 0 : o << "\n" << indentation << "{\n" << indentation
502 0 : << " return " << delegate.getStr() << "get" << i->name
503 0 : << "();\n" << indentation << "}\n\n";
504 : }
505 : } else {
506 0 : o << ";\n";
507 : }
508 :
509 : // REMOVE next line
510 0 : if (!i->readOnly) {
511 0 : o << indentation << "public void set" << i->name << '(';
512 0 : printType(o, options, manager, i->type, false);
513 0 : o << " the_value)";
514 0 : printExceptionSpecification(o, options, manager, i->setExceptions);
515 0 : if ( body ) {
516 0 : if ( defaultbody ) {
517 0 : if ( usepropertymixin ) {
518 0 : printSetPropertyMixinBody(o, *i, indentation);
519 : } else {
520 0 : o << "\n" << indentation << "{\n\n" << indentation
521 0 : << "}\n\n";
522 : }
523 : } else {
524 0 : o << "\n" << indentation << "{\n" << indentation
525 0 : << " " << delegate.getStr() << "set" << i->name
526 0 : << "(the_value);\n" << indentation << "}\n\n";
527 : }
528 : } else {
529 0 : o << ";\n";
530 : }
531 : }
532 : }
533 0 : for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
534 0 : ent2->getDirectMethods().begin());
535 0 : i != ent2->getDirectMethods().end(); ++i)
536 : {
537 0 : o << indentation << "public ";
538 0 : printType(o, options, manager, i->returnType, false);
539 0 : o << ' ' << i->name << '(';
540 0 : printMethodParameters(o, options, manager, i->parameters, true);
541 0 : o << ')';
542 0 : printExceptionSpecification(o, options, manager, i->exceptions);
543 0 : if ( body ) {
544 0 : if ( defaultbody ) {
545 0 : o << "\n" << indentation << "{\n";
546 0 : if (i->returnType != "void") {
547 0 : o << indentation << " // TODO: Exchange the default return "
548 0 : << "implementation for \"" << i->name << "\" !!!\n";
549 0 : o << indentation << " // NOTE: "
550 : "Default initialized polymorphic structs can cause problems"
551 0 : "\n" << indentation << " // because of missing default "
552 0 : "initialization of primitive types of\n" << indentation
553 : << " // some C++ compilers or different Any initialization"
554 0 : " in Java and C++\n" << indentation
555 0 : << " // polymorphic structs.\n" << indentation
556 0 : << " return ";
557 0 : printType(o, options, manager, i->returnType, false, true);
558 0 : o << ";";
559 : } else {
560 0 : o << indentation << " // TODO: Insert your implementation for \""
561 0 : << i->name << "\" here.";
562 : }
563 0 : o << "\n" << indentation << "}\n\n";
564 : } else {
565 0 : o << "\n" << indentation << "{\n" << indentation << " ";
566 0 : if (i->returnType != "void") {
567 0 : o << "return ";
568 : }
569 0 : o << delegate.getStr() << i->name << '(';
570 : printMethodParameters(
571 0 : o, options, manager, i->parameters, false);
572 0 : o << ");\n" << indentation << "}\n\n";
573 : }
574 : } else {
575 0 : o << ";\n";
576 : }
577 0 : }
578 : }
579 :
580 0 : void printConstructors(
581 : std::ostream & o, ProgramOptions const & options,
582 : rtl::Reference< TypeManager > const & manager, OUString const & name)
583 : {
584 0 : rtl::Reference< unoidl::Entity > ent;
585 0 : if (manager->getSort(name, &ent)
586 : != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE)
587 : {
588 : throw CannotDumpException(
589 0 : "unexpected entity \"" + name
590 0 : + "\" in call to skeletonmaker::java::printConstructors");
591 : }
592 : rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
593 0 : dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
594 : assert(ent2.is());
595 0 : for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
596 0 : const_iterator i(ent2->getConstructors().begin());
597 0 : i != ent2->getConstructors().end(); ++i)
598 : {
599 0 : o << "public static ";
600 0 : printType(o, options, manager, ent2->getBase(), false);
601 0 : o << ' ';
602 0 : if (i->defaultConstructor) {
603 0 : o << "create";
604 : } else {
605 : o << codemaker::java::translateUnoToJavaIdentifier(
606 0 : u2b(i->name), "method");
607 : }
608 0 : o << "(com.sun.star.uno.XComponentContext the_context";
609 0 : for (std::vector<
610 : unoidl::SingleInterfaceBasedServiceEntity::Constructor::
611 0 : Parameter >::const_iterator j(i->parameters.begin());
612 0 : j != i->parameters.end(); ++i)
613 : {
614 0 : o << ", ";
615 0 : printType(o, options, manager, j->type, false);
616 0 : if (j->rest) {
617 0 : o << (options.java5 ? "..." : "[]");
618 : }
619 0 : o << ' '
620 : << codemaker::java::translateUnoToJavaIdentifier(
621 0 : u2b(j->name), "param");
622 : }
623 0 : o << ')';
624 0 : printExceptionSpecification(o, options, manager, i->exceptions);
625 0 : o << ";\n";
626 0 : }
627 0 : }
628 :
629 : void generateDocumentation(std::ostream & o,
630 : ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
631 : OString const & type);
632 :
633 0 : void printServiceMembers(
634 : std::ostream & o, ProgramOptions const & options,
635 : rtl::Reference< TypeManager > const & manager,
636 : OUString const & name,
637 : rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
638 : OString const & delegate)
639 : {
640 : assert(entity.is());
641 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
642 0 : entity->getDirectMandatoryBaseServices().begin());
643 0 : i != entity->getDirectMandatoryBaseServices().end(); ++i)
644 : {
645 0 : o << "\n// exported service " << i->name << "\n";
646 0 : generateDocumentation(o, options, manager, u2b(i->name), delegate);
647 : }
648 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
649 0 : entity->getDirectMandatoryBaseInterfaces().begin());
650 0 : i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
651 : {
652 0 : o << "\n// supported interface " << i->name << "\n";
653 0 : generateDocumentation(o, options, manager, u2b(i->name), delegate);
654 : }
655 0 : o << "\n// properties of service \""<< name << "\"\n";
656 0 : for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
657 0 : const_iterator i(entity->getDirectProperties().begin());
658 0 : i != entity->getDirectProperties().end(); ++i)
659 : {
660 0 : o << "// private ";
661 0 : printType(o, options, manager, i->type, false);
662 0 : o << " "
663 : << codemaker::java::translateUnoToJavaIdentifier(
664 0 : u2b(i->name), "property")
665 0 : << ";\n";
666 : }
667 0 : }
668 :
669 0 : void printMapsToJavaType(
670 : std::ostream & o, ProgramOptions const & options,
671 : rtl::Reference< TypeManager > const & manager,
672 : codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
673 : std::vector< OUString > const & arguments, const char * javaTypeSort)
674 : {
675 0 : o << "maps to Java " << (options.java5 ? "1.5" : "1.4") << " ";
676 0 : if (javaTypeSort != 0) {
677 0 : o << javaTypeSort << ' ';
678 : }
679 0 : o << "type \"";
680 0 : if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
681 0 : o << "com.sun.star.uno.XInterface";
682 : } else {
683 : printType(
684 0 : o, options, manager, sort, nucleus, rank, arguments, false, false);
685 : }
686 0 : o << '"';
687 0 : }
688 :
689 0 : void generateDocumentation(std::ostream & o,
690 : ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
691 : OString const & type, OString const & delegate)
692 : {
693 0 : OUString nucleus;
694 : sal_Int32 rank;
695 : codemaker::UnoType::Sort sort = manager->decompose(
696 0 : b2u(type), false, &nucleus, &rank, 0, 0);
697 :
698 0 : bool comment = true;
699 0 : if (!delegate.isEmpty()) {
700 0 : if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE &&
701 0 : sort != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE &&
702 : sort != codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE )
703 : {
704 0 : return;
705 : }
706 0 : comment = false;
707 : }
708 :
709 0 : if (comment) {
710 0 : o << "\n// UNO";
711 0 : if (rank != 0) {
712 0 : o << " sequence type";
713 0 : } else if (sort <= codemaker::UnoType::SORT_ANY) {
714 0 : o << " simple type";
715 : } else {
716 0 : switch (sort) {
717 : case codemaker::UnoType::SORT_INTERFACE_TYPE:
718 0 : o << " interface type";
719 0 : break;
720 :
721 : case codemaker::UnoType::SORT_MODULE:
722 0 : o << "IDL module";
723 0 : break;
724 :
725 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
726 0 : o << " simple struct type";
727 0 : break;
728 :
729 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
730 0 : o << " polymorphic struct type template";
731 0 : break;
732 :
733 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
734 0 : o << " instantiated polymorphic struct type";
735 0 : break;
736 :
737 : case codemaker::UnoType::SORT_ENUM_TYPE:
738 0 : o << " enum type";
739 0 : break;
740 :
741 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
742 0 : o << " exception type";
743 0 : break;
744 :
745 : case codemaker::UnoType::SORT_TYPEDEF:
746 0 : o << "IDL typedef";
747 0 : break;
748 :
749 : case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
750 0 : o << " single-inheritance--based service";
751 0 : break;
752 :
753 : case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
754 0 : o << "IDL accumulation-based service";
755 0 : break;
756 :
757 : case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
758 0 : o << " inheritance-based singleton";
759 0 : break;
760 :
761 : case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
762 0 : o << "IDL service-based singleton";
763 0 : break;
764 :
765 : case codemaker::UnoType::SORT_CONSTANT_GROUP:
766 0 : o << "IDL constant group";
767 0 : break;
768 :
769 : default:
770 : OSL_ASSERT(false);
771 0 : break;
772 : }
773 : }
774 0 : o << " \"" << type << "\" ";
775 : }
776 0 : std::vector< OUString > arguments;
777 0 : rtl::Reference< unoidl::Entity > entity;
778 : sort = manager->decompose(
779 0 : b2u(type), true, &nucleus, &rank, &arguments, &entity);
780 0 : if (rank != 0) {
781 : printMapsToJavaType(
782 0 : o, options, manager, sort, nucleus, rank, arguments, "array");
783 0 : o << '\n';
784 0 : } else if (sort <= codemaker::UnoType::SORT_ANY) {
785 : printMapsToJavaType(
786 0 : o, options, manager, sort, nucleus, rank, arguments, 0);
787 0 : o << '\n';
788 : } else {
789 0 : switch (sort) {
790 : case codemaker::UnoType::SORT_INTERFACE_TYPE:
791 : printMapsToJavaType(
792 : o, options, manager, sort, nucleus, rank, arguments,
793 0 : "interface");
794 0 : if (nucleus == "com.sun.star.uno.XInterface") {
795 0 : o << '\n';
796 : } else {
797 0 : o << "; " << (options.all ? "all" : "direct") << " methods:\n";
798 0 : codemaker::GeneratedTypeSet generated;
799 : printMethods(
800 0 : o, options, manager, nucleus, generated, delegate, "");
801 : }
802 0 : break;
803 :
804 : case codemaker::UnoType::SORT_MODULE:
805 : printMapsToJavaType(
806 0 : o, options, manager, sort, nucleus, rank, arguments, "package");
807 0 : o << '\n';
808 0 : break;
809 :
810 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
811 : printMapsToJavaType(
812 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
813 0 : o << "; full constructor:\n";
814 : printConstructor(
815 : o, options, manager, codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE,
816 0 : entity, nucleus, arguments);
817 0 : break;
818 :
819 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
820 : printMapsToJavaType(
821 : o, options, manager, sort, nucleus, rank, arguments,
822 0 : options.java5 ? "generic class" : "class");
823 0 : o << "; full constructor:\n";
824 : printConstructor(
825 : o, options, manager,
826 : codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE,
827 0 : entity, nucleus, arguments);
828 0 : break;
829 :
830 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
831 : printMapsToJavaType(
832 : o, options, manager, sort, nucleus, rank, arguments,
833 0 : options.java5 ? "generic class instantiation" : "class");
834 0 : o << "; full constructor:\n";
835 : printConstructor(
836 : o, options, manager,
837 : codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE,
838 0 : entity, nucleus, arguments);
839 0 : break;
840 :
841 : case codemaker::UnoType::SORT_ENUM_TYPE:
842 : case codemaker::UnoType::SORT_CONSTANT_GROUP:
843 : printMapsToJavaType(
844 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
845 0 : o << '\n';
846 0 : break;
847 :
848 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
849 : printMapsToJavaType(
850 : o, options, manager, sort, nucleus, rank, arguments,
851 0 : "exception class");
852 0 : o << "; full constructor:\n";
853 : printConstructor(
854 : o, options, manager, codemaker::UnoType::SORT_EXCEPTION_TYPE,
855 0 : entity, nucleus, arguments);
856 0 : break;
857 :
858 : case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
859 : printMapsToJavaType(
860 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
861 0 : o << "; construction methods:\n";
862 0 : printConstructors(o, options, manager, nucleus);
863 : generateDocumentation(
864 : o, options, manager,
865 : u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
866 0 : entity.get())->getBase()),
867 0 : delegate);
868 0 : break;
869 :
870 : case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
871 : o << ("does not map to Java\n"
872 0 : "// the service members are generated instead\n");
873 : printServiceMembers(
874 : o, options, manager, nucleus,
875 : dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
876 0 : entity.get()),
877 0 : delegate);
878 0 : break;
879 :
880 : case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
881 : printMapsToJavaType(
882 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
883 0 : o << "; get method:\npublic static ";
884 : printType(
885 : o, options, manager,
886 : dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
887 0 : entity.get())->getBase(),
888 0 : false);
889 0 : o << " get(com.sun.star.uno.XComponentContext context);\n";
890 0 : break;
891 :
892 : case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
893 0 : o << "does not map to Java\n";
894 0 : break;
895 :
896 : default:
897 : OSL_ASSERT(false);
898 0 : break;
899 : }
900 0 : }
901 : }
902 :
903 : } }
904 :
905 :
906 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|