android: Update app-specific/MIME type icons
[LibreOffice.git] / cppuhelper / source / typemanager.cxx
blob0408234c4b398105082d5a0ad5de404c9f4f750b
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>
23 #include <com/sun/star/container/NoSuchElementException.hpp>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/reflection/NoSuchTypeNameException.hpp>
26 #include <com/sun/star/reflection/TypeDescriptionSearchDepth.hpp>
27 #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
28 #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
29 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
30 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
31 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
32 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
33 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
34 #include <com/sun/star/reflection/XModuleTypeDescription.hpp>
35 #include <com/sun/star/reflection/XPublished.hpp>
36 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
37 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
38 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
39 #include <com/sun/star/reflection/XTypeDescription.hpp>
40 #include <com/sun/star/uno/Any.hxx>
41 #include <com/sun/star/uno/DeploymentException.hpp>
42 #include <com/sun/star/uno/Reference.hxx>
43 #include <com/sun/star/uno/RuntimeException.hpp>
44 #include <com/sun/star/uno/Sequence.hxx>
45 #include <com/sun/star/uno/Type.hxx>
46 #include <com/sun/star/uno/TypeClass.hpp>
47 #include <cppu/unotype.hxx>
48 #include <cppuhelper/implbase.hxx>
49 #include <cppuhelper/supportsservice.hxx>
50 #include <osl/file.hxx>
51 #include <rtl/ref.hxx>
52 #include <rtl/ustring.hxx>
53 #include <sal/log.hxx>
54 #include <sal/macros.h>
55 #include <sal/types.h>
56 #include <o3tl/string_view.hxx>
58 #include <unoidl/unoidl.hxx>
60 #include "paths.hxx"
61 #include "typemanager.hxx"
63 namespace {
65 OUString makePrefix(OUString const & name) {
66 return name.isEmpty() ? name : name + ".";
69 css::uno::Any resolveTypedefs(css::uno::Any const & type) {
70 for (css::uno::Any t(type);;) {
71 css::uno::Reference< css::reflection::XIndirectTypeDescription > ind(
72 type, css::uno::UNO_QUERY);
73 if (!ind.is() || ind->getTypeClass() != css::uno::TypeClass_TYPEDEF) {
74 return t;
76 t <<= ind->getReferencedType();
80 class SimpleTypeDescription:
81 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
83 public:
84 SimpleTypeDescription(
85 css::uno::TypeClass typeClass, OUString name):
86 typeClass_(typeClass), name_(std::move(name))
89 private:
90 virtual ~SimpleTypeDescription() override {}
92 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
93 { return typeClass_; }
95 virtual OUString SAL_CALL getName() override
96 { return name_; }
98 css::uno::TypeClass typeClass_;
99 OUString name_;
102 class SequenceTypeDescription:
103 public cppu::WeakImplHelper< css::reflection::XIndirectTypeDescription >
105 public:
106 SequenceTypeDescription(
107 rtl::Reference< cppuhelper::TypeManager > const & manager,
108 OUString name, OUString componentType):
109 manager_(manager), name_(std::move(name)), componentType_(std::move(componentType))
110 { assert(manager.is()); }
112 private:
113 virtual ~SequenceTypeDescription() override {}
115 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
116 { return css::uno::TypeClass_SEQUENCE; }
118 virtual OUString SAL_CALL getName() override
119 { return name_; }
121 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
122 getReferencedType() override
123 { return manager_->resolve(componentType_); }
125 rtl::Reference< cppuhelper::TypeManager > manager_;
126 OUString name_;
127 OUString componentType_;
130 class PublishableDescription:
131 public cppu::WeakImplHelper< css::reflection::XPublished >
133 protected:
134 explicit PublishableDescription(bool published): published_(published) {}
136 virtual ~PublishableDescription() override {}
138 private:
139 virtual sal_Bool SAL_CALL isPublished() override
140 { return published_; }
142 bool published_;
145 class ModuleDescription:
146 public cppu::WeakImplHelper< css::reflection::XModuleTypeDescription >
148 public:
149 ModuleDescription(
150 rtl::Reference< cppuhelper::TypeManager > const & manager,
151 OUString name,
152 rtl::Reference< unoidl::ModuleEntity > const & entity):
153 manager_(manager), name_(std::move(name)), entity_(entity)
154 { assert(manager.is()); assert(entity.is()); }
156 private:
157 virtual ~ModuleDescription() override {}
159 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
160 { return css::uno::TypeClass_MODULE; }
162 virtual OUString SAL_CALL getName() override
163 { return name_; }
165 virtual
166 css::uno::Sequence<
167 css::uno::Reference< css::reflection::XTypeDescription > >
168 SAL_CALL getMembers() override;
170 rtl::Reference< cppuhelper::TypeManager > manager_;
171 OUString name_;
172 rtl::Reference< unoidl::ModuleEntity > entity_;
175 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
176 ModuleDescription::getMembers() {
177 try {
178 std::vector< OUString > names(entity_->getMemberNames());
179 assert(names.size() <= SAL_MAX_INT32);
180 sal_Int32 n = static_cast< sal_Int32 >(names.size());
181 css::uno::Sequence<
182 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
183 auto r = asNonConstRange(s);
184 for (sal_Int32 i = 0; i != n; ++i) {
185 r[i] = manager_->resolve(makePrefix(name_) + names[i]);
187 return s;
188 } catch (unoidl::FileFormatException & e) {
189 throw css::uno::DeploymentException(
190 e.getUri() + ": " + e.getDetail(),
191 static_cast< cppu::OWeakObject * >(this));
195 typedef cppu::ImplInheritanceHelper<
196 PublishableDescription, css::reflection::XEnumTypeDescription >
197 EnumTypeDescription_Base;
199 class EnumTypeDescription: public EnumTypeDescription_Base {
200 public:
201 EnumTypeDescription(
202 OUString name,
203 rtl::Reference< unoidl::EnumTypeEntity > const & entity):
204 EnumTypeDescription_Base(entity->isPublished()), name_(std::move(name)),
205 entity_(entity)
206 { assert(entity.is()); }
208 private:
209 virtual ~EnumTypeDescription() override {}
211 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
212 { return css::uno::TypeClass_ENUM; }
214 virtual OUString SAL_CALL getName() override
215 { return name_; }
217 virtual sal_Int32 SAL_CALL getDefaultEnumValue() override
218 { return entity_->getMembers()[0].value; }
220 virtual css::uno::Sequence< OUString > SAL_CALL getEnumNames() override;
222 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getEnumValues() override;
224 OUString name_;
225 rtl::Reference< unoidl::EnumTypeEntity > entity_;
228 css::uno::Sequence< OUString > EnumTypeDescription::getEnumNames()
230 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
231 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
232 css::uno::Sequence< OUString > s(n);
233 auto r = asNonConstRange(s);
234 for (sal_Int32 i = 0; i != n; ++i) {
235 r[i] = entity_->getMembers()[i].name;
237 return s;
240 css::uno::Sequence< sal_Int32 > EnumTypeDescription::getEnumValues()
242 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
243 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
244 css::uno::Sequence< sal_Int32 > s(n);
245 auto r = asNonConstRange(s);
246 for (sal_Int32 i = 0; i != n; ++i) {
247 r[i] = entity_->getMembers()[i].value;
249 return s;
252 typedef cppu::ImplInheritanceHelper<
253 PublishableDescription, css::reflection::XStructTypeDescription >
254 PlainStructTypeDescription_Base;
256 class PlainStructTypeDescription: public PlainStructTypeDescription_Base {
257 public:
258 PlainStructTypeDescription(
259 rtl::Reference< cppuhelper::TypeManager > const & manager,
260 OUString name,
261 rtl::Reference< unoidl::PlainStructTypeEntity > const & entity):
262 PlainStructTypeDescription_Base(entity->isPublished()),
263 manager_(manager), name_(std::move(name)), entity_(entity)
264 { assert(manager.is()); assert(entity.is()); }
266 private:
267 virtual ~PlainStructTypeDescription() override {}
269 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
270 { return css::uno::TypeClass_STRUCT; }
272 virtual OUString SAL_CALL getName() override
273 { return name_; }
275 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
276 getBaseType() override {
277 return entity_->getDirectBase().isEmpty()
278 ? css::uno::Reference< css::reflection::XTypeDescription >()
279 : manager_->resolve(entity_->getDirectBase());
282 virtual
283 css::uno::Sequence<
284 css::uno::Reference< css::reflection::XTypeDescription > >
285 SAL_CALL getMemberTypes() override;
287 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
289 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
290 { return css::uno::Sequence< OUString >(); }
292 virtual
293 css::uno::Sequence<
294 css::uno::Reference< css::reflection::XTypeDescription > >
295 SAL_CALL getTypeArguments() override {
296 return css::uno::Sequence<
297 css::uno::Reference< css::reflection::XTypeDescription > >();
300 rtl::Reference< cppuhelper::TypeManager > manager_;
301 OUString name_;
302 rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
305 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
306 PlainStructTypeDescription::getMemberTypes()
308 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
309 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
310 css::uno::Sequence<
311 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
312 auto r = asNonConstRange(s);
313 for (sal_Int32 i = 0; i != n; ++i) {
314 r[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
316 return s;
319 css::uno::Sequence< OUString > PlainStructTypeDescription::getMemberNames()
321 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
322 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
323 css::uno::Sequence< OUString > s(n);
324 auto r = asNonConstRange(s);
325 for (sal_Int32 i = 0; i != n; ++i) {
326 r[i] = entity_->getDirectMembers()[i].name;
328 return s;
331 class ParameterizedMemberTypeDescription:
332 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
334 public:
335 explicit ParameterizedMemberTypeDescription(
336 OUString typeParameterName):
337 typeParameterName_(std::move(typeParameterName))
340 private:
341 virtual ~ParameterizedMemberTypeDescription() override {}
343 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
344 { return css::uno::TypeClass_UNKNOWN; }
346 virtual OUString SAL_CALL getName() override
347 { return typeParameterName_; }
349 OUString typeParameterName_;
352 typedef cppu::ImplInheritanceHelper<
353 PublishableDescription, css::reflection::XStructTypeDescription >
354 PolymorphicStructTypeTemplateDescription_Base;
356 class PolymorphicStructTypeTemplateDescription:
357 public PolymorphicStructTypeTemplateDescription_Base
359 public:
360 PolymorphicStructTypeTemplateDescription(
361 rtl::Reference< cppuhelper::TypeManager > const & manager,
362 OUString name,
363 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
364 entity):
365 PolymorphicStructTypeTemplateDescription_Base(entity->isPublished()),
366 manager_(manager), name_(std::move(name)), entity_(entity)
367 { assert(manager.is()); assert(entity.is()); }
369 private:
370 virtual ~PolymorphicStructTypeTemplateDescription() override {}
372 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
373 { return css::uno::TypeClass_STRUCT; }
375 virtual OUString SAL_CALL getName() override
376 { return name_; }
378 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
379 getBaseType() override
380 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
382 virtual
383 css::uno::Sequence<
384 css::uno::Reference< css::reflection::XTypeDescription > >
385 SAL_CALL getMemberTypes() override;
387 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
389 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override;
391 virtual
392 css::uno::Sequence<
393 css::uno::Reference< css::reflection::XTypeDescription > >
394 SAL_CALL getTypeArguments() override {
395 return css::uno::Sequence<
396 css::uno::Reference< css::reflection::XTypeDescription > >();
399 rtl::Reference< cppuhelper::TypeManager > manager_;
400 OUString name_;
401 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
404 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
405 PolymorphicStructTypeTemplateDescription::getMemberTypes()
407 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
408 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
409 css::uno::Sequence<
410 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
411 auto r = asNonConstRange(s);
412 for (sal_Int32 i = 0; i != n; ++i) {
413 r[i] = entity_->getMembers()[i].parameterized
414 ? new ParameterizedMemberTypeDescription(
415 entity_->getMembers()[i].type)
416 : manager_->resolve(entity_->getMembers()[i].type);
418 return s;
421 css::uno::Sequence< OUString >
422 PolymorphicStructTypeTemplateDescription::getMemberNames()
424 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
425 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
426 css::uno::Sequence< OUString > s(n);
427 auto r = asNonConstRange(s);
428 for (sal_Int32 i = 0; i != n; ++i) {
429 r[i] = entity_->getMembers()[i].name;
431 return s;
434 css::uno::Sequence< OUString >
435 PolymorphicStructTypeTemplateDescription::getTypeParameters()
437 assert(entity_->getTypeParameters().size() <= SAL_MAX_INT32);
438 sal_Int32 n = static_cast< sal_Int32 >(entity_->getTypeParameters().size());
439 css::uno::Sequence< OUString > s(n);
440 auto r = asNonConstRange(s);
441 for (sal_Int32 i = 0; i != n; ++i) {
442 r[i] = entity_->getTypeParameters()[i];
444 return s;
447 class InstantiatedPolymorphicStructTypeDescription:
448 public cppu::WeakImplHelper< css::reflection::XStructTypeDescription >
450 public:
451 InstantiatedPolymorphicStructTypeDescription(
452 rtl::Reference< cppuhelper::TypeManager > const & manager,
453 OUString name,
454 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
455 entity,
456 std::vector< OUString >&& arguments):
457 manager_(manager), name_(std::move(name)), entity_(entity), arguments_(std::move(arguments))
459 assert(manager.is());
460 assert(entity.is());
461 assert(arguments_.size() == entity->getTypeParameters().size());
464 private:
465 virtual ~InstantiatedPolymorphicStructTypeDescription() override {}
467 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
468 { return css::uno::TypeClass_STRUCT; }
470 virtual OUString SAL_CALL getName() override
471 { return name_; }
473 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
474 getBaseType() override
475 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
477 virtual
478 css::uno::Sequence<
479 css::uno::Reference< css::reflection::XTypeDescription > >
480 SAL_CALL getMemberTypes() override;
482 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
484 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
485 { return css::uno::Sequence< OUString >(); }
487 virtual
488 css::uno::Sequence<
489 css::uno::Reference< css::reflection::XTypeDescription > >
490 SAL_CALL getTypeArguments() override;
492 rtl::Reference< cppuhelper::TypeManager > manager_;
493 OUString name_;
494 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
495 std::vector< OUString > arguments_;
498 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
499 InstantiatedPolymorphicStructTypeDescription::getMemberTypes()
501 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
502 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
503 css::uno::Sequence<
504 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
505 auto r = asNonConstRange(s);
506 for (sal_Int32 i = 0; i != n; ++i) {
507 OUString type(entity_->getMembers()[i].type);
508 if (entity_->getMembers()[i].parameterized) {
509 auto j = std::find(entity_->getTypeParameters().begin(), entity_->getTypeParameters().end(), type);
510 if (j != entity_->getTypeParameters().end()) {
511 type = arguments_[j - entity_->getTypeParameters().begin()];
512 goto found;
514 assert(false); // this cannot happen //TODO!
515 found:;
517 r[i] = manager_->resolve(type);
519 return s;
522 css::uno::Sequence< OUString >
523 InstantiatedPolymorphicStructTypeDescription::getMemberNames()
525 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
526 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
527 css::uno::Sequence< OUString > s(n);
528 auto r = asNonConstRange(s);
529 for (sal_Int32 i = 0; i != n; ++i) {
530 r[i] = entity_->getMembers()[i].name;
532 return s;
534 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
535 InstantiatedPolymorphicStructTypeDescription::getTypeArguments()
537 assert(arguments_.size() <= SAL_MAX_INT32);
538 sal_Int32 n = static_cast< sal_Int32 >(arguments_.size());
539 css::uno::Sequence<
540 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
541 auto r = asNonConstRange(s);
542 for (sal_Int32 i = 0; i != n; ++i) {
543 r[i] = manager_->resolve(arguments_[i]);
545 return s;
548 typedef cppu::ImplInheritanceHelper<
549 PublishableDescription, css::reflection::XCompoundTypeDescription >
550 ExceptionTypeDescription_Base;
552 class ExceptionTypeDescription: public ExceptionTypeDescription_Base {
553 public:
554 ExceptionTypeDescription(
555 rtl::Reference< cppuhelper::TypeManager > const & manager,
556 OUString name,
557 rtl::Reference< unoidl::ExceptionTypeEntity > const & entity):
558 ExceptionTypeDescription_Base(entity->isPublished()), manager_(manager),
559 name_(std::move(name)), entity_(entity)
560 { assert(manager.is()); assert(entity.is()); }
562 private:
563 virtual ~ExceptionTypeDescription() override {}
565 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
566 { return css::uno::TypeClass_EXCEPTION; }
568 virtual OUString SAL_CALL getName() override
569 { return name_; }
571 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
572 getBaseType() override {
573 return entity_->getDirectBase().isEmpty()
574 ? css::uno::Reference< css::reflection::XTypeDescription >()
575 : manager_->resolve(entity_->getDirectBase());
578 virtual
579 css::uno::Sequence<
580 css::uno::Reference< css::reflection::XTypeDescription > >
581 SAL_CALL getMemberTypes() override;
583 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
585 rtl::Reference< cppuhelper::TypeManager > manager_;
586 OUString name_;
587 rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
590 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
591 ExceptionTypeDescription::getMemberTypes() {
592 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
593 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
594 css::uno::Sequence<
595 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
596 auto r = asNonConstRange(s);
597 for (sal_Int32 i = 0; i != n; ++i) {
598 r[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
600 return s;
603 css::uno::Sequence< OUString > ExceptionTypeDescription::getMemberNames()
605 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
606 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
607 css::uno::Sequence< OUString > s(n);
608 auto r = asNonConstRange(s);
609 for (sal_Int32 i = 0; i != n; ++i) {
610 r[i] = entity_->getDirectMembers()[i].name;
612 return s;
615 class AttributeDescription:
616 public cppu::WeakImplHelper<
617 css::reflection::XInterfaceAttributeTypeDescription2 >
619 public:
620 AttributeDescription(
621 rtl::Reference< cppuhelper::TypeManager > const & manager,
622 OUString name,
623 unoidl::InterfaceTypeEntity::Attribute attribute,
624 sal_Int32 position):
625 manager_(manager), name_(std::move(name)), attribute_(std::move(attribute)),
626 position_(position)
627 { assert(manager.is()); }
629 private:
630 virtual ~AttributeDescription() override {}
632 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
633 { return css::uno::TypeClass_INTERFACE_ATTRIBUTE; }
635 virtual OUString SAL_CALL getName() override
636 { return name_; }
638 virtual OUString SAL_CALL getMemberName() override
639 { return attribute_.name; }
641 virtual sal_Int32 SAL_CALL getPosition() override
642 { return position_; }
644 virtual sal_Bool SAL_CALL isReadOnly() override
645 { return attribute_.readOnly; }
647 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
648 getType() override
649 { return manager_->resolve(attribute_.type); }
651 virtual sal_Bool SAL_CALL isBound() override
652 { return attribute_.bound; }
654 virtual
655 css::uno::Sequence<
656 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
657 SAL_CALL getGetExceptions() override;
659 virtual
660 css::uno::Sequence<
661 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
662 SAL_CALL getSetExceptions() override;
664 rtl::Reference< cppuhelper::TypeManager > manager_;
665 OUString name_;
666 unoidl::InterfaceTypeEntity::Attribute attribute_;
667 sal_Int32 position_;
670 css::uno::Sequence<
671 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
672 AttributeDescription::getGetExceptions() {
673 assert(attribute_.getExceptions.size() <= SAL_MAX_INT32);
674 sal_Int32 n = static_cast< sal_Int32 >(attribute_.getExceptions.size());
675 css::uno::Sequence<
676 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
677 auto r = asNonConstRange(s);
678 for (sal_Int32 i = 0; i != n; ++i) {
679 r[i].set(
680 manager_->resolve(attribute_.getExceptions[i]),
681 css::uno::UNO_QUERY_THROW);
683 return s;
686 css::uno::Sequence<
687 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
688 AttributeDescription::getSetExceptions() {
689 assert(attribute_.setExceptions.size() <= SAL_MAX_INT32);
690 sal_Int32 n = static_cast< sal_Int32 >(attribute_.setExceptions.size());
691 css::uno::Sequence<
692 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
693 auto r = asNonConstRange(s);
694 for (sal_Int32 i = 0; i != n; ++i) {
695 r[i].set(
696 manager_->resolve(attribute_.setExceptions[i]),
697 css::uno::UNO_QUERY_THROW);
699 return s;
702 class MethodParameter:
703 public cppu::WeakImplHelper< css::reflection::XMethodParameter >
705 public:
706 MethodParameter(
707 rtl::Reference< cppuhelper::TypeManager > const & manager,
708 unoidl::InterfaceTypeEntity::Method::Parameter parameter,
709 sal_Int32 position):
710 manager_(manager), parameter_(std::move(parameter)), position_(position)
711 { assert(manager.is()); }
713 private:
714 virtual ~MethodParameter() override {}
716 virtual OUString SAL_CALL getName() override
717 { return parameter_.name; }
719 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
720 getType() override
721 { return manager_->resolve(parameter_.type); }
723 virtual sal_Bool SAL_CALL isIn() override {
724 return
725 (parameter_.direction
726 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
727 || (parameter_.direction
728 == unoidl::InterfaceTypeEntity::Method::Parameter::
729 DIRECTION_IN_OUT);
732 virtual sal_Bool SAL_CALL isOut() override {
733 return
734 (parameter_.direction
735 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT)
736 || (parameter_.direction
737 == unoidl::InterfaceTypeEntity::Method::Parameter::
738 DIRECTION_IN_OUT);
741 virtual sal_Int32 SAL_CALL getPosition() override
742 { return position_; }
744 rtl::Reference< cppuhelper::TypeManager > manager_;
745 unoidl::InterfaceTypeEntity::Method::Parameter parameter_;
746 sal_Int32 position_;
749 class MethodDescription:
750 public cppu::WeakImplHelper<
751 css::reflection::XInterfaceMethodTypeDescription >
753 public:
754 MethodDescription(
755 rtl::Reference< cppuhelper::TypeManager > const & manager,
756 OUString name,
757 unoidl::InterfaceTypeEntity::Method method, sal_Int32 position):
758 manager_(manager), name_(std::move(name)), method_(std::move(method)), position_(position)
759 { assert(manager.is()); }
761 private:
762 virtual ~MethodDescription() override {}
764 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
765 { return css::uno::TypeClass_INTERFACE_METHOD; }
767 virtual OUString SAL_CALL getName() override
768 { return name_; }
770 virtual OUString SAL_CALL getMemberName() override
771 { return method_.name; }
773 virtual sal_Int32 SAL_CALL getPosition() override
774 { return position_; }
776 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
777 getReturnType() override
778 { return manager_->resolve(method_.returnType); }
780 virtual sal_Bool SAL_CALL isOneway() override
781 { return false; }
783 virtual
784 css::uno::Sequence<
785 css::uno::Reference< css::reflection::XMethodParameter > >
786 SAL_CALL getParameters() override;
788 virtual
789 css::uno::Sequence<
790 css::uno::Reference< css::reflection::XTypeDescription > >
791 SAL_CALL getExceptions() override;
793 rtl::Reference< cppuhelper::TypeManager > manager_;
794 OUString name_;
795 unoidl::InterfaceTypeEntity::Method method_;
796 sal_Int32 position_;
799 css::uno::Sequence< css::uno::Reference< css::reflection::XMethodParameter > >
800 MethodDescription::getParameters() {
801 assert(method_.parameters.size() <= SAL_MAX_INT32);
802 sal_Int32 n = static_cast< sal_Int32 >(method_.parameters.size());
803 css::uno::Sequence<
804 css::uno::Reference< css::reflection::XMethodParameter > > s(n);
805 auto r = asNonConstRange(s);
806 for (sal_Int32 i = 0; i != n; ++i) {
807 r[i] = new MethodParameter(manager_, method_.parameters[i], i);
809 return s;
812 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
813 MethodDescription::getExceptions() {
814 assert(method_.exceptions.size() <= SAL_MAX_INT32);
815 sal_Int32 n = static_cast< sal_Int32 >(method_.exceptions.size());
816 css::uno::Sequence<
817 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
818 auto r = asNonConstRange(s);
819 for (sal_Int32 i = 0; i != n; ++i) {
820 r[i] = manager_->resolve(method_.exceptions[i]);
822 return s;
825 class BaseOffset {
826 public:
827 explicit BaseOffset(
828 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
829 const & description);
831 BaseOffset(const BaseOffset&) = delete;
832 const BaseOffset& operator=(const BaseOffset&) = delete;
834 sal_Int32 get() const { return offset_; }
836 private:
837 void calculateBases(
838 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
839 const & description);
841 void calculate(
842 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
843 const & description);
845 std::set< OUString > set_;
846 sal_Int32 offset_;
849 BaseOffset::BaseOffset(
850 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
851 description):
852 offset_(0)
854 calculateBases(description);
857 void BaseOffset::calculateBases(
858 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
859 description)
861 const css::uno::Sequence<
862 css::uno::Reference < css::reflection::XTypeDescription > > bases(
863 description->getBaseTypes());
864 for (const auto & i : bases) {
865 calculate(
866 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >(
867 resolveTypedefs(css::uno::Any(i)),
868 css::uno::UNO_QUERY_THROW));
872 void BaseOffset::calculate(
873 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
874 description)
876 if (set_.insert(description->getName()).second) {
877 calculateBases(description);
878 offset_ += description->getMembers().getLength();
882 typedef cppu::ImplInheritanceHelper<
883 PublishableDescription, css::reflection::XInterfaceTypeDescription2 >
884 InterfaceTypeDescription_Base;
886 class InterfaceTypeDescription: public InterfaceTypeDescription_Base {
887 public:
888 InterfaceTypeDescription(
889 rtl::Reference< cppuhelper::TypeManager > const & manager,
890 OUString name,
891 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
892 InterfaceTypeDescription_Base(entity->isPublished()), manager_(manager),
893 name_(std::move(name)), entity_(entity)
894 { assert(manager.is()); assert(entity.is()); }
896 private:
897 virtual ~InterfaceTypeDescription() override {}
899 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
900 { return css::uno::TypeClass_INTERFACE; }
902 virtual OUString SAL_CALL getName() override
903 { return name_; }
905 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
906 getBaseType() override {
907 return entity_->getDirectMandatoryBases().empty()
908 ? css::uno::Reference< css::reflection::XTypeDescription >()
909 : manager_->resolve(entity_->getDirectMandatoryBases()[0].name);
912 virtual css::uno::Uik SAL_CALL getUik() override
913 { return css::uno::Uik(); }
915 virtual
916 css::uno::Sequence<
917 css::uno::Reference<
918 css::reflection::XInterfaceMemberTypeDescription > >
919 SAL_CALL getMembers() override;
921 virtual
922 css::uno::Sequence<
923 css::uno::Reference< css::reflection::XTypeDescription > >
924 SAL_CALL getBaseTypes() override;
926 virtual
927 css::uno::Sequence<
928 css::uno::Reference< css::reflection::XTypeDescription > >
929 SAL_CALL getOptionalBaseTypes() override;
931 rtl::Reference< cppuhelper::TypeManager > manager_;
932 OUString name_;
933 rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
936 css::uno::Sequence<
937 css::uno::Reference< css::reflection::XInterfaceMemberTypeDescription > >
938 InterfaceTypeDescription::getMembers() {
939 assert(
940 entity_->getDirectAttributes().size() <= SAL_MAX_INT32
941 && (entity_->getDirectMethods().size()
942 <= SAL_MAX_INT32 - entity_->getDirectAttributes().size()));
943 sal_Int32 n1 = static_cast< sal_Int32 >(
944 entity_->getDirectAttributes().size());
945 sal_Int32 n2 = static_cast< sal_Int32 >(entity_->getDirectMethods().size());
946 css::uno::Sequence<
947 css::uno::Reference<
948 css::reflection::XInterfaceMemberTypeDescription > > s(n1 + n2);
949 auto r = asNonConstRange(s);
950 sal_Int32 off = BaseOffset(this).get();
951 for (sal_Int32 i = 0; i != n1; ++i) {
952 r[i] = new AttributeDescription(
953 manager_, name_ + "::" + entity_->getDirectAttributes()[i].name,
954 entity_->getDirectAttributes()[i], off + i);
956 for (sal_Int32 i = 0; i != n2; ++i) {
957 r[n1 + i] = new MethodDescription(
958 manager_, name_ + "::" + entity_->getDirectMethods()[i].name,
959 entity_->getDirectMethods()[i], off + n1 + i);
961 return s;
964 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
965 InterfaceTypeDescription::getBaseTypes() {
966 assert(entity_->getDirectMandatoryBases().size() <= SAL_MAX_INT32);
967 sal_Int32 n = static_cast< sal_Int32 >(
968 entity_->getDirectMandatoryBases().size());
969 css::uno::Sequence<
970 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
971 auto r = asNonConstRange(s);
972 for (sal_Int32 i = 0; i != n; ++i) {
973 r[i] = manager_->resolve(entity_->getDirectMandatoryBases()[i].name);
975 return s;
978 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
979 InterfaceTypeDescription::getOptionalBaseTypes()
981 assert(entity_->getDirectOptionalBases().size() <= SAL_MAX_INT32);
982 sal_Int32 n = static_cast< sal_Int32 >(
983 entity_->getDirectOptionalBases().size());
984 css::uno::Sequence<
985 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
986 auto r = asNonConstRange(s);
987 for (sal_Int32 i = 0; i != n; ++i) {
988 r[i] = manager_->resolve(entity_->getDirectOptionalBases()[i].name);
990 return s;
993 class ConstantDescription:
994 public cppu::WeakImplHelper< css::reflection::XConstantTypeDescription >
996 public:
997 ConstantDescription(
998 OUString const & constantGroupName,
999 unoidl::ConstantGroupEntity::Member const & member);
1001 private:
1002 virtual ~ConstantDescription() override {}
1004 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1005 { return css::uno::TypeClass_CONSTANT; }
1007 virtual OUString SAL_CALL getName() override
1008 { return name_; }
1010 virtual css::uno::Any SAL_CALL getConstantValue() override
1011 { return value_; }
1013 OUString name_;
1014 css::uno::Any value_;
1017 ConstantDescription::ConstantDescription(
1018 OUString const & constantGroupName,
1019 unoidl::ConstantGroupEntity::Member const & member):
1020 name_(makePrefix(constantGroupName) + member.name)
1022 switch (member.value.type) {
1023 case unoidl::ConstantValue::TYPE_BOOLEAN:
1024 value_ <<= member.value.booleanValue;
1025 break;
1026 case unoidl::ConstantValue::TYPE_BYTE:
1027 value_ <<= member.value.byteValue;
1028 break;
1029 case unoidl::ConstantValue::TYPE_SHORT:
1030 value_ <<= member.value.shortValue;
1031 break;
1032 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1033 value_ <<= member.value.unsignedShortValue;
1034 break;
1035 case unoidl::ConstantValue::TYPE_LONG:
1036 value_ <<= member.value.longValue;
1037 break;
1038 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1039 value_ <<= member.value.unsignedLongValue;
1040 break;
1041 case unoidl::ConstantValue::TYPE_HYPER:
1042 value_ <<= member.value.hyperValue;
1043 break;
1044 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1045 value_ <<= member.value.unsignedHyperValue;
1046 break;
1047 case unoidl::ConstantValue::TYPE_FLOAT:
1048 value_ <<= member.value.floatValue;
1049 break;
1050 case unoidl::ConstantValue::TYPE_DOUBLE:
1051 value_ <<= member.value.doubleValue;
1052 break;
1053 default:
1054 for (;;) { std::abort(); } // this cannot happen
1058 typedef cppu::ImplInheritanceHelper<
1059 PublishableDescription, css::reflection::XConstantsTypeDescription >
1060 ConstantGroupDescription_Base;
1062 class ConstantGroupDescription: public ConstantGroupDescription_Base {
1063 public:
1064 ConstantGroupDescription(
1065 OUString name,
1066 rtl::Reference< unoidl::ConstantGroupEntity > const & entity):
1067 ConstantGroupDescription_Base(entity->isPublished()), name_(std::move(name)),
1068 entity_(entity)
1069 { assert(entity.is()); }
1071 private:
1072 virtual ~ConstantGroupDescription() override {}
1074 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1075 { return css::uno::TypeClass_CONSTANTS; }
1077 virtual OUString SAL_CALL getName() override
1078 { return name_; }
1080 virtual
1081 css::uno::Sequence<
1082 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1083 SAL_CALL getConstants() override;
1085 OUString name_;
1086 rtl::Reference< unoidl::ConstantGroupEntity > entity_;
1089 css::uno::Sequence<
1090 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1091 ConstantGroupDescription::getConstants() {
1092 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
1093 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
1094 css::uno::Sequence<
1095 css::uno::Reference< css::reflection::XConstantTypeDescription > > s(n);
1096 auto r = asNonConstRange(s);
1097 for (sal_Int32 i = 0; i != n; ++i) {
1098 r[i] = new ConstantDescription(name_, entity_->getMembers()[i]);
1100 return s;
1103 typedef cppu::ImplInheritanceHelper<
1104 PublishableDescription, css::reflection::XIndirectTypeDescription >
1105 TypedefDescription_Base;
1107 class TypedefDescription: public TypedefDescription_Base {
1108 public:
1109 TypedefDescription(
1110 rtl::Reference< cppuhelper::TypeManager > const & manager,
1111 OUString name,
1112 rtl::Reference< unoidl::TypedefEntity > const & entity):
1113 TypedefDescription_Base(entity->isPublished()), manager_(manager),
1114 name_(std::move(name)), entity_(entity)
1115 { assert(manager.is()); assert(entity.is()); }
1117 private:
1118 virtual ~TypedefDescription() override {}
1120 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1121 { return css::uno::TypeClass_TYPEDEF; }
1123 virtual OUString SAL_CALL getName() override
1124 { return name_; }
1126 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1127 getReferencedType() override
1128 { return manager_->resolve(entity_->getType()); }
1130 rtl::Reference< cppuhelper::TypeManager > manager_;
1131 OUString name_;
1132 rtl::Reference< unoidl::TypedefEntity > entity_;
1135 class ConstructorParameter:
1136 public cppu::WeakImplHelper< css::reflection::XParameter >
1138 public:
1139 ConstructorParameter(
1140 rtl::Reference< cppuhelper::TypeManager > const & manager,
1141 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter parameter,
1142 sal_Int32 position):
1143 manager_(manager), parameter_(std::move(parameter)), position_(position)
1144 { assert(manager.is()); }
1146 private:
1147 virtual ~ConstructorParameter() override {}
1149 virtual OUString SAL_CALL getName() override
1150 { return parameter_.name; }
1152 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1153 getType() override
1154 { return manager_->resolve(parameter_.type); }
1156 virtual sal_Bool SAL_CALL isIn() override
1157 { return true; }
1159 virtual sal_Bool SAL_CALL isOut() override
1160 { return false; }
1162 virtual sal_Int32 SAL_CALL getPosition() override
1163 { return position_; }
1165 virtual sal_Bool SAL_CALL isRestParameter() override
1166 { return parameter_.rest; }
1168 rtl::Reference< cppuhelper::TypeManager > manager_;
1169 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1170 parameter_;
1171 sal_Int32 position_;
1174 class ConstructorDescription:
1175 public cppu::WeakImplHelper<
1176 css::reflection::XServiceConstructorDescription >
1178 public:
1179 ConstructorDescription(
1180 rtl::Reference< cppuhelper::TypeManager > const & manager,
1181 unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor):
1182 manager_(manager), constructor_(std::move(constructor))
1183 { assert(manager.is()); }
1185 private:
1186 virtual ~ConstructorDescription() override {}
1188 virtual sal_Bool SAL_CALL isDefaultConstructor() override
1189 { return constructor_.defaultConstructor; }
1191 virtual OUString SAL_CALL getName() override
1192 { return constructor_.name; }
1194 virtual
1195 css::uno::Sequence<
1196 css::uno::Reference< css::reflection::XParameter > >
1197 SAL_CALL getParameters() override;
1199 virtual
1200 css::uno::Sequence<
1201 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1202 SAL_CALL getExceptions() override;
1204 rtl::Reference< cppuhelper::TypeManager > manager_;
1205 unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor_;
1208 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
1209 ConstructorDescription::getParameters() {
1210 assert(constructor_.parameters.size() <= SAL_MAX_INT32);
1211 sal_Int32 n = static_cast< sal_Int32 >(constructor_.parameters.size());
1212 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > s(
1214 auto r = asNonConstRange(s);
1215 for (sal_Int32 i = 0; i != n; ++i) {
1216 r[i] = new ConstructorParameter(
1217 manager_, constructor_.parameters[i], i);
1219 return s;
1222 css::uno::Sequence<
1223 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1224 ConstructorDescription::getExceptions() {
1225 assert(constructor_.exceptions.size() <= SAL_MAX_INT32);
1226 sal_Int32 n = static_cast< sal_Int32 >(constructor_.exceptions.size());
1227 css::uno::Sequence<
1228 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
1229 auto r = asNonConstRange(s);
1230 for (sal_Int32 i = 0; i != n; ++i) {
1231 r[i].set(
1232 manager_->resolve(constructor_.exceptions[i]),
1233 css::uno::UNO_QUERY_THROW);
1235 return s;
1238 typedef cppu::ImplInheritanceHelper<
1239 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1240 SingleInterfaceBasedServiceDescription_Base;
1242 class SingleInterfaceBasedServiceDescription:
1243 public SingleInterfaceBasedServiceDescription_Base
1245 public:
1246 SingleInterfaceBasedServiceDescription(
1247 rtl::Reference< cppuhelper::TypeManager > const & manager,
1248 OUString name,
1249 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
1250 entity):
1251 SingleInterfaceBasedServiceDescription_Base(entity->isPublished()),
1252 manager_(manager), name_(std::move(name)), entity_(entity)
1253 { assert(manager.is()); assert(entity.is()); }
1255 private:
1256 virtual ~SingleInterfaceBasedServiceDescription() override {}
1258 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1259 { return css::uno::TypeClass_SERVICE; }
1261 virtual OUString SAL_CALL getName() override
1262 { return name_; }
1264 virtual
1265 css::uno::Sequence<
1266 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1267 SAL_CALL getMandatoryServices() override
1269 return css::uno::Sequence<
1270 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1273 virtual
1274 css::uno::Sequence<
1275 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1276 SAL_CALL getOptionalServices() override
1278 return css::uno::Sequence<
1279 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1282 virtual
1283 css::uno::Sequence<
1284 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1285 SAL_CALL getMandatoryInterfaces() override
1287 return css::uno::Sequence<
1288 css::uno::Reference<
1289 css::reflection::XInterfaceTypeDescription > >();
1292 virtual
1293 css::uno::Sequence<
1294 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1295 SAL_CALL getOptionalInterfaces() override
1297 return css::uno::Sequence<
1298 css::uno::Reference<
1299 css::reflection::XInterfaceTypeDescription > >();
1302 virtual
1303 css::uno::Sequence<
1304 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1305 SAL_CALL getProperties() override
1307 return css::uno::Sequence<
1308 css::uno::Reference<
1309 css::reflection::XPropertyTypeDescription > >();
1312 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1313 { return true; }
1315 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1316 getInterface() override
1317 { return manager_->resolve(entity_->getBase()); }
1319 virtual
1320 css::uno::Sequence<
1321 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1322 SAL_CALL getConstructors() override;
1324 rtl::Reference< cppuhelper::TypeManager > manager_;
1325 OUString name_;
1326 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
1329 css::uno::Sequence<
1330 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1331 SingleInterfaceBasedServiceDescription::getConstructors()
1333 assert(entity_->getConstructors().size() <= SAL_MAX_INT32);
1334 sal_Int32 n = static_cast< sal_Int32 >(entity_->getConstructors().size());
1335 css::uno::Sequence<
1336 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1337 s(n);
1338 auto r = asNonConstRange(s);
1339 for (sal_Int32 i = 0; i != n; ++i) {
1340 r[i] = new ConstructorDescription(
1341 manager_, entity_->getConstructors()[i]);
1343 return s;
1346 class PropertyDescription:
1347 public cppu::WeakImplHelper< css::reflection::XPropertyTypeDescription >
1349 public:
1350 PropertyDescription(
1351 rtl::Reference< cppuhelper::TypeManager > const & manager,
1352 unoidl::AccumulationBasedServiceEntity::Property property):
1353 manager_(manager), property_(std::move(property))
1354 { assert(manager.is()); }
1356 private:
1357 virtual ~PropertyDescription() override {}
1359 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1360 { return css::uno::TypeClass_PROPERTY; }
1362 virtual OUString SAL_CALL getName() override
1363 { return property_.name; }
1365 virtual sal_Int16 SAL_CALL getPropertyFlags() override
1366 { return property_.attributes; }
1368 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1369 getPropertyTypeDescription() override
1370 { return manager_->resolve(property_.type); }
1372 rtl::Reference< cppuhelper::TypeManager > manager_;
1373 unoidl::AccumulationBasedServiceEntity::Property property_;
1376 typedef cppu::ImplInheritanceHelper<
1377 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1378 AccumulationBasedServiceDescription_Base;
1380 class AccumulationBasedServiceDescription:
1381 public AccumulationBasedServiceDescription_Base
1383 public:
1384 AccumulationBasedServiceDescription(
1385 rtl::Reference< cppuhelper::TypeManager > const & manager,
1386 OUString name,
1387 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const &
1388 entity):
1389 AccumulationBasedServiceDescription_Base(entity->isPublished()),
1390 manager_(manager), name_(std::move(name)), entity_(entity)
1391 { assert(manager.is()); assert(entity.is()); }
1393 private:
1394 virtual ~AccumulationBasedServiceDescription() override {}
1396 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1397 { return css::uno::TypeClass_SERVICE; }
1399 virtual OUString SAL_CALL getName() override
1400 { return name_; }
1402 virtual
1403 css::uno::Sequence<
1404 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1405 SAL_CALL getMandatoryServices() override;
1407 virtual
1408 css::uno::Sequence<
1409 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1410 SAL_CALL getOptionalServices() override;
1412 virtual
1413 css::uno::Sequence<
1414 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1415 SAL_CALL getMandatoryInterfaces() override;
1417 virtual
1418 css::uno::Sequence<
1419 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1420 SAL_CALL getOptionalInterfaces() override;
1422 virtual
1423 css::uno::Sequence<
1424 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1425 SAL_CALL getProperties() override;
1427 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1428 { return false; }
1430 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1431 getInterface() override
1432 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1434 virtual
1435 css::uno::Sequence<
1436 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1437 SAL_CALL getConstructors() override
1439 return css::uno::Sequence<
1440 css::uno::Reference<
1441 css::reflection::XServiceConstructorDescription > >();
1444 rtl::Reference< cppuhelper::TypeManager > manager_;
1445 OUString name_;
1446 rtl::Reference< unoidl::AccumulationBasedServiceEntity > entity_;
1449 css::uno::Sequence<
1450 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1451 AccumulationBasedServiceDescription::getMandatoryServices()
1453 assert(entity_->getDirectMandatoryBaseServices().size() <= SAL_MAX_INT32);
1454 sal_Int32 n = static_cast< sal_Int32 >(
1455 entity_->getDirectMandatoryBaseServices().size());
1456 css::uno::Sequence<
1457 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1458 auto r = asNonConstRange(s);
1459 for (sal_Int32 i = 0; i != n; ++i) {
1460 r[i].set(
1461 manager_->resolve(
1462 entity_->getDirectMandatoryBaseServices()[i].name),
1463 css::uno::UNO_QUERY_THROW);
1465 return s;
1468 css::uno::Sequence<
1469 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1470 AccumulationBasedServiceDescription::getOptionalServices()
1472 assert(entity_->getDirectOptionalBaseServices().size() <= SAL_MAX_INT32);
1473 sal_Int32 n = static_cast< sal_Int32 >(
1474 entity_->getDirectOptionalBaseServices().size());
1475 css::uno::Sequence<
1476 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1477 auto r = asNonConstRange(s);
1478 for (sal_Int32 i = 0; i != n; ++i) {
1479 r[i].set(
1480 manager_->resolve(entity_->getDirectOptionalBaseServices()[i].name),
1481 css::uno::UNO_QUERY_THROW);
1483 return s;
1486 css::uno::Sequence<
1487 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1488 AccumulationBasedServiceDescription::getMandatoryInterfaces()
1490 assert(entity_->getDirectMandatoryBaseInterfaces().size() <= SAL_MAX_INT32);
1491 sal_Int32 n = static_cast< sal_Int32 >(
1492 entity_->getDirectMandatoryBaseInterfaces().size());
1493 css::uno::Sequence<
1494 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1496 auto r = asNonConstRange(s);
1497 for (sal_Int32 i = 0; i != n; ++i) {
1498 r[i].set(
1499 resolveTypedefs(
1500 manager_->find(
1501 entity_->getDirectMandatoryBaseInterfaces()[i].name)),
1502 css::uno::UNO_QUERY_THROW);
1504 return s;
1507 css::uno::Sequence<
1508 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1509 AccumulationBasedServiceDescription::getOptionalInterfaces()
1511 assert(entity_->getDirectOptionalBaseInterfaces().size() <= SAL_MAX_INT32);
1512 sal_Int32 n = static_cast< sal_Int32 >(
1513 entity_->getDirectOptionalBaseInterfaces().size());
1514 css::uno::Sequence<
1515 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1517 auto r = asNonConstRange(s);
1518 for (sal_Int32 i = 0; i != n; ++i) {
1519 r[i].set(
1520 resolveTypedefs(
1521 manager_->find(
1522 entity_->getDirectOptionalBaseInterfaces()[i].name)),
1523 css::uno::UNO_QUERY_THROW);
1525 return s;
1528 css::uno::Sequence<
1529 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1530 AccumulationBasedServiceDescription::getProperties()
1532 assert(entity_->getDirectProperties().size() <= SAL_MAX_INT32);
1533 sal_Int32 n = static_cast< sal_Int32 >(
1534 entity_->getDirectProperties().size());
1535 css::uno::Sequence<
1536 css::uno::Reference< css::reflection::XPropertyTypeDescription > > s(n);
1537 auto r = asNonConstRange(s);
1538 for (sal_Int32 i = 0; i != n; ++i) {
1539 r[i] = new PropertyDescription(
1540 manager_, entity_->getDirectProperties()[i]);
1542 return s;
1545 typedef cppu::ImplInheritanceHelper<
1546 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1547 InterfaceBasedSingletonDescription_Base;
1549 class InterfaceBasedSingletonDescription:
1550 public InterfaceBasedSingletonDescription_Base
1552 public:
1553 InterfaceBasedSingletonDescription(
1554 rtl::Reference< cppuhelper::TypeManager > const & manager,
1555 OUString name,
1556 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity):
1557 InterfaceBasedSingletonDescription_Base(entity->isPublished()),
1558 manager_(manager), name_(std::move(name)), entity_(entity)
1559 { assert(manager.is()); assert(entity.is()); }
1561 private:
1562 virtual ~InterfaceBasedSingletonDescription() override {}
1564 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1565 { return css::uno::TypeClass_SINGLETON; }
1567 virtual OUString SAL_CALL getName() override
1568 { return name_; }
1570 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1571 SAL_CALL getService() override
1573 return
1574 css::uno::Reference< css::reflection::XServiceTypeDescription >();
1577 virtual sal_Bool SAL_CALL isInterfaceBased() override
1578 { return true; }
1580 virtual css::uno::Reference< css::reflection::XTypeDescription >
1581 SAL_CALL getInterface() override
1582 { return manager_->resolve(entity_->getBase()); }
1584 rtl::Reference< cppuhelper::TypeManager > manager_;
1585 OUString name_;
1586 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
1589 typedef cppu::ImplInheritanceHelper<
1590 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1591 ServiceBasedSingletonDescription_Base;
1593 class ServiceBasedSingletonDescription:
1594 public ServiceBasedSingletonDescription_Base
1596 public:
1597 ServiceBasedSingletonDescription(
1598 rtl::Reference< cppuhelper::TypeManager > const & manager,
1599 OUString name,
1600 rtl::Reference< unoidl::ServiceBasedSingletonEntity > const & entity):
1601 ServiceBasedSingletonDescription_Base(entity->isPublished()),
1602 manager_(manager), name_(std::move(name)), entity_(entity)
1603 { assert(manager.is()); assert(entity.is()); }
1605 private:
1606 virtual ~ServiceBasedSingletonDescription() override {}
1608 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1609 { return css::uno::TypeClass_SINGLETON; }
1611 virtual OUString SAL_CALL getName() override
1612 { return name_; }
1614 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1615 SAL_CALL getService() override
1617 return css::uno::Reference< css::reflection::XServiceTypeDescription >(
1618 manager_->resolve(entity_->getBase()), css::uno::UNO_QUERY_THROW);
1621 virtual sal_Bool SAL_CALL isInterfaceBased() override
1622 { return false; }
1624 virtual css::uno::Reference< css::reflection::XTypeDescription >
1625 SAL_CALL getInterface() override
1626 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1628 rtl::Reference< cppuhelper::TypeManager > manager_;
1629 OUString name_;
1630 rtl::Reference< unoidl::ServiceBasedSingletonEntity > entity_;
1633 class Enumeration:
1634 public cppu::WeakImplHelper< css::reflection::XTypeDescriptionEnumeration >
1636 public:
1637 Enumeration(
1638 rtl::Reference< cppuhelper::TypeManager > const & manager,
1639 OUString const & prefix,
1640 rtl::Reference< unoidl::MapCursor > const & cursor,
1641 css::uno::Sequence< css::uno::TypeClass > const & types, bool deep):
1642 manager_(manager), types_(types), deep_(deep)
1644 assert(manager.is());
1645 positions_.push(Position(prefix, cursor));
1646 findNextMatch();
1649 private:
1650 virtual ~Enumeration() override {}
1652 virtual sal_Bool SAL_CALL hasMoreElements() override
1653 { return !positions_.empty(); }
1655 virtual css::uno::Any SAL_CALL nextElement() override
1656 { return css::uno::Any(nextTypeDescription()); }
1658 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1659 nextTypeDescription() override;
1661 bool matches(css::uno::TypeClass tc) const;
1663 void findNextMatch();
1665 struct Position {
1666 Position(
1667 OUString thePrefix,
1668 rtl::Reference< unoidl::MapCursor > const & theCursor):
1669 prefix(std::move(thePrefix)), cursor(theCursor)
1670 { assert(theCursor.is()); }
1672 Position(
1673 OUString thePrefix,
1674 rtl::Reference< unoidl::ConstantGroupEntity > const &
1675 theConstantGroup):
1676 prefix(std::move(thePrefix)), constantGroup(theConstantGroup),
1677 constantGroupIndex(constantGroup->getMembers().begin())
1678 { assert(theConstantGroup.is()); }
1680 Position(Position const & other):
1681 prefix(other.prefix), cursor(other.cursor),
1682 constantGroup(other.constantGroup)
1684 if (constantGroup.is()) {
1685 constantGroupIndex = other.constantGroupIndex;
1689 OUString prefix;
1690 rtl::Reference< unoidl::MapCursor > cursor;
1691 rtl::Reference< unoidl::ConstantGroupEntity > constantGroup;
1692 std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator
1693 constantGroupIndex;
1696 rtl::Reference< cppuhelper::TypeManager > manager_;
1697 css::uno::Sequence< css::uno::TypeClass > types_;
1698 bool deep_;
1700 std::mutex mutex_;
1701 std::stack< Position, std::vector<Position> > positions_;
1702 OUString current_;
1705 css::uno::Reference< css::reflection::XTypeDescription >
1706 Enumeration::nextTypeDescription()
1708 OUString name;
1710 std::scoped_lock g(mutex_);
1711 if (positions_.empty()) {
1712 throw css::container::NoSuchElementException(
1713 "exhausted XTypeDescriptionEnumeration",
1714 static_cast< cppu::OWeakObject * >(this));
1716 name = current_;
1717 findNextMatch();
1719 return manager_->resolve(name);
1722 bool Enumeration::matches(css::uno::TypeClass tc) const {
1723 if (!types_.hasElements()) {
1724 return true;
1726 for (const auto & i : types_) {
1727 if (i == tc) {
1728 return true;
1731 return false;
1734 void Enumeration::findNextMatch() {
1735 try {
1736 for (;;) {
1737 assert(!positions_.empty());
1738 OUString name;
1739 if (positions_.top().cursor.is()) { // root or module
1740 rtl::Reference< unoidl::Entity > ent(
1741 positions_.top().cursor->getNext(&name));
1742 if (!ent.is()) {
1743 positions_.pop();
1744 if (positions_.empty()) {
1745 break;
1747 continue;
1749 name = positions_.top().prefix + name;
1750 css::uno::TypeClass tc;
1751 switch (ent->getSort()) {
1752 case unoidl::Entity::SORT_MODULE:
1753 tc = css::uno::TypeClass_MODULE;
1754 if (deep_) {
1755 positions_.push(
1756 Position(
1757 makePrefix(name),
1758 static_cast< unoidl::ModuleEntity * >(
1759 ent.get())->createCursor()));
1761 break;
1762 case unoidl::Entity::SORT_ENUM_TYPE:
1763 tc = css::uno::TypeClass_ENUM;
1764 break;
1765 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
1766 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
1767 tc = css::uno::TypeClass_STRUCT;
1768 break;
1769 case unoidl::Entity::SORT_EXCEPTION_TYPE:
1770 tc = css::uno::TypeClass_EXCEPTION;
1771 break;
1772 case unoidl::Entity::SORT_INTERFACE_TYPE:
1773 tc = css::uno::TypeClass_INTERFACE;
1774 break;
1775 case unoidl::Entity::SORT_TYPEDEF:
1776 tc = css::uno::TypeClass_TYPEDEF;
1777 break;
1778 case unoidl::Entity::SORT_CONSTANT_GROUP:
1779 tc = css::uno::TypeClass_CONSTANTS;
1780 if (deep_ && matches(css::uno::TypeClass_CONSTANT)) {
1781 positions_.push(
1782 Position(
1783 makePrefix(name),
1784 static_cast< unoidl::ConstantGroupEntity * >(
1785 ent.get())));
1787 break;
1788 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
1789 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
1790 tc = css::uno::TypeClass_SERVICE;
1791 break;
1792 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
1793 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
1794 tc = css::uno::TypeClass_SINGLETON;
1795 break;
1796 default:
1797 for (;;) { std::abort(); } // this cannot happen
1799 if (matches(tc)) {
1800 current_ = name;
1801 break;
1803 } else { // constant group
1804 if (positions_.top().constantGroupIndex
1805 == positions_.top().constantGroup->getMembers().end())
1807 positions_.pop();
1808 if (positions_.empty()) {
1809 break;
1811 continue;
1813 current_ = positions_.top().prefix
1814 + positions_.top().constantGroupIndex++->name;
1815 break;
1818 } catch (unoidl::FileFormatException & e) {
1819 throw css::uno::DeploymentException(
1820 e.getUri() + ": " + e.getDetail(),
1821 static_cast< cppu::OWeakObject * >(this));
1827 cppuhelper::TypeManager::TypeManager():
1828 manager_(new unoidl::Manager)
1831 css::uno::Any cppuhelper::TypeManager::find(OUString const & name) {
1832 //TODO: caching? (here or in unoidl::Manager?)
1833 static constexpr std::pair<std::u16string_view, css::uno::TypeClass> const simple[] = {
1834 { u"void", css::uno::TypeClass_VOID },
1835 { u"boolean", css::uno::TypeClass_BOOLEAN },
1836 { u"byte", css::uno::TypeClass_BYTE },
1837 { u"short", css::uno::TypeClass_SHORT },
1838 { u"unsigned short", css::uno::TypeClass_UNSIGNED_SHORT },
1839 { u"long", css::uno::TypeClass_LONG },
1840 { u"unsigned long", css::uno::TypeClass_UNSIGNED_LONG },
1841 { u"hyper", css::uno::TypeClass_HYPER },
1842 { u"unsigned hyper", css::uno::TypeClass_UNSIGNED_HYPER },
1843 { u"float", css::uno::TypeClass_FLOAT },
1844 { u"double", css::uno::TypeClass_DOUBLE },
1845 { u"char", css::uno::TypeClass_CHAR },
1846 { u"string", css::uno::TypeClass_STRING },
1847 { u"type", css::uno::TypeClass_TYPE },
1848 { u"any", css::uno::TypeClass_ANY } };
1849 for (const auto& [ rName, rTypeClass ] : simple) {
1850 if (name == rName) {
1851 return css::uno::Any(
1852 css::uno::Reference< css::reflection::XTypeDescription >(
1853 new SimpleTypeDescription(rTypeClass, name)));
1856 if (name.startsWith("[]")) {
1857 return getSequenceType(name);
1859 sal_Int32 i = name.indexOf('<');
1860 if (i != -1) {
1861 return getInstantiatedStruct(name, i);
1863 i = name.indexOf("::");
1864 if (i != -1) {
1865 return getInterfaceMember(name, i);
1867 rtl::Reference< unoidl::Entity > ent(findEntity(name));
1868 if (ent.is()) {
1869 return getNamed(name, ent);
1871 i = name.lastIndexOf('.');
1872 if (i != -1) {
1873 OUString parent(name.copy(0, i));
1874 ent = findEntity(parent);
1875 if (ent.is()) {
1876 switch (ent->getSort()) {
1877 case unoidl::Entity::SORT_ENUM_TYPE:
1878 return getEnumMember(
1879 static_cast< unoidl::EnumTypeEntity * >(ent.get()),
1880 name.subView(i + 1));
1881 case unoidl::Entity::SORT_CONSTANT_GROUP:
1882 return getConstant(
1883 parent,
1884 static_cast< unoidl::ConstantGroupEntity * >(ent.get()),
1885 name.subView(i + 1));
1886 default:
1887 break;
1891 return css::uno::Any();
1894 css::uno::Reference< css::reflection::XTypeDescription >
1895 cppuhelper::TypeManager::resolve(OUString const & name) {
1896 css::uno::Reference< css::reflection::XTypeDescription > desc(
1897 find(name), css::uno::UNO_QUERY);
1898 if (!desc.is()) {
1899 throw css::uno::DeploymentException(
1900 "cannot resolve type \"" + name + "\"",
1901 static_cast< cppu::OWeakObject * >(this));
1903 return desc;
1906 cppuhelper::TypeManager::~TypeManager() noexcept {}
1908 OUString cppuhelper::TypeManager::getImplementationName()
1910 return
1911 "com.sun.star.comp.cppuhelper.bootstrap.TypeManager";
1914 sal_Bool cppuhelper::TypeManager::supportsService(
1915 OUString const & ServiceName)
1917 return cppu::supportsService(this, ServiceName);
1920 css::uno::Sequence< OUString >
1921 cppuhelper::TypeManager::getSupportedServiceNames()
1923 return { "com.sun.star.reflection.TypeDescriptionManager" }; //TODO
1926 css::uno::Any cppuhelper::TypeManager::getByHierarchicalName(
1927 OUString const & aName)
1929 css::uno::Any desc(find(aName));
1930 if (!desc.hasValue()) {
1931 throw css::container::NoSuchElementException(
1932 aName, static_cast< cppu::OWeakObject * >(this));
1934 return desc;
1937 sal_Bool cppuhelper::TypeManager::hasByHierarchicalName(
1938 OUString const & aName)
1940 return find(aName).hasValue();
1943 css::uno::Type cppuhelper::TypeManager::getElementType()
1945 return cppu::UnoType< OUString >::get();
1948 sal_Bool cppuhelper::TypeManager::hasElements()
1950 throw css::uno::RuntimeException(
1951 "TypeManager hasElements: method not supported",
1952 static_cast< cppu::OWeakObject * >(this));
1955 css::uno::Reference< css::container::XEnumeration >
1956 cppuhelper::TypeManager::createEnumeration()
1958 throw css::uno::RuntimeException(
1959 "TypeManager createEnumeration: method not supported",
1960 static_cast< cppu::OWeakObject * >(this));
1963 sal_Bool cppuhelper::TypeManager::has(css::uno::Any const &)
1965 throw css::uno::RuntimeException(
1966 "TypeManager has: method not supported",
1967 static_cast< cppu::OWeakObject * >(this));
1970 void cppuhelper::TypeManager::insert(css::uno::Any const & aElement)
1972 OUString uri;
1973 if (!(aElement >>= uri)) {
1974 throw css::lang::IllegalArgumentException(
1975 ("css.uno.theTypeDescriptionManager.insert expects a string URI"
1976 " argument"),
1977 static_cast< cppu::OWeakObject * >(this), 0);
1979 //TODO: check for ElementExistException
1980 //TODO: check for consistency with existing data
1981 readRdbFile(uri, false);
1984 void cppuhelper::TypeManager::remove(css::uno::Any const & aElement)
1986 OUString uri;
1987 if (!(aElement >>= uri)) {
1988 throw css::lang::IllegalArgumentException(
1989 ("css.uno.theTypeDescriptionManager.remove expects a string URI"
1990 " argument"),
1991 static_cast< cppu::OWeakObject * >(this), 0);
1993 //TODO: remove requests are silently ignored for now
1996 css::uno::Reference< css::reflection::XTypeDescriptionEnumeration >
1997 cppuhelper::TypeManager::createTypeDescriptionEnumeration(
1998 OUString const & moduleName,
1999 css::uno::Sequence< css::uno::TypeClass > const & types,
2000 css::reflection::TypeDescriptionSearchDepth depth)
2002 rtl::Reference< unoidl::MapCursor > cursor;
2003 try {
2004 cursor = manager_->createCursor(moduleName);
2005 } catch (unoidl::FileFormatException & e) {
2006 throw css::uno::DeploymentException(
2007 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2008 + e.getDetail()),
2009 static_cast< cppu::OWeakObject * >(this));
2011 if (!cursor.is()) {
2012 //TODO: css::reflection::InvalidTypeNameException if moduleName names a
2013 // non-module
2014 throw css::reflection::NoSuchTypeNameException(
2015 moduleName, static_cast< cppu::OWeakObject * >(this));
2017 return new Enumeration(
2018 this, makePrefix(moduleName), cursor, types,
2019 depth == css::reflection::TypeDescriptionSearchDepth_INFINITE);
2022 void cppuhelper::TypeManager::init(std::u16string_view rdbUris) {
2023 for (sal_Int32 i = 0; i != -1;) {
2024 std::u16string_view uri(o3tl::getToken(rdbUris, 0, ' ', i));
2025 if (uri.empty()) {
2026 continue;
2028 bool optional;
2029 bool directory;
2030 cppu::decodeRdbUri(&uri, &optional, &directory);
2031 if (directory) {
2032 readRdbDirectory(uri, optional);
2033 } else {
2034 readRdbFile(uri, optional);
2039 void cppuhelper::TypeManager::readRdbDirectory(
2040 std::u16string_view uri, bool optional)
2042 osl::Directory dir = OUString(uri);
2043 switch (dir.open()) {
2044 case osl::FileBase::E_None:
2045 break;
2046 case osl::FileBase::E_NOENT:
2047 if (optional) {
2048 SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri));
2049 return;
2051 [[fallthrough]];
2052 default:
2053 throw css::uno::DeploymentException(
2054 OUString::Concat("Cannot open directory ") + uri,
2055 static_cast< cppu::OWeakObject * >(this));
2057 for (;;) {
2058 OUString url;
2059 if (!cppu::nextDirectoryItem(dir, &url)) {
2060 break;
2062 readRdbFile(url, false);
2066 void cppuhelper::TypeManager::readRdbFile(
2067 std::u16string_view uri, bool optional)
2069 try {
2070 manager_->addProvider(OUString(uri));
2071 } catch (unoidl::NoSuchFileException &) {
2072 if (!optional) {
2073 throw css::uno::DeploymentException(
2074 OUString::Concat(uri) + ": no such file",
2075 static_cast< cppu::OWeakObject * >(this));
2077 SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri));
2078 } catch (unoidl::FileFormatException & e) {
2079 throw css::uno::DeploymentException(
2080 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2081 + e.getDetail()),
2082 static_cast< cppu::OWeakObject * >(this));
2086 css::uno::Any cppuhelper::TypeManager::getSequenceType(
2087 OUString const & name)
2089 assert(name.startsWith("[]"));
2090 return css::uno::Any(
2091 css::uno::Reference< css::reflection::XTypeDescription >(
2092 new SequenceTypeDescription(
2093 this, name, name.copy(std::strlen("[]")))));
2096 css::uno::Any cppuhelper::TypeManager::getInstantiatedStruct(
2097 OUString const & name, sal_Int32 separator)
2099 assert(name.indexOf('<') == separator && separator != -1);
2100 rtl::Reference< unoidl::Entity > ent(findEntity(name.copy(0, separator)));
2101 if (!ent.is()
2102 || (ent->getSort()
2103 != unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE))
2105 return css::uno::Any();
2107 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
2108 static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
2109 ent.get()));
2110 std::vector< OUString > args;
2111 sal_Int32 i = separator;
2112 do {
2113 ++i; // skip '<' or ','
2114 sal_Int32 j = i;
2115 for (sal_Int32 level = 0; j != name.getLength(); ++j) {
2116 sal_Unicode c = name[j];
2117 if (c == ',') {
2118 if (level == 0) {
2119 break;
2121 } else if (c == '<') {
2122 ++level;
2123 } else if (c == '>') {
2124 if (level == 0) {
2125 break;
2127 --level;
2130 if (j != name.getLength()) {
2131 args.push_back(name.copy(i, j - i));
2133 i = j;
2134 } while (i != name.getLength() && name[i] != '>');
2135 if (i != name.getLength() - 1 || name[i] != '>'
2136 || args.size() != ent2->getTypeParameters().size())
2138 return css::uno::Any();
2140 return css::uno::Any(
2141 css::uno::Reference< css::reflection::XTypeDescription >(
2142 new InstantiatedPolymorphicStructTypeDescription(
2143 this, name, ent2, std::move(args))));
2146 css::uno::Any cppuhelper::TypeManager::getInterfaceMember(
2147 std::u16string_view name, std::size_t separator)
2149 assert(name.find(u"::") == separator && separator != std::u16string_view::npos);
2150 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > ifc(
2151 resolveTypedefs(find(OUString(name.substr(0, separator)))), css::uno::UNO_QUERY);
2152 if (!ifc.is()) {
2153 return css::uno::Any();
2155 std::u16string_view member = name.substr(separator + std::strlen("::"));
2156 const css::uno::Sequence<
2157 css::uno::Reference<
2158 css::reflection::XInterfaceMemberTypeDescription > > mems(
2159 ifc->getMembers());
2160 for (const auto & m : mems) {
2161 if (m->getMemberName() == member) {
2162 return css::uno::Any(
2163 css::uno::Reference< css::reflection::XTypeDescription >(m));
2166 return css::uno::Any();
2169 css::uno::Any cppuhelper::TypeManager::getNamed(
2170 OUString const & name, rtl::Reference< unoidl::Entity > const & entity)
2172 assert(entity.is());
2173 switch (entity->getSort()) {
2174 case unoidl::Entity::SORT_MODULE:
2175 return css::uno::Any(
2176 css::uno::Reference< css::reflection::XTypeDescription >(
2177 new ModuleDescription(
2178 this, name,
2179 static_cast< unoidl::ModuleEntity * >(entity.get()))));
2180 case unoidl::Entity::SORT_ENUM_TYPE:
2181 return css::uno::Any(
2182 css::uno::Reference< css::reflection::XTypeDescription >(
2183 new EnumTypeDescription(
2184 name,
2185 static_cast< unoidl::EnumTypeEntity * >(entity.get()))));
2186 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
2187 return css::uno::Any(
2188 css::uno::Reference< css::reflection::XTypeDescription >(
2189 new PlainStructTypeDescription(
2190 this, name,
2191 static_cast< unoidl::PlainStructTypeEntity * >(
2192 entity.get()))));
2193 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
2194 return css::uno::Any(
2195 css::uno::Reference< css::reflection::XTypeDescription >(
2196 new PolymorphicStructTypeTemplateDescription(
2197 this, name,
2198 static_cast<
2199 unoidl::PolymorphicStructTypeTemplateEntity * >(
2200 entity.get()))));
2201 case unoidl::Entity::SORT_EXCEPTION_TYPE:
2202 return css::uno::Any(
2203 css::uno::Reference< css::reflection::XTypeDescription >(
2204 new ExceptionTypeDescription(
2205 this, name,
2206 static_cast< unoidl::ExceptionTypeEntity * >(
2207 entity.get()))));
2208 case unoidl::Entity::SORT_INTERFACE_TYPE:
2209 return css::uno::Any(
2210 css::uno::Reference< css::reflection::XTypeDescription >(
2211 new InterfaceTypeDescription(
2212 this, name,
2213 static_cast< unoidl::InterfaceTypeEntity * >(
2214 entity.get()))));
2215 case unoidl::Entity::SORT_TYPEDEF:
2216 return css::uno::Any(
2217 css::uno::Reference< css::reflection::XTypeDescription >(
2218 new TypedefDescription(
2219 this, name,
2220 static_cast< unoidl::TypedefEntity * >(entity.get()))));
2221 case unoidl::Entity::SORT_CONSTANT_GROUP:
2222 return css::uno::Any(
2223 css::uno::Reference< css::reflection::XTypeDescription >(
2224 new ConstantGroupDescription(
2225 name,
2226 static_cast< unoidl::ConstantGroupEntity * >(
2227 entity.get()))));
2228 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
2229 return css::uno::Any(
2230 css::uno::Reference< css::reflection::XTypeDescription >(
2231 new SingleInterfaceBasedServiceDescription(
2232 this, name,
2233 static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
2234 entity.get()))));
2235 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
2236 return css::uno::Any(
2237 css::uno::Reference< css::reflection::XTypeDescription >(
2238 new AccumulationBasedServiceDescription(
2239 this, name,
2240 static_cast< unoidl::AccumulationBasedServiceEntity * >(
2241 entity.get()))));
2242 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
2243 return css::uno::Any(
2244 css::uno::Reference< css::reflection::XTypeDescription >(
2245 new InterfaceBasedSingletonDescription(
2246 this, name,
2247 static_cast< unoidl::InterfaceBasedSingletonEntity * >(
2248 entity.get()))));
2249 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
2250 return css::uno::Any(
2251 css::uno::Reference< css::reflection::XTypeDescription >(
2252 new ServiceBasedSingletonDescription(
2253 this, name,
2254 static_cast< unoidl::ServiceBasedSingletonEntity * >(
2255 entity.get()))));
2256 default:
2257 for (;;) { std::abort(); } // this cannot happen
2261 css::uno::Any cppuhelper::TypeManager::getEnumMember(
2262 rtl::Reference< unoidl::EnumTypeEntity > const & entity,
2263 std::u16string_view member)
2265 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2266 [&member](const unoidl::EnumTypeEntity::Member& rMember) { return rMember.name == member; });
2267 if (i != entity->getMembers().end())
2268 return css::uno::Any(i->value);
2269 return css::uno::Any();
2272 css::uno::Any cppuhelper::TypeManager::getConstant(
2273 std::u16string_view constantGroupName,
2274 rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
2275 std::u16string_view member)
2277 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2278 [&member](const unoidl::ConstantGroupEntity::Member& rMember) { return rMember.name == member; });
2279 if (i != entity->getMembers().end())
2280 return css::uno::Any(
2281 css::uno::Reference< css::reflection::XTypeDescription >(
2282 new ConstantDescription(OUString(constantGroupName), *i)));
2283 return css::uno::Any();
2286 rtl::Reference< unoidl::Entity > cppuhelper::TypeManager::findEntity(
2287 OUString const & name)
2289 try {
2290 return manager_->findEntity(name);
2291 } catch (unoidl::FileFormatException & e) {
2292 throw css::uno::DeploymentException(
2293 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2294 + e.getDetail()),
2295 static_cast< cppu::OWeakObject * >(this));
2299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */