Bump version to 24.04.3.4
[LibreOffice.git] / cppuhelper / source / typemanager.cxx
blob29f7025cdf6a08c123e7cb1a4afa8ae8f927349f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/config.h>
12 #include <cassert>
13 #include <cstddef>
14 #include <cstdlib>
15 #include <cstring>
16 #include <mutex>
17 #include <set>
18 #include <stack>
19 #include <string_view>
20 #include <utility>
21 #include <vector>
22 #include <algorithm>
24 #include <com/sun/star/container/NoSuchElementException.hpp>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <com/sun/star/reflection/NoSuchTypeNameException.hpp>
27 #include <com/sun/star/reflection/TypeDescriptionSearchDepth.hpp>
28 #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
29 #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
30 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
31 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
32 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
33 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
34 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
35 #include <com/sun/star/reflection/XModuleTypeDescription.hpp>
36 #include <com/sun/star/reflection/XPublished.hpp>
37 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
38 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
39 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
40 #include <com/sun/star/reflection/XTypeDescription.hpp>
41 #include <com/sun/star/uno/Any.hxx>
42 #include <com/sun/star/uno/DeploymentException.hpp>
43 #include <com/sun/star/uno/Reference.hxx>
44 #include <com/sun/star/uno/RuntimeException.hpp>
45 #include <com/sun/star/uno/Sequence.hxx>
46 #include <com/sun/star/uno/Type.hxx>
47 #include <com/sun/star/uno/TypeClass.hpp>
48 #include <cppu/unotype.hxx>
49 #include <cppuhelper/implbase.hxx>
50 #include <cppuhelper/supportsservice.hxx>
51 #include <osl/file.hxx>
52 #include <rtl/ref.hxx>
53 #include <rtl/ustring.hxx>
54 #include <sal/log.hxx>
55 #include <sal/macros.h>
56 #include <sal/types.h>
57 #include <o3tl/string_view.hxx>
59 #include <unoidl/unoidl.hxx>
61 #include "paths.hxx"
62 #include "typemanager.hxx"
64 namespace {
66 OUString makePrefix(OUString const & name) {
67 return name.isEmpty() ? name : name + ".";
70 css::uno::Any resolveTypedefs(css::uno::Any const & type) {
71 for (css::uno::Any t(type);;) {
72 css::uno::Reference< css::reflection::XIndirectTypeDescription > ind(
73 type, css::uno::UNO_QUERY);
74 if (!ind.is() || ind->getTypeClass() != css::uno::TypeClass_TYPEDEF) {
75 return t;
77 t <<= ind->getReferencedType();
81 class SimpleTypeDescription:
82 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
84 public:
85 SimpleTypeDescription(
86 css::uno::TypeClass typeClass, OUString name):
87 typeClass_(typeClass), name_(std::move(name))
90 private:
91 virtual ~SimpleTypeDescription() override {}
93 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
94 { return typeClass_; }
96 virtual OUString SAL_CALL getName() override
97 { return name_; }
99 css::uno::TypeClass typeClass_;
100 OUString name_;
103 class SequenceTypeDescription:
104 public cppu::WeakImplHelper< css::reflection::XIndirectTypeDescription >
106 public:
107 SequenceTypeDescription(
108 rtl::Reference< cppuhelper::TypeManager > const & manager,
109 OUString name, OUString componentType):
110 manager_(manager), name_(std::move(name)), componentType_(std::move(componentType))
111 { assert(manager.is()); }
113 private:
114 virtual ~SequenceTypeDescription() override {}
116 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
117 { return css::uno::TypeClass_SEQUENCE; }
119 virtual OUString SAL_CALL getName() override
120 { return name_; }
122 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
123 getReferencedType() override
124 { return manager_->resolve(componentType_); }
126 rtl::Reference< cppuhelper::TypeManager > manager_;
127 OUString name_;
128 OUString componentType_;
131 class PublishableDescription:
132 public cppu::WeakImplHelper< css::reflection::XPublished >
134 protected:
135 explicit PublishableDescription(bool published): published_(published) {}
137 virtual ~PublishableDescription() override {}
139 private:
140 virtual sal_Bool SAL_CALL isPublished() override
141 { return published_; }
143 bool published_;
146 class ModuleDescription:
147 public cppu::WeakImplHelper< css::reflection::XModuleTypeDescription >
149 public:
150 ModuleDescription(
151 rtl::Reference< cppuhelper::TypeManager > const & manager,
152 OUString name,
153 rtl::Reference< unoidl::ModuleEntity > const & entity):
154 manager_(manager), name_(std::move(name)), entity_(entity)
155 { assert(manager.is()); assert(entity.is()); }
157 private:
158 virtual ~ModuleDescription() override {}
160 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
161 { return css::uno::TypeClass_MODULE; }
163 virtual OUString SAL_CALL getName() override
164 { return name_; }
166 virtual
167 css::uno::Sequence<
168 css::uno::Reference< css::reflection::XTypeDescription > >
169 SAL_CALL getMembers() override;
171 rtl::Reference< cppuhelper::TypeManager > manager_;
172 OUString name_;
173 rtl::Reference< unoidl::ModuleEntity > entity_;
176 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
177 ModuleDescription::getMembers() {
178 try {
179 std::vector< OUString > names(entity_->getMemberNames());
180 assert(names.size() <= SAL_MAX_INT32);
181 sal_Int32 n = static_cast< sal_Int32 >(names.size());
182 css::uno::Sequence<
183 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
184 auto r = asNonConstRange(s);
185 for (sal_Int32 i = 0; i != n; ++i) {
186 r[i] = manager_->resolve(makePrefix(name_) + names[i]);
188 return s;
189 } catch (unoidl::FileFormatException & e) {
190 throw css::uno::DeploymentException(
191 e.getUri() + ": " + e.getDetail(),
192 static_cast< cppu::OWeakObject * >(this));
196 typedef cppu::ImplInheritanceHelper<
197 PublishableDescription, css::reflection::XEnumTypeDescription >
198 EnumTypeDescription_Base;
200 class EnumTypeDescription: public EnumTypeDescription_Base {
201 public:
202 EnumTypeDescription(
203 OUString name,
204 rtl::Reference< unoidl::EnumTypeEntity > const & entity):
205 EnumTypeDescription_Base(entity->isPublished()), name_(std::move(name)),
206 entity_(entity)
207 { assert(entity.is()); }
209 private:
210 virtual ~EnumTypeDescription() override {}
212 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
213 { return css::uno::TypeClass_ENUM; }
215 virtual OUString SAL_CALL getName() override
216 { return name_; }
218 virtual sal_Int32 SAL_CALL getDefaultEnumValue() override
219 { return entity_->getMembers()[0].value; }
221 virtual css::uno::Sequence< OUString > SAL_CALL getEnumNames() override;
223 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getEnumValues() override;
225 OUString name_;
226 rtl::Reference< unoidl::EnumTypeEntity > entity_;
229 css::uno::Sequence< OUString > EnumTypeDescription::getEnumNames()
231 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
232 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
233 css::uno::Sequence< OUString > s(n);
234 auto r = asNonConstRange(s);
235 for (sal_Int32 i = 0; i != n; ++i) {
236 r[i] = entity_->getMembers()[i].name;
238 return s;
241 css::uno::Sequence< sal_Int32 > EnumTypeDescription::getEnumValues()
243 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
244 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
245 css::uno::Sequence< sal_Int32 > s(n);
246 auto r = asNonConstRange(s);
247 for (sal_Int32 i = 0; i != n; ++i) {
248 r[i] = entity_->getMembers()[i].value;
250 return s;
253 typedef cppu::ImplInheritanceHelper<
254 PublishableDescription, css::reflection::XStructTypeDescription >
255 PlainStructTypeDescription_Base;
257 class PlainStructTypeDescription: public PlainStructTypeDescription_Base {
258 public:
259 PlainStructTypeDescription(
260 rtl::Reference< cppuhelper::TypeManager > const & manager,
261 OUString name,
262 rtl::Reference< unoidl::PlainStructTypeEntity > const & entity):
263 PlainStructTypeDescription_Base(entity->isPublished()),
264 manager_(manager), name_(std::move(name)), entity_(entity)
265 { assert(manager.is()); assert(entity.is()); }
267 private:
268 virtual ~PlainStructTypeDescription() override {}
270 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
271 { return css::uno::TypeClass_STRUCT; }
273 virtual OUString SAL_CALL getName() override
274 { return name_; }
276 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
277 getBaseType() override {
278 return entity_->getDirectBase().isEmpty()
279 ? css::uno::Reference< css::reflection::XTypeDescription >()
280 : manager_->resolve(entity_->getDirectBase());
283 virtual
284 css::uno::Sequence<
285 css::uno::Reference< css::reflection::XTypeDescription > >
286 SAL_CALL getMemberTypes() override;
288 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
290 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
291 { return css::uno::Sequence< OUString >(); }
293 virtual
294 css::uno::Sequence<
295 css::uno::Reference< css::reflection::XTypeDescription > >
296 SAL_CALL getTypeArguments() override {
297 return css::uno::Sequence<
298 css::uno::Reference< css::reflection::XTypeDescription > >();
301 rtl::Reference< cppuhelper::TypeManager > manager_;
302 OUString name_;
303 rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
306 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
307 PlainStructTypeDescription::getMemberTypes()
309 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
310 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
311 css::uno::Sequence<
312 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
313 auto r = asNonConstRange(s);
314 for (sal_Int32 i = 0; i != n; ++i) {
315 r[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
317 return s;
320 css::uno::Sequence< OUString > PlainStructTypeDescription::getMemberNames()
322 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
323 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
324 css::uno::Sequence< OUString > s(n);
325 auto r = asNonConstRange(s);
326 for (sal_Int32 i = 0; i != n; ++i) {
327 r[i] = entity_->getDirectMembers()[i].name;
329 return s;
332 class ParameterizedMemberTypeDescription:
333 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
335 public:
336 explicit ParameterizedMemberTypeDescription(
337 OUString typeParameterName):
338 typeParameterName_(std::move(typeParameterName))
341 private:
342 virtual ~ParameterizedMemberTypeDescription() override {}
344 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
345 { return css::uno::TypeClass_UNKNOWN; }
347 virtual OUString SAL_CALL getName() override
348 { return typeParameterName_; }
350 OUString typeParameterName_;
353 typedef cppu::ImplInheritanceHelper<
354 PublishableDescription, css::reflection::XStructTypeDescription >
355 PolymorphicStructTypeTemplateDescription_Base;
357 class PolymorphicStructTypeTemplateDescription:
358 public PolymorphicStructTypeTemplateDescription_Base
360 public:
361 PolymorphicStructTypeTemplateDescription(
362 rtl::Reference< cppuhelper::TypeManager > const & manager,
363 OUString name,
364 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
365 entity):
366 PolymorphicStructTypeTemplateDescription_Base(entity->isPublished()),
367 manager_(manager), name_(std::move(name)), entity_(entity)
368 { assert(manager.is()); assert(entity.is()); }
370 private:
371 virtual ~PolymorphicStructTypeTemplateDescription() override {}
373 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
374 { return css::uno::TypeClass_STRUCT; }
376 virtual OUString SAL_CALL getName() override
377 { return name_; }
379 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
380 getBaseType() override
381 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
383 virtual
384 css::uno::Sequence<
385 css::uno::Reference< css::reflection::XTypeDescription > >
386 SAL_CALL getMemberTypes() override;
388 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
390 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override;
392 virtual
393 css::uno::Sequence<
394 css::uno::Reference< css::reflection::XTypeDescription > >
395 SAL_CALL getTypeArguments() override {
396 return css::uno::Sequence<
397 css::uno::Reference< css::reflection::XTypeDescription > >();
400 rtl::Reference< cppuhelper::TypeManager > manager_;
401 OUString name_;
402 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
405 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
406 PolymorphicStructTypeTemplateDescription::getMemberTypes()
408 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
409 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
410 css::uno::Sequence<
411 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
412 auto r = asNonConstRange(s);
413 for (sal_Int32 i = 0; i != n; ++i) {
414 r[i] = entity_->getMembers()[i].parameterized
415 ? new ParameterizedMemberTypeDescription(
416 entity_->getMembers()[i].type)
417 : manager_->resolve(entity_->getMembers()[i].type);
419 return s;
422 css::uno::Sequence< OUString >
423 PolymorphicStructTypeTemplateDescription::getMemberNames()
425 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
426 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
427 css::uno::Sequence< OUString > s(n);
428 auto r = asNonConstRange(s);
429 for (sal_Int32 i = 0; i != n; ++i) {
430 r[i] = entity_->getMembers()[i].name;
432 return s;
435 css::uno::Sequence< OUString >
436 PolymorphicStructTypeTemplateDescription::getTypeParameters()
438 assert(entity_->getTypeParameters().size() <= SAL_MAX_INT32);
439 sal_Int32 n = static_cast< sal_Int32 >(entity_->getTypeParameters().size());
440 css::uno::Sequence< OUString > s(n);
441 auto r = asNonConstRange(s);
442 for (sal_Int32 i = 0; i != n; ++i) {
443 r[i] = entity_->getTypeParameters()[i];
445 return s;
448 class InstantiatedPolymorphicStructTypeDescription:
449 public cppu::WeakImplHelper< css::reflection::XStructTypeDescription >
451 public:
452 InstantiatedPolymorphicStructTypeDescription(
453 rtl::Reference< cppuhelper::TypeManager > const & manager,
454 OUString name,
455 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
456 entity,
457 std::vector< OUString >&& arguments):
458 manager_(manager), name_(std::move(name)), entity_(entity), arguments_(std::move(arguments))
460 assert(manager.is());
461 assert(entity.is());
462 assert(arguments_.size() == entity->getTypeParameters().size());
465 private:
466 virtual ~InstantiatedPolymorphicStructTypeDescription() override {}
468 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
469 { return css::uno::TypeClass_STRUCT; }
471 virtual OUString SAL_CALL getName() override
472 { return name_; }
474 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
475 getBaseType() override
476 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
478 virtual
479 css::uno::Sequence<
480 css::uno::Reference< css::reflection::XTypeDescription > >
481 SAL_CALL getMemberTypes() override;
483 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
485 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
486 { return css::uno::Sequence< OUString >(); }
488 virtual
489 css::uno::Sequence<
490 css::uno::Reference< css::reflection::XTypeDescription > >
491 SAL_CALL getTypeArguments() override;
493 rtl::Reference< cppuhelper::TypeManager > manager_;
494 OUString name_;
495 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
496 std::vector< OUString > arguments_;
499 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
500 InstantiatedPolymorphicStructTypeDescription::getMemberTypes()
502 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
503 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
504 css::uno::Sequence<
505 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
506 auto r = asNonConstRange(s);
507 for (sal_Int32 i = 0; i != n; ++i) {
508 OUString type(entity_->getMembers()[i].type);
509 if (entity_->getMembers()[i].parameterized) {
510 auto j = std::find(entity_->getTypeParameters().begin(), entity_->getTypeParameters().end(), type);
511 if (j != entity_->getTypeParameters().end()) {
512 type = arguments_[j - entity_->getTypeParameters().begin()];
513 goto found;
515 assert(false); // this cannot happen //TODO!
516 found:;
518 r[i] = manager_->resolve(type);
520 return s;
523 css::uno::Sequence< OUString >
524 InstantiatedPolymorphicStructTypeDescription::getMemberNames()
526 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
527 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
528 css::uno::Sequence< OUString > s(n);
529 auto r = asNonConstRange(s);
530 for (sal_Int32 i = 0; i != n; ++i) {
531 r[i] = entity_->getMembers()[i].name;
533 return s;
535 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
536 InstantiatedPolymorphicStructTypeDescription::getTypeArguments()
538 assert(arguments_.size() <= SAL_MAX_INT32);
539 sal_Int32 n = static_cast< sal_Int32 >(arguments_.size());
540 css::uno::Sequence<
541 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
542 auto r = asNonConstRange(s);
543 for (sal_Int32 i = 0; i != n; ++i) {
544 r[i] = manager_->resolve(arguments_[i]);
546 return s;
549 typedef cppu::ImplInheritanceHelper<
550 PublishableDescription, css::reflection::XCompoundTypeDescription >
551 ExceptionTypeDescription_Base;
553 class ExceptionTypeDescription: public ExceptionTypeDescription_Base {
554 public:
555 ExceptionTypeDescription(
556 rtl::Reference< cppuhelper::TypeManager > const & manager,
557 OUString name,
558 rtl::Reference< unoidl::ExceptionTypeEntity > const & entity):
559 ExceptionTypeDescription_Base(entity->isPublished()), manager_(manager),
560 name_(std::move(name)), entity_(entity)
561 { assert(manager.is()); assert(entity.is()); }
563 private:
564 virtual ~ExceptionTypeDescription() override {}
566 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
567 { return css::uno::TypeClass_EXCEPTION; }
569 virtual OUString SAL_CALL getName() override
570 { return name_; }
572 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
573 getBaseType() override {
574 return entity_->getDirectBase().isEmpty()
575 ? css::uno::Reference< css::reflection::XTypeDescription >()
576 : manager_->resolve(entity_->getDirectBase());
579 virtual
580 css::uno::Sequence<
581 css::uno::Reference< css::reflection::XTypeDescription > >
582 SAL_CALL getMemberTypes() override;
584 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
586 rtl::Reference< cppuhelper::TypeManager > manager_;
587 OUString name_;
588 rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
591 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
592 ExceptionTypeDescription::getMemberTypes() {
593 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
594 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
595 css::uno::Sequence<
596 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
597 auto r = asNonConstRange(s);
598 for (sal_Int32 i = 0; i != n; ++i) {
599 r[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
601 return s;
604 css::uno::Sequence< OUString > ExceptionTypeDescription::getMemberNames()
606 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
607 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
608 css::uno::Sequence< OUString > s(n);
609 auto r = asNonConstRange(s);
610 for (sal_Int32 i = 0; i != n; ++i) {
611 r[i] = entity_->getDirectMembers()[i].name;
613 return s;
616 class AttributeDescription:
617 public cppu::WeakImplHelper<
618 css::reflection::XInterfaceAttributeTypeDescription2 >
620 public:
621 AttributeDescription(
622 rtl::Reference< cppuhelper::TypeManager > const & manager,
623 OUString name,
624 unoidl::InterfaceTypeEntity::Attribute attribute,
625 sal_Int32 position):
626 manager_(manager), name_(std::move(name)), attribute_(std::move(attribute)),
627 position_(position)
628 { assert(manager.is()); }
630 private:
631 virtual ~AttributeDescription() override {}
633 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
634 { return css::uno::TypeClass_INTERFACE_ATTRIBUTE; }
636 virtual OUString SAL_CALL getName() override
637 { return name_; }
639 virtual OUString SAL_CALL getMemberName() override
640 { return attribute_.name; }
642 virtual sal_Int32 SAL_CALL getPosition() override
643 { return position_; }
645 virtual sal_Bool SAL_CALL isReadOnly() override
646 { return attribute_.readOnly; }
648 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
649 getType() override
650 { return manager_->resolve(attribute_.type); }
652 virtual sal_Bool SAL_CALL isBound() override
653 { return attribute_.bound; }
655 virtual
656 css::uno::Sequence<
657 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
658 SAL_CALL getGetExceptions() override;
660 virtual
661 css::uno::Sequence<
662 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
663 SAL_CALL getSetExceptions() override;
665 rtl::Reference< cppuhelper::TypeManager > manager_;
666 OUString name_;
667 unoidl::InterfaceTypeEntity::Attribute attribute_;
668 sal_Int32 position_;
671 css::uno::Sequence<
672 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
673 AttributeDescription::getGetExceptions() {
674 assert(attribute_.getExceptions.size() <= SAL_MAX_INT32);
675 sal_Int32 n = static_cast< sal_Int32 >(attribute_.getExceptions.size());
676 css::uno::Sequence<
677 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
678 auto r = asNonConstRange(s);
679 for (sal_Int32 i = 0; i != n; ++i) {
680 r[i].set(
681 manager_->resolve(attribute_.getExceptions[i]),
682 css::uno::UNO_QUERY_THROW);
684 return s;
687 css::uno::Sequence<
688 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
689 AttributeDescription::getSetExceptions() {
690 assert(attribute_.setExceptions.size() <= SAL_MAX_INT32);
691 sal_Int32 n = static_cast< sal_Int32 >(attribute_.setExceptions.size());
692 css::uno::Sequence<
693 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
694 auto r = asNonConstRange(s);
695 for (sal_Int32 i = 0; i != n; ++i) {
696 r[i].set(
697 manager_->resolve(attribute_.setExceptions[i]),
698 css::uno::UNO_QUERY_THROW);
700 return s;
703 class MethodParameter:
704 public cppu::WeakImplHelper< css::reflection::XMethodParameter >
706 public:
707 MethodParameter(
708 rtl::Reference< cppuhelper::TypeManager > const & manager,
709 unoidl::InterfaceTypeEntity::Method::Parameter parameter,
710 sal_Int32 position):
711 manager_(manager), parameter_(std::move(parameter)), position_(position)
712 { assert(manager.is()); }
714 private:
715 virtual ~MethodParameter() override {}
717 virtual OUString SAL_CALL getName() override
718 { return parameter_.name; }
720 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
721 getType() override
722 { return manager_->resolve(parameter_.type); }
724 virtual sal_Bool SAL_CALL isIn() override {
725 return
726 (parameter_.direction
727 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
728 || (parameter_.direction
729 == unoidl::InterfaceTypeEntity::Method::Parameter::
730 DIRECTION_IN_OUT);
733 virtual sal_Bool SAL_CALL isOut() override {
734 return
735 (parameter_.direction
736 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT)
737 || (parameter_.direction
738 == unoidl::InterfaceTypeEntity::Method::Parameter::
739 DIRECTION_IN_OUT);
742 virtual sal_Int32 SAL_CALL getPosition() override
743 { return position_; }
745 rtl::Reference< cppuhelper::TypeManager > manager_;
746 unoidl::InterfaceTypeEntity::Method::Parameter parameter_;
747 sal_Int32 position_;
750 class MethodDescription:
751 public cppu::WeakImplHelper<
752 css::reflection::XInterfaceMethodTypeDescription >
754 public:
755 MethodDescription(
756 rtl::Reference< cppuhelper::TypeManager > const & manager,
757 OUString name,
758 unoidl::InterfaceTypeEntity::Method method, sal_Int32 position):
759 manager_(manager), name_(std::move(name)), method_(std::move(method)), position_(position)
760 { assert(manager.is()); }
762 private:
763 virtual ~MethodDescription() override {}
765 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
766 { return css::uno::TypeClass_INTERFACE_METHOD; }
768 virtual OUString SAL_CALL getName() override
769 { return name_; }
771 virtual OUString SAL_CALL getMemberName() override
772 { return method_.name; }
774 virtual sal_Int32 SAL_CALL getPosition() override
775 { return position_; }
777 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
778 getReturnType() override
779 { return manager_->resolve(method_.returnType); }
781 virtual sal_Bool SAL_CALL isOneway() override
782 { return false; }
784 virtual
785 css::uno::Sequence<
786 css::uno::Reference< css::reflection::XMethodParameter > >
787 SAL_CALL getParameters() override;
789 virtual
790 css::uno::Sequence<
791 css::uno::Reference< css::reflection::XTypeDescription > >
792 SAL_CALL getExceptions() override;
794 rtl::Reference< cppuhelper::TypeManager > manager_;
795 OUString name_;
796 unoidl::InterfaceTypeEntity::Method method_;
797 sal_Int32 position_;
800 css::uno::Sequence< css::uno::Reference< css::reflection::XMethodParameter > >
801 MethodDescription::getParameters() {
802 assert(method_.parameters.size() <= SAL_MAX_INT32);
803 sal_Int32 n = static_cast< sal_Int32 >(method_.parameters.size());
804 css::uno::Sequence<
805 css::uno::Reference< css::reflection::XMethodParameter > > s(n);
806 auto r = asNonConstRange(s);
807 for (sal_Int32 i = 0; i != n; ++i) {
808 r[i] = new MethodParameter(manager_, method_.parameters[i], i);
810 return s;
813 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
814 MethodDescription::getExceptions() {
815 assert(method_.exceptions.size() <= SAL_MAX_INT32);
816 sal_Int32 n = static_cast< sal_Int32 >(method_.exceptions.size());
817 css::uno::Sequence<
818 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
819 auto r = asNonConstRange(s);
820 for (sal_Int32 i = 0; i != n; ++i) {
821 r[i] = manager_->resolve(method_.exceptions[i]);
823 return s;
826 class BaseOffset {
827 public:
828 explicit BaseOffset(
829 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
830 const & description);
832 BaseOffset(const BaseOffset&) = delete;
833 const BaseOffset& operator=(const BaseOffset&) = delete;
835 sal_Int32 get() const { return offset_; }
837 private:
838 void calculateBases(
839 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
840 const & description);
842 void calculate(
843 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
844 const & description);
846 std::set< OUString > set_;
847 sal_Int32 offset_;
850 BaseOffset::BaseOffset(
851 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
852 description):
853 offset_(0)
855 calculateBases(description);
858 void BaseOffset::calculateBases(
859 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
860 description)
862 const css::uno::Sequence<
863 css::uno::Reference < css::reflection::XTypeDescription > > bases(
864 description->getBaseTypes());
865 for (const auto & i : bases) {
866 calculate(
867 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >(
868 resolveTypedefs(css::uno::Any(i)),
869 css::uno::UNO_QUERY_THROW));
873 void BaseOffset::calculate(
874 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
875 description)
877 if (set_.insert(description->getName()).second) {
878 calculateBases(description);
879 offset_ += description->getMembers().getLength();
883 typedef cppu::ImplInheritanceHelper<
884 PublishableDescription, css::reflection::XInterfaceTypeDescription2 >
885 InterfaceTypeDescription_Base;
887 class InterfaceTypeDescription: public InterfaceTypeDescription_Base {
888 public:
889 InterfaceTypeDescription(
890 rtl::Reference< cppuhelper::TypeManager > const & manager,
891 OUString name,
892 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
893 InterfaceTypeDescription_Base(entity->isPublished()), manager_(manager),
894 name_(std::move(name)), entity_(entity)
895 { assert(manager.is()); assert(entity.is()); }
897 private:
898 virtual ~InterfaceTypeDescription() override {}
900 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
901 { return css::uno::TypeClass_INTERFACE; }
903 virtual OUString SAL_CALL getName() override
904 { return name_; }
906 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
907 getBaseType() override {
908 return entity_->getDirectMandatoryBases().empty()
909 ? css::uno::Reference< css::reflection::XTypeDescription >()
910 : manager_->resolve(entity_->getDirectMandatoryBases()[0].name);
913 virtual css::uno::Uik SAL_CALL getUik() override
914 { return css::uno::Uik(); }
916 virtual
917 css::uno::Sequence<
918 css::uno::Reference<
919 css::reflection::XInterfaceMemberTypeDescription > >
920 SAL_CALL getMembers() override;
922 virtual
923 css::uno::Sequence<
924 css::uno::Reference< css::reflection::XTypeDescription > >
925 SAL_CALL getBaseTypes() override;
927 virtual
928 css::uno::Sequence<
929 css::uno::Reference< css::reflection::XTypeDescription > >
930 SAL_CALL getOptionalBaseTypes() override;
932 rtl::Reference< cppuhelper::TypeManager > manager_;
933 OUString name_;
934 rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
937 css::uno::Sequence<
938 css::uno::Reference< css::reflection::XInterfaceMemberTypeDescription > >
939 InterfaceTypeDescription::getMembers() {
940 assert(
941 entity_->getDirectAttributes().size() <= SAL_MAX_INT32
942 && (entity_->getDirectMethods().size()
943 <= SAL_MAX_INT32 - entity_->getDirectAttributes().size()));
944 sal_Int32 n1 = static_cast< sal_Int32 >(
945 entity_->getDirectAttributes().size());
946 sal_Int32 n2 = static_cast< sal_Int32 >(entity_->getDirectMethods().size());
947 css::uno::Sequence<
948 css::uno::Reference<
949 css::reflection::XInterfaceMemberTypeDescription > > s(n1 + n2);
950 auto r = asNonConstRange(s);
951 sal_Int32 off = BaseOffset(this).get();
952 for (sal_Int32 i = 0; i != n1; ++i) {
953 r[i] = new AttributeDescription(
954 manager_, name_ + "::" + entity_->getDirectAttributes()[i].name,
955 entity_->getDirectAttributes()[i], off + i);
957 for (sal_Int32 i = 0; i != n2; ++i) {
958 r[n1 + i] = new MethodDescription(
959 manager_, name_ + "::" + entity_->getDirectMethods()[i].name,
960 entity_->getDirectMethods()[i], off + n1 + i);
962 return s;
965 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
966 InterfaceTypeDescription::getBaseTypes() {
967 assert(entity_->getDirectMandatoryBases().size() <= SAL_MAX_INT32);
968 sal_Int32 n = static_cast< sal_Int32 >(
969 entity_->getDirectMandatoryBases().size());
970 css::uno::Sequence<
971 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
972 auto r = asNonConstRange(s);
973 for (sal_Int32 i = 0; i != n; ++i) {
974 r[i] = manager_->resolve(entity_->getDirectMandatoryBases()[i].name);
976 return s;
979 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
980 InterfaceTypeDescription::getOptionalBaseTypes()
982 assert(entity_->getDirectOptionalBases().size() <= SAL_MAX_INT32);
983 sal_Int32 n = static_cast< sal_Int32 >(
984 entity_->getDirectOptionalBases().size());
985 css::uno::Sequence<
986 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
987 auto r = asNonConstRange(s);
988 for (sal_Int32 i = 0; i != n; ++i) {
989 r[i] = manager_->resolve(entity_->getDirectOptionalBases()[i].name);
991 return s;
994 class ConstantDescription:
995 public cppu::WeakImplHelper< css::reflection::XConstantTypeDescription >
997 public:
998 ConstantDescription(
999 OUString const & constantGroupName,
1000 unoidl::ConstantGroupEntity::Member const & member);
1002 private:
1003 virtual ~ConstantDescription() override {}
1005 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1006 { return css::uno::TypeClass_CONSTANT; }
1008 virtual OUString SAL_CALL getName() override
1009 { return name_; }
1011 virtual css::uno::Any SAL_CALL getConstantValue() override
1012 { return value_; }
1014 OUString name_;
1015 css::uno::Any value_;
1018 ConstantDescription::ConstantDescription(
1019 OUString const & constantGroupName,
1020 unoidl::ConstantGroupEntity::Member const & member):
1021 name_(makePrefix(constantGroupName) + member.name)
1023 switch (member.value.type) {
1024 case unoidl::ConstantValue::TYPE_BOOLEAN:
1025 value_ <<= member.value.booleanValue;
1026 break;
1027 case unoidl::ConstantValue::TYPE_BYTE:
1028 value_ <<= member.value.byteValue;
1029 break;
1030 case unoidl::ConstantValue::TYPE_SHORT:
1031 value_ <<= member.value.shortValue;
1032 break;
1033 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1034 value_ <<= member.value.unsignedShortValue;
1035 break;
1036 case unoidl::ConstantValue::TYPE_LONG:
1037 value_ <<= member.value.longValue;
1038 break;
1039 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1040 value_ <<= member.value.unsignedLongValue;
1041 break;
1042 case unoidl::ConstantValue::TYPE_HYPER:
1043 value_ <<= member.value.hyperValue;
1044 break;
1045 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1046 value_ <<= member.value.unsignedHyperValue;
1047 break;
1048 case unoidl::ConstantValue::TYPE_FLOAT:
1049 value_ <<= member.value.floatValue;
1050 break;
1051 case unoidl::ConstantValue::TYPE_DOUBLE:
1052 value_ <<= member.value.doubleValue;
1053 break;
1054 default:
1055 for (;;) { std::abort(); } // this cannot happen
1059 typedef cppu::ImplInheritanceHelper<
1060 PublishableDescription, css::reflection::XConstantsTypeDescription >
1061 ConstantGroupDescription_Base;
1063 class ConstantGroupDescription: public ConstantGroupDescription_Base {
1064 public:
1065 ConstantGroupDescription(
1066 OUString name,
1067 rtl::Reference< unoidl::ConstantGroupEntity > const & entity):
1068 ConstantGroupDescription_Base(entity->isPublished()), name_(std::move(name)),
1069 entity_(entity)
1070 { assert(entity.is()); }
1072 private:
1073 virtual ~ConstantGroupDescription() override {}
1075 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1076 { return css::uno::TypeClass_CONSTANTS; }
1078 virtual OUString SAL_CALL getName() override
1079 { return name_; }
1081 virtual
1082 css::uno::Sequence<
1083 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1084 SAL_CALL getConstants() override;
1086 OUString name_;
1087 rtl::Reference< unoidl::ConstantGroupEntity > entity_;
1090 css::uno::Sequence<
1091 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1092 ConstantGroupDescription::getConstants() {
1093 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
1094 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
1095 css::uno::Sequence<
1096 css::uno::Reference< css::reflection::XConstantTypeDescription > > s(n);
1097 auto r = asNonConstRange(s);
1098 for (sal_Int32 i = 0; i != n; ++i) {
1099 r[i] = new ConstantDescription(name_, entity_->getMembers()[i]);
1101 return s;
1104 typedef cppu::ImplInheritanceHelper<
1105 PublishableDescription, css::reflection::XIndirectTypeDescription >
1106 TypedefDescription_Base;
1108 class TypedefDescription: public TypedefDescription_Base {
1109 public:
1110 TypedefDescription(
1111 rtl::Reference< cppuhelper::TypeManager > const & manager,
1112 OUString name,
1113 rtl::Reference< unoidl::TypedefEntity > const & entity):
1114 TypedefDescription_Base(entity->isPublished()), manager_(manager),
1115 name_(std::move(name)), entity_(entity)
1116 { assert(manager.is()); assert(entity.is()); }
1118 private:
1119 virtual ~TypedefDescription() override {}
1121 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1122 { return css::uno::TypeClass_TYPEDEF; }
1124 virtual OUString SAL_CALL getName() override
1125 { return name_; }
1127 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1128 getReferencedType() override
1129 { return manager_->resolve(entity_->getType()); }
1131 rtl::Reference< cppuhelper::TypeManager > manager_;
1132 OUString name_;
1133 rtl::Reference< unoidl::TypedefEntity > entity_;
1136 class ConstructorParameter:
1137 public cppu::WeakImplHelper< css::reflection::XParameter >
1139 public:
1140 ConstructorParameter(
1141 rtl::Reference< cppuhelper::TypeManager > const & manager,
1142 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter parameter,
1143 sal_Int32 position):
1144 manager_(manager), parameter_(std::move(parameter)), position_(position)
1145 { assert(manager.is()); }
1147 private:
1148 virtual ~ConstructorParameter() override {}
1150 virtual OUString SAL_CALL getName() override
1151 { return parameter_.name; }
1153 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1154 getType() override
1155 { return manager_->resolve(parameter_.type); }
1157 virtual sal_Bool SAL_CALL isIn() override
1158 { return true; }
1160 virtual sal_Bool SAL_CALL isOut() override
1161 { return false; }
1163 virtual sal_Int32 SAL_CALL getPosition() override
1164 { return position_; }
1166 virtual sal_Bool SAL_CALL isRestParameter() override
1167 { return parameter_.rest; }
1169 rtl::Reference< cppuhelper::TypeManager > manager_;
1170 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1171 parameter_;
1172 sal_Int32 position_;
1175 class ConstructorDescription:
1176 public cppu::WeakImplHelper<
1177 css::reflection::XServiceConstructorDescription >
1179 public:
1180 ConstructorDescription(
1181 rtl::Reference< cppuhelper::TypeManager > const & manager,
1182 unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor):
1183 manager_(manager), constructor_(std::move(constructor))
1184 { assert(manager.is()); }
1186 private:
1187 virtual ~ConstructorDescription() override {}
1189 virtual sal_Bool SAL_CALL isDefaultConstructor() override
1190 { return constructor_.defaultConstructor; }
1192 virtual OUString SAL_CALL getName() override
1193 { return constructor_.name; }
1195 virtual
1196 css::uno::Sequence<
1197 css::uno::Reference< css::reflection::XParameter > >
1198 SAL_CALL getParameters() override;
1200 virtual
1201 css::uno::Sequence<
1202 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1203 SAL_CALL getExceptions() override;
1205 rtl::Reference< cppuhelper::TypeManager > manager_;
1206 unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor_;
1209 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
1210 ConstructorDescription::getParameters() {
1211 assert(constructor_.parameters.size() <= SAL_MAX_INT32);
1212 sal_Int32 n = static_cast< sal_Int32 >(constructor_.parameters.size());
1213 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > s(
1215 auto r = asNonConstRange(s);
1216 for (sal_Int32 i = 0; i != n; ++i) {
1217 r[i] = new ConstructorParameter(
1218 manager_, constructor_.parameters[i], i);
1220 return s;
1223 css::uno::Sequence<
1224 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1225 ConstructorDescription::getExceptions() {
1226 assert(constructor_.exceptions.size() <= SAL_MAX_INT32);
1227 sal_Int32 n = static_cast< sal_Int32 >(constructor_.exceptions.size());
1228 css::uno::Sequence<
1229 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
1230 auto r = asNonConstRange(s);
1231 for (sal_Int32 i = 0; i != n; ++i) {
1232 r[i].set(
1233 manager_->resolve(constructor_.exceptions[i]),
1234 css::uno::UNO_QUERY_THROW);
1236 return s;
1239 typedef cppu::ImplInheritanceHelper<
1240 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1241 SingleInterfaceBasedServiceDescription_Base;
1243 class SingleInterfaceBasedServiceDescription:
1244 public SingleInterfaceBasedServiceDescription_Base
1246 public:
1247 SingleInterfaceBasedServiceDescription(
1248 rtl::Reference< cppuhelper::TypeManager > const & manager,
1249 OUString name,
1250 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
1251 entity):
1252 SingleInterfaceBasedServiceDescription_Base(entity->isPublished()),
1253 manager_(manager), name_(std::move(name)), entity_(entity)
1254 { assert(manager.is()); assert(entity.is()); }
1256 private:
1257 virtual ~SingleInterfaceBasedServiceDescription() override {}
1259 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1260 { return css::uno::TypeClass_SERVICE; }
1262 virtual OUString SAL_CALL getName() override
1263 { return name_; }
1265 virtual
1266 css::uno::Sequence<
1267 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1268 SAL_CALL getMandatoryServices() override
1270 return css::uno::Sequence<
1271 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1274 virtual
1275 css::uno::Sequence<
1276 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1277 SAL_CALL getOptionalServices() override
1279 return css::uno::Sequence<
1280 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1283 virtual
1284 css::uno::Sequence<
1285 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1286 SAL_CALL getMandatoryInterfaces() override
1288 return css::uno::Sequence<
1289 css::uno::Reference<
1290 css::reflection::XInterfaceTypeDescription > >();
1293 virtual
1294 css::uno::Sequence<
1295 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1296 SAL_CALL getOptionalInterfaces() override
1298 return css::uno::Sequence<
1299 css::uno::Reference<
1300 css::reflection::XInterfaceTypeDescription > >();
1303 virtual
1304 css::uno::Sequence<
1305 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1306 SAL_CALL getProperties() override
1308 return css::uno::Sequence<
1309 css::uno::Reference<
1310 css::reflection::XPropertyTypeDescription > >();
1313 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1314 { return true; }
1316 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1317 getInterface() override
1318 { return manager_->resolve(entity_->getBase()); }
1320 virtual
1321 css::uno::Sequence<
1322 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1323 SAL_CALL getConstructors() override;
1325 rtl::Reference< cppuhelper::TypeManager > manager_;
1326 OUString name_;
1327 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
1330 css::uno::Sequence<
1331 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1332 SingleInterfaceBasedServiceDescription::getConstructors()
1334 assert(entity_->getConstructors().size() <= SAL_MAX_INT32);
1335 sal_Int32 n = static_cast< sal_Int32 >(entity_->getConstructors().size());
1336 css::uno::Sequence<
1337 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1338 s(n);
1339 auto r = asNonConstRange(s);
1340 for (sal_Int32 i = 0; i != n; ++i) {
1341 r[i] = new ConstructorDescription(
1342 manager_, entity_->getConstructors()[i]);
1344 return s;
1347 class PropertyDescription:
1348 public cppu::WeakImplHelper< css::reflection::XPropertyTypeDescription >
1350 public:
1351 PropertyDescription(
1352 rtl::Reference< cppuhelper::TypeManager > const & manager,
1353 unoidl::AccumulationBasedServiceEntity::Property property):
1354 manager_(manager), property_(std::move(property))
1355 { assert(manager.is()); }
1357 private:
1358 virtual ~PropertyDescription() override {}
1360 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1361 { return css::uno::TypeClass_PROPERTY; }
1363 virtual OUString SAL_CALL getName() override
1364 { return property_.name; }
1366 virtual sal_Int16 SAL_CALL getPropertyFlags() override
1367 { return property_.attributes; }
1369 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1370 getPropertyTypeDescription() override
1371 { return manager_->resolve(property_.type); }
1373 rtl::Reference< cppuhelper::TypeManager > manager_;
1374 unoidl::AccumulationBasedServiceEntity::Property property_;
1377 typedef cppu::ImplInheritanceHelper<
1378 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1379 AccumulationBasedServiceDescription_Base;
1381 class AccumulationBasedServiceDescription:
1382 public AccumulationBasedServiceDescription_Base
1384 public:
1385 AccumulationBasedServiceDescription(
1386 rtl::Reference< cppuhelper::TypeManager > const & manager,
1387 OUString name,
1388 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const &
1389 entity):
1390 AccumulationBasedServiceDescription_Base(entity->isPublished()),
1391 manager_(manager), name_(std::move(name)), entity_(entity)
1392 { assert(manager.is()); assert(entity.is()); }
1394 private:
1395 virtual ~AccumulationBasedServiceDescription() override {}
1397 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1398 { return css::uno::TypeClass_SERVICE; }
1400 virtual OUString SAL_CALL getName() override
1401 { return name_; }
1403 virtual
1404 css::uno::Sequence<
1405 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1406 SAL_CALL getMandatoryServices() override;
1408 virtual
1409 css::uno::Sequence<
1410 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1411 SAL_CALL getOptionalServices() override;
1413 virtual
1414 css::uno::Sequence<
1415 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1416 SAL_CALL getMandatoryInterfaces() override;
1418 virtual
1419 css::uno::Sequence<
1420 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1421 SAL_CALL getOptionalInterfaces() override;
1423 virtual
1424 css::uno::Sequence<
1425 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1426 SAL_CALL getProperties() override;
1428 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1429 { return false; }
1431 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1432 getInterface() override
1433 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1435 virtual
1436 css::uno::Sequence<
1437 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1438 SAL_CALL getConstructors() override
1440 return css::uno::Sequence<
1441 css::uno::Reference<
1442 css::reflection::XServiceConstructorDescription > >();
1445 rtl::Reference< cppuhelper::TypeManager > manager_;
1446 OUString name_;
1447 rtl::Reference< unoidl::AccumulationBasedServiceEntity > entity_;
1450 css::uno::Sequence<
1451 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1452 AccumulationBasedServiceDescription::getMandatoryServices()
1454 assert(entity_->getDirectMandatoryBaseServices().size() <= SAL_MAX_INT32);
1455 sal_Int32 n = static_cast< sal_Int32 >(
1456 entity_->getDirectMandatoryBaseServices().size());
1457 css::uno::Sequence<
1458 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1459 auto r = asNonConstRange(s);
1460 for (sal_Int32 i = 0; i != n; ++i) {
1461 r[i].set(
1462 manager_->resolve(
1463 entity_->getDirectMandatoryBaseServices()[i].name),
1464 css::uno::UNO_QUERY_THROW);
1466 return s;
1469 css::uno::Sequence<
1470 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1471 AccumulationBasedServiceDescription::getOptionalServices()
1473 assert(entity_->getDirectOptionalBaseServices().size() <= SAL_MAX_INT32);
1474 sal_Int32 n = static_cast< sal_Int32 >(
1475 entity_->getDirectOptionalBaseServices().size());
1476 css::uno::Sequence<
1477 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1478 auto r = asNonConstRange(s);
1479 for (sal_Int32 i = 0; i != n; ++i) {
1480 r[i].set(
1481 manager_->resolve(entity_->getDirectOptionalBaseServices()[i].name),
1482 css::uno::UNO_QUERY_THROW);
1484 return s;
1487 css::uno::Sequence<
1488 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1489 AccumulationBasedServiceDescription::getMandatoryInterfaces()
1491 assert(entity_->getDirectMandatoryBaseInterfaces().size() <= SAL_MAX_INT32);
1492 sal_Int32 n = static_cast< sal_Int32 >(
1493 entity_->getDirectMandatoryBaseInterfaces().size());
1494 css::uno::Sequence<
1495 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1497 auto r = asNonConstRange(s);
1498 for (sal_Int32 i = 0; i != n; ++i) {
1499 r[i].set(
1500 resolveTypedefs(
1501 manager_->find(
1502 entity_->getDirectMandatoryBaseInterfaces()[i].name)),
1503 css::uno::UNO_QUERY_THROW);
1505 return s;
1508 css::uno::Sequence<
1509 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1510 AccumulationBasedServiceDescription::getOptionalInterfaces()
1512 assert(entity_->getDirectOptionalBaseInterfaces().size() <= SAL_MAX_INT32);
1513 sal_Int32 n = static_cast< sal_Int32 >(
1514 entity_->getDirectOptionalBaseInterfaces().size());
1515 css::uno::Sequence<
1516 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1518 auto r = asNonConstRange(s);
1519 for (sal_Int32 i = 0; i != n; ++i) {
1520 r[i].set(
1521 resolveTypedefs(
1522 manager_->find(
1523 entity_->getDirectOptionalBaseInterfaces()[i].name)),
1524 css::uno::UNO_QUERY_THROW);
1526 return s;
1529 css::uno::Sequence<
1530 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1531 AccumulationBasedServiceDescription::getProperties()
1533 assert(entity_->getDirectProperties().size() <= SAL_MAX_INT32);
1534 sal_Int32 n = static_cast< sal_Int32 >(
1535 entity_->getDirectProperties().size());
1536 css::uno::Sequence<
1537 css::uno::Reference< css::reflection::XPropertyTypeDescription > > s(n);
1538 auto r = asNonConstRange(s);
1539 for (sal_Int32 i = 0; i != n; ++i) {
1540 r[i] = new PropertyDescription(
1541 manager_, entity_->getDirectProperties()[i]);
1543 return s;
1546 typedef cppu::ImplInheritanceHelper<
1547 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1548 InterfaceBasedSingletonDescription_Base;
1550 class InterfaceBasedSingletonDescription:
1551 public InterfaceBasedSingletonDescription_Base
1553 public:
1554 InterfaceBasedSingletonDescription(
1555 rtl::Reference< cppuhelper::TypeManager > const & manager,
1556 OUString name,
1557 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity):
1558 InterfaceBasedSingletonDescription_Base(entity->isPublished()),
1559 manager_(manager), name_(std::move(name)), entity_(entity)
1560 { assert(manager.is()); assert(entity.is()); }
1562 private:
1563 virtual ~InterfaceBasedSingletonDescription() override {}
1565 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1566 { return css::uno::TypeClass_SINGLETON; }
1568 virtual OUString SAL_CALL getName() override
1569 { return name_; }
1571 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1572 SAL_CALL getService() override
1574 return
1575 css::uno::Reference< css::reflection::XServiceTypeDescription >();
1578 virtual sal_Bool SAL_CALL isInterfaceBased() override
1579 { return true; }
1581 virtual css::uno::Reference< css::reflection::XTypeDescription >
1582 SAL_CALL getInterface() override
1583 { return manager_->resolve(entity_->getBase()); }
1585 rtl::Reference< cppuhelper::TypeManager > manager_;
1586 OUString name_;
1587 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
1590 typedef cppu::ImplInheritanceHelper<
1591 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1592 ServiceBasedSingletonDescription_Base;
1594 class ServiceBasedSingletonDescription:
1595 public ServiceBasedSingletonDescription_Base
1597 public:
1598 ServiceBasedSingletonDescription(
1599 rtl::Reference< cppuhelper::TypeManager > const & manager,
1600 OUString name,
1601 rtl::Reference< unoidl::ServiceBasedSingletonEntity > const & entity):
1602 ServiceBasedSingletonDescription_Base(entity->isPublished()),
1603 manager_(manager), name_(std::move(name)), entity_(entity)
1604 { assert(manager.is()); assert(entity.is()); }
1606 private:
1607 virtual ~ServiceBasedSingletonDescription() override {}
1609 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1610 { return css::uno::TypeClass_SINGLETON; }
1612 virtual OUString SAL_CALL getName() override
1613 { return name_; }
1615 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1616 SAL_CALL getService() override
1618 return css::uno::Reference< css::reflection::XServiceTypeDescription >(
1619 manager_->resolve(entity_->getBase()), css::uno::UNO_QUERY_THROW);
1622 virtual sal_Bool SAL_CALL isInterfaceBased() override
1623 { return false; }
1625 virtual css::uno::Reference< css::reflection::XTypeDescription >
1626 SAL_CALL getInterface() override
1627 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1629 rtl::Reference< cppuhelper::TypeManager > manager_;
1630 OUString name_;
1631 rtl::Reference< unoidl::ServiceBasedSingletonEntity > entity_;
1634 class Enumeration:
1635 public cppu::WeakImplHelper< css::reflection::XTypeDescriptionEnumeration >
1637 public:
1638 Enumeration(
1639 rtl::Reference< cppuhelper::TypeManager > const & manager,
1640 OUString const & prefix,
1641 rtl::Reference< unoidl::MapCursor > const & cursor,
1642 css::uno::Sequence< css::uno::TypeClass > const & types, bool deep):
1643 manager_(manager), types_(types), deep_(deep)
1645 assert(manager.is());
1646 positions_.push(Position(prefix, cursor));
1647 findNextMatch();
1650 private:
1651 virtual ~Enumeration() override {}
1653 virtual sal_Bool SAL_CALL hasMoreElements() override
1654 { return !positions_.empty(); }
1656 virtual css::uno::Any SAL_CALL nextElement() override
1657 { return css::uno::Any(nextTypeDescription()); }
1659 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1660 nextTypeDescription() override;
1662 bool matches(css::uno::TypeClass tc) const;
1664 void findNextMatch();
1666 struct Position {
1667 Position(
1668 OUString thePrefix,
1669 rtl::Reference< unoidl::MapCursor > const & theCursor):
1670 prefix(std::move(thePrefix)), cursor(theCursor)
1671 { assert(theCursor.is()); }
1673 Position(
1674 OUString thePrefix,
1675 rtl::Reference< unoidl::ConstantGroupEntity > const &
1676 theConstantGroup):
1677 prefix(std::move(thePrefix)), constantGroup(theConstantGroup),
1678 constantGroupIndex(constantGroup->getMembers().begin())
1679 { assert(theConstantGroup.is()); }
1681 Position(Position const & other):
1682 prefix(other.prefix), cursor(other.cursor),
1683 constantGroup(other.constantGroup)
1685 if (constantGroup.is()) {
1686 constantGroupIndex = other.constantGroupIndex;
1690 OUString prefix;
1691 rtl::Reference< unoidl::MapCursor > cursor;
1692 rtl::Reference< unoidl::ConstantGroupEntity > constantGroup;
1693 std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator
1694 constantGroupIndex;
1697 rtl::Reference< cppuhelper::TypeManager > manager_;
1698 css::uno::Sequence< css::uno::TypeClass > types_;
1699 bool deep_;
1701 std::mutex mutex_;
1702 std::stack< Position, std::vector<Position> > positions_;
1703 OUString current_;
1706 css::uno::Reference< css::reflection::XTypeDescription >
1707 Enumeration::nextTypeDescription()
1709 OUString name;
1711 std::scoped_lock g(mutex_);
1712 if (positions_.empty()) {
1713 throw css::container::NoSuchElementException(
1714 "exhausted XTypeDescriptionEnumeration",
1715 static_cast< cppu::OWeakObject * >(this));
1717 name = current_;
1718 findNextMatch();
1720 return manager_->resolve(name);
1723 bool Enumeration::matches(css::uno::TypeClass tc) const {
1724 if (!types_.hasElements()) {
1725 return true;
1728 return std::any_of(types_.begin(), types_.end(), [&tc](const auto& i) { return i == tc; });
1731 void Enumeration::findNextMatch() {
1732 try {
1733 for (;;) {
1734 assert(!positions_.empty());
1735 OUString name;
1736 if (positions_.top().cursor.is()) { // root or module
1737 rtl::Reference< unoidl::Entity > ent(
1738 positions_.top().cursor->getNext(&name));
1739 if (!ent.is()) {
1740 positions_.pop();
1741 if (positions_.empty()) {
1742 break;
1744 continue;
1746 name = positions_.top().prefix + name;
1747 css::uno::TypeClass tc;
1748 switch (ent->getSort()) {
1749 case unoidl::Entity::SORT_MODULE:
1750 tc = css::uno::TypeClass_MODULE;
1751 if (deep_) {
1752 positions_.push(
1753 Position(
1754 makePrefix(name),
1755 static_cast< unoidl::ModuleEntity * >(
1756 ent.get())->createCursor()));
1758 break;
1759 case unoidl::Entity::SORT_ENUM_TYPE:
1760 tc = css::uno::TypeClass_ENUM;
1761 break;
1762 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
1763 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
1764 tc = css::uno::TypeClass_STRUCT;
1765 break;
1766 case unoidl::Entity::SORT_EXCEPTION_TYPE:
1767 tc = css::uno::TypeClass_EXCEPTION;
1768 break;
1769 case unoidl::Entity::SORT_INTERFACE_TYPE:
1770 tc = css::uno::TypeClass_INTERFACE;
1771 break;
1772 case unoidl::Entity::SORT_TYPEDEF:
1773 tc = css::uno::TypeClass_TYPEDEF;
1774 break;
1775 case unoidl::Entity::SORT_CONSTANT_GROUP:
1776 tc = css::uno::TypeClass_CONSTANTS;
1777 if (deep_ && matches(css::uno::TypeClass_CONSTANT)) {
1778 positions_.push(
1779 Position(
1780 makePrefix(name),
1781 static_cast< unoidl::ConstantGroupEntity * >(
1782 ent.get())));
1784 break;
1785 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
1786 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
1787 tc = css::uno::TypeClass_SERVICE;
1788 break;
1789 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
1790 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
1791 tc = css::uno::TypeClass_SINGLETON;
1792 break;
1793 default:
1794 for (;;) { std::abort(); } // this cannot happen
1796 if (matches(tc)) {
1797 current_ = name;
1798 break;
1800 } else { // constant group
1801 if (positions_.top().constantGroupIndex
1802 == positions_.top().constantGroup->getMembers().end())
1804 positions_.pop();
1805 if (positions_.empty()) {
1806 break;
1808 continue;
1810 current_ = positions_.top().prefix
1811 + positions_.top().constantGroupIndex++->name;
1812 break;
1815 } catch (unoidl::FileFormatException & e) {
1816 throw css::uno::DeploymentException(
1817 e.getUri() + ": " + e.getDetail(),
1818 static_cast< cppu::OWeakObject * >(this));
1824 cppuhelper::TypeManager::TypeManager():
1825 manager_(new unoidl::Manager)
1828 css::uno::Any cppuhelper::TypeManager::find(OUString const & name) {
1829 //TODO: caching? (here or in unoidl::Manager?)
1830 static constexpr std::pair<std::u16string_view, css::uno::TypeClass> const simple[] = {
1831 { u"void", css::uno::TypeClass_VOID },
1832 { u"boolean", css::uno::TypeClass_BOOLEAN },
1833 { u"byte", css::uno::TypeClass_BYTE },
1834 { u"short", css::uno::TypeClass_SHORT },
1835 { u"unsigned short", css::uno::TypeClass_UNSIGNED_SHORT },
1836 { u"long", css::uno::TypeClass_LONG },
1837 { u"unsigned long", css::uno::TypeClass_UNSIGNED_LONG },
1838 { u"hyper", css::uno::TypeClass_HYPER },
1839 { u"unsigned hyper", css::uno::TypeClass_UNSIGNED_HYPER },
1840 { u"float", css::uno::TypeClass_FLOAT },
1841 { u"double", css::uno::TypeClass_DOUBLE },
1842 { u"char", css::uno::TypeClass_CHAR },
1843 { u"string", css::uno::TypeClass_STRING },
1844 { u"type", css::uno::TypeClass_TYPE },
1845 { u"any", css::uno::TypeClass_ANY } };
1846 for (const auto& [ rName, rTypeClass ] : simple) {
1847 if (name == rName) {
1848 return css::uno::Any(
1849 css::uno::Reference< css::reflection::XTypeDescription >(
1850 new SimpleTypeDescription(rTypeClass, name)));
1853 if (name.startsWith("[]")) {
1854 return getSequenceType(name);
1856 sal_Int32 i = name.indexOf('<');
1857 if (i != -1) {
1858 return getInstantiatedStruct(name, i);
1860 i = name.indexOf("::");
1861 if (i != -1) {
1862 return getInterfaceMember(name, i);
1864 rtl::Reference< unoidl::Entity > ent(findEntity(name));
1865 if (ent.is()) {
1866 return getNamed(name, ent);
1868 i = name.lastIndexOf('.');
1869 if (i != -1) {
1870 OUString parent(name.copy(0, i));
1871 ent = findEntity(parent);
1872 if (ent.is()) {
1873 switch (ent->getSort()) {
1874 case unoidl::Entity::SORT_ENUM_TYPE:
1875 return getEnumMember(
1876 static_cast< unoidl::EnumTypeEntity * >(ent.get()),
1877 name.subView(i + 1));
1878 case unoidl::Entity::SORT_CONSTANT_GROUP:
1879 return getConstant(
1880 parent,
1881 static_cast< unoidl::ConstantGroupEntity * >(ent.get()),
1882 name.subView(i + 1));
1883 default:
1884 break;
1888 return css::uno::Any();
1891 css::uno::Reference< css::reflection::XTypeDescription >
1892 cppuhelper::TypeManager::resolve(OUString const & name) {
1893 css::uno::Reference< css::reflection::XTypeDescription > desc(
1894 find(name), css::uno::UNO_QUERY);
1895 if (!desc.is()) {
1896 throw css::uno::DeploymentException(
1897 "cannot resolve type \"" + name + "\"",
1898 static_cast< cppu::OWeakObject * >(this));
1900 return desc;
1903 cppuhelper::TypeManager::~TypeManager() noexcept {}
1905 OUString cppuhelper::TypeManager::getImplementationName()
1907 return
1908 "com.sun.star.comp.cppuhelper.bootstrap.TypeManager";
1911 sal_Bool cppuhelper::TypeManager::supportsService(
1912 OUString const & ServiceName)
1914 return cppu::supportsService(this, ServiceName);
1917 css::uno::Sequence< OUString >
1918 cppuhelper::TypeManager::getSupportedServiceNames()
1920 return { "com.sun.star.reflection.TypeDescriptionManager" }; //TODO
1923 css::uno::Any cppuhelper::TypeManager::getByHierarchicalName(
1924 OUString const & aName)
1926 css::uno::Any desc(find(aName));
1927 if (!desc.hasValue()) {
1928 throw css::container::NoSuchElementException(
1929 aName, static_cast< cppu::OWeakObject * >(this));
1931 return desc;
1934 sal_Bool cppuhelper::TypeManager::hasByHierarchicalName(
1935 OUString const & aName)
1937 return find(aName).hasValue();
1940 css::uno::Type cppuhelper::TypeManager::getElementType()
1942 return cppu::UnoType< OUString >::get();
1945 sal_Bool cppuhelper::TypeManager::hasElements()
1947 throw css::uno::RuntimeException(
1948 "TypeManager hasElements: method not supported",
1949 static_cast< cppu::OWeakObject * >(this));
1952 css::uno::Reference< css::container::XEnumeration >
1953 cppuhelper::TypeManager::createEnumeration()
1955 throw css::uno::RuntimeException(
1956 "TypeManager createEnumeration: method not supported",
1957 static_cast< cppu::OWeakObject * >(this));
1960 sal_Bool cppuhelper::TypeManager::has(css::uno::Any const &)
1962 throw css::uno::RuntimeException(
1963 "TypeManager has: method not supported",
1964 static_cast< cppu::OWeakObject * >(this));
1967 void cppuhelper::TypeManager::insert(css::uno::Any const & aElement)
1969 OUString uri;
1970 if (!(aElement >>= uri)) {
1971 throw css::lang::IllegalArgumentException(
1972 ("css.uno.theTypeDescriptionManager.insert expects a string URI"
1973 " argument"),
1974 static_cast< cppu::OWeakObject * >(this), 0);
1976 //TODO: check for ElementExistException
1977 //TODO: check for consistency with existing data
1978 readRdbFile(uri, false);
1981 void cppuhelper::TypeManager::remove(css::uno::Any const & aElement)
1983 OUString uri;
1984 if (!(aElement >>= uri)) {
1985 throw css::lang::IllegalArgumentException(
1986 ("css.uno.theTypeDescriptionManager.remove expects a string URI"
1987 " argument"),
1988 static_cast< cppu::OWeakObject * >(this), 0);
1990 //TODO: remove requests are silently ignored for now
1993 css::uno::Reference< css::reflection::XTypeDescriptionEnumeration >
1994 cppuhelper::TypeManager::createTypeDescriptionEnumeration(
1995 OUString const & moduleName,
1996 css::uno::Sequence< css::uno::TypeClass > const & types,
1997 css::reflection::TypeDescriptionSearchDepth depth)
1999 rtl::Reference< unoidl::MapCursor > cursor;
2000 try {
2001 cursor = manager_->createCursor(moduleName);
2002 } catch (unoidl::FileFormatException & e) {
2003 throw css::uno::DeploymentException(
2004 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2005 + e.getDetail()),
2006 static_cast< cppu::OWeakObject * >(this));
2008 if (!cursor.is()) {
2009 //TODO: css::reflection::InvalidTypeNameException if moduleName names a
2010 // non-module
2011 throw css::reflection::NoSuchTypeNameException(
2012 moduleName, static_cast< cppu::OWeakObject * >(this));
2014 return new Enumeration(
2015 this, makePrefix(moduleName), cursor, types,
2016 depth == css::reflection::TypeDescriptionSearchDepth_INFINITE);
2019 void cppuhelper::TypeManager::init(std::u16string_view rdbUris) {
2020 for (sal_Int32 i = 0; i != -1;) {
2021 std::u16string_view uri(o3tl::getToken(rdbUris, 0, ' ', i));
2022 if (uri.empty()) {
2023 continue;
2025 bool optional;
2026 bool directory;
2027 cppu::decodeRdbUri(&uri, &optional, &directory);
2028 if (directory) {
2029 readRdbDirectory(uri, optional);
2030 } else {
2031 readRdbFile(uri, optional);
2036 void cppuhelper::TypeManager::readRdbDirectory(
2037 std::u16string_view uri, bool optional)
2039 osl::Directory dir = OUString(uri);
2040 switch (dir.open()) {
2041 case osl::FileBase::E_None:
2042 break;
2043 case osl::FileBase::E_NOENT:
2044 if (optional) {
2045 SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri));
2046 return;
2048 [[fallthrough]];
2049 default:
2050 throw css::uno::DeploymentException(
2051 OUString::Concat("Cannot open directory ") + uri,
2052 static_cast< cppu::OWeakObject * >(this));
2054 for (;;) {
2055 OUString url;
2056 if (!cppu::nextDirectoryItem(dir, &url)) {
2057 break;
2059 readRdbFile(url, false);
2063 void cppuhelper::TypeManager::readRdbFile(
2064 std::u16string_view uri, bool optional)
2066 try {
2067 manager_->addProvider(OUString(uri));
2068 } catch (unoidl::NoSuchFileException &) {
2069 if (!optional) {
2070 throw css::uno::DeploymentException(
2071 OUString::Concat(uri) + ": no such file",
2072 static_cast< cppu::OWeakObject * >(this));
2074 SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri));
2075 } catch (unoidl::FileFormatException & e) {
2076 throw css::uno::DeploymentException(
2077 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2078 + e.getDetail()),
2079 static_cast< cppu::OWeakObject * >(this));
2083 css::uno::Any cppuhelper::TypeManager::getSequenceType(
2084 OUString const & name)
2086 assert(name.startsWith("[]"));
2087 return css::uno::Any(
2088 css::uno::Reference< css::reflection::XTypeDescription >(
2089 new SequenceTypeDescription(
2090 this, name, name.copy(std::strlen("[]")))));
2093 css::uno::Any cppuhelper::TypeManager::getInstantiatedStruct(
2094 OUString const & name, sal_Int32 separator)
2096 assert(name.indexOf('<') == separator && separator != -1);
2097 rtl::Reference< unoidl::Entity > ent(findEntity(name.copy(0, separator)));
2098 if (!ent.is()
2099 || (ent->getSort()
2100 != unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE))
2102 return css::uno::Any();
2104 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
2105 static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
2106 ent.get()));
2107 std::vector< OUString > args;
2108 sal_Int32 i = separator;
2109 do {
2110 ++i; // skip '<' or ','
2111 sal_Int32 j = i;
2112 for (sal_Int32 level = 0; j != name.getLength(); ++j) {
2113 sal_Unicode c = name[j];
2114 if (c == ',') {
2115 if (level == 0) {
2116 break;
2118 } else if (c == '<') {
2119 ++level;
2120 } else if (c == '>') {
2121 if (level == 0) {
2122 break;
2124 --level;
2127 if (j != name.getLength()) {
2128 args.push_back(name.copy(i, j - i));
2130 i = j;
2131 } while (i != name.getLength() && name[i] != '>');
2132 if (i != name.getLength() - 1 || name[i] != '>'
2133 || args.size() != ent2->getTypeParameters().size())
2135 return css::uno::Any();
2137 return css::uno::Any(
2138 css::uno::Reference< css::reflection::XTypeDescription >(
2139 new InstantiatedPolymorphicStructTypeDescription(
2140 this, name, ent2, std::move(args))));
2143 css::uno::Any cppuhelper::TypeManager::getInterfaceMember(
2144 std::u16string_view name, std::size_t separator)
2146 assert(name.find(u"::") == separator && separator != std::u16string_view::npos);
2147 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > ifc(
2148 resolveTypedefs(find(OUString(name.substr(0, separator)))), css::uno::UNO_QUERY);
2149 if (!ifc.is()) {
2150 return css::uno::Any();
2152 std::u16string_view member = name.substr(separator + std::strlen("::"));
2153 const css::uno::Sequence<
2154 css::uno::Reference<
2155 css::reflection::XInterfaceMemberTypeDescription > > mems(
2156 ifc->getMembers());
2157 for (const auto & m : mems) {
2158 if (m->getMemberName() == member) {
2159 return css::uno::Any(
2160 css::uno::Reference< css::reflection::XTypeDescription >(m));
2163 return css::uno::Any();
2166 css::uno::Any cppuhelper::TypeManager::getNamed(
2167 OUString const & name, rtl::Reference< unoidl::Entity > const & entity)
2169 assert(entity.is());
2170 switch (entity->getSort()) {
2171 case unoidl::Entity::SORT_MODULE:
2172 return css::uno::Any(
2173 css::uno::Reference< css::reflection::XTypeDescription >(
2174 new ModuleDescription(
2175 this, name,
2176 static_cast< unoidl::ModuleEntity * >(entity.get()))));
2177 case unoidl::Entity::SORT_ENUM_TYPE:
2178 return css::uno::Any(
2179 css::uno::Reference< css::reflection::XTypeDescription >(
2180 new EnumTypeDescription(
2181 name,
2182 static_cast< unoidl::EnumTypeEntity * >(entity.get()))));
2183 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
2184 return css::uno::Any(
2185 css::uno::Reference< css::reflection::XTypeDescription >(
2186 new PlainStructTypeDescription(
2187 this, name,
2188 static_cast< unoidl::PlainStructTypeEntity * >(
2189 entity.get()))));
2190 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
2191 return css::uno::Any(
2192 css::uno::Reference< css::reflection::XTypeDescription >(
2193 new PolymorphicStructTypeTemplateDescription(
2194 this, name,
2195 static_cast<
2196 unoidl::PolymorphicStructTypeTemplateEntity * >(
2197 entity.get()))));
2198 case unoidl::Entity::SORT_EXCEPTION_TYPE:
2199 return css::uno::Any(
2200 css::uno::Reference< css::reflection::XTypeDescription >(
2201 new ExceptionTypeDescription(
2202 this, name,
2203 static_cast< unoidl::ExceptionTypeEntity * >(
2204 entity.get()))));
2205 case unoidl::Entity::SORT_INTERFACE_TYPE:
2206 return css::uno::Any(
2207 css::uno::Reference< css::reflection::XTypeDescription >(
2208 new InterfaceTypeDescription(
2209 this, name,
2210 static_cast< unoidl::InterfaceTypeEntity * >(
2211 entity.get()))));
2212 case unoidl::Entity::SORT_TYPEDEF:
2213 return css::uno::Any(
2214 css::uno::Reference< css::reflection::XTypeDescription >(
2215 new TypedefDescription(
2216 this, name,
2217 static_cast< unoidl::TypedefEntity * >(entity.get()))));
2218 case unoidl::Entity::SORT_CONSTANT_GROUP:
2219 return css::uno::Any(
2220 css::uno::Reference< css::reflection::XTypeDescription >(
2221 new ConstantGroupDescription(
2222 name,
2223 static_cast< unoidl::ConstantGroupEntity * >(
2224 entity.get()))));
2225 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
2226 return css::uno::Any(
2227 css::uno::Reference< css::reflection::XTypeDescription >(
2228 new SingleInterfaceBasedServiceDescription(
2229 this, name,
2230 static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
2231 entity.get()))));
2232 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
2233 return css::uno::Any(
2234 css::uno::Reference< css::reflection::XTypeDescription >(
2235 new AccumulationBasedServiceDescription(
2236 this, name,
2237 static_cast< unoidl::AccumulationBasedServiceEntity * >(
2238 entity.get()))));
2239 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
2240 return css::uno::Any(
2241 css::uno::Reference< css::reflection::XTypeDescription >(
2242 new InterfaceBasedSingletonDescription(
2243 this, name,
2244 static_cast< unoidl::InterfaceBasedSingletonEntity * >(
2245 entity.get()))));
2246 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
2247 return css::uno::Any(
2248 css::uno::Reference< css::reflection::XTypeDescription >(
2249 new ServiceBasedSingletonDescription(
2250 this, name,
2251 static_cast< unoidl::ServiceBasedSingletonEntity * >(
2252 entity.get()))));
2253 default:
2254 for (;;) { std::abort(); } // this cannot happen
2258 css::uno::Any cppuhelper::TypeManager::getEnumMember(
2259 rtl::Reference< unoidl::EnumTypeEntity > const & entity,
2260 std::u16string_view member)
2262 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2263 [&member](const unoidl::EnumTypeEntity::Member& rMember) { return rMember.name == member; });
2264 if (i != entity->getMembers().end())
2265 return css::uno::Any(i->value);
2266 return css::uno::Any();
2269 css::uno::Any cppuhelper::TypeManager::getConstant(
2270 std::u16string_view constantGroupName,
2271 rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
2272 std::u16string_view member)
2274 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2275 [&member](const unoidl::ConstantGroupEntity::Member& rMember) { return rMember.name == member; });
2276 if (i != entity->getMembers().end())
2277 return css::uno::Any(
2278 css::uno::Reference< css::reflection::XTypeDescription >(
2279 new ConstantDescription(OUString(constantGroupName), *i)));
2280 return css::uno::Any();
2283 rtl::Reference< unoidl::Entity > cppuhelper::TypeManager::findEntity(
2284 OUString const & name)
2286 try {
2287 return manager_->findEntity(name);
2288 } catch (unoidl::FileFormatException & e) {
2289 throw css::uno::DeploymentException(
2290 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2291 + e.getDetail()),
2292 static_cast< cppu::OWeakObject * >(this));
2296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */