nss: upgrade to release 3.73
[LibreOffice.git] / cppuhelper / source / typemanager.cxx
blob194d746d9452623d9e9719aa7edefec60970813c
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 <set>
17 #include <stack>
18 #include <string_view>
19 #include <vector>
21 #include <com/sun/star/container/NoSuchElementException.hpp>
22 #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include <com/sun/star/reflection/NoSuchTypeNameException.hpp>
24 #include <com/sun/star/reflection/TypeDescriptionSearchDepth.hpp>
25 #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
26 #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
27 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
28 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
29 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
30 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
31 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
32 #include <com/sun/star/reflection/XModuleTypeDescription.hpp>
33 #include <com/sun/star/reflection/XPublished.hpp>
34 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
35 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
36 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
37 #include <com/sun/star/reflection/XTypeDescription.hpp>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <com/sun/star/uno/DeploymentException.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <com/sun/star/uno/RuntimeException.hpp>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/uno/Type.hxx>
44 #include <com/sun/star/uno/TypeClass.hpp>
45 #include <cppu/unotype.hxx>
46 #include <cppuhelper/implbase.hxx>
47 #include <cppuhelper/supportsservice.hxx>
48 #include <osl/file.hxx>
49 #include <osl/mutex.hxx>
50 #include <rtl/ref.hxx>
51 #include <rtl/ustring.hxx>
52 #include <sal/log.hxx>
53 #include <sal/macros.h>
54 #include <sal/types.h>
56 #include <unoidl/unoidl.hxx>
58 #include "paths.hxx"
59 #include "typemanager.hxx"
61 namespace {
63 OUString makePrefix(OUString const & name) {
64 return name.isEmpty() ? name : name + ".";
67 css::uno::Any resolveTypedefs(css::uno::Any const & type) {
68 for (css::uno::Any t(type);;) {
69 css::uno::Reference< css::reflection::XIndirectTypeDescription > ind(
70 type, css::uno::UNO_QUERY);
71 if (!ind.is() || ind->getTypeClass() != css::uno::TypeClass_TYPEDEF) {
72 return t;
74 t <<= ind->getReferencedType();
78 class SimpleTypeDescription:
79 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
81 public:
82 SimpleTypeDescription(
83 css::uno::TypeClass typeClass, OUString const & name):
84 typeClass_(typeClass), name_(name)
87 private:
88 virtual ~SimpleTypeDescription() override {}
90 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
91 { return typeClass_; }
93 virtual OUString SAL_CALL getName() override
94 { return name_; }
96 css::uno::TypeClass typeClass_;
97 OUString name_;
100 class SequenceTypeDescription:
101 public cppu::WeakImplHelper< css::reflection::XIndirectTypeDescription >
103 public:
104 SequenceTypeDescription(
105 rtl::Reference< cppuhelper::TypeManager > const & manager,
106 OUString const & name, OUString const & componentType):
107 manager_(manager), name_(name), componentType_(componentType)
108 { assert(manager.is()); }
110 private:
111 virtual ~SequenceTypeDescription() override {}
113 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
114 { return css::uno::TypeClass_SEQUENCE; }
116 virtual OUString SAL_CALL getName() override
117 { return name_; }
119 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
120 getReferencedType() override
121 { return manager_->resolve(componentType_); }
123 rtl::Reference< cppuhelper::TypeManager > manager_;
124 OUString name_;
125 OUString componentType_;
128 class PublishableDescription:
129 public cppu::WeakImplHelper< css::reflection::XPublished >
131 protected:
132 explicit PublishableDescription(bool published): published_(published) {}
134 virtual ~PublishableDescription() override {}
136 private:
137 virtual sal_Bool SAL_CALL isPublished() override
138 { return published_; }
140 bool published_;
143 class ModuleDescription:
144 public cppu::WeakImplHelper< css::reflection::XModuleTypeDescription >
146 public:
147 ModuleDescription(
148 rtl::Reference< cppuhelper::TypeManager > const & manager,
149 OUString const & name,
150 rtl::Reference< unoidl::ModuleEntity > const & entity):
151 manager_(manager), name_(name), entity_(entity)
152 { assert(manager.is()); assert(entity.is()); }
154 private:
155 virtual ~ModuleDescription() override {}
157 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
158 { return css::uno::TypeClass_MODULE; }
160 virtual OUString SAL_CALL getName() override
161 { return name_; }
163 virtual
164 css::uno::Sequence<
165 css::uno::Reference< css::reflection::XTypeDescription > >
166 SAL_CALL getMembers() override;
168 rtl::Reference< cppuhelper::TypeManager > manager_;
169 OUString name_;
170 rtl::Reference< unoidl::ModuleEntity > entity_;
173 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
174 ModuleDescription::getMembers() {
175 try {
176 std::vector< OUString > names(entity_->getMemberNames());
177 assert(names.size() <= SAL_MAX_INT32);
178 sal_Int32 n = static_cast< sal_Int32 >(names.size());
179 css::uno::Sequence<
180 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
181 for (sal_Int32 i = 0; i != n; ++i) {
182 s[i] = manager_->resolve(makePrefix(name_) + names[i]);
184 return s;
185 } catch (unoidl::FileFormatException & e) {
186 throw css::uno::DeploymentException(
187 e.getUri() + ": " + e.getDetail(),
188 static_cast< cppu::OWeakObject * >(this));
192 typedef cppu::ImplInheritanceHelper<
193 PublishableDescription, css::reflection::XEnumTypeDescription >
194 EnumTypeDescription_Base;
196 class EnumTypeDescription: public EnumTypeDescription_Base {
197 public:
198 EnumTypeDescription(
199 OUString const & name,
200 rtl::Reference< unoidl::EnumTypeEntity > const & entity):
201 EnumTypeDescription_Base(entity->isPublished()), name_(name),
202 entity_(entity)
203 { assert(entity.is()); }
205 private:
206 virtual ~EnumTypeDescription() override {}
208 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
209 { return css::uno::TypeClass_ENUM; }
211 virtual OUString SAL_CALL getName() override
212 { return name_; }
214 virtual sal_Int32 SAL_CALL getDefaultEnumValue() override
215 { return entity_->getMembers()[0].value; }
217 virtual css::uno::Sequence< OUString > SAL_CALL getEnumNames() override;
219 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getEnumValues() override;
221 OUString name_;
222 rtl::Reference< unoidl::EnumTypeEntity > entity_;
225 css::uno::Sequence< OUString > EnumTypeDescription::getEnumNames()
227 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
228 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
229 css::uno::Sequence< OUString > s(n);
230 for (sal_Int32 i = 0; i != n; ++i) {
231 s[i] = entity_->getMembers()[i].name;
233 return s;
236 css::uno::Sequence< sal_Int32 > EnumTypeDescription::getEnumValues()
238 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
239 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
240 css::uno::Sequence< sal_Int32 > s(n);
241 for (sal_Int32 i = 0; i != n; ++i) {
242 s[i] = entity_->getMembers()[i].value;
244 return s;
247 typedef cppu::ImplInheritanceHelper<
248 PublishableDescription, css::reflection::XStructTypeDescription >
249 PlainStructTypeDescription_Base;
251 class PlainStructTypeDescription: public PlainStructTypeDescription_Base {
252 public:
253 PlainStructTypeDescription(
254 rtl::Reference< cppuhelper::TypeManager > const & manager,
255 OUString const & name,
256 rtl::Reference< unoidl::PlainStructTypeEntity > const & entity):
257 PlainStructTypeDescription_Base(entity->isPublished()),
258 manager_(manager), name_(name), entity_(entity)
259 { assert(manager.is()); assert(entity.is()); }
261 private:
262 virtual ~PlainStructTypeDescription() override {}
264 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
265 { return css::uno::TypeClass_STRUCT; }
267 virtual OUString SAL_CALL getName() override
268 { return name_; }
270 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
271 getBaseType() override {
272 return entity_->getDirectBase().isEmpty()
273 ? css::uno::Reference< css::reflection::XTypeDescription >()
274 : manager_->resolve(entity_->getDirectBase());
277 virtual
278 css::uno::Sequence<
279 css::uno::Reference< css::reflection::XTypeDescription > >
280 SAL_CALL getMemberTypes() override;
282 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
284 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
285 { return css::uno::Sequence< OUString >(); }
287 virtual
288 css::uno::Sequence<
289 css::uno::Reference< css::reflection::XTypeDescription > >
290 SAL_CALL getTypeArguments() override {
291 return css::uno::Sequence<
292 css::uno::Reference< css::reflection::XTypeDescription > >();
295 rtl::Reference< cppuhelper::TypeManager > manager_;
296 OUString name_;
297 rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
300 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
301 PlainStructTypeDescription::getMemberTypes()
303 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
304 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
305 css::uno::Sequence<
306 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
307 for (sal_Int32 i = 0; i != n; ++i) {
308 s[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
310 return s;
313 css::uno::Sequence< OUString > PlainStructTypeDescription::getMemberNames()
315 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
316 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
317 css::uno::Sequence< OUString > s(n);
318 for (sal_Int32 i = 0; i != n; ++i) {
319 s[i] = entity_->getDirectMembers()[i].name;
321 return s;
324 class ParameterizedMemberTypeDescription:
325 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
327 public:
328 explicit ParameterizedMemberTypeDescription(
329 OUString const & typeParameterName):
330 typeParameterName_(typeParameterName)
333 private:
334 virtual ~ParameterizedMemberTypeDescription() override {}
336 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
337 { return css::uno::TypeClass_UNKNOWN; }
339 virtual OUString SAL_CALL getName() override
340 { return typeParameterName_; }
342 OUString typeParameterName_;
345 typedef cppu::ImplInheritanceHelper<
346 PublishableDescription, css::reflection::XStructTypeDescription >
347 PolymorphicStructTypeTemplateDescription_Base;
349 class PolymorphicStructTypeTemplateDescription:
350 public PolymorphicStructTypeTemplateDescription_Base
352 public:
353 PolymorphicStructTypeTemplateDescription(
354 rtl::Reference< cppuhelper::TypeManager > const & manager,
355 OUString const & name,
356 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
357 entity):
358 PolymorphicStructTypeTemplateDescription_Base(entity->isPublished()),
359 manager_(manager), name_(name), entity_(entity)
360 { assert(manager.is()); assert(entity.is()); }
362 private:
363 virtual ~PolymorphicStructTypeTemplateDescription() override {}
365 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
366 { return css::uno::TypeClass_STRUCT; }
368 virtual OUString SAL_CALL getName() override
369 { return name_; }
371 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
372 getBaseType() override
373 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
375 virtual
376 css::uno::Sequence<
377 css::uno::Reference< css::reflection::XTypeDescription > >
378 SAL_CALL getMemberTypes() override;
380 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
382 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override;
384 virtual
385 css::uno::Sequence<
386 css::uno::Reference< css::reflection::XTypeDescription > >
387 SAL_CALL getTypeArguments() override {
388 return css::uno::Sequence<
389 css::uno::Reference< css::reflection::XTypeDescription > >();
392 rtl::Reference< cppuhelper::TypeManager > manager_;
393 OUString name_;
394 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
397 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
398 PolymorphicStructTypeTemplateDescription::getMemberTypes()
400 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
401 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
402 css::uno::Sequence<
403 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
404 for (sal_Int32 i = 0; i != n; ++i) {
405 s[i] = entity_->getMembers()[i].parameterized
406 ? new ParameterizedMemberTypeDescription(
407 entity_->getMembers()[i].type)
408 : manager_->resolve(entity_->getMembers()[i].type);
410 return s;
413 css::uno::Sequence< OUString >
414 PolymorphicStructTypeTemplateDescription::getMemberNames()
416 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
417 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
418 css::uno::Sequence< OUString > s(n);
419 for (sal_Int32 i = 0; i != n; ++i) {
420 s[i] = entity_->getMembers()[i].name;
422 return s;
425 css::uno::Sequence< OUString >
426 PolymorphicStructTypeTemplateDescription::getTypeParameters()
428 assert(entity_->getTypeParameters().size() <= SAL_MAX_INT32);
429 sal_Int32 n = static_cast< sal_Int32 >(entity_->getTypeParameters().size());
430 css::uno::Sequence< OUString > s(n);
431 for (sal_Int32 i = 0; i != n; ++i) {
432 s[i] = entity_->getTypeParameters()[i];
434 return s;
437 class InstantiatedPolymorphicStructTypeDescription:
438 public cppu::WeakImplHelper< css::reflection::XStructTypeDescription >
440 public:
441 InstantiatedPolymorphicStructTypeDescription(
442 rtl::Reference< cppuhelper::TypeManager > const & manager,
443 OUString const & name,
444 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
445 entity,
446 std::vector< OUString > const & arguments):
447 manager_(manager), name_(name), entity_(entity), arguments_(arguments)
449 assert(manager.is());
450 assert(entity.is());
451 assert(arguments.size() == entity->getTypeParameters().size());
454 private:
455 virtual ~InstantiatedPolymorphicStructTypeDescription() override {}
457 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
458 { return css::uno::TypeClass_STRUCT; }
460 virtual OUString SAL_CALL getName() override
461 { return name_; }
463 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
464 getBaseType() override
465 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
467 virtual
468 css::uno::Sequence<
469 css::uno::Reference< css::reflection::XTypeDescription > >
470 SAL_CALL getMemberTypes() override;
472 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
474 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
475 { return css::uno::Sequence< OUString >(); }
477 virtual
478 css::uno::Sequence<
479 css::uno::Reference< css::reflection::XTypeDescription > >
480 SAL_CALL getTypeArguments() override;
482 rtl::Reference< cppuhelper::TypeManager > manager_;
483 OUString name_;
484 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
485 std::vector< OUString > arguments_;
488 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
489 InstantiatedPolymorphicStructTypeDescription::getMemberTypes()
491 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
492 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
493 css::uno::Sequence<
494 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
495 for (sal_Int32 i = 0; i != n; ++i) {
496 OUString type(entity_->getMembers()[i].type);
497 if (entity_->getMembers()[i].parameterized) {
498 auto j = std::find(entity_->getTypeParameters().begin(), entity_->getTypeParameters().end(), type);
499 if (j != entity_->getTypeParameters().end()) {
500 type = arguments_[j - entity_->getTypeParameters().begin()];
501 goto found;
503 assert(false); // this cannot happen //TODO!
504 found:;
506 s[i] = manager_->resolve(type);
508 return s;
511 css::uno::Sequence< OUString >
512 InstantiatedPolymorphicStructTypeDescription::getMemberNames()
514 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
515 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
516 css::uno::Sequence< OUString > s(n);
517 for (sal_Int32 i = 0; i != n; ++i) {
518 s[i] = entity_->getMembers()[i].name;
520 return s;
522 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
523 InstantiatedPolymorphicStructTypeDescription::getTypeArguments()
525 assert(arguments_.size() <= SAL_MAX_INT32);
526 sal_Int32 n = static_cast< sal_Int32 >(arguments_.size());
527 css::uno::Sequence<
528 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
529 for (sal_Int32 i = 0; i != n; ++i) {
530 s[i] = manager_->resolve(arguments_[i]);
532 return s;
535 typedef cppu::ImplInheritanceHelper<
536 PublishableDescription, css::reflection::XCompoundTypeDescription >
537 ExceptionTypeDescription_Base;
539 class ExceptionTypeDescription: public ExceptionTypeDescription_Base {
540 public:
541 ExceptionTypeDescription(
542 rtl::Reference< cppuhelper::TypeManager > const & manager,
543 OUString const & name,
544 rtl::Reference< unoidl::ExceptionTypeEntity > const & entity):
545 ExceptionTypeDescription_Base(entity->isPublished()), manager_(manager),
546 name_(name), entity_(entity)
547 { assert(manager.is()); assert(entity.is()); }
549 private:
550 virtual ~ExceptionTypeDescription() override {}
552 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
553 { return css::uno::TypeClass_EXCEPTION; }
555 virtual OUString SAL_CALL getName() override
556 { return name_; }
558 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
559 getBaseType() override {
560 return entity_->getDirectBase().isEmpty()
561 ? css::uno::Reference< css::reflection::XTypeDescription >()
562 : manager_->resolve(entity_->getDirectBase());
565 virtual
566 css::uno::Sequence<
567 css::uno::Reference< css::reflection::XTypeDescription > >
568 SAL_CALL getMemberTypes() override;
570 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
572 rtl::Reference< cppuhelper::TypeManager > manager_;
573 OUString name_;
574 rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
577 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
578 ExceptionTypeDescription::getMemberTypes() {
579 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
580 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
581 css::uno::Sequence<
582 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
583 for (sal_Int32 i = 0; i != n; ++i) {
584 s[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
586 return s;
589 css::uno::Sequence< OUString > ExceptionTypeDescription::getMemberNames()
591 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
592 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
593 css::uno::Sequence< OUString > s(n);
594 for (sal_Int32 i = 0; i != n; ++i) {
595 s[i] = entity_->getDirectMembers()[i].name;
597 return s;
600 class AttributeDescription:
601 public cppu::WeakImplHelper<
602 css::reflection::XInterfaceAttributeTypeDescription2 >
604 public:
605 AttributeDescription(
606 rtl::Reference< cppuhelper::TypeManager > const & manager,
607 OUString const & name,
608 unoidl::InterfaceTypeEntity::Attribute const & attribute,
609 sal_Int32 position):
610 manager_(manager), name_(name), attribute_(attribute),
611 position_(position)
612 { assert(manager.is()); }
614 private:
615 virtual ~AttributeDescription() override {}
617 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
618 { return css::uno::TypeClass_INTERFACE_ATTRIBUTE; }
620 virtual OUString SAL_CALL getName() override
621 { return name_; }
623 virtual OUString SAL_CALL getMemberName() override
624 { return attribute_.name; }
626 virtual sal_Int32 SAL_CALL getPosition() override
627 { return position_; }
629 virtual sal_Bool SAL_CALL isReadOnly() override
630 { return attribute_.readOnly; }
632 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
633 getType() override
634 { return manager_->resolve(attribute_.type); }
636 virtual sal_Bool SAL_CALL isBound() override
637 { return attribute_.bound; }
639 virtual
640 css::uno::Sequence<
641 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
642 SAL_CALL getGetExceptions() override;
644 virtual
645 css::uno::Sequence<
646 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
647 SAL_CALL getSetExceptions() override;
649 rtl::Reference< cppuhelper::TypeManager > manager_;
650 OUString name_;
651 unoidl::InterfaceTypeEntity::Attribute attribute_;
652 sal_Int32 position_;
655 css::uno::Sequence<
656 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
657 AttributeDescription::getGetExceptions() {
658 assert(attribute_.getExceptions.size() <= SAL_MAX_INT32);
659 sal_Int32 n = static_cast< sal_Int32 >(attribute_.getExceptions.size());
660 css::uno::Sequence<
661 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
662 for (sal_Int32 i = 0; i != n; ++i) {
663 s[i].set(
664 manager_->resolve(attribute_.getExceptions[i]),
665 css::uno::UNO_QUERY_THROW);
667 return s;
670 css::uno::Sequence<
671 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
672 AttributeDescription::getSetExceptions() {
673 assert(attribute_.setExceptions.size() <= SAL_MAX_INT32);
674 sal_Int32 n = static_cast< sal_Int32 >(attribute_.setExceptions.size());
675 css::uno::Sequence<
676 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
677 for (sal_Int32 i = 0; i != n; ++i) {
678 s[i].set(
679 manager_->resolve(attribute_.setExceptions[i]),
680 css::uno::UNO_QUERY_THROW);
682 return s;
685 class MethodParameter:
686 public cppu::WeakImplHelper< css::reflection::XMethodParameter >
688 public:
689 MethodParameter(
690 rtl::Reference< cppuhelper::TypeManager > const & manager,
691 unoidl::InterfaceTypeEntity::Method::Parameter const & parameter,
692 sal_Int32 position):
693 manager_(manager), parameter_(parameter), position_(position)
694 { assert(manager.is()); }
696 private:
697 virtual ~MethodParameter() override {}
699 virtual OUString SAL_CALL getName() override
700 { return parameter_.name; }
702 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
703 getType() override
704 { return manager_->resolve(parameter_.type); }
706 virtual sal_Bool SAL_CALL isIn() override {
707 return
708 (parameter_.direction
709 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
710 || (parameter_.direction
711 == unoidl::InterfaceTypeEntity::Method::Parameter::
712 DIRECTION_IN_OUT);
715 virtual sal_Bool SAL_CALL isOut() override {
716 return
717 (parameter_.direction
718 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT)
719 || (parameter_.direction
720 == unoidl::InterfaceTypeEntity::Method::Parameter::
721 DIRECTION_IN_OUT);
724 virtual sal_Int32 SAL_CALL getPosition() override
725 { return position_; }
727 rtl::Reference< cppuhelper::TypeManager > manager_;
728 unoidl::InterfaceTypeEntity::Method::Parameter parameter_;
729 sal_Int32 position_;
732 class MethodDescription:
733 public cppu::WeakImplHelper<
734 css::reflection::XInterfaceMethodTypeDescription >
736 public:
737 MethodDescription(
738 rtl::Reference< cppuhelper::TypeManager > const & manager,
739 OUString const & name,
740 unoidl::InterfaceTypeEntity::Method const & method, sal_Int32 position):
741 manager_(manager), name_(name), method_(method), position_(position)
742 { assert(manager.is()); }
744 private:
745 virtual ~MethodDescription() override {}
747 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
748 { return css::uno::TypeClass_INTERFACE_METHOD; }
750 virtual OUString SAL_CALL getName() override
751 { return name_; }
753 virtual OUString SAL_CALL getMemberName() override
754 { return method_.name; }
756 virtual sal_Int32 SAL_CALL getPosition() override
757 { return position_; }
759 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
760 getReturnType() override
761 { return manager_->resolve(method_.returnType); }
763 virtual sal_Bool SAL_CALL isOneway() override
764 { return false; }
766 virtual
767 css::uno::Sequence<
768 css::uno::Reference< css::reflection::XMethodParameter > >
769 SAL_CALL getParameters() override;
771 virtual
772 css::uno::Sequence<
773 css::uno::Reference< css::reflection::XTypeDescription > >
774 SAL_CALL getExceptions() override;
776 rtl::Reference< cppuhelper::TypeManager > manager_;
777 OUString name_;
778 unoidl::InterfaceTypeEntity::Method method_;
779 sal_Int32 position_;
782 css::uno::Sequence< css::uno::Reference< css::reflection::XMethodParameter > >
783 MethodDescription::getParameters() {
784 assert(method_.parameters.size() <= SAL_MAX_INT32);
785 sal_Int32 n = static_cast< sal_Int32 >(method_.parameters.size());
786 css::uno::Sequence<
787 css::uno::Reference< css::reflection::XMethodParameter > > s(n);
788 for (sal_Int32 i = 0; i != n; ++i) {
789 s[i] = new MethodParameter(manager_, method_.parameters[i], i);
791 return s;
794 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
795 MethodDescription::getExceptions() {
796 assert(method_.exceptions.size() <= SAL_MAX_INT32);
797 sal_Int32 n = static_cast< sal_Int32 >(method_.exceptions.size());
798 css::uno::Sequence<
799 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
800 for (sal_Int32 i = 0; i != n; ++i) {
801 s[i] = manager_->resolve(method_.exceptions[i]);
803 return s;
806 class BaseOffset {
807 public:
808 explicit BaseOffset(
809 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
810 const & description);
812 BaseOffset(const BaseOffset&) = delete;
813 const BaseOffset& operator=(const BaseOffset&) = delete;
815 sal_Int32 get() const { return offset_; }
817 private:
818 void calculateBases(
819 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
820 const & description);
822 void calculate(
823 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
824 const & description);
826 std::set< OUString > set_;
827 sal_Int32 offset_;
830 BaseOffset::BaseOffset(
831 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
832 description):
833 offset_(0)
835 calculateBases(description);
838 void BaseOffset::calculateBases(
839 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
840 description)
842 const css::uno::Sequence<
843 css::uno::Reference < css::reflection::XTypeDescription > > bases(
844 description->getBaseTypes());
845 for (const auto & i : bases) {
846 calculate(
847 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >(
848 resolveTypedefs(css::uno::makeAny(i)),
849 css::uno::UNO_QUERY_THROW));
853 void BaseOffset::calculate(
854 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
855 description)
857 if (set_.insert(description->getName()).second) {
858 calculateBases(description);
859 offset_ += description->getMembers().getLength();
863 typedef cppu::ImplInheritanceHelper<
864 PublishableDescription, css::reflection::XInterfaceTypeDescription2 >
865 InterfaceTypeDescription_Base;
867 class InterfaceTypeDescription: public InterfaceTypeDescription_Base {
868 public:
869 InterfaceTypeDescription(
870 rtl::Reference< cppuhelper::TypeManager > const & manager,
871 OUString const & name,
872 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
873 InterfaceTypeDescription_Base(entity->isPublished()), manager_(manager),
874 name_(name), entity_(entity)
875 { assert(manager.is()); assert(entity.is()); }
877 private:
878 virtual ~InterfaceTypeDescription() override {}
880 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
881 { return css::uno::TypeClass_INTERFACE; }
883 virtual OUString SAL_CALL getName() override
884 { return name_; }
886 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
887 getBaseType() override {
888 return entity_->getDirectMandatoryBases().empty()
889 ? css::uno::Reference< css::reflection::XTypeDescription >()
890 : manager_->resolve(entity_->getDirectMandatoryBases()[0].name);
893 virtual css::uno::Uik SAL_CALL getUik() override
894 { return css::uno::Uik(); }
896 virtual
897 css::uno::Sequence<
898 css::uno::Reference<
899 css::reflection::XInterfaceMemberTypeDescription > >
900 SAL_CALL getMembers() override;
902 virtual
903 css::uno::Sequence<
904 css::uno::Reference< css::reflection::XTypeDescription > >
905 SAL_CALL getBaseTypes() override;
907 virtual
908 css::uno::Sequence<
909 css::uno::Reference< css::reflection::XTypeDescription > >
910 SAL_CALL getOptionalBaseTypes() override;
912 rtl::Reference< cppuhelper::TypeManager > manager_;
913 OUString name_;
914 rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
917 css::uno::Sequence<
918 css::uno::Reference< css::reflection::XInterfaceMemberTypeDescription > >
919 InterfaceTypeDescription::getMembers() {
920 assert(
921 entity_->getDirectAttributes().size() <= SAL_MAX_INT32
922 && (entity_->getDirectMethods().size()
923 <= SAL_MAX_INT32 - entity_->getDirectAttributes().size()));
924 sal_Int32 n1 = static_cast< sal_Int32 >(
925 entity_->getDirectAttributes().size());
926 sal_Int32 n2 = static_cast< sal_Int32 >(entity_->getDirectMethods().size());
927 css::uno::Sequence<
928 css::uno::Reference<
929 css::reflection::XInterfaceMemberTypeDescription > > s(n1 + n2);
930 sal_Int32 off = BaseOffset(this).get();
931 for (sal_Int32 i = 0; i != n1; ++i) {
932 s[i] = new AttributeDescription(
933 manager_, name_ + "::" + entity_->getDirectAttributes()[i].name,
934 entity_->getDirectAttributes()[i], off + i);
936 for (sal_Int32 i = 0; i != n2; ++i) {
937 s[n1 + i] = new MethodDescription(
938 manager_, name_ + "::" + entity_->getDirectMethods()[i].name,
939 entity_->getDirectMethods()[i], off + n1 + i);
941 return s;
944 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
945 InterfaceTypeDescription::getBaseTypes() {
946 assert(entity_->getDirectMandatoryBases().size() <= SAL_MAX_INT32);
947 sal_Int32 n = static_cast< sal_Int32 >(
948 entity_->getDirectMandatoryBases().size());
949 css::uno::Sequence<
950 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
951 for (sal_Int32 i = 0; i != n; ++i) {
952 s[i] = manager_->resolve(entity_->getDirectMandatoryBases()[i].name);
954 return s;
957 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
958 InterfaceTypeDescription::getOptionalBaseTypes()
960 assert(entity_->getDirectOptionalBases().size() <= SAL_MAX_INT32);
961 sal_Int32 n = static_cast< sal_Int32 >(
962 entity_->getDirectOptionalBases().size());
963 css::uno::Sequence<
964 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
965 for (sal_Int32 i = 0; i != n; ++i) {
966 s[i] = manager_->resolve(entity_->getDirectOptionalBases()[i].name);
968 return s;
971 class ConstantDescription:
972 public cppu::WeakImplHelper< css::reflection::XConstantTypeDescription >
974 public:
975 ConstantDescription(
976 OUString const & constantGroupName,
977 unoidl::ConstantGroupEntity::Member const & member);
979 private:
980 virtual ~ConstantDescription() override {}
982 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
983 { return css::uno::TypeClass_CONSTANT; }
985 virtual OUString SAL_CALL getName() override
986 { return name_; }
988 virtual css::uno::Any SAL_CALL getConstantValue() override
989 { return value_; }
991 OUString name_;
992 css::uno::Any value_;
995 ConstantDescription::ConstantDescription(
996 OUString const & constantGroupName,
997 unoidl::ConstantGroupEntity::Member const & member):
998 name_(makePrefix(constantGroupName) + member.name)
1000 switch (member.value.type) {
1001 case unoidl::ConstantValue::TYPE_BOOLEAN:
1002 value_ <<= member.value.booleanValue;
1003 break;
1004 case unoidl::ConstantValue::TYPE_BYTE:
1005 value_ <<= member.value.byteValue;
1006 break;
1007 case unoidl::ConstantValue::TYPE_SHORT:
1008 value_ <<= member.value.shortValue;
1009 break;
1010 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1011 value_ <<= member.value.unsignedShortValue;
1012 break;
1013 case unoidl::ConstantValue::TYPE_LONG:
1014 value_ <<= member.value.longValue;
1015 break;
1016 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1017 value_ <<= member.value.unsignedLongValue;
1018 break;
1019 case unoidl::ConstantValue::TYPE_HYPER:
1020 value_ <<= member.value.hyperValue;
1021 break;
1022 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1023 value_ <<= member.value.unsignedHyperValue;
1024 break;
1025 case unoidl::ConstantValue::TYPE_FLOAT:
1026 value_ <<= member.value.floatValue;
1027 break;
1028 case unoidl::ConstantValue::TYPE_DOUBLE:
1029 value_ <<= member.value.doubleValue;
1030 break;
1031 default:
1032 for (;;) { std::abort(); } // this cannot happen
1036 typedef cppu::ImplInheritanceHelper<
1037 PublishableDescription, css::reflection::XConstantsTypeDescription >
1038 ConstantGroupDescription_Base;
1040 class ConstantGroupDescription: public ConstantGroupDescription_Base {
1041 public:
1042 ConstantGroupDescription(
1043 OUString const & name,
1044 rtl::Reference< unoidl::ConstantGroupEntity > const & entity):
1045 ConstantGroupDescription_Base(entity->isPublished()), name_(name),
1046 entity_(entity)
1047 { assert(entity.is()); }
1049 private:
1050 virtual ~ConstantGroupDescription() override {}
1052 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1053 { return css::uno::TypeClass_CONSTANTS; }
1055 virtual OUString SAL_CALL getName() override
1056 { return name_; }
1058 virtual
1059 css::uno::Sequence<
1060 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1061 SAL_CALL getConstants() override;
1063 OUString name_;
1064 rtl::Reference< unoidl::ConstantGroupEntity > entity_;
1067 css::uno::Sequence<
1068 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1069 ConstantGroupDescription::getConstants() {
1070 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
1071 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
1072 css::uno::Sequence<
1073 css::uno::Reference< css::reflection::XConstantTypeDescription > > s(n);
1074 for (sal_Int32 i = 0; i != n; ++i) {
1075 s[i] = new ConstantDescription(name_, entity_->getMembers()[i]);
1077 return s;
1080 typedef cppu::ImplInheritanceHelper<
1081 PublishableDescription, css::reflection::XIndirectTypeDescription >
1082 TypedefDescription_Base;
1084 class TypedefDescription: public TypedefDescription_Base {
1085 public:
1086 TypedefDescription(
1087 rtl::Reference< cppuhelper::TypeManager > const & manager,
1088 OUString const & name,
1089 rtl::Reference< unoidl::TypedefEntity > const & entity):
1090 TypedefDescription_Base(entity->isPublished()), manager_(manager),
1091 name_(name), entity_(entity)
1092 { assert(manager.is()); assert(entity.is()); }
1094 private:
1095 virtual ~TypedefDescription() override {}
1097 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1098 { return css::uno::TypeClass_TYPEDEF; }
1100 virtual OUString SAL_CALL getName() override
1101 { return name_; }
1103 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1104 getReferencedType() override
1105 { return manager_->resolve(entity_->getType()); }
1107 rtl::Reference< cppuhelper::TypeManager > manager_;
1108 OUString name_;
1109 rtl::Reference< unoidl::TypedefEntity > entity_;
1112 class ConstructorParameter:
1113 public cppu::WeakImplHelper< css::reflection::XParameter >
1115 public:
1116 ConstructorParameter(
1117 rtl::Reference< cppuhelper::TypeManager > const & manager,
1118 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1119 const & parameter,
1120 sal_Int32 position):
1121 manager_(manager), parameter_(parameter), position_(position)
1122 { assert(manager.is()); }
1124 private:
1125 virtual ~ConstructorParameter() override {}
1127 virtual OUString SAL_CALL getName() override
1128 { return parameter_.name; }
1130 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1131 getType() override
1132 { return manager_->resolve(parameter_.type); }
1134 virtual sal_Bool SAL_CALL isIn() override
1135 { return true; }
1137 virtual sal_Bool SAL_CALL isOut() override
1138 { return false; }
1140 virtual sal_Int32 SAL_CALL getPosition() override
1141 { return position_; }
1143 virtual sal_Bool SAL_CALL isRestParameter() override
1144 { return parameter_.rest; }
1146 rtl::Reference< cppuhelper::TypeManager > manager_;
1147 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1148 parameter_;
1149 sal_Int32 position_;
1152 class ConstructorDescription:
1153 public cppu::WeakImplHelper<
1154 css::reflection::XServiceConstructorDescription >
1156 public:
1157 ConstructorDescription(
1158 rtl::Reference< cppuhelper::TypeManager > const & manager,
1159 unoidl::SingleInterfaceBasedServiceEntity::Constructor const &
1160 constructor):
1161 manager_(manager), constructor_(constructor)
1162 { assert(manager.is()); }
1164 private:
1165 virtual ~ConstructorDescription() override {}
1167 virtual sal_Bool SAL_CALL isDefaultConstructor() override
1168 { return constructor_.defaultConstructor; }
1170 virtual OUString SAL_CALL getName() override
1171 { return constructor_.name; }
1173 virtual
1174 css::uno::Sequence<
1175 css::uno::Reference< css::reflection::XParameter > >
1176 SAL_CALL getParameters() override;
1178 virtual
1179 css::uno::Sequence<
1180 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1181 SAL_CALL getExceptions() override;
1183 rtl::Reference< cppuhelper::TypeManager > manager_;
1184 unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor_;
1187 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
1188 ConstructorDescription::getParameters() {
1189 assert(constructor_.parameters.size() <= SAL_MAX_INT32);
1190 sal_Int32 n = static_cast< sal_Int32 >(constructor_.parameters.size());
1191 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > s(
1193 for (sal_Int32 i = 0; i != n; ++i) {
1194 s[i] = new ConstructorParameter(
1195 manager_, constructor_.parameters[i], i);
1197 return s;
1200 css::uno::Sequence<
1201 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1202 ConstructorDescription::getExceptions() {
1203 assert(constructor_.exceptions.size() <= SAL_MAX_INT32);
1204 sal_Int32 n = static_cast< sal_Int32 >(constructor_.exceptions.size());
1205 css::uno::Sequence<
1206 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
1207 for (sal_Int32 i = 0; i != n; ++i) {
1208 s[i].set(
1209 manager_->resolve(constructor_.exceptions[i]),
1210 css::uno::UNO_QUERY_THROW);
1212 return s;
1215 typedef cppu::ImplInheritanceHelper<
1216 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1217 SingleInterfaceBasedServiceDescription_Base;
1219 class SingleInterfaceBasedServiceDescription:
1220 public SingleInterfaceBasedServiceDescription_Base
1222 public:
1223 SingleInterfaceBasedServiceDescription(
1224 rtl::Reference< cppuhelper::TypeManager > const & manager,
1225 OUString const & name,
1226 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
1227 entity):
1228 SingleInterfaceBasedServiceDescription_Base(entity->isPublished()),
1229 manager_(manager), name_(name), entity_(entity)
1230 { assert(manager.is()); assert(entity.is()); }
1232 private:
1233 virtual ~SingleInterfaceBasedServiceDescription() override {}
1235 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1236 { return css::uno::TypeClass_SERVICE; }
1238 virtual OUString SAL_CALL getName() override
1239 { return name_; }
1241 virtual
1242 css::uno::Sequence<
1243 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1244 SAL_CALL getMandatoryServices() override
1246 return css::uno::Sequence<
1247 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1250 virtual
1251 css::uno::Sequence<
1252 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1253 SAL_CALL getOptionalServices() override
1255 return css::uno::Sequence<
1256 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1259 virtual
1260 css::uno::Sequence<
1261 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1262 SAL_CALL getMandatoryInterfaces() override
1264 return css::uno::Sequence<
1265 css::uno::Reference<
1266 css::reflection::XInterfaceTypeDescription > >();
1269 virtual
1270 css::uno::Sequence<
1271 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1272 SAL_CALL getOptionalInterfaces() override
1274 return css::uno::Sequence<
1275 css::uno::Reference<
1276 css::reflection::XInterfaceTypeDescription > >();
1279 virtual
1280 css::uno::Sequence<
1281 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1282 SAL_CALL getProperties() override
1284 return css::uno::Sequence<
1285 css::uno::Reference<
1286 css::reflection::XPropertyTypeDescription > >();
1289 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1290 { return true; }
1292 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1293 getInterface() override
1294 { return manager_->resolve(entity_->getBase()); }
1296 virtual
1297 css::uno::Sequence<
1298 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1299 SAL_CALL getConstructors() override;
1301 rtl::Reference< cppuhelper::TypeManager > manager_;
1302 OUString name_;
1303 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
1306 css::uno::Sequence<
1307 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1308 SingleInterfaceBasedServiceDescription::getConstructors()
1310 assert(entity_->getConstructors().size() <= SAL_MAX_INT32);
1311 sal_Int32 n = static_cast< sal_Int32 >(entity_->getConstructors().size());
1312 css::uno::Sequence<
1313 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1314 s(n);
1315 for (sal_Int32 i = 0; i != n; ++i) {
1316 s[i] = new ConstructorDescription(
1317 manager_, entity_->getConstructors()[i]);
1319 return s;
1322 class PropertyDescription:
1323 public cppu::WeakImplHelper< css::reflection::XPropertyTypeDescription >
1325 public:
1326 PropertyDescription(
1327 rtl::Reference< cppuhelper::TypeManager > const & manager,
1328 unoidl::AccumulationBasedServiceEntity::Property const & property):
1329 manager_(manager), property_(property)
1330 { assert(manager.is()); }
1332 private:
1333 virtual ~PropertyDescription() override {}
1335 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1336 { return css::uno::TypeClass_PROPERTY; }
1338 virtual OUString SAL_CALL getName() override
1339 { return property_.name; }
1341 virtual sal_Int16 SAL_CALL getPropertyFlags() override
1342 { return property_.attributes; }
1344 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1345 getPropertyTypeDescription() override
1346 { return manager_->resolve(property_.type); }
1348 rtl::Reference< cppuhelper::TypeManager > manager_;
1349 unoidl::AccumulationBasedServiceEntity::Property property_;
1352 typedef cppu::ImplInheritanceHelper<
1353 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1354 AccumulationBasedServiceDescription_Base;
1356 class AccumulationBasedServiceDescription:
1357 public AccumulationBasedServiceDescription_Base
1359 public:
1360 AccumulationBasedServiceDescription(
1361 rtl::Reference< cppuhelper::TypeManager > const & manager,
1362 OUString const & name,
1363 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const &
1364 entity):
1365 AccumulationBasedServiceDescription_Base(entity->isPublished()),
1366 manager_(manager), name_(name), entity_(entity)
1367 { assert(manager.is()); assert(entity.is()); }
1369 private:
1370 virtual ~AccumulationBasedServiceDescription() override {}
1372 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1373 { return css::uno::TypeClass_SERVICE; }
1375 virtual OUString SAL_CALL getName() override
1376 { return name_; }
1378 virtual
1379 css::uno::Sequence<
1380 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1381 SAL_CALL getMandatoryServices() override;
1383 virtual
1384 css::uno::Sequence<
1385 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1386 SAL_CALL getOptionalServices() override;
1388 virtual
1389 css::uno::Sequence<
1390 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1391 SAL_CALL getMandatoryInterfaces() override;
1393 virtual
1394 css::uno::Sequence<
1395 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1396 SAL_CALL getOptionalInterfaces() override;
1398 virtual
1399 css::uno::Sequence<
1400 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1401 SAL_CALL getProperties() override;
1403 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1404 { return false; }
1406 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1407 getInterface() override
1408 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1410 virtual
1411 css::uno::Sequence<
1412 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1413 SAL_CALL getConstructors() override
1415 return css::uno::Sequence<
1416 css::uno::Reference<
1417 css::reflection::XServiceConstructorDescription > >();
1420 rtl::Reference< cppuhelper::TypeManager > manager_;
1421 OUString name_;
1422 rtl::Reference< unoidl::AccumulationBasedServiceEntity > entity_;
1425 css::uno::Sequence<
1426 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1427 AccumulationBasedServiceDescription::getMandatoryServices()
1429 assert(entity_->getDirectMandatoryBaseServices().size() <= SAL_MAX_INT32);
1430 sal_Int32 n = static_cast< sal_Int32 >(
1431 entity_->getDirectMandatoryBaseServices().size());
1432 css::uno::Sequence<
1433 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1434 for (sal_Int32 i = 0; i != n; ++i) {
1435 s[i].set(
1436 manager_->resolve(
1437 entity_->getDirectMandatoryBaseServices()[i].name),
1438 css::uno::UNO_QUERY_THROW);
1440 return s;
1443 css::uno::Sequence<
1444 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1445 AccumulationBasedServiceDescription::getOptionalServices()
1447 assert(entity_->getDirectOptionalBaseServices().size() <= SAL_MAX_INT32);
1448 sal_Int32 n = static_cast< sal_Int32 >(
1449 entity_->getDirectOptionalBaseServices().size());
1450 css::uno::Sequence<
1451 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1452 for (sal_Int32 i = 0; i != n; ++i) {
1453 s[i].set(
1454 manager_->resolve(entity_->getDirectOptionalBaseServices()[i].name),
1455 css::uno::UNO_QUERY_THROW);
1457 return s;
1460 css::uno::Sequence<
1461 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1462 AccumulationBasedServiceDescription::getMandatoryInterfaces()
1464 assert(entity_->getDirectMandatoryBaseInterfaces().size() <= SAL_MAX_INT32);
1465 sal_Int32 n = static_cast< sal_Int32 >(
1466 entity_->getDirectMandatoryBaseInterfaces().size());
1467 css::uno::Sequence<
1468 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1470 for (sal_Int32 i = 0; i != n; ++i) {
1471 s[i].set(
1472 resolveTypedefs(
1473 manager_->find(
1474 entity_->getDirectMandatoryBaseInterfaces()[i].name)),
1475 css::uno::UNO_QUERY_THROW);
1477 return s;
1480 css::uno::Sequence<
1481 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1482 AccumulationBasedServiceDescription::getOptionalInterfaces()
1484 assert(entity_->getDirectOptionalBaseInterfaces().size() <= SAL_MAX_INT32);
1485 sal_Int32 n = static_cast< sal_Int32 >(
1486 entity_->getDirectOptionalBaseInterfaces().size());
1487 css::uno::Sequence<
1488 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1490 for (sal_Int32 i = 0; i != n; ++i) {
1491 s[i].set(
1492 resolveTypedefs(
1493 manager_->find(
1494 entity_->getDirectOptionalBaseInterfaces()[i].name)),
1495 css::uno::UNO_QUERY_THROW);
1497 return s;
1500 css::uno::Sequence<
1501 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1502 AccumulationBasedServiceDescription::getProperties()
1504 assert(entity_->getDirectProperties().size() <= SAL_MAX_INT32);
1505 sal_Int32 n = static_cast< sal_Int32 >(
1506 entity_->getDirectProperties().size());
1507 css::uno::Sequence<
1508 css::uno::Reference< css::reflection::XPropertyTypeDescription > > s(n);
1509 for (sal_Int32 i = 0; i != n; ++i) {
1510 s[i] = new PropertyDescription(
1511 manager_, entity_->getDirectProperties()[i]);
1513 return s;
1516 typedef cppu::ImplInheritanceHelper<
1517 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1518 InterfaceBasedSingletonDescription_Base;
1520 class InterfaceBasedSingletonDescription:
1521 public InterfaceBasedSingletonDescription_Base
1523 public:
1524 InterfaceBasedSingletonDescription(
1525 rtl::Reference< cppuhelper::TypeManager > const & manager,
1526 OUString const & name,
1527 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity):
1528 InterfaceBasedSingletonDescription_Base(entity->isPublished()),
1529 manager_(manager), name_(name), entity_(entity)
1530 { assert(manager.is()); assert(entity.is()); }
1532 private:
1533 virtual ~InterfaceBasedSingletonDescription() override {}
1535 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1536 { return css::uno::TypeClass_SINGLETON; }
1538 virtual OUString SAL_CALL getName() override
1539 { return name_; }
1541 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1542 SAL_CALL getService() override
1544 return
1545 css::uno::Reference< css::reflection::XServiceTypeDescription >();
1548 virtual sal_Bool SAL_CALL isInterfaceBased() override
1549 { return true; }
1551 virtual css::uno::Reference< css::reflection::XTypeDescription >
1552 SAL_CALL getInterface() override
1553 { return manager_->resolve(entity_->getBase()); }
1555 rtl::Reference< cppuhelper::TypeManager > manager_;
1556 OUString name_;
1557 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
1560 typedef cppu::ImplInheritanceHelper<
1561 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1562 ServiceBasedSingletonDescription_Base;
1564 class ServiceBasedSingletonDescription:
1565 public ServiceBasedSingletonDescription_Base
1567 public:
1568 ServiceBasedSingletonDescription(
1569 rtl::Reference< cppuhelper::TypeManager > const & manager,
1570 OUString const & name,
1571 rtl::Reference< unoidl::ServiceBasedSingletonEntity > const & entity):
1572 ServiceBasedSingletonDescription_Base(entity->isPublished()),
1573 manager_(manager), name_(name), entity_(entity)
1574 { assert(manager.is()); assert(entity.is()); }
1576 private:
1577 virtual ~ServiceBasedSingletonDescription() override {}
1579 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1580 { return css::uno::TypeClass_SINGLETON; }
1582 virtual OUString SAL_CALL getName() override
1583 { return name_; }
1585 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1586 SAL_CALL getService() override
1588 return css::uno::Reference< css::reflection::XServiceTypeDescription >(
1589 manager_->resolve(entity_->getBase()), css::uno::UNO_QUERY_THROW);
1592 virtual sal_Bool SAL_CALL isInterfaceBased() override
1593 { return false; }
1595 virtual css::uno::Reference< css::reflection::XTypeDescription >
1596 SAL_CALL getInterface() override
1597 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1599 rtl::Reference< cppuhelper::TypeManager > manager_;
1600 OUString name_;
1601 rtl::Reference< unoidl::ServiceBasedSingletonEntity > entity_;
1604 class Enumeration:
1605 public cppu::WeakImplHelper< css::reflection::XTypeDescriptionEnumeration >
1607 public:
1608 Enumeration(
1609 rtl::Reference< cppuhelper::TypeManager > const & manager,
1610 OUString const & prefix,
1611 rtl::Reference< unoidl::MapCursor > const & cursor,
1612 css::uno::Sequence< css::uno::TypeClass > const & types, bool deep):
1613 manager_(manager), types_(types), deep_(deep)
1615 assert(manager.is());
1616 positions_.push(Position(prefix, cursor));
1617 findNextMatch();
1620 private:
1621 virtual ~Enumeration() override {}
1623 virtual sal_Bool SAL_CALL hasMoreElements() override
1624 { return !positions_.empty(); }
1626 virtual css::uno::Any SAL_CALL nextElement() override
1627 { return css::uno::makeAny(nextTypeDescription()); }
1629 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1630 nextTypeDescription() override;
1632 bool matches(css::uno::TypeClass tc) const;
1634 void findNextMatch();
1636 struct Position {
1637 Position(
1638 OUString const & thePrefix,
1639 rtl::Reference< unoidl::MapCursor > const & theCursor):
1640 prefix(thePrefix), cursor(theCursor)
1641 { assert(theCursor.is()); }
1643 Position(
1644 OUString const & thePrefix,
1645 rtl::Reference< unoidl::ConstantGroupEntity > const &
1646 theConstantGroup):
1647 prefix(thePrefix), constantGroup(theConstantGroup),
1648 constantGroupIndex(constantGroup->getMembers().begin())
1649 { assert(theConstantGroup.is()); }
1651 Position(Position const & other):
1652 prefix(other.prefix), cursor(other.cursor),
1653 constantGroup(other.constantGroup)
1655 if (constantGroup.is()) {
1656 constantGroupIndex = other.constantGroupIndex;
1660 OUString prefix;
1661 rtl::Reference< unoidl::MapCursor > cursor;
1662 rtl::Reference< unoidl::ConstantGroupEntity > constantGroup;
1663 std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator
1664 constantGroupIndex;
1667 rtl::Reference< cppuhelper::TypeManager > manager_;
1668 css::uno::Sequence< css::uno::TypeClass > types_;
1669 bool deep_;
1671 osl::Mutex mutex_;
1672 std::stack< Position > positions_;
1673 OUString current_;
1676 css::uno::Reference< css::reflection::XTypeDescription >
1677 Enumeration::nextTypeDescription()
1679 OUString name;
1681 osl::MutexGuard g(mutex_);
1682 if (positions_.empty()) {
1683 throw css::container::NoSuchElementException(
1684 "exhausted XTypeDescriptionEnumeration",
1685 static_cast< cppu::OWeakObject * >(this));
1687 name = current_;
1688 findNextMatch();
1690 return manager_->resolve(name);
1693 bool Enumeration::matches(css::uno::TypeClass tc) const {
1694 if (!types_.hasElements()) {
1695 return true;
1697 for (const auto & i : types_) {
1698 if (i == tc) {
1699 return true;
1702 return false;
1705 void Enumeration::findNextMatch() {
1706 try {
1707 for (;;) {
1708 assert(!positions_.empty());
1709 OUString name;
1710 if (positions_.top().cursor.is()) { // root or module
1711 rtl::Reference< unoidl::Entity > ent(
1712 positions_.top().cursor->getNext(&name));
1713 if (!ent.is()) {
1714 positions_.pop();
1715 if (positions_.empty()) {
1716 break;
1718 continue;
1720 name = positions_.top().prefix + name;
1721 css::uno::TypeClass tc;
1722 switch (ent->getSort()) {
1723 case unoidl::Entity::SORT_MODULE:
1724 tc = css::uno::TypeClass_MODULE;
1725 if (deep_) {
1726 positions_.push(
1727 Position(
1728 makePrefix(name),
1729 static_cast< unoidl::ModuleEntity * >(
1730 ent.get())->createCursor()));
1732 break;
1733 case unoidl::Entity::SORT_ENUM_TYPE:
1734 tc = css::uno::TypeClass_ENUM;
1735 break;
1736 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
1737 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
1738 tc = css::uno::TypeClass_STRUCT;
1739 break;
1740 case unoidl::Entity::SORT_EXCEPTION_TYPE:
1741 tc = css::uno::TypeClass_EXCEPTION;
1742 break;
1743 case unoidl::Entity::SORT_INTERFACE_TYPE:
1744 tc = css::uno::TypeClass_INTERFACE;
1745 break;
1746 case unoidl::Entity::SORT_TYPEDEF:
1747 tc = css::uno::TypeClass_TYPEDEF;
1748 break;
1749 case unoidl::Entity::SORT_CONSTANT_GROUP:
1750 tc = css::uno::TypeClass_CONSTANTS;
1751 if (deep_ && matches(css::uno::TypeClass_CONSTANT)) {
1752 positions_.push(
1753 Position(
1754 makePrefix(name),
1755 static_cast< unoidl::ConstantGroupEntity * >(
1756 ent.get())));
1758 break;
1759 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
1760 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
1761 tc = css::uno::TypeClass_SERVICE;
1762 break;
1763 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
1764 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
1765 tc = css::uno::TypeClass_SINGLETON;
1766 break;
1767 default:
1768 for (;;) { std::abort(); } // this cannot happen
1770 if (matches(tc)) {
1771 current_ = name;
1772 break;
1774 } else { // constant group
1775 if (positions_.top().constantGroupIndex
1776 == positions_.top().constantGroup->getMembers().end())
1778 positions_.pop();
1779 if (positions_.empty()) {
1780 break;
1782 continue;
1784 current_ = positions_.top().prefix
1785 + positions_.top().constantGroupIndex++->name;
1786 break;
1789 } catch (unoidl::FileFormatException & e) {
1790 throw css::uno::DeploymentException(
1791 e.getUri() + ": " + e.getDetail(),
1792 static_cast< cppu::OWeakObject * >(this));
1798 cppuhelper::TypeManager::TypeManager():
1799 TypeManager_Base(m_aMutex),
1800 manager_(new unoidl::Manager)
1803 css::uno::Any cppuhelper::TypeManager::find(OUString const & name) {
1804 //TODO: caching? (here or in unoidl::Manager?)
1805 struct Simple {
1806 std::u16string_view name;
1807 css::uno::TypeClass typeClass;
1809 static Simple const simple[] = {
1810 { std::u16string_view(u"void"), css::uno::TypeClass_VOID },
1811 { std::u16string_view(u"boolean"), css::uno::TypeClass_BOOLEAN },
1812 { std::u16string_view(u"byte"), css::uno::TypeClass_BYTE },
1813 { std::u16string_view(u"short"), css::uno::TypeClass_SHORT },
1814 { std::u16string_view(u"unsigned short"),
1815 css::uno::TypeClass_UNSIGNED_SHORT },
1816 { std::u16string_view(u"long"), css::uno::TypeClass_LONG },
1817 { std::u16string_view(u"unsigned long"), css::uno::TypeClass_UNSIGNED_LONG },
1818 { std::u16string_view(u"hyper"), css::uno::TypeClass_HYPER },
1819 { std::u16string_view(u"unsigned hyper"),
1820 css::uno::TypeClass_UNSIGNED_HYPER },
1821 { std::u16string_view(u"float"), css::uno::TypeClass_FLOAT },
1822 { std::u16string_view(u"double"), css::uno::TypeClass_DOUBLE },
1823 { std::u16string_view(u"char"), css::uno::TypeClass_CHAR },
1824 { std::u16string_view(u"string"), css::uno::TypeClass_STRING },
1825 { std::u16string_view(u"type"), css::uno::TypeClass_TYPE },
1826 { std::u16string_view(u"any"), css::uno::TypeClass_ANY } };
1827 for (std::size_t i = 0; i != SAL_N_ELEMENTS(simple); ++i) {
1828 if (name == simple[i].name) {
1829 return css::uno::makeAny<
1830 css::uno::Reference< css::reflection::XTypeDescription > >(
1831 new SimpleTypeDescription(simple[i].typeClass, name));
1834 if (name.startsWith("[]")) {
1835 return getSequenceType(name);
1837 sal_Int32 i = name.indexOf('<');
1838 if (i != -1) {
1839 return getInstantiatedStruct(name, i);
1841 i = name.indexOf("::");
1842 if (i != -1) {
1843 return getInterfaceMember(name, i);
1845 rtl::Reference< unoidl::Entity > ent(findEntity(name));
1846 if (ent.is()) {
1847 return getNamed(name, ent);
1849 i = name.lastIndexOf('.');
1850 if (i != -1) {
1851 OUString parent(name.copy(0, i));
1852 ent = findEntity(parent);
1853 if (ent.is()) {
1854 switch (ent->getSort()) {
1855 case unoidl::Entity::SORT_ENUM_TYPE:
1856 return getEnumMember(
1857 static_cast< unoidl::EnumTypeEntity * >(ent.get()),
1858 name.copy(i + 1));
1859 case unoidl::Entity::SORT_CONSTANT_GROUP:
1860 return getConstant(
1861 parent,
1862 static_cast< unoidl::ConstantGroupEntity * >(ent.get()),
1863 name.copy(i + 1));
1864 default:
1865 break;
1869 return css::uno::Any();
1872 css::uno::Reference< css::reflection::XTypeDescription >
1873 cppuhelper::TypeManager::resolve(OUString const & name) {
1874 css::uno::Reference< css::reflection::XTypeDescription > desc(
1875 find(name), css::uno::UNO_QUERY);
1876 if (!desc.is()) {
1877 throw css::uno::DeploymentException(
1878 "cannot resolve type \"" + name + "\"",
1879 static_cast< cppu::OWeakObject * >(this));
1881 return desc;
1884 cppuhelper::TypeManager::~TypeManager() throw () {}
1886 void cppuhelper::TypeManager::disposing() {} //TODO
1888 OUString cppuhelper::TypeManager::getImplementationName()
1890 return
1891 "com.sun.star.comp.cppuhelper.bootstrap.TypeManager";
1894 sal_Bool cppuhelper::TypeManager::supportsService(
1895 OUString const & ServiceName)
1897 return cppu::supportsService(this, ServiceName);
1900 css::uno::Sequence< OUString >
1901 cppuhelper::TypeManager::getSupportedServiceNames()
1903 return { "com.sun.star.reflection.TypeDescriptionManager" }; //TODO
1906 css::uno::Any cppuhelper::TypeManager::getByHierarchicalName(
1907 OUString const & aName)
1909 css::uno::Any desc(find(aName));
1910 if (!desc.hasValue()) {
1911 throw css::container::NoSuchElementException(
1912 aName, static_cast< cppu::OWeakObject * >(this));
1914 return desc;
1917 sal_Bool cppuhelper::TypeManager::hasByHierarchicalName(
1918 OUString const & aName)
1920 return find(aName).hasValue();
1923 css::uno::Type cppuhelper::TypeManager::getElementType()
1925 return cppu::UnoType< OUString >::get();
1928 sal_Bool cppuhelper::TypeManager::hasElements()
1930 throw css::uno::RuntimeException(
1931 "TypeManager hasElements: method not supported",
1932 static_cast< cppu::OWeakObject * >(this));
1935 css::uno::Reference< css::container::XEnumeration >
1936 cppuhelper::TypeManager::createEnumeration()
1938 throw css::uno::RuntimeException(
1939 "TypeManager createEnumeration: method not supported",
1940 static_cast< cppu::OWeakObject * >(this));
1943 sal_Bool cppuhelper::TypeManager::has(css::uno::Any const &)
1945 throw css::uno::RuntimeException(
1946 "TypeManager has: method not supported",
1947 static_cast< cppu::OWeakObject * >(this));
1950 void cppuhelper::TypeManager::insert(css::uno::Any const & aElement)
1952 OUString uri;
1953 if (!(aElement >>= uri)) {
1954 throw css::lang::IllegalArgumentException(
1955 ("css.uno.theTypeDescriptionManager.insert expects a string URI"
1956 " argument"),
1957 static_cast< cppu::OWeakObject * >(this), 0);
1959 //TODO: check for ElementExistException
1960 //TODO: check for consistency with existing data
1961 readRdbFile(uri, false);
1964 void cppuhelper::TypeManager::remove(css::uno::Any const & aElement)
1966 OUString uri;
1967 if (!(aElement >>= uri)) {
1968 throw css::lang::IllegalArgumentException(
1969 ("css.uno.theTypeDescriptionManager.remove expects a string URI"
1970 " argument"),
1971 static_cast< cppu::OWeakObject * >(this), 0);
1973 //TODO: remove requests are silently ignored for now
1976 css::uno::Reference< css::reflection::XTypeDescriptionEnumeration >
1977 cppuhelper::TypeManager::createTypeDescriptionEnumeration(
1978 OUString const & moduleName,
1979 css::uno::Sequence< css::uno::TypeClass > const & types,
1980 css::reflection::TypeDescriptionSearchDepth depth)
1982 rtl::Reference< unoidl::MapCursor > cursor;
1983 try {
1984 cursor = manager_->createCursor(moduleName);
1985 } catch (unoidl::FileFormatException & e) {
1986 throw css::uno::DeploymentException(
1987 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
1988 + e.getDetail()),
1989 static_cast< cppu::OWeakObject * >(this));
1991 if (!cursor.is()) {
1992 //TODO: css::reflection::InvalidTypeNameException if moduleName names a
1993 // non-module
1994 throw css::reflection::NoSuchTypeNameException(
1995 moduleName, static_cast< cppu::OWeakObject * >(this));
1997 return new Enumeration(
1998 this, makePrefix(moduleName), cursor, types,
1999 depth == css::reflection::TypeDescriptionSearchDepth_INFINITE);
2002 void cppuhelper::TypeManager::init(OUString const & rdbUris) {
2003 for (sal_Int32 i = 0; i != -1;) {
2004 OUString uri(rdbUris.getToken(0, ' ', i));
2005 if (uri.isEmpty()) {
2006 continue;
2008 bool optional;
2009 bool directory;
2010 cppu::decodeRdbUri(&uri, &optional, &directory);
2011 if (directory) {
2012 readRdbDirectory(uri, optional);
2013 } else {
2014 readRdbFile(uri, optional);
2019 void cppuhelper::TypeManager::readRdbDirectory(
2020 OUString const & uri, bool optional)
2022 osl::Directory dir(uri);
2023 switch (dir.open()) {
2024 case osl::FileBase::E_None:
2025 break;
2026 case osl::FileBase::E_NOENT:
2027 if (optional) {
2028 SAL_INFO("cppuhelper", "Ignored optional " << uri);
2029 return;
2031 [[fallthrough]];
2032 default:
2033 throw css::uno::DeploymentException(
2034 "Cannot open directory " + uri,
2035 static_cast< cppu::OWeakObject * >(this));
2037 for (;;) {
2038 OUString url;
2039 if (!cppu::nextDirectoryItem(dir, &url)) {
2040 break;
2042 readRdbFile(url, false);
2046 void cppuhelper::TypeManager::readRdbFile(
2047 OUString const & uri, bool optional)
2049 try {
2050 manager_->addProvider(uri);
2051 } catch (unoidl::NoSuchFileException &) {
2052 if (!optional) {
2053 throw css::uno::DeploymentException(
2054 uri + ": no such file",
2055 static_cast< cppu::OWeakObject * >(this));
2057 SAL_INFO("cppuhelper", "Ignored optional " << uri);
2058 } catch (unoidl::FileFormatException & e) {
2059 throw css::uno::DeploymentException(
2060 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2061 + e.getDetail()),
2062 static_cast< cppu::OWeakObject * >(this));
2066 css::uno::Any cppuhelper::TypeManager::getSequenceType(
2067 OUString const & name)
2069 assert(name.startsWith("[]"));
2070 return css::uno::makeAny<
2071 css::uno::Reference< css::reflection::XTypeDescription > >(
2072 new SequenceTypeDescription(
2073 this, name, name.copy(std::strlen("[]"))));
2076 css::uno::Any cppuhelper::TypeManager::getInstantiatedStruct(
2077 OUString const & name, sal_Int32 separator)
2079 assert(name.indexOf('<') == separator && separator != -1);
2080 rtl::Reference< unoidl::Entity > ent(findEntity(name.copy(0, separator)));
2081 if (!ent.is()
2082 || (ent->getSort()
2083 != unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE))
2085 return css::uno::Any();
2087 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
2088 static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
2089 ent.get()));
2090 std::vector< OUString > args;
2091 sal_Int32 i = separator;
2092 do {
2093 ++i; // skip '<' or ','
2094 sal_Int32 j = i;
2095 for (sal_Int32 level = 0; j != name.getLength(); ++j) {
2096 sal_Unicode c = name[j];
2097 if (c == ',') {
2098 if (level == 0) {
2099 break;
2101 } else if (c == '<') {
2102 ++level;
2103 } else if (c == '>') {
2104 if (level == 0) {
2105 break;
2107 --level;
2110 if (j != name.getLength()) {
2111 args.push_back(name.copy(i, j - i));
2113 i = j;
2114 } while (i != name.getLength() && name[i] != '>');
2115 if (i != name.getLength() - 1 || name[i] != '>'
2116 || args.size() != ent2->getTypeParameters().size())
2118 return css::uno::Any();
2120 return css::uno::makeAny<
2121 css::uno::Reference< css::reflection::XTypeDescription > >(
2122 new InstantiatedPolymorphicStructTypeDescription(
2123 this, name, ent2, args));
2126 css::uno::Any cppuhelper::TypeManager::getInterfaceMember(
2127 OUString const & name, sal_Int32 separator)
2129 assert(name.indexOf("::") == separator && separator != -1);
2130 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > ifc(
2131 resolveTypedefs(find(name.copy(0, separator))), css::uno::UNO_QUERY);
2132 if (!ifc.is()) {
2133 return css::uno::Any();
2135 OUString member(name.copy(separator + std::strlen("::")));
2136 const css::uno::Sequence<
2137 css::uno::Reference<
2138 css::reflection::XInterfaceMemberTypeDescription > > mems(
2139 ifc->getMembers());
2140 for (const auto & m : mems) {
2141 if (m->getMemberName() == member) {
2142 return css::uno::makeAny<
2143 css::uno::Reference< css::reflection::XTypeDescription > >(m);
2146 return css::uno::Any();
2149 css::uno::Any cppuhelper::TypeManager::getNamed(
2150 OUString const & name, rtl::Reference< unoidl::Entity > const & entity)
2152 assert(entity.is());
2153 switch (entity->getSort()) {
2154 case unoidl::Entity::SORT_MODULE:
2155 return css::uno::makeAny<
2156 css::uno::Reference< css::reflection::XTypeDescription > >(
2157 new ModuleDescription(
2158 this, name,
2159 static_cast< unoidl::ModuleEntity * >(entity.get())));
2160 case unoidl::Entity::SORT_ENUM_TYPE:
2161 return css::uno::makeAny<
2162 css::uno::Reference< css::reflection::XTypeDescription > >(
2163 new EnumTypeDescription(
2164 name,
2165 static_cast< unoidl::EnumTypeEntity * >(entity.get())));
2166 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
2167 return css::uno::makeAny<
2168 css::uno::Reference< css::reflection::XTypeDescription > >(
2169 new PlainStructTypeDescription(
2170 this, name,
2171 static_cast< unoidl::PlainStructTypeEntity * >(
2172 entity.get())));
2173 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
2174 return css::uno::makeAny<
2175 css::uno::Reference< css::reflection::XTypeDescription > >(
2176 new PolymorphicStructTypeTemplateDescription(
2177 this, name,
2178 static_cast<
2179 unoidl::PolymorphicStructTypeTemplateEntity * >(
2180 entity.get())));
2181 case unoidl::Entity::SORT_EXCEPTION_TYPE:
2182 return css::uno::makeAny<
2183 css::uno::Reference< css::reflection::XTypeDescription > >(
2184 new ExceptionTypeDescription(
2185 this, name,
2186 static_cast< unoidl::ExceptionTypeEntity * >(
2187 entity.get())));
2188 case unoidl::Entity::SORT_INTERFACE_TYPE:
2189 return css::uno::makeAny<
2190 css::uno::Reference< css::reflection::XTypeDescription > >(
2191 new InterfaceTypeDescription(
2192 this, name,
2193 static_cast< unoidl::InterfaceTypeEntity * >(
2194 entity.get())));
2195 case unoidl::Entity::SORT_TYPEDEF:
2196 return css::uno::makeAny<
2197 css::uno::Reference< css::reflection::XTypeDescription > >(
2198 new TypedefDescription(
2199 this, name,
2200 static_cast< unoidl::TypedefEntity * >(entity.get())));
2201 case unoidl::Entity::SORT_CONSTANT_GROUP:
2202 return css::uno::makeAny<
2203 css::uno::Reference< css::reflection::XTypeDescription > >(
2204 new ConstantGroupDescription(
2205 name,
2206 static_cast< unoidl::ConstantGroupEntity * >(
2207 entity.get())));
2208 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
2209 return css::uno::makeAny<
2210 css::uno::Reference< css::reflection::XTypeDescription > >(
2211 new SingleInterfaceBasedServiceDescription(
2212 this, name,
2213 static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
2214 entity.get())));
2215 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
2216 return css::uno::makeAny<
2217 css::uno::Reference< css::reflection::XTypeDescription > >(
2218 new AccumulationBasedServiceDescription(
2219 this, name,
2220 static_cast< unoidl::AccumulationBasedServiceEntity * >(
2221 entity.get())));
2222 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
2223 return css::uno::makeAny<
2224 css::uno::Reference< css::reflection::XTypeDescription > >(
2225 new InterfaceBasedSingletonDescription(
2226 this, name,
2227 static_cast< unoidl::InterfaceBasedSingletonEntity * >(
2228 entity.get())));
2229 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
2230 return css::uno::makeAny<
2231 css::uno::Reference< css::reflection::XTypeDescription > >(
2232 new ServiceBasedSingletonDescription(
2233 this, name,
2234 static_cast< unoidl::ServiceBasedSingletonEntity * >(
2235 entity.get())));
2236 default:
2237 for (;;) { std::abort(); } // this cannot happen
2241 css::uno::Any cppuhelper::TypeManager::getEnumMember(
2242 rtl::Reference< unoidl::EnumTypeEntity > const & entity,
2243 OUString const & member)
2245 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2246 [&member](const unoidl::EnumTypeEntity::Member& rMember) { return rMember.name == member; });
2247 if (i != entity->getMembers().end())
2248 return css::uno::makeAny(i->value);
2249 return css::uno::Any();
2252 css::uno::Any cppuhelper::TypeManager::getConstant(
2253 OUString const & constantGroupName,
2254 rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
2255 OUString const & member)
2257 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2258 [&member](const unoidl::ConstantGroupEntity::Member& rMember) { return rMember.name == member; });
2259 if (i != entity->getMembers().end())
2260 return css::uno::makeAny<
2261 css::uno::Reference< css::reflection::XTypeDescription > >(
2262 new ConstantDescription(constantGroupName, *i));
2263 return css::uno::Any();
2266 rtl::Reference< unoidl::Entity > cppuhelper::TypeManager::findEntity(
2267 OUString const & name)
2269 try {
2270 return manager_->findEntity(name);
2271 } catch (unoidl::FileFormatException & e) {
2272 throw css::uno::DeploymentException(
2273 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2274 + e.getDetail()),
2275 static_cast< cppu::OWeakObject * >(this));
2279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */