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()) {
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 0 : void printMethods(std::ostream & o,
414 : ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
415 : OUString const & name,
416 : codemaker::GeneratedTypeSet & generated,
417 : OString const & delegate, OString const & indentation,
418 : bool defaultvalue, bool usepropertymixin)
419 : {
420 0 : if ( generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
421 0 : ( defaultvalue &&
422 0 : ( name == "com.sun.star.lang.XComponent" ||
423 0 : name == "com.sun.star.lang.XTypeProvider" ||
424 0 : name == "com.sun.star.uno.XWeak" ) ) ) {
425 0 : return;
426 : }
427 :
428 0 : if ( usepropertymixin ) {
429 0 : if (name == "com.sun.star.beans.XPropertySet") {
430 0 : generated.add(u2b(name));
431 0 : generateXPropertySetBodies(o);
432 0 : return;
433 0 : } else if (name == "com.sun.star.beans.XFastPropertySet") {
434 0 : generated.add(u2b(name));
435 0 : generateXFastPropertySetBodies(o);
436 0 : return;
437 0 : } else if (name == "com.sun.star.beans.XPropertyAccess") {
438 0 : generated.add(u2b(name));
439 0 : generateXPropertyAccessBodies(o);
440 0 : return;
441 : }
442 : }
443 :
444 0 : static OString sd("_");
445 0 : bool body = !delegate.isEmpty();
446 0 : bool defaultbody = ((delegate.equals(sd)) ? true : false);
447 :
448 0 : generated.add(u2b(name));
449 0 : rtl::Reference< unoidl::Entity > ent;
450 0 : if (manager->getSort(name, &ent) != codemaker::UnoType::SORT_INTERFACE_TYPE)
451 : {
452 : throw CannotDumpException(
453 0 : "unexpected entity \"" + name
454 0 : + "\" in call to skeletonmaker::java::printMethods");
455 : }
456 : rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
457 0 : dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
458 : assert(ent2.is());
459 0 : if ( options.all || defaultvalue ) {
460 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
461 0 : ent2->getDirectMandatoryBases().begin());
462 0 : i != ent2->getDirectMandatoryBases().end(); ++i)
463 : {
464 : printMethods(
465 0 : o, options, manager, i->name, generated, delegate, indentation,
466 0 : defaultvalue, usepropertymixin);
467 : }
468 0 : if (!(ent2->getDirectAttributes().empty()
469 0 : && ent2->getDirectMethods().empty()))
470 : {
471 0 : o << indentation << "// ";
472 0 : printType(o, options, manager, name, false);
473 0 : o << ":\n";
474 : }
475 : }
476 0 : for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
477 0 : i(ent2->getDirectAttributes().begin());
478 0 : i != ent2->getDirectAttributes().end(); ++i)
479 : {
480 0 : o << indentation << "public ";
481 0 : printType(o, options, manager, i->type, false);
482 0 : o << " get" << i->name << "()";
483 0 : printExceptionSpecification(o, options, manager, i->getExceptions);
484 0 : if ( body ) {
485 0 : if ( defaultbody ) {
486 0 : if ( usepropertymixin ) {
487 0 : o << "\n" << indentation << "{\n" << indentation
488 0 : << " return m_" << i->name << ";\n" << indentation
489 0 : << "}\n\n";
490 : } else {
491 0 : o << "\n" << indentation << "{\n" << indentation
492 0 : << " return ";
493 0 : printType(o, options, manager, i->type, false, true);
494 0 : o << ";\n" << indentation << "}\n\n";
495 : }
496 : } else {
497 0 : o << "\n" << indentation << "{\n" << indentation
498 0 : << " return " << delegate.getStr() << "get" << i->name
499 0 : << "();\n" << indentation << "}\n\n";
500 : }
501 : } else {
502 0 : o << ";\n";
503 : }
504 :
505 : // REMOVE next line
506 0 : if (!i->readOnly) {
507 0 : o << indentation << "public void set" << i->name << '(';
508 0 : printType(o, options, manager, i->type, false);
509 0 : o << " the_value)";
510 0 : printExceptionSpecification(o, options, manager, i->setExceptions);
511 0 : if ( body ) {
512 0 : if ( defaultbody ) {
513 0 : if ( usepropertymixin ) {
514 0 : printSetPropertyMixinBody(o, *i, indentation);
515 : } else {
516 0 : o << "\n" << indentation << "{\n\n" << indentation
517 0 : << "}\n\n";
518 : }
519 : } else {
520 0 : o << "\n" << indentation << "{\n" << indentation
521 0 : << " " << delegate.getStr() << "set" << i->name
522 0 : << "(the_value);\n" << indentation << "}\n\n";
523 : }
524 : } else {
525 0 : o << ";\n";
526 : }
527 : }
528 : }
529 0 : for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
530 0 : ent2->getDirectMethods().begin());
531 0 : i != ent2->getDirectMethods().end(); ++i)
532 : {
533 0 : o << indentation << "public ";
534 0 : printType(o, options, manager, i->returnType, false);
535 0 : o << ' ' << i->name << '(';
536 0 : printMethodParameters(o, options, manager, i->parameters, true);
537 0 : o << ')';
538 0 : printExceptionSpecification(o, options, manager, i->exceptions);
539 0 : if ( body ) {
540 0 : if ( defaultbody ) {
541 0 : o << "\n" << indentation << "{\n";
542 0 : if (i->returnType != "void") {
543 0 : o << indentation << " // TODO: Exchange the default return "
544 0 : << "implementation for \"" << i->name << "\" !!!\n";
545 0 : o << indentation << " // NOTE: "
546 : "Default initialized polymorphic structs can cause problems"
547 0 : "\n" << indentation << " // because of missing default "
548 0 : "initialization of primitive types of\n" << indentation
549 : << " // some C++ compilers or different Any initialization"
550 0 : " in Java and C++\n" << indentation
551 0 : << " // polymorphic structs.\n" << indentation
552 0 : << " return ";
553 0 : printType(o, options, manager, i->returnType, false, true);
554 0 : o << ";";
555 : } else {
556 0 : o << indentation << " // TODO: Insert your implementation for \""
557 0 : << i->name << "\" here.";
558 : }
559 0 : o << "\n" << indentation << "}\n\n";
560 : } else {
561 0 : o << "\n" << indentation << "{\n" << indentation << " ";
562 0 : if (i->returnType != "void") {
563 0 : o << "return ";
564 : }
565 0 : o << delegate.getStr() << i->name << '(';
566 : printMethodParameters(
567 0 : o, options, manager, i->parameters, false);
568 0 : o << ");\n" << indentation << "}\n\n";
569 : }
570 : } else {
571 0 : o << ";\n";
572 : }
573 0 : }
574 : }
575 :
576 0 : void printConstructors(
577 : std::ostream & o, ProgramOptions const & options,
578 : rtl::Reference< TypeManager > const & manager, OUString const & name)
579 : {
580 0 : rtl::Reference< unoidl::Entity > ent;
581 0 : if (manager->getSort(name, &ent)
582 : != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE)
583 : {
584 : throw CannotDumpException(
585 0 : "unexpected entity \"" + name
586 0 : + "\" in call to skeletonmaker::java::printConstructors");
587 : }
588 : rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
589 0 : dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
590 : assert(ent2.is());
591 0 : for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
592 0 : const_iterator i(ent2->getConstructors().begin());
593 0 : i != ent2->getConstructors().end(); ++i)
594 : {
595 0 : o << "public static ";
596 0 : printType(o, options, manager, ent2->getBase(), false);
597 0 : o << ' ';
598 0 : if (i->defaultConstructor) {
599 0 : o << "create";
600 : } else {
601 : o << codemaker::java::translateUnoToJavaIdentifier(
602 0 : u2b(i->name), "method");
603 : }
604 0 : o << "(com.sun.star.uno.XComponentContext the_context";
605 0 : for (std::vector<
606 : unoidl::SingleInterfaceBasedServiceEntity::Constructor::
607 0 : Parameter >::const_iterator j(i->parameters.begin());
608 0 : j != i->parameters.end(); ++i)
609 : {
610 0 : o << ", ";
611 0 : printType(o, options, manager, j->type, false);
612 0 : if (j->rest) {
613 0 : o << "...";
614 : }
615 0 : o << ' '
616 : << codemaker::java::translateUnoToJavaIdentifier(
617 0 : u2b(j->name), "param");
618 : }
619 0 : o << ')';
620 0 : printExceptionSpecification(o, options, manager, i->exceptions);
621 0 : o << ";\n";
622 0 : }
623 0 : }
624 :
625 0 : void printServiceMembers(
626 : std::ostream & o, ProgramOptions const & options,
627 : rtl::Reference< TypeManager > const & manager,
628 : OUString const & name,
629 : rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
630 : OString const & delegate)
631 : {
632 : assert(entity.is());
633 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
634 0 : entity->getDirectMandatoryBaseServices().begin());
635 0 : i != entity->getDirectMandatoryBaseServices().end(); ++i)
636 : {
637 0 : o << "\n// exported service " << i->name << "\n";
638 0 : generateDocumentation(o, options, manager, u2b(i->name), delegate);
639 : }
640 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
641 0 : entity->getDirectMandatoryBaseInterfaces().begin());
642 0 : i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
643 : {
644 0 : o << "\n// supported interface " << i->name << "\n";
645 0 : generateDocumentation(o, options, manager, u2b(i->name), delegate);
646 : }
647 0 : o << "\n// properties of service \""<< name << "\"\n";
648 0 : for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
649 0 : const_iterator i(entity->getDirectProperties().begin());
650 0 : i != entity->getDirectProperties().end(); ++i)
651 : {
652 0 : o << "// private ";
653 0 : printType(o, options, manager, i->type, false);
654 0 : o << " "
655 : << codemaker::java::translateUnoToJavaIdentifier(
656 0 : u2b(i->name), "property")
657 0 : << ";\n";
658 : }
659 0 : }
660 :
661 0 : void printMapsToJavaType(
662 : std::ostream & o, ProgramOptions const & options,
663 : rtl::Reference< TypeManager > const & manager,
664 : codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
665 : std::vector< OUString > const & arguments, const char * javaTypeSort)
666 : {
667 0 : o << "maps to Java " << "1.5" << " ";
668 0 : if (javaTypeSort != 0) {
669 0 : o << javaTypeSort << ' ';
670 : }
671 0 : o << "type \"";
672 0 : if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
673 0 : o << "com.sun.star.uno.XInterface";
674 : } else {
675 : printType(
676 0 : o, options, manager, sort, nucleus, rank, arguments, false, false);
677 : }
678 0 : o << '"';
679 0 : }
680 :
681 0 : void generateDocumentation(std::ostream & o,
682 : ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
683 : OString const & type, OString const & delegate)
684 : {
685 0 : OUString nucleus;
686 : sal_Int32 rank;
687 : codemaker::UnoType::Sort sort = manager->decompose(
688 0 : b2u(type), false, &nucleus, &rank, 0, 0);
689 :
690 0 : bool comment = true;
691 0 : if (!delegate.isEmpty()) {
692 0 : if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE &&
693 0 : sort != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE &&
694 : sort != codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE )
695 : {
696 0 : return;
697 : }
698 0 : comment = false;
699 : }
700 :
701 0 : if (comment) {
702 0 : o << "\n// UNO";
703 0 : if (rank != 0) {
704 0 : o << " sequence type";
705 0 : } else if (sort <= codemaker::UnoType::SORT_ANY) {
706 0 : o << " simple type";
707 : } else {
708 0 : switch (sort) {
709 : case codemaker::UnoType::SORT_INTERFACE_TYPE:
710 0 : o << " interface type";
711 0 : break;
712 :
713 : case codemaker::UnoType::SORT_MODULE:
714 0 : o << "IDL module";
715 0 : break;
716 :
717 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
718 0 : o << " simple struct type";
719 0 : break;
720 :
721 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
722 0 : o << " polymorphic struct type template";
723 0 : break;
724 :
725 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
726 0 : o << " instantiated polymorphic struct type";
727 0 : break;
728 :
729 : case codemaker::UnoType::SORT_ENUM_TYPE:
730 0 : o << " enum type";
731 0 : break;
732 :
733 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
734 0 : o << " exception type";
735 0 : break;
736 :
737 : case codemaker::UnoType::SORT_TYPEDEF:
738 0 : o << "IDL typedef";
739 0 : break;
740 :
741 : case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
742 0 : o << " single-inheritance--based service";
743 0 : break;
744 :
745 : case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
746 0 : o << "IDL accumulation-based service";
747 0 : break;
748 :
749 : case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
750 0 : o << " inheritance-based singleton";
751 0 : break;
752 :
753 : case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
754 0 : o << "IDL service-based singleton";
755 0 : break;
756 :
757 : case codemaker::UnoType::SORT_CONSTANT_GROUP:
758 0 : o << "IDL constant group";
759 0 : break;
760 :
761 : default:
762 : OSL_ASSERT(false);
763 0 : break;
764 : }
765 : }
766 0 : o << " \"" << type << "\" ";
767 : }
768 0 : std::vector< OUString > arguments;
769 0 : rtl::Reference< unoidl::Entity > entity;
770 : sort = manager->decompose(
771 0 : b2u(type), true, &nucleus, &rank, &arguments, &entity);
772 0 : if (rank != 0) {
773 : printMapsToJavaType(
774 0 : o, options, manager, sort, nucleus, rank, arguments, "array");
775 0 : o << '\n';
776 0 : } else if (sort <= codemaker::UnoType::SORT_ANY) {
777 : printMapsToJavaType(
778 0 : o, options, manager, sort, nucleus, rank, arguments, 0);
779 0 : o << '\n';
780 : } else {
781 0 : switch (sort) {
782 : case codemaker::UnoType::SORT_INTERFACE_TYPE:
783 : printMapsToJavaType(
784 : o, options, manager, sort, nucleus, rank, arguments,
785 0 : "interface");
786 0 : if (nucleus == "com.sun.star.uno.XInterface") {
787 0 : o << '\n';
788 : } else {
789 0 : o << "; " << (options.all ? "all" : "direct") << " methods:\n";
790 0 : codemaker::GeneratedTypeSet generated;
791 : printMethods(
792 0 : o, options, manager, nucleus, generated, delegate, "");
793 : }
794 0 : break;
795 :
796 : case codemaker::UnoType::SORT_MODULE:
797 : printMapsToJavaType(
798 0 : o, options, manager, sort, nucleus, rank, arguments, "package");
799 0 : o << '\n';
800 0 : break;
801 :
802 : case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
803 : printMapsToJavaType(
804 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
805 0 : o << "; full constructor:\n";
806 : printConstructor(
807 : o, options, manager, codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE,
808 0 : entity, nucleus, arguments);
809 0 : break;
810 :
811 : case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
812 : printMapsToJavaType(
813 : o, options, manager, sort, nucleus, rank, arguments,
814 0 : "generic class");
815 0 : o << "; full constructor:\n";
816 : printConstructor(
817 : o, options, manager,
818 : codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE,
819 0 : entity, nucleus, arguments);
820 0 : break;
821 :
822 : case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
823 : printMapsToJavaType(
824 : o, options, manager, sort, nucleus, rank, arguments,
825 0 : "generic class instantiation");
826 0 : o << "; full constructor:\n";
827 : printConstructor(
828 : o, options, manager,
829 : codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE,
830 0 : entity, nucleus, arguments);
831 0 : break;
832 :
833 : case codemaker::UnoType::SORT_ENUM_TYPE:
834 : case codemaker::UnoType::SORT_CONSTANT_GROUP:
835 : printMapsToJavaType(
836 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
837 0 : o << '\n';
838 0 : break;
839 :
840 : case codemaker::UnoType::SORT_EXCEPTION_TYPE:
841 : printMapsToJavaType(
842 : o, options, manager, sort, nucleus, rank, arguments,
843 0 : "exception class");
844 0 : o << "; full constructor:\n";
845 : printConstructor(
846 : o, options, manager, codemaker::UnoType::SORT_EXCEPTION_TYPE,
847 0 : entity, nucleus, arguments);
848 0 : break;
849 :
850 : case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
851 : printMapsToJavaType(
852 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
853 0 : o << "; construction methods:\n";
854 0 : printConstructors(o, options, manager, nucleus);
855 : generateDocumentation(
856 : o, options, manager,
857 : u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
858 0 : entity.get())->getBase()),
859 0 : delegate);
860 0 : break;
861 :
862 : case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
863 : o << ("does not map to Java\n"
864 0 : "// the service members are generated instead\n");
865 : printServiceMembers(
866 : o, options, manager, nucleus,
867 : dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
868 0 : entity.get()),
869 0 : delegate);
870 0 : break;
871 :
872 : case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
873 : printMapsToJavaType(
874 0 : o, options, manager, sort, nucleus, rank, arguments, "class");
875 0 : o << "; get method:\npublic static ";
876 : printType(
877 : o, options, manager,
878 : dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
879 0 : entity.get())->getBase(),
880 0 : false);
881 0 : o << " get(com.sun.star.uno.XComponentContext context);\n";
882 0 : break;
883 :
884 : case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
885 0 : o << "does not map to Java\n";
886 0 : break;
887 :
888 : default:
889 : OSL_ASSERT(false);
890 0 : break;
891 : }
892 0 : }
893 : }
894 :
895 : } }
896 :
897 :
898 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|