cURL: follow redirects
[LibreOffice.git] / cppuhelper / source / typemanager.cxx
blob7faddafee8ce5a5e1b494967b2df1a56b006c305
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 <vector>
20 #include <com/sun/star/container/ElementExistException.hpp>
21 #include <com/sun/star/container/NoSuchElementException.hpp>
22 #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include <com/sun/star/reflection/InvalidTypeNameException.hpp>
24 #include <com/sun/star/reflection/NoSuchTypeNameException.hpp>
25 #include <com/sun/star/reflection/TypeDescriptionSearchDepth.hpp>
26 #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
27 #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
28 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
29 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
30 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
31 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
32 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
33 #include <com/sun/star/reflection/XModuleTypeDescription.hpp>
34 #include <com/sun/star/reflection/XPublished.hpp>
35 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
36 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
37 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
38 #include <com/sun/star/reflection/XTypeDescription.hpp>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/uno/DeploymentException.hpp>
41 #include <com/sun/star/uno/Reference.hxx>
42 #include <com/sun/star/uno/RuntimeException.hpp>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <com/sun/star/uno/Type.hxx>
45 #include <com/sun/star/uno/TypeClass.hpp>
46 #include <cppu/unotype.hxx>
47 #include <cppuhelper/implbase1.hxx>
48 #include <cppuhelper/supportsservice.hxx>
49 #include <osl/file.hxx>
50 #include <osl/mutex.hxx>
51 #include <rtl/ref.hxx>
52 #include <rtl/string.h>
53 #include <rtl/ustring.hxx>
54 #include <sal/log.hxx>
55 #include <sal/macros.h>
56 #include <sal/types.h>
58 using rtl::OUString;
60 #include <unoidl/unoidl.hxx>
62 #include "paths.hxx"
63 #include "typemanager.hxx"
65 namespace {
67 rtl::OUString makePrefix(rtl::OUString const & name) {
68 return name.isEmpty() ? name : name + ".";
71 css::uno::Any resolveTypedefs(css::uno::Any const & type) {
72 for (css::uno::Any t(type);;) {
73 css::uno::Reference< css::reflection::XIndirectTypeDescription > ind(
74 type, css::uno::UNO_QUERY);
75 if (!ind.is() || ind->getTypeClass() != css::uno::TypeClass_TYPEDEF) {
76 return t;
78 t = css::uno::makeAny(ind->getReferencedType());
82 class SimpleTypeDescription:
83 public cppu::WeakImplHelper1< css::reflection::XTypeDescription >
85 public:
86 SimpleTypeDescription(
87 css::uno::TypeClass typeClass, rtl::OUString const & name):
88 typeClass_(typeClass), name_(name)
91 private:
92 virtual ~SimpleTypeDescription() override {}
94 virtual css::uno::TypeClass SAL_CALL getTypeClass()
95 throw (css::uno::RuntimeException, std::exception) override
96 { return typeClass_; }
98 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
99 { return name_; }
101 css::uno::TypeClass typeClass_;
102 rtl::OUString name_;
105 class SequenceTypeDescription:
106 public cppu::WeakImplHelper1< css::reflection::XIndirectTypeDescription >
108 public:
109 SequenceTypeDescription(
110 rtl::Reference< cppuhelper::TypeManager > const & manager,
111 rtl::OUString const & name, rtl::OUString const & componentType):
112 manager_(manager), name_(name), componentType_(componentType)
113 { assert(manager.is()); }
115 private:
116 virtual ~SequenceTypeDescription() override {}
118 virtual css::uno::TypeClass SAL_CALL getTypeClass()
119 throw (css::uno::RuntimeException, std::exception) override
120 { return css::uno::TypeClass_SEQUENCE; }
122 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
123 { return name_; }
125 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
126 getReferencedType() throw (css::uno::RuntimeException, std::exception) override
127 { return manager_->resolve(componentType_); }
129 rtl::Reference< cppuhelper::TypeManager > manager_;
130 rtl::OUString name_;
131 rtl::OUString componentType_;
134 class PublishableDescription:
135 public cppu::WeakImplHelper1< css::reflection::XPublished >
137 protected:
138 explicit PublishableDescription(bool published): published_(published) {}
140 virtual ~PublishableDescription() override {}
142 private:
143 virtual sal_Bool SAL_CALL isPublished() throw (css::uno::RuntimeException, std::exception) override
144 { return published_; }
146 bool published_;
149 class ModuleDescription:
150 public cppu::WeakImplHelper1< css::reflection::XModuleTypeDescription >
152 public:
153 ModuleDescription(
154 rtl::Reference< cppuhelper::TypeManager > const & manager,
155 rtl::OUString const & name,
156 rtl::Reference< unoidl::ModuleEntity > const & entity):
157 manager_(manager), name_(name), entity_(entity)
158 { assert(manager.is()); assert(entity.is()); }
160 private:
161 virtual ~ModuleDescription() override {}
163 virtual css::uno::TypeClass SAL_CALL getTypeClass()
164 throw (css::uno::RuntimeException, std::exception) override
165 { return css::uno::TypeClass_MODULE; }
167 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
168 { return name_; }
170 virtual
171 css::uno::Sequence<
172 css::uno::Reference< css::reflection::XTypeDescription > >
173 SAL_CALL getMembers() throw (css::uno::RuntimeException, std::exception) override;
175 rtl::Reference< cppuhelper::TypeManager > manager_;
176 rtl::OUString name_;
177 rtl::Reference< unoidl::ModuleEntity > entity_;
180 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
181 ModuleDescription::getMembers() throw (css::uno::RuntimeException, std::exception) {
182 try {
183 std::vector< rtl::OUString > names(entity_->getMemberNames());
184 assert(names.size() <= SAL_MAX_INT32);
185 sal_Int32 n = static_cast< sal_Int32 >(names.size());
186 css::uno::Sequence<
187 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
188 for (sal_Int32 i = 0; i != n; ++i) {
189 s[i] = manager_->resolve(makePrefix(name_) + names[i]);
191 return s;
192 } catch (unoidl::FileFormatException & e) {
193 throw css::uno::DeploymentException(
194 e.getUri() + ": " + e.getDetail(),
195 static_cast< cppu::OWeakObject * >(this));
199 typedef cppu::ImplInheritanceHelper1<
200 PublishableDescription, css::reflection::XEnumTypeDescription >
201 EnumTypeDescription_Base;
203 class EnumTypeDescription: public EnumTypeDescription_Base {
204 public:
205 EnumTypeDescription(
206 rtl::OUString const & name,
207 rtl::Reference< unoidl::EnumTypeEntity > const & entity):
208 EnumTypeDescription_Base(entity->isPublished()), name_(name),
209 entity_(entity)
210 { assert(entity.is()); }
212 private:
213 virtual ~EnumTypeDescription() override {}
215 virtual css::uno::TypeClass SAL_CALL getTypeClass()
216 throw (css::uno::RuntimeException, std::exception) override
217 { return css::uno::TypeClass_ENUM; }
219 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
220 { return name_; }
222 virtual sal_Int32 SAL_CALL getDefaultEnumValue()
223 throw (css::uno::RuntimeException, std::exception) override
224 { return entity_->getMembers()[0].value; }
226 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getEnumNames()
227 throw (css::uno::RuntimeException, std::exception) override;
229 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getEnumValues()
230 throw (css::uno::RuntimeException, std::exception) override;
232 rtl::OUString name_;
233 rtl::Reference< unoidl::EnumTypeEntity > entity_;
236 css::uno::Sequence< rtl::OUString > EnumTypeDescription::getEnumNames()
237 throw (css::uno::RuntimeException, std::exception)
239 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
240 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
241 css::uno::Sequence< rtl::OUString > s(n);
242 for (sal_Int32 i = 0; i != n; ++i) {
243 s[i] = entity_->getMembers()[i].name;
245 return s;
248 css::uno::Sequence< sal_Int32 > EnumTypeDescription::getEnumValues()
249 throw (css::uno::RuntimeException, std::exception)
251 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
252 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
253 css::uno::Sequence< sal_Int32 > s(n);
254 for (sal_Int32 i = 0; i != n; ++i) {
255 s[i] = entity_->getMembers()[i].value;
257 return s;
260 typedef cppu::ImplInheritanceHelper1<
261 PublishableDescription, css::reflection::XStructTypeDescription >
262 PlainStructTypeDescription_Base;
264 class PlainStructTypeDescription: public PlainStructTypeDescription_Base {
265 public:
266 PlainStructTypeDescription(
267 rtl::Reference< cppuhelper::TypeManager > const & manager,
268 rtl::OUString const & name,
269 rtl::Reference< unoidl::PlainStructTypeEntity > const & entity):
270 PlainStructTypeDescription_Base(entity->isPublished()),
271 manager_(manager), name_(name), entity_(entity)
272 { assert(manager.is()); assert(entity.is()); }
274 private:
275 virtual ~PlainStructTypeDescription() override {}
277 virtual css::uno::TypeClass SAL_CALL getTypeClass()
278 throw (css::uno::RuntimeException, std::exception) override
279 { return css::uno::TypeClass_STRUCT; }
281 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
282 { return name_; }
284 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
285 getBaseType() throw (css::uno::RuntimeException, std::exception) override {
286 return entity_->getDirectBase().isEmpty()
287 ? css::uno::Reference< css::reflection::XTypeDescription >()
288 : manager_->resolve(entity_->getDirectBase());
291 virtual
292 css::uno::Sequence<
293 css::uno::Reference< css::reflection::XTypeDescription > >
294 SAL_CALL getMemberTypes() throw (css::uno::RuntimeException, std::exception) override;
296 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getMemberNames()
297 throw (css::uno::RuntimeException, std::exception) override;
299 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getTypeParameters()
300 throw (css::uno::RuntimeException, std::exception) override
301 { return css::uno::Sequence< rtl::OUString >(); }
303 virtual
304 css::uno::Sequence<
305 css::uno::Reference< css::reflection::XTypeDescription > >
306 SAL_CALL getTypeArguments() throw (css::uno::RuntimeException, std::exception) override {
307 return css::uno::Sequence<
308 css::uno::Reference< css::reflection::XTypeDescription > >();
311 rtl::Reference< cppuhelper::TypeManager > manager_;
312 rtl::OUString name_;
313 rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
316 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
317 PlainStructTypeDescription::getMemberTypes() throw (css::uno::RuntimeException, std::exception)
319 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
320 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
321 css::uno::Sequence<
322 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
323 for (sal_Int32 i = 0; i != n; ++i) {
324 s[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
326 return s;
329 css::uno::Sequence< rtl::OUString > PlainStructTypeDescription::getMemberNames()
330 throw (css::uno::RuntimeException, std::exception)
332 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
333 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
334 css::uno::Sequence< rtl::OUString > s(n);
335 for (sal_Int32 i = 0; i != n; ++i) {
336 s[i] = entity_->getDirectMembers()[i].name;
338 return s;
341 class ParameterizedMemberTypeDescription:
342 public cppu::WeakImplHelper1< css::reflection::XTypeDescription >
344 public:
345 explicit ParameterizedMemberTypeDescription(
346 rtl::OUString const & typeParameterName):
347 typeParameterName_(typeParameterName)
350 private:
351 virtual ~ParameterizedMemberTypeDescription() override {}
353 virtual css::uno::TypeClass SAL_CALL getTypeClass()
354 throw (css::uno::RuntimeException, std::exception) override
355 { return css::uno::TypeClass_UNKNOWN; }
357 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
358 { return typeParameterName_; }
360 rtl::OUString typeParameterName_;
363 typedef cppu::ImplInheritanceHelper1<
364 PublishableDescription, css::reflection::XStructTypeDescription >
365 PolymorphicStructTypeTemplateDescription_Base;
367 class PolymorphicStructTypeTemplateDescription:
368 public PolymorphicStructTypeTemplateDescription_Base
370 public:
371 PolymorphicStructTypeTemplateDescription(
372 rtl::Reference< cppuhelper::TypeManager > const & manager,
373 rtl::OUString const & name,
374 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
375 entity):
376 PolymorphicStructTypeTemplateDescription_Base(entity->isPublished()),
377 manager_(manager), name_(name), entity_(entity)
378 { assert(manager.is()); assert(entity.is()); }
380 private:
381 virtual ~PolymorphicStructTypeTemplateDescription() override {}
383 virtual css::uno::TypeClass SAL_CALL getTypeClass()
384 throw (css::uno::RuntimeException, std::exception) override
385 { return css::uno::TypeClass_STRUCT; }
387 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
388 { return name_; }
390 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
391 getBaseType() throw (css::uno::RuntimeException, std::exception) override
392 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
394 virtual
395 css::uno::Sequence<
396 css::uno::Reference< css::reflection::XTypeDescription > >
397 SAL_CALL getMemberTypes() throw (css::uno::RuntimeException, std::exception) override;
399 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getMemberNames()
400 throw (css::uno::RuntimeException, std::exception) override;
402 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getTypeParameters()
403 throw (css::uno::RuntimeException, std::exception) override;
405 virtual
406 css::uno::Sequence<
407 css::uno::Reference< css::reflection::XTypeDescription > >
408 SAL_CALL getTypeArguments() throw (css::uno::RuntimeException, std::exception) override {
409 return css::uno::Sequence<
410 css::uno::Reference< css::reflection::XTypeDescription > >();
413 rtl::Reference< cppuhelper::TypeManager > manager_;
414 rtl::OUString name_;
415 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
418 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
419 PolymorphicStructTypeTemplateDescription::getMemberTypes()
420 throw (css::uno::RuntimeException, std::exception)
422 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
423 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
424 css::uno::Sequence<
425 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
426 for (sal_Int32 i = 0; i != n; ++i) {
427 s[i] = entity_->getMembers()[i].parameterized
428 ? new ParameterizedMemberTypeDescription(
429 entity_->getMembers()[i].type)
430 : manager_->resolve(entity_->getMembers()[i].type);
432 return s;
435 css::uno::Sequence< rtl::OUString >
436 PolymorphicStructTypeTemplateDescription::getMemberNames()
437 throw (css::uno::RuntimeException, std::exception)
439 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
440 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
441 css::uno::Sequence< rtl::OUString > s(n);
442 for (sal_Int32 i = 0; i != n; ++i) {
443 s[i] = entity_->getMembers()[i].name;
445 return s;
448 css::uno::Sequence< rtl::OUString >
449 PolymorphicStructTypeTemplateDescription::getTypeParameters()
450 throw (css::uno::RuntimeException, std::exception)
452 assert(entity_->getTypeParameters().size() <= SAL_MAX_INT32);
453 sal_Int32 n = static_cast< sal_Int32 >(entity_->getTypeParameters().size());
454 css::uno::Sequence< rtl::OUString > s(n);
455 for (sal_Int32 i = 0; i != n; ++i) {
456 s[i] = entity_->getTypeParameters()[i];
458 return s;
461 class InstantiatedPolymorphicStructTypeDescription:
462 public cppu::WeakImplHelper1< css::reflection::XStructTypeDescription >
464 public:
465 InstantiatedPolymorphicStructTypeDescription(
466 rtl::Reference< cppuhelper::TypeManager > const & manager,
467 rtl::OUString const & name,
468 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
469 entity,
470 std::vector< rtl::OUString > const & arguments):
471 manager_(manager), name_(name), entity_(entity), arguments_(arguments)
473 assert(manager.is());
474 assert(entity.is());
475 assert(arguments.size() == entity->getTypeParameters().size());
478 private:
479 virtual ~InstantiatedPolymorphicStructTypeDescription() override {}
481 virtual css::uno::TypeClass SAL_CALL getTypeClass()
482 throw (css::uno::RuntimeException, std::exception) override
483 { return css::uno::TypeClass_STRUCT; }
485 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
486 { return name_; }
488 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
489 getBaseType() throw (css::uno::RuntimeException, std::exception) override
490 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
492 virtual
493 css::uno::Sequence<
494 css::uno::Reference< css::reflection::XTypeDescription > >
495 SAL_CALL getMemberTypes() throw (css::uno::RuntimeException, std::exception) override;
497 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getMemberNames()
498 throw (css::uno::RuntimeException, std::exception) override;
500 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getTypeParameters()
501 throw (css::uno::RuntimeException, std::exception) override
502 { return css::uno::Sequence< rtl::OUString >(); }
504 virtual
505 css::uno::Sequence<
506 css::uno::Reference< css::reflection::XTypeDescription > >
507 SAL_CALL getTypeArguments() throw (css::uno::RuntimeException, std::exception) override;
509 rtl::Reference< cppuhelper::TypeManager > manager_;
510 rtl::OUString name_;
511 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
512 std::vector< rtl::OUString > arguments_;
515 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
516 InstantiatedPolymorphicStructTypeDescription::getMemberTypes()
517 throw (css::uno::RuntimeException, std::exception)
519 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
520 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
521 css::uno::Sequence<
522 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
523 for (sal_Int32 i = 0; i != n; ++i) {
524 rtl::OUString type(entity_->getMembers()[i].type);
525 if (entity_->getMembers()[i].parameterized) {
526 for (std::vector< rtl::OUString >::const_iterator j(
527 entity_->getTypeParameters().begin());
528 j != entity_->getTypeParameters().end(); ++j)
530 if (*j == type) {
531 type = arguments_[j - entity_->getTypeParameters().begin()];
532 goto found;
535 assert(false); // this cannot happen //TODO!
536 found:;
538 s[i] = manager_->resolve(type);
540 return s;
543 css::uno::Sequence< rtl::OUString >
544 InstantiatedPolymorphicStructTypeDescription::getMemberNames()
545 throw (css::uno::RuntimeException, std::exception)
547 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
548 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
549 css::uno::Sequence< rtl::OUString > s(n);
550 for (sal_Int32 i = 0; i != n; ++i) {
551 s[i] = entity_->getMembers()[i].name;
553 return s;
555 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
556 InstantiatedPolymorphicStructTypeDescription::getTypeArguments()
557 throw (css::uno::RuntimeException, std::exception)
559 assert(arguments_.size() <= SAL_MAX_INT32);
560 sal_Int32 n = static_cast< sal_Int32 >(arguments_.size());
561 css::uno::Sequence<
562 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
563 for (sal_Int32 i = 0; i != n; ++i) {
564 s[i] = manager_->resolve(arguments_[i]);
566 return s;
569 typedef cppu::ImplInheritanceHelper1<
570 PublishableDescription, css::reflection::XCompoundTypeDescription >
571 ExceptionTypeDescription_Base;
573 class ExceptionTypeDescription: public ExceptionTypeDescription_Base {
574 public:
575 ExceptionTypeDescription(
576 rtl::Reference< cppuhelper::TypeManager > const & manager,
577 rtl::OUString const & name,
578 rtl::Reference< unoidl::ExceptionTypeEntity > const & entity):
579 ExceptionTypeDescription_Base(entity->isPublished()), manager_(manager),
580 name_(name), entity_(entity)
581 { assert(manager.is()); assert(entity.is()); }
583 private:
584 virtual ~ExceptionTypeDescription() override {}
586 virtual css::uno::TypeClass SAL_CALL getTypeClass()
587 throw (css::uno::RuntimeException, std::exception) override
588 { return css::uno::TypeClass_EXCEPTION; }
590 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
591 { return name_; }
593 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
594 getBaseType() throw (css::uno::RuntimeException, std::exception) override {
595 return entity_->getDirectBase().isEmpty()
596 ? css::uno::Reference< css::reflection::XTypeDescription >()
597 : manager_->resolve(entity_->getDirectBase());
600 virtual
601 css::uno::Sequence<
602 css::uno::Reference< css::reflection::XTypeDescription > >
603 SAL_CALL getMemberTypes() throw (css::uno::RuntimeException, std::exception) override;
605 virtual css::uno::Sequence< rtl::OUString > SAL_CALL getMemberNames()
606 throw (css::uno::RuntimeException, std::exception) override;
608 rtl::Reference< cppuhelper::TypeManager > manager_;
609 rtl::OUString name_;
610 rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
613 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
614 ExceptionTypeDescription::getMemberTypes() throw (css::uno::RuntimeException, std::exception) {
615 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
616 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
617 css::uno::Sequence<
618 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
619 for (sal_Int32 i = 0; i != n; ++i) {
620 s[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
622 return s;
625 css::uno::Sequence< rtl::OUString > ExceptionTypeDescription::getMemberNames()
626 throw (css::uno::RuntimeException, std::exception)
628 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
629 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
630 css::uno::Sequence< rtl::OUString > s(n);
631 for (sal_Int32 i = 0; i != n; ++i) {
632 s[i] = entity_->getDirectMembers()[i].name;
634 return s;
637 class AttributeDescription:
638 public cppu::WeakImplHelper1<
639 css::reflection::XInterfaceAttributeTypeDescription2 >
641 public:
642 AttributeDescription(
643 rtl::Reference< cppuhelper::TypeManager > const & manager,
644 rtl::OUString const & name,
645 unoidl::InterfaceTypeEntity::Attribute const & attribute,
646 sal_Int32 position):
647 manager_(manager), name_(name), attribute_(attribute),
648 position_(position)
649 { assert(manager.is()); }
651 private:
652 virtual ~AttributeDescription() override {}
654 virtual css::uno::TypeClass SAL_CALL getTypeClass()
655 throw (css::uno::RuntimeException, std::exception) override
656 { return css::uno::TypeClass_INTERFACE_ATTRIBUTE; }
658 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
659 { return name_; }
661 virtual rtl::OUString SAL_CALL getMemberName()
662 throw (css::uno::RuntimeException, std::exception) override
663 { return attribute_.name; }
665 virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException, std::exception) override
666 { return position_; }
668 virtual sal_Bool SAL_CALL isReadOnly() throw (css::uno::RuntimeException, std::exception) override
669 { return attribute_.readOnly; }
671 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
672 getType() throw (css::uno::RuntimeException, std::exception) override
673 { return manager_->resolve(attribute_.type); }
675 virtual sal_Bool SAL_CALL isBound() throw (css::uno::RuntimeException, std::exception) override
676 { return attribute_.bound; }
678 virtual
679 css::uno::Sequence<
680 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
681 SAL_CALL getGetExceptions() throw (css::uno::RuntimeException, std::exception) override;
683 virtual
684 css::uno::Sequence<
685 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
686 SAL_CALL getSetExceptions() throw (css::uno::RuntimeException, std::exception) override;
688 rtl::Reference< cppuhelper::TypeManager > manager_;
689 rtl::OUString name_;
690 unoidl::InterfaceTypeEntity::Attribute attribute_;
691 sal_Int32 position_;
694 css::uno::Sequence<
695 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
696 AttributeDescription::getGetExceptions() throw (css::uno::RuntimeException, std::exception) {
697 assert(attribute_.getExceptions.size() <= SAL_MAX_INT32);
698 sal_Int32 n = static_cast< sal_Int32 >(attribute_.getExceptions.size());
699 css::uno::Sequence<
700 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
701 for (sal_Int32 i = 0; i != n; ++i) {
702 s[i].set(
703 manager_->resolve(attribute_.getExceptions[i]),
704 css::uno::UNO_QUERY_THROW);
706 return s;
709 css::uno::Sequence<
710 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
711 AttributeDescription::getSetExceptions() throw (css::uno::RuntimeException, std::exception) {
712 assert(attribute_.setExceptions.size() <= SAL_MAX_INT32);
713 sal_Int32 n = static_cast< sal_Int32 >(attribute_.setExceptions.size());
714 css::uno::Sequence<
715 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
716 for (sal_Int32 i = 0; i != n; ++i) {
717 s[i].set(
718 manager_->resolve(attribute_.setExceptions[i]),
719 css::uno::UNO_QUERY_THROW);
721 return s;
724 class MethodParameter:
725 public cppu::WeakImplHelper1< css::reflection::XMethodParameter >
727 public:
728 MethodParameter(
729 rtl::Reference< cppuhelper::TypeManager > const & manager,
730 unoidl::InterfaceTypeEntity::Method::Parameter const & parameter,
731 sal_Int32 position):
732 manager_(manager), parameter_(parameter), position_(position)
733 { assert(manager.is()); }
735 private:
736 virtual ~MethodParameter() override {}
738 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
739 { return parameter_.name; }
741 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
742 getType() throw (css::uno::RuntimeException, std::exception) override
743 { return manager_->resolve(parameter_.type); }
745 virtual sal_Bool SAL_CALL isIn() throw (css::uno::RuntimeException, std::exception) override {
746 return
747 (parameter_.direction
748 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
749 || (parameter_.direction
750 == unoidl::InterfaceTypeEntity::Method::Parameter::
751 DIRECTION_IN_OUT);
754 virtual sal_Bool SAL_CALL isOut() throw (css::uno::RuntimeException, std::exception) override {
755 return
756 (parameter_.direction
757 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT)
758 || (parameter_.direction
759 == unoidl::InterfaceTypeEntity::Method::Parameter::
760 DIRECTION_IN_OUT);
763 virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException, std::exception) override
764 { return position_; }
766 rtl::Reference< cppuhelper::TypeManager > manager_;
767 unoidl::InterfaceTypeEntity::Method::Parameter parameter_;
768 sal_Int32 position_;
771 class MethodDescription:
772 public cppu::WeakImplHelper1<
773 css::reflection::XInterfaceMethodTypeDescription >
775 public:
776 MethodDescription(
777 rtl::Reference< cppuhelper::TypeManager > const & manager,
778 rtl::OUString const & name,
779 unoidl::InterfaceTypeEntity::Method const & method, sal_Int32 position):
780 manager_(manager), name_(name), method_(method), position_(position)
781 { assert(manager.is()); }
783 private:
784 virtual ~MethodDescription() override {}
786 virtual css::uno::TypeClass SAL_CALL getTypeClass()
787 throw (css::uno::RuntimeException, std::exception) override
788 { return css::uno::TypeClass_INTERFACE_METHOD; }
790 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
791 { return name_; }
793 virtual rtl::OUString SAL_CALL getMemberName()
794 throw (css::uno::RuntimeException, std::exception) override
795 { return method_.name; }
797 virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException, std::exception) override
798 { return position_; }
800 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
801 getReturnType() throw (css::uno::RuntimeException, std::exception) override
802 { return manager_->resolve(method_.returnType); }
804 virtual sal_Bool SAL_CALL isOneway() throw (css::uno::RuntimeException, std::exception) override
805 { return false; }
807 virtual
808 css::uno::Sequence<
809 css::uno::Reference< css::reflection::XMethodParameter > >
810 SAL_CALL getParameters() throw (css::uno::RuntimeException, std::exception) override;
812 virtual
813 css::uno::Sequence<
814 css::uno::Reference< css::reflection::XTypeDescription > >
815 SAL_CALL getExceptions() throw (css::uno::RuntimeException, std::exception) override;
817 rtl::Reference< cppuhelper::TypeManager > manager_;
818 rtl::OUString name_;
819 unoidl::InterfaceTypeEntity::Method method_;
820 sal_Int32 position_;
823 css::uno::Sequence< css::uno::Reference< css::reflection::XMethodParameter > >
824 MethodDescription::getParameters() throw (css::uno::RuntimeException, std::exception) {
825 assert(method_.parameters.size() <= SAL_MAX_INT32);
826 sal_Int32 n = static_cast< sal_Int32 >(method_.parameters.size());
827 css::uno::Sequence<
828 css::uno::Reference< css::reflection::XMethodParameter > > s(n);
829 for (sal_Int32 i = 0; i != n; ++i) {
830 s[i] = new MethodParameter(manager_, method_.parameters[i], i);
832 return s;
835 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
836 MethodDescription::getExceptions() throw (css::uno::RuntimeException, std::exception) {
837 assert(method_.exceptions.size() <= SAL_MAX_INT32);
838 sal_Int32 n = static_cast< sal_Int32 >(method_.exceptions.size());
839 css::uno::Sequence<
840 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
841 for (sal_Int32 i = 0; i != n; ++i) {
842 s[i] = manager_->resolve(method_.exceptions[i]);
844 return s;
847 class BaseOffset {
848 public:
849 explicit BaseOffset(
850 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
851 const & description);
853 BaseOffset(const BaseOffset&) = delete;
854 const BaseOffset& operator=(const BaseOffset&) = delete;
856 sal_Int32 get() const { return offset_; }
858 private:
859 void calculateBases(
860 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
861 const & description);
863 void calculate(
864 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
865 const & description);
867 std::set< rtl::OUString > set_;
868 sal_Int32 offset_;
871 BaseOffset::BaseOffset(
872 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
873 description):
874 offset_(0)
876 calculateBases(description);
879 void BaseOffset::calculateBases(
880 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
881 description)
883 css::uno::Sequence<
884 css::uno::Reference < css::reflection::XTypeDescription > > bases(
885 description->getBaseTypes());
886 for (sal_Int32 i = 0; i != bases.getLength(); ++i) {
887 calculate(
888 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >(
889 resolveTypedefs(css::uno::makeAny(bases[i])),
890 css::uno::UNO_QUERY_THROW));
894 void BaseOffset::calculate(
895 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
896 description)
898 if (set_.insert(description->getName()).second) {
899 calculateBases(description);
900 offset_ += description->getMembers().getLength();
904 typedef cppu::ImplInheritanceHelper1<
905 PublishableDescription, css::reflection::XInterfaceTypeDescription2 >
906 InterfaceTypeDescription_Base;
908 class InterfaceTypeDescription: public InterfaceTypeDescription_Base {
909 public:
910 InterfaceTypeDescription(
911 rtl::Reference< cppuhelper::TypeManager > const & manager,
912 rtl::OUString const & name,
913 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
914 InterfaceTypeDescription_Base(entity->isPublished()), manager_(manager),
915 name_(name), entity_(entity)
916 { assert(manager.is()); assert(entity.is()); }
918 private:
919 virtual ~InterfaceTypeDescription() override {}
921 virtual css::uno::TypeClass SAL_CALL getTypeClass()
922 throw (css::uno::RuntimeException, std::exception) override
923 { return css::uno::TypeClass_INTERFACE; }
925 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
926 { return name_; }
928 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
929 getBaseType() throw (css::uno::RuntimeException, std::exception) override {
930 return entity_->getDirectMandatoryBases().empty()
931 ? css::uno::Reference< css::reflection::XTypeDescription >()
932 : manager_->resolve(entity_->getDirectMandatoryBases()[0].name);
935 virtual css::uno::Uik SAL_CALL getUik() throw (css::uno::RuntimeException, std::exception) override
936 { return css::uno::Uik(); }
938 virtual
939 css::uno::Sequence<
940 css::uno::Reference<
941 css::reflection::XInterfaceMemberTypeDescription > >
942 SAL_CALL getMembers() throw (css::uno::RuntimeException, std::exception) override;
944 virtual
945 css::uno::Sequence<
946 css::uno::Reference< css::reflection::XTypeDescription > >
947 SAL_CALL getBaseTypes() throw (css::uno::RuntimeException, std::exception) override;
949 virtual
950 css::uno::Sequence<
951 css::uno::Reference< css::reflection::XTypeDescription > >
952 SAL_CALL getOptionalBaseTypes() throw (css::uno::RuntimeException, std::exception) override;
954 rtl::Reference< cppuhelper::TypeManager > manager_;
955 rtl::OUString name_;
956 rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
959 css::uno::Sequence<
960 css::uno::Reference< css::reflection::XInterfaceMemberTypeDescription > >
961 InterfaceTypeDescription::getMembers() throw (css::uno::RuntimeException, std::exception) {
962 assert(
963 entity_->getDirectAttributes().size() <= SAL_MAX_INT32
964 && (entity_->getDirectMethods().size()
965 <= SAL_MAX_INT32 - entity_->getDirectAttributes().size()));
966 sal_Int32 n1 = static_cast< sal_Int32 >(
967 entity_->getDirectAttributes().size());
968 sal_Int32 n2 = static_cast< sal_Int32 >(entity_->getDirectMethods().size());
969 css::uno::Sequence<
970 css::uno::Reference<
971 css::reflection::XInterfaceMemberTypeDescription > > s(n1 + n2);
972 sal_Int32 off = BaseOffset(this).get();
973 for (sal_Int32 i = 0; i != n1; ++i) {
974 s[i] = new AttributeDescription(
975 manager_, name_ + "::" + entity_->getDirectAttributes()[i].name,
976 entity_->getDirectAttributes()[i], off + i);
978 for (sal_Int32 i = 0; i != n2; ++i) {
979 s[n1 + i] = new MethodDescription(
980 manager_, name_ + "::" + entity_->getDirectMethods()[i].name,
981 entity_->getDirectMethods()[i], off + n1 + i);
983 return s;
986 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
987 InterfaceTypeDescription::getBaseTypes() throw (css::uno::RuntimeException, std::exception) {
988 assert(entity_->getDirectMandatoryBases().size() <= SAL_MAX_INT32);
989 sal_Int32 n = static_cast< sal_Int32 >(
990 entity_->getDirectMandatoryBases().size());
991 css::uno::Sequence<
992 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
993 for (sal_Int32 i = 0; i != n; ++i) {
994 s[i] = manager_->resolve(entity_->getDirectMandatoryBases()[i].name);
996 return s;
999 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
1000 InterfaceTypeDescription::getOptionalBaseTypes()
1001 throw (css::uno::RuntimeException, std::exception)
1003 assert(entity_->getDirectOptionalBases().size() <= SAL_MAX_INT32);
1004 sal_Int32 n = static_cast< sal_Int32 >(
1005 entity_->getDirectOptionalBases().size());
1006 css::uno::Sequence<
1007 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
1008 for (sal_Int32 i = 0; i != n; ++i) {
1009 s[i] = manager_->resolve(entity_->getDirectOptionalBases()[i].name);
1011 return s;
1014 class ConstantDescription:
1015 public cppu::WeakImplHelper1< css::reflection::XConstantTypeDescription >
1017 public:
1018 ConstantDescription(
1019 rtl::OUString const & constantGroupName,
1020 unoidl::ConstantGroupEntity::Member const & member);
1022 private:
1023 virtual ~ConstantDescription() override {}
1025 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1026 throw (css::uno::RuntimeException, std::exception) override
1027 { return css::uno::TypeClass_CONSTANT; }
1029 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1030 { return name_; }
1032 virtual css::uno::Any SAL_CALL getConstantValue()
1033 throw (css::uno::RuntimeException, std::exception) override
1034 { return value_; }
1036 rtl::OUString name_;
1037 css::uno::Any value_;
1040 ConstantDescription::ConstantDescription(
1041 rtl::OUString const & constantGroupName,
1042 unoidl::ConstantGroupEntity::Member const & member):
1043 name_(makePrefix(constantGroupName) + member.name)
1045 switch (member.value.type) {
1046 case unoidl::ConstantValue::TYPE_BOOLEAN:
1047 value_ <<= member.value.booleanValue;
1048 break;
1049 case unoidl::ConstantValue::TYPE_BYTE:
1050 value_ <<= member.value.byteValue;
1051 break;
1052 case unoidl::ConstantValue::TYPE_SHORT:
1053 value_ <<= member.value.shortValue;
1054 break;
1055 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1056 value_ <<= member.value.unsignedShortValue;
1057 break;
1058 case unoidl::ConstantValue::TYPE_LONG:
1059 value_ <<= member.value.longValue;
1060 break;
1061 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1062 value_ <<= member.value.unsignedLongValue;
1063 break;
1064 case unoidl::ConstantValue::TYPE_HYPER:
1065 value_ <<= member.value.hyperValue;
1066 break;
1067 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1068 value_ <<= member.value.unsignedHyperValue;
1069 break;
1070 case unoidl::ConstantValue::TYPE_FLOAT:
1071 value_ <<= member.value.floatValue;
1072 break;
1073 case unoidl::ConstantValue::TYPE_DOUBLE:
1074 value_ <<= member.value.doubleValue;
1075 break;
1076 default:
1077 for (;;) { std::abort(); } // this cannot happen
1081 typedef cppu::ImplInheritanceHelper1<
1082 PublishableDescription, css::reflection::XConstantsTypeDescription >
1083 ConstantGroupDescription_Base;
1085 class ConstantGroupDescription: public ConstantGroupDescription_Base {
1086 public:
1087 ConstantGroupDescription(
1088 rtl::OUString const & name,
1089 rtl::Reference< unoidl::ConstantGroupEntity > const & entity):
1090 ConstantGroupDescription_Base(entity->isPublished()), name_(name),
1091 entity_(entity)
1092 { assert(entity.is()); }
1094 private:
1095 virtual ~ConstantGroupDescription() override {}
1097 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1098 throw (css::uno::RuntimeException, std::exception) override
1099 { return css::uno::TypeClass_CONSTANTS; }
1101 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1102 { return name_; }
1104 virtual
1105 css::uno::Sequence<
1106 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1107 SAL_CALL getConstants() throw (css::uno::RuntimeException, std::exception) override;
1109 rtl::OUString name_;
1110 rtl::Reference< unoidl::ConstantGroupEntity > entity_;
1113 css::uno::Sequence<
1114 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1115 ConstantGroupDescription::getConstants() throw (css::uno::RuntimeException, std::exception) {
1116 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
1117 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
1118 css::uno::Sequence<
1119 css::uno::Reference< css::reflection::XConstantTypeDescription > > s(n);
1120 for (sal_Int32 i = 0; i != n; ++i) {
1121 s[i] = new ConstantDescription(name_, entity_->getMembers()[i]);
1123 return s;
1126 typedef cppu::ImplInheritanceHelper1<
1127 PublishableDescription, css::reflection::XIndirectTypeDescription >
1128 TypedefDescription_Base;
1130 class TypedefDescription: public TypedefDescription_Base {
1131 public:
1132 TypedefDescription(
1133 rtl::Reference< cppuhelper::TypeManager > const & manager,
1134 rtl::OUString const & name,
1135 rtl::Reference< unoidl::TypedefEntity > const & entity):
1136 TypedefDescription_Base(entity->isPublished()), manager_(manager),
1137 name_(name), entity_(entity)
1138 { assert(manager.is()); assert(entity.is()); }
1140 private:
1141 virtual ~TypedefDescription() override {}
1143 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1144 throw (css::uno::RuntimeException, std::exception) override
1145 { return css::uno::TypeClass_TYPEDEF; }
1147 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1148 { return name_; }
1150 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1151 getReferencedType() throw (css::uno::RuntimeException, std::exception) override
1152 { return manager_->resolve(entity_->getType()); }
1154 rtl::Reference< cppuhelper::TypeManager > manager_;
1155 rtl::OUString name_;
1156 rtl::Reference< unoidl::TypedefEntity > entity_;
1159 class ConstructorParameter:
1160 public cppu::WeakImplHelper1< css::reflection::XParameter >
1162 public:
1163 ConstructorParameter(
1164 rtl::Reference< cppuhelper::TypeManager > const & manager,
1165 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1166 const & parameter,
1167 sal_Int32 position):
1168 manager_(manager), parameter_(parameter), position_(position)
1169 { assert(manager.is()); }
1171 private:
1172 virtual ~ConstructorParameter() override {}
1174 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1175 { return parameter_.name; }
1177 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1178 getType() throw (css::uno::RuntimeException, std::exception) override
1179 { return manager_->resolve(parameter_.type); }
1181 virtual sal_Bool SAL_CALL isIn() throw (css::uno::RuntimeException, std::exception) override
1182 { return true; }
1184 virtual sal_Bool SAL_CALL isOut() throw (css::uno::RuntimeException, std::exception) override
1185 { return false; }
1187 virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException, std::exception) override
1188 { return position_; }
1190 virtual sal_Bool SAL_CALL isRestParameter()
1191 throw (css::uno::RuntimeException, std::exception) override
1192 { return parameter_.rest; }
1194 rtl::Reference< cppuhelper::TypeManager > manager_;
1195 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1196 parameter_;
1197 sal_Int32 position_;
1200 class ConstructorDescription:
1201 public cppu::WeakImplHelper1<
1202 css::reflection::XServiceConstructorDescription >
1204 public:
1205 ConstructorDescription(
1206 rtl::Reference< cppuhelper::TypeManager > const & manager,
1207 unoidl::SingleInterfaceBasedServiceEntity::Constructor const &
1208 constructor):
1209 manager_(manager), constructor_(constructor)
1210 { assert(manager.is()); }
1212 private:
1213 virtual ~ConstructorDescription() override {}
1215 virtual sal_Bool SAL_CALL isDefaultConstructor()
1216 throw (css::uno::RuntimeException, std::exception) override
1217 { return constructor_.defaultConstructor; }
1219 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1220 { return constructor_.name; }
1222 virtual
1223 css::uno::Sequence<
1224 css::uno::Reference< css::reflection::XParameter > >
1225 SAL_CALL getParameters() throw (css::uno::RuntimeException, std::exception) override;
1227 virtual
1228 css::uno::Sequence<
1229 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1230 SAL_CALL getExceptions() throw (css::uno::RuntimeException, std::exception) override;
1232 rtl::Reference< cppuhelper::TypeManager > manager_;
1233 unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor_;
1236 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
1237 ConstructorDescription::getParameters() throw (css::uno::RuntimeException, std::exception) {
1238 assert(constructor_.parameters.size() <= SAL_MAX_INT32);
1239 sal_Int32 n = static_cast< sal_Int32 >(constructor_.parameters.size());
1240 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > s(
1242 for (sal_Int32 i = 0; i != n; ++i) {
1243 s[i] = new ConstructorParameter(
1244 manager_, constructor_.parameters[i], i);
1246 return s;
1249 css::uno::Sequence<
1250 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1251 ConstructorDescription::getExceptions() throw (css::uno::RuntimeException, std::exception) {
1252 assert(constructor_.exceptions.size() <= SAL_MAX_INT32);
1253 sal_Int32 n = static_cast< sal_Int32 >(constructor_.exceptions.size());
1254 css::uno::Sequence<
1255 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
1256 for (sal_Int32 i = 0; i != n; ++i) {
1257 s[i].set(
1258 manager_->resolve(constructor_.exceptions[i]),
1259 css::uno::UNO_QUERY_THROW);
1261 return s;
1264 typedef cppu::ImplInheritanceHelper1<
1265 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1266 SingleInterfaceBasedServiceDescription_Base;
1268 class SingleInterfaceBasedServiceDescription:
1269 public SingleInterfaceBasedServiceDescription_Base
1271 public:
1272 SingleInterfaceBasedServiceDescription(
1273 rtl::Reference< cppuhelper::TypeManager > const & manager,
1274 rtl::OUString const & name,
1275 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
1276 entity):
1277 SingleInterfaceBasedServiceDescription_Base(entity->isPublished()),
1278 manager_(manager), name_(name), entity_(entity)
1279 { assert(manager.is()); assert(entity.is()); }
1281 private:
1282 virtual ~SingleInterfaceBasedServiceDescription() override {}
1284 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1285 throw (css::uno::RuntimeException, std::exception) override
1286 { return css::uno::TypeClass_SERVICE; }
1288 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1289 { return name_; }
1291 virtual
1292 css::uno::Sequence<
1293 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1294 SAL_CALL getMandatoryServices() throw (css::uno::RuntimeException, std::exception) override
1296 return css::uno::Sequence<
1297 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1300 virtual
1301 css::uno::Sequence<
1302 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1303 SAL_CALL getOptionalServices() throw (css::uno::RuntimeException, std::exception) override
1305 return css::uno::Sequence<
1306 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1309 virtual
1310 css::uno::Sequence<
1311 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1312 SAL_CALL getMandatoryInterfaces() throw (css::uno::RuntimeException, std::exception) override
1314 return css::uno::Sequence<
1315 css::uno::Reference<
1316 css::reflection::XInterfaceTypeDescription > >();
1319 virtual
1320 css::uno::Sequence<
1321 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1322 SAL_CALL getOptionalInterfaces() throw (css::uno::RuntimeException, std::exception) override
1324 return css::uno::Sequence<
1325 css::uno::Reference<
1326 css::reflection::XInterfaceTypeDescription > >();
1329 virtual
1330 css::uno::Sequence<
1331 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1332 SAL_CALL getProperties() throw (css::uno::RuntimeException, std::exception) override
1334 return css::uno::Sequence<
1335 css::uno::Reference<
1336 css::reflection::XPropertyTypeDescription > >();
1339 virtual sal_Bool SAL_CALL isSingleInterfaceBased()
1340 throw (css::uno::RuntimeException, std::exception) override
1341 { return true; }
1343 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1344 getInterface() throw (css::uno::RuntimeException, std::exception) override
1345 { return manager_->resolve(entity_->getBase()); }
1347 virtual
1348 css::uno::Sequence<
1349 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1350 SAL_CALL getConstructors() throw (css::uno::RuntimeException, std::exception) override;
1352 rtl::Reference< cppuhelper::TypeManager > manager_;
1353 rtl::OUString name_;
1354 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
1357 css::uno::Sequence<
1358 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1359 SingleInterfaceBasedServiceDescription::getConstructors()
1360 throw (css::uno::RuntimeException, std::exception)
1362 assert(entity_->getConstructors().size() <= SAL_MAX_INT32);
1363 sal_Int32 n = static_cast< sal_Int32 >(entity_->getConstructors().size());
1364 css::uno::Sequence<
1365 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1366 s(n);
1367 for (sal_Int32 i = 0; i != n; ++i) {
1368 s[i] = new ConstructorDescription(
1369 manager_, entity_->getConstructors()[i]);
1371 return s;
1374 class PropertyDescription:
1375 public cppu::WeakImplHelper1< css::reflection::XPropertyTypeDescription >
1377 public:
1378 PropertyDescription(
1379 rtl::Reference< cppuhelper::TypeManager > const & manager,
1380 unoidl::AccumulationBasedServiceEntity::Property const & property):
1381 manager_(manager), property_(property)
1382 { assert(manager.is()); }
1384 private:
1385 virtual ~PropertyDescription() override {}
1387 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1388 throw (css::uno::RuntimeException, std::exception) override
1389 { return css::uno::TypeClass_PROPERTY; }
1391 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1392 { return property_.name; }
1394 virtual sal_Int16 SAL_CALL getPropertyFlags()
1395 throw (css::uno::RuntimeException, std::exception) override
1396 { return property_.attributes; }
1398 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1399 getPropertyTypeDescription() throw (css::uno::RuntimeException, std::exception) override
1400 { return manager_->resolve(property_.type); }
1402 rtl::Reference< cppuhelper::TypeManager > manager_;
1403 unoidl::AccumulationBasedServiceEntity::Property property_;
1406 typedef cppu::ImplInheritanceHelper1<
1407 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1408 AccumulationBasedServiceDescription_Base;
1410 class AccumulationBasedServiceDescription:
1411 public AccumulationBasedServiceDescription_Base
1413 public:
1414 AccumulationBasedServiceDescription(
1415 rtl::Reference< cppuhelper::TypeManager > const & manager,
1416 rtl::OUString const & name,
1417 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const &
1418 entity):
1419 AccumulationBasedServiceDescription_Base(entity->isPublished()),
1420 manager_(manager), name_(name), entity_(entity)
1421 { assert(manager.is()); assert(entity.is()); }
1423 private:
1424 virtual ~AccumulationBasedServiceDescription() override {}
1426 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1427 throw (css::uno::RuntimeException, std::exception) override
1428 { return css::uno::TypeClass_SERVICE; }
1430 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1431 { return name_; }
1433 virtual
1434 css::uno::Sequence<
1435 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1436 SAL_CALL getMandatoryServices() throw (css::uno::RuntimeException, std::exception) override;
1438 virtual
1439 css::uno::Sequence<
1440 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1441 SAL_CALL getOptionalServices() throw (css::uno::RuntimeException, std::exception) override;
1443 virtual
1444 css::uno::Sequence<
1445 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1446 SAL_CALL getMandatoryInterfaces() throw (css::uno::RuntimeException, std::exception) override;
1448 virtual
1449 css::uno::Sequence<
1450 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1451 SAL_CALL getOptionalInterfaces() throw (css::uno::RuntimeException, std::exception) override;
1453 virtual
1454 css::uno::Sequence<
1455 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1456 SAL_CALL getProperties() throw (css::uno::RuntimeException, std::exception) override;
1458 virtual sal_Bool SAL_CALL isSingleInterfaceBased()
1459 throw (css::uno::RuntimeException, std::exception) override
1460 { return false; }
1462 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1463 getInterface() throw (css::uno::RuntimeException, std::exception) override
1464 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1466 virtual
1467 css::uno::Sequence<
1468 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1469 SAL_CALL getConstructors() throw (css::uno::RuntimeException, std::exception) override
1471 return css::uno::Sequence<
1472 css::uno::Reference<
1473 css::reflection::XServiceConstructorDescription > >();
1476 rtl::Reference< cppuhelper::TypeManager > manager_;
1477 rtl::OUString name_;
1478 rtl::Reference< unoidl::AccumulationBasedServiceEntity > entity_;
1481 css::uno::Sequence<
1482 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1483 AccumulationBasedServiceDescription::getMandatoryServices()
1484 throw (css::uno::RuntimeException, std::exception)
1486 assert(entity_->getDirectMandatoryBaseServices().size() <= SAL_MAX_INT32);
1487 sal_Int32 n = static_cast< sal_Int32 >(
1488 entity_->getDirectMandatoryBaseServices().size());
1489 css::uno::Sequence<
1490 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1491 for (sal_Int32 i = 0; i != n; ++i) {
1492 s[i].set(
1493 manager_->resolve(
1494 entity_->getDirectMandatoryBaseServices()[i].name),
1495 css::uno::UNO_QUERY_THROW);
1497 return s;
1500 css::uno::Sequence<
1501 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1502 AccumulationBasedServiceDescription::getOptionalServices()
1503 throw (css::uno::RuntimeException, std::exception)
1505 assert(entity_->getDirectOptionalBaseServices().size() <= SAL_MAX_INT32);
1506 sal_Int32 n = static_cast< sal_Int32 >(
1507 entity_->getDirectOptionalBaseServices().size());
1508 css::uno::Sequence<
1509 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1510 for (sal_Int32 i = 0; i != n; ++i) {
1511 s[i].set(
1512 manager_->resolve(entity_->getDirectOptionalBaseServices()[i].name),
1513 css::uno::UNO_QUERY_THROW);
1515 return s;
1518 css::uno::Sequence<
1519 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1520 AccumulationBasedServiceDescription::getMandatoryInterfaces()
1521 throw (css::uno::RuntimeException, std::exception)
1523 assert(entity_->getDirectMandatoryBaseInterfaces().size() <= SAL_MAX_INT32);
1524 sal_Int32 n = static_cast< sal_Int32 >(
1525 entity_->getDirectMandatoryBaseInterfaces().size());
1526 css::uno::Sequence<
1527 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1529 for (sal_Int32 i = 0; i != n; ++i) {
1530 s[i].set(
1531 resolveTypedefs(
1532 manager_->find(
1533 entity_->getDirectMandatoryBaseInterfaces()[i].name)),
1534 css::uno::UNO_QUERY_THROW);
1536 return s;
1539 css::uno::Sequence<
1540 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1541 AccumulationBasedServiceDescription::getOptionalInterfaces()
1542 throw (css::uno::RuntimeException, std::exception)
1544 assert(entity_->getDirectOptionalBaseInterfaces().size() <= SAL_MAX_INT32);
1545 sal_Int32 n = static_cast< sal_Int32 >(
1546 entity_->getDirectOptionalBaseInterfaces().size());
1547 css::uno::Sequence<
1548 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1550 for (sal_Int32 i = 0; i != n; ++i) {
1551 s[i].set(
1552 resolveTypedefs(
1553 manager_->find(
1554 entity_->getDirectOptionalBaseInterfaces()[i].name)),
1555 css::uno::UNO_QUERY_THROW);
1557 return s;
1560 css::uno::Sequence<
1561 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1562 AccumulationBasedServiceDescription::getProperties()
1563 throw (css::uno::RuntimeException, std::exception)
1565 assert(entity_->getDirectProperties().size() <= SAL_MAX_INT32);
1566 sal_Int32 n = static_cast< sal_Int32 >(
1567 entity_->getDirectProperties().size());
1568 css::uno::Sequence<
1569 css::uno::Reference< css::reflection::XPropertyTypeDescription > > s(n);
1570 for (sal_Int32 i = 0; i != n; ++i) {
1571 s[i] = new PropertyDescription(
1572 manager_, entity_->getDirectProperties()[i]);
1574 return s;
1577 typedef cppu::ImplInheritanceHelper1<
1578 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1579 InterfaceBasedSingletonDescription_Base;
1581 class InterfaceBasedSingletonDescription:
1582 public InterfaceBasedSingletonDescription_Base
1584 public:
1585 InterfaceBasedSingletonDescription(
1586 rtl::Reference< cppuhelper::TypeManager > const & manager,
1587 rtl::OUString const & name,
1588 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity):
1589 InterfaceBasedSingletonDescription_Base(entity->isPublished()),
1590 manager_(manager), name_(name), entity_(entity)
1591 { assert(manager.is()); assert(entity.is()); }
1593 private:
1594 virtual ~InterfaceBasedSingletonDescription() override {}
1596 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1597 throw (css::uno::RuntimeException, std::exception) override
1598 { return css::uno::TypeClass_SINGLETON; }
1600 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1601 { return name_; }
1603 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1604 SAL_CALL getService() throw (css::uno::RuntimeException, std::exception) override
1606 return
1607 css::uno::Reference< css::reflection::XServiceTypeDescription >();
1610 virtual sal_Bool SAL_CALL isInterfaceBased()
1611 throw (css::uno::RuntimeException, std::exception) override
1612 { return true; }
1614 virtual css::uno::Reference< css::reflection::XTypeDescription >
1615 SAL_CALL getInterface() throw (css::uno::RuntimeException, std::exception) override
1616 { return manager_->resolve(entity_->getBase()); }
1618 rtl::Reference< cppuhelper::TypeManager > manager_;
1619 rtl::OUString name_;
1620 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
1623 typedef cppu::ImplInheritanceHelper1<
1624 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1625 ServiceBasedSingletonDescription_Base;
1627 class ServiceBasedSingletonDescription:
1628 public ServiceBasedSingletonDescription_Base
1630 public:
1631 ServiceBasedSingletonDescription(
1632 rtl::Reference< cppuhelper::TypeManager > const & manager,
1633 rtl::OUString const & name,
1634 rtl::Reference< unoidl::ServiceBasedSingletonEntity > const & entity):
1635 ServiceBasedSingletonDescription_Base(entity_->isPublished()),
1636 manager_(manager), name_(name), entity_(entity)
1637 { assert(manager.is()); assert(entity.is()); }
1639 private:
1640 virtual ~ServiceBasedSingletonDescription() override {}
1642 virtual css::uno::TypeClass SAL_CALL getTypeClass()
1643 throw (css::uno::RuntimeException, std::exception) override
1644 { return css::uno::TypeClass_SINGLETON; }
1646 virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException, std::exception) override
1647 { return name_; }
1649 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1650 SAL_CALL getService() throw (css::uno::RuntimeException, std::exception) override
1652 return css::uno::Reference< css::reflection::XServiceTypeDescription >(
1653 manager_->resolve(entity_->getBase()), css::uno::UNO_QUERY_THROW);
1656 virtual sal_Bool SAL_CALL isInterfaceBased()
1657 throw (css::uno::RuntimeException, std::exception) override
1658 { return false; }
1660 virtual css::uno::Reference< css::reflection::XTypeDescription >
1661 SAL_CALL getInterface() throw (css::uno::RuntimeException, std::exception) override
1662 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1664 rtl::Reference< cppuhelper::TypeManager > manager_;
1665 rtl::OUString name_;
1666 rtl::Reference< unoidl::ServiceBasedSingletonEntity > entity_;
1669 class Enumeration:
1670 public cppu::WeakImplHelper1< css::reflection::XTypeDescriptionEnumeration >
1672 public:
1673 Enumeration(
1674 rtl::Reference< cppuhelper::TypeManager > const & manager,
1675 rtl::OUString const & prefix,
1676 rtl::Reference< unoidl::MapCursor > const & cursor,
1677 css::uno::Sequence< css::uno::TypeClass > const & types, bool deep):
1678 manager_(manager), types_(types), deep_(deep)
1680 assert(manager.is());
1681 positions_.push(Position(prefix, cursor));
1682 findNextMatch();
1685 private:
1686 virtual ~Enumeration() override {}
1688 virtual sal_Bool SAL_CALL hasMoreElements()
1689 throw (css::uno::RuntimeException, std::exception) override
1690 { return !positions_.empty(); }
1692 virtual css::uno::Any SAL_CALL nextElement()
1693 throw (
1694 css::container::NoSuchElementException,
1695 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override
1696 { return css::uno::makeAny(nextTypeDescription()); }
1698 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1699 nextTypeDescription()
1700 throw (
1701 css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) override;
1703 bool matches(css::uno::TypeClass tc) const;
1705 void findNextMatch();
1707 struct Position {
1708 Position(
1709 rtl::OUString const & thePrefix,
1710 rtl::Reference< unoidl::MapCursor > const & theCursor):
1711 prefix(thePrefix), cursor(theCursor)
1712 { assert(theCursor.is()); }
1714 Position(
1715 rtl::OUString const & thePrefix,
1716 rtl::Reference< unoidl::ConstantGroupEntity > const &
1717 theConstantGroup):
1718 prefix(thePrefix), constantGroup(theConstantGroup),
1719 constantGroupIndex(constantGroup->getMembers().begin())
1720 { assert(theConstantGroup.is()); }
1722 Position(Position const & other):
1723 prefix(other.prefix), cursor(other.cursor),
1724 constantGroup(other.constantGroup)
1726 if (constantGroup.is()) {
1727 constantGroupIndex = other.constantGroupIndex;
1731 rtl::OUString prefix;
1732 rtl::Reference< unoidl::MapCursor > cursor;
1733 rtl::Reference< unoidl::ConstantGroupEntity > constantGroup;
1734 std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator
1735 constantGroupIndex;
1738 rtl::Reference< cppuhelper::TypeManager > manager_;
1739 css::uno::Sequence< css::uno::TypeClass > types_;
1740 bool deep_;
1742 osl::Mutex mutex_;
1743 std::stack< Position > positions_;
1744 rtl::OUString current_;
1747 css::uno::Reference< css::reflection::XTypeDescription >
1748 Enumeration::nextTypeDescription()
1749 throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception)
1751 rtl::OUString name;
1753 osl::MutexGuard g(mutex_);
1754 if (positions_.empty()) {
1755 throw css::container::NoSuchElementException(
1756 "exhausted XTypeDescriptionEnumeration",
1757 static_cast< cppu::OWeakObject * >(this));
1759 name = current_;
1760 findNextMatch();
1762 return manager_->resolve(name);
1765 bool Enumeration::matches(css::uno::TypeClass tc) const {
1766 if (types_.getLength() == 0) {
1767 return true;
1769 for (sal_Int32 i = 0; i != types_.getLength(); ++i) {
1770 if (types_[i] == tc) {
1771 return true;
1774 return false;
1777 void Enumeration::findNextMatch() {
1778 try {
1779 for (;;) {
1780 assert(!positions_.empty());
1781 rtl::OUString name;
1782 if (positions_.top().cursor.is()) { // root or module
1783 rtl::Reference< unoidl::Entity > ent(
1784 positions_.top().cursor->getNext(&name));
1785 if (!ent.is()) {
1786 positions_.pop();
1787 if (positions_.empty()) {
1788 break;
1790 continue;
1792 name = positions_.top().prefix + name;
1793 css::uno::TypeClass tc;
1794 switch (ent->getSort()) {
1795 case unoidl::Entity::SORT_MODULE:
1796 tc = css::uno::TypeClass_MODULE;
1797 if (deep_) {
1798 positions_.push(
1799 Position(
1800 makePrefix(name),
1801 static_cast< unoidl::ModuleEntity * >(
1802 ent.get())->createCursor()));
1804 break;
1805 case unoidl::Entity::SORT_ENUM_TYPE:
1806 tc = css::uno::TypeClass_ENUM;
1807 break;
1808 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
1809 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
1810 tc = css::uno::TypeClass_STRUCT;
1811 break;
1812 case unoidl::Entity::SORT_EXCEPTION_TYPE:
1813 tc = css::uno::TypeClass_EXCEPTION;
1814 break;
1815 case unoidl::Entity::SORT_INTERFACE_TYPE:
1816 tc = css::uno::TypeClass_INTERFACE;
1817 break;
1818 case unoidl::Entity::SORT_TYPEDEF:
1819 tc = css::uno::TypeClass_TYPEDEF;
1820 break;
1821 case unoidl::Entity::SORT_CONSTANT_GROUP:
1822 tc = css::uno::TypeClass_CONSTANTS;
1823 if (deep_ && matches(css::uno::TypeClass_CONSTANT)) {
1824 positions_.push(
1825 Position(
1826 makePrefix(name),
1827 static_cast< unoidl::ConstantGroupEntity * >(
1828 ent.get())));
1830 break;
1831 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
1832 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
1833 tc = css::uno::TypeClass_SERVICE;
1834 break;
1835 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
1836 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
1837 tc = css::uno::TypeClass_SINGLETON;
1838 break;
1839 default:
1840 for (;;) { std::abort(); } // this cannot happen
1842 if (matches(tc)) {
1843 current_ = name;
1844 break;
1846 } else { // constant group
1847 if (positions_.top().constantGroupIndex
1848 == positions_.top().constantGroup->getMembers().end())
1850 positions_.pop();
1851 if (positions_.empty()) {
1852 break;
1854 continue;
1856 current_ = positions_.top().prefix
1857 + positions_.top().constantGroupIndex++->name;
1858 break;
1861 } catch (unoidl::FileFormatException & e) {
1862 throw css::uno::DeploymentException(
1863 e.getUri() + ": " + e.getDetail(),
1864 static_cast< cppu::OWeakObject * >(this));
1870 cppuhelper::TypeManager::TypeManager():
1871 TypeManager_Base(m_aMutex),
1872 manager_(new unoidl::Manager)
1875 css::uno::Any cppuhelper::TypeManager::find(rtl::OUString const & name) {
1876 //TODO: caching? (here or in unoidl::Manager?)
1877 struct Simple {
1878 char const * name; sal_Int32 length;
1879 css::uno::TypeClass typeClass;
1881 static Simple const simple[] = {
1882 { RTL_CONSTASCII_STRINGPARAM("void"), css::uno::TypeClass_VOID },
1883 { RTL_CONSTASCII_STRINGPARAM("boolean"), css::uno::TypeClass_BOOLEAN },
1884 { RTL_CONSTASCII_STRINGPARAM("byte"), css::uno::TypeClass_BYTE },
1885 { RTL_CONSTASCII_STRINGPARAM("short"), css::uno::TypeClass_SHORT },
1886 { RTL_CONSTASCII_STRINGPARAM("unsigned short"),
1887 css::uno::TypeClass_UNSIGNED_SHORT },
1888 { RTL_CONSTASCII_STRINGPARAM("long"), css::uno::TypeClass_LONG },
1889 { RTL_CONSTASCII_STRINGPARAM("unsigned long"),
1890 css::uno::TypeClass_UNSIGNED_LONG },
1891 { RTL_CONSTASCII_STRINGPARAM("hyper"), css::uno::TypeClass_HYPER },
1892 { RTL_CONSTASCII_STRINGPARAM("unsigned hyper"),
1893 css::uno::TypeClass_UNSIGNED_HYPER },
1894 { RTL_CONSTASCII_STRINGPARAM("float"), css::uno::TypeClass_FLOAT },
1895 { RTL_CONSTASCII_STRINGPARAM("double"), css::uno::TypeClass_DOUBLE },
1896 { RTL_CONSTASCII_STRINGPARAM("char"), css::uno::TypeClass_CHAR },
1897 { RTL_CONSTASCII_STRINGPARAM("string"), css::uno::TypeClass_STRING },
1898 { RTL_CONSTASCII_STRINGPARAM("type"), css::uno::TypeClass_TYPE },
1899 { RTL_CONSTASCII_STRINGPARAM("any"), css::uno::TypeClass_ANY } };
1900 for (std::size_t i = 0; i != SAL_N_ELEMENTS(simple); ++i) {
1901 if (name.equalsAsciiL(simple[i].name, simple[i].length)) {
1902 return css::uno::makeAny<
1903 css::uno::Reference< css::reflection::XTypeDescription > >(
1904 new SimpleTypeDescription(simple[i].typeClass, name));
1907 if (name.startsWith("[]")) {
1908 return getSequenceType(name);
1910 sal_Int32 i = name.indexOf('<');
1911 if (i != -1) {
1912 return getInstantiatedStruct(name, i);
1914 i = name.indexOf("::");
1915 if (i != -1) {
1916 return getInterfaceMember(name, i);
1918 rtl::Reference< unoidl::Entity > ent(findEntity(name));
1919 if (ent.is()) {
1920 return getNamed(name, ent);
1922 i = name.lastIndexOf('.');
1923 if (i != -1) {
1924 rtl::OUString parent(name.copy(0, i));
1925 ent = findEntity(parent);
1926 if (ent.is()) {
1927 switch (ent->getSort()) {
1928 case unoidl::Entity::SORT_ENUM_TYPE:
1929 return getEnumMember(
1930 static_cast< unoidl::EnumTypeEntity * >(ent.get()),
1931 name.copy(i + 1));
1932 case unoidl::Entity::SORT_CONSTANT_GROUP:
1933 return getConstant(
1934 parent,
1935 static_cast< unoidl::ConstantGroupEntity * >(ent.get()),
1936 name.copy(i + 1));
1937 default:
1938 break;
1942 return css::uno::Any();
1945 css::uno::Reference< css::reflection::XTypeDescription >
1946 cppuhelper::TypeManager::resolve(rtl::OUString const & name) {
1947 css::uno::Reference< css::reflection::XTypeDescription > desc(
1948 find(name), css::uno::UNO_QUERY);
1949 if (!desc.is()) {
1950 throw css::uno::DeploymentException(
1951 "cannot resolve type \"" + name + "\"",
1952 static_cast< cppu::OWeakObject * >(this));
1954 return desc;
1957 cppuhelper::TypeManager::~TypeManager() throw () {}
1959 void cppuhelper::TypeManager::disposing() {} //TODO
1961 rtl::OUString cppuhelper::TypeManager::getImplementationName()
1962 throw (css::uno::RuntimeException, std::exception)
1964 return rtl::OUString(
1965 "com.sun.star.comp.cppuhelper.bootstrap.TypeManager");
1968 sal_Bool cppuhelper::TypeManager::supportsService(
1969 rtl::OUString const & ServiceName)
1970 throw (css::uno::RuntimeException, std::exception)
1972 return cppu::supportsService(this, ServiceName);
1975 css::uno::Sequence< rtl::OUString >
1976 cppuhelper::TypeManager::getSupportedServiceNames()
1977 throw (css::uno::RuntimeException, std::exception)
1979 css::uno::Sequence<OUString> names { "com.sun.star.reflection.TypeDescriptionManager" }; //TODO
1980 return names;
1983 css::uno::Any cppuhelper::TypeManager::getByHierarchicalName(
1984 rtl::OUString const & aName)
1985 throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception)
1987 css::uno::Any desc(find(aName));
1988 if (!desc.hasValue()) {
1989 throw css::container::NoSuchElementException(
1990 aName, static_cast< cppu::OWeakObject * >(this));
1992 return desc;
1995 sal_Bool cppuhelper::TypeManager::hasByHierarchicalName(
1996 rtl::OUString const & aName)
1997 throw (css::uno::RuntimeException, std::exception)
1999 return find(aName).hasValue();
2002 css::uno::Type cppuhelper::TypeManager::getElementType()
2003 throw (css::uno::RuntimeException, std::exception)
2005 return cppu::UnoType< rtl::OUString >::get();
2008 sal_Bool cppuhelper::TypeManager::hasElements()
2009 throw (css::uno::RuntimeException, std::exception)
2011 throw css::uno::RuntimeException(
2012 "TypeManager hasElements: method not supported",
2013 static_cast< cppu::OWeakObject * >(this));
2016 css::uno::Reference< css::container::XEnumeration >
2017 cppuhelper::TypeManager::createEnumeration()
2018 throw (css::uno::RuntimeException, std::exception)
2020 throw css::uno::RuntimeException(
2021 "TypeManager createEnumeration: method not supported",
2022 static_cast< cppu::OWeakObject * >(this));
2025 sal_Bool cppuhelper::TypeManager::has(css::uno::Any const &)
2026 throw (css::uno::RuntimeException, std::exception)
2028 throw css::uno::RuntimeException(
2029 "TypeManager has: method not supported",
2030 static_cast< cppu::OWeakObject * >(this));
2033 void cppuhelper::TypeManager::insert(css::uno::Any const & aElement)
2034 throw (
2035 css::lang::IllegalArgumentException,
2036 css::container::ElementExistException, css::uno::RuntimeException, std::exception)
2038 rtl::OUString uri;
2039 if (!(aElement >>= uri)) {
2040 throw css::lang::IllegalArgumentException(
2041 ("css.uno.theTypeDescriptionManager.insert expects a string URI"
2042 " argument"),
2043 static_cast< cppu::OWeakObject * >(this), 0);
2045 //TODO: check for ElementExistException
2046 //TODO: check for consistency with existing data
2047 readRdbFile(uri, false);
2050 void cppuhelper::TypeManager::remove(css::uno::Any const & aElement)
2051 throw (
2052 css::lang::IllegalArgumentException,
2053 css::container::NoSuchElementException, css::uno::RuntimeException, std::exception)
2055 rtl::OUString uri;
2056 if (!(aElement >>= uri)) {
2057 throw css::lang::IllegalArgumentException(
2058 ("css.uno.theTypeDescriptionManager.remove expects a string URI"
2059 " argument"),
2060 static_cast< cppu::OWeakObject * >(this), 0);
2062 //TODO: remove requests are silently ignored for now
2065 css::uno::Reference< css::reflection::XTypeDescriptionEnumeration >
2066 cppuhelper::TypeManager::createTypeDescriptionEnumeration(
2067 rtl::OUString const & moduleName,
2068 css::uno::Sequence< css::uno::TypeClass > const & types,
2069 css::reflection::TypeDescriptionSearchDepth depth)
2070 throw (
2071 css::reflection::NoSuchTypeNameException,
2072 css::reflection::InvalidTypeNameException,
2073 css::uno::RuntimeException, std::exception)
2075 rtl::Reference< unoidl::MapCursor > cursor;
2076 try {
2077 cursor = manager_->createCursor(moduleName);
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));
2084 if (!cursor.is()) {
2085 //TODO: css::reflection::InvalidTypeNameException if moduleName names a
2086 // non-module
2087 throw css::reflection::NoSuchTypeNameException(
2088 moduleName, static_cast< cppu::OWeakObject * >(this));
2090 return new Enumeration(
2091 this, makePrefix(moduleName), cursor, types,
2092 depth == css::reflection::TypeDescriptionSearchDepth_INFINITE);
2095 void cppuhelper::TypeManager::init(rtl::OUString const & rdbUris) {
2096 for (sal_Int32 i = 0; i != -1;) {
2097 rtl::OUString uri(rdbUris.getToken(0, ' ', i));
2098 if (uri.isEmpty()) {
2099 continue;
2101 bool optional;
2102 bool directory;
2103 cppu::decodeRdbUri(&uri, &optional, &directory);
2104 if (directory) {
2105 readRdbDirectory(uri, optional);
2106 } else {
2107 readRdbFile(uri, optional);
2112 void cppuhelper::TypeManager::readRdbDirectory(
2113 rtl::OUString const & uri, bool optional)
2115 osl::Directory dir(uri);
2116 switch (dir.open()) {
2117 case osl::FileBase::E_None:
2118 break;
2119 case osl::FileBase::E_NOENT:
2120 if (optional) {
2121 SAL_INFO("cppuhelper", "Ignored optional " << uri);
2122 return;
2124 SAL_FALLTHROUGH;
2125 default:
2126 throw css::uno::DeploymentException(
2127 "Cannot open directory " + uri,
2128 static_cast< cppu::OWeakObject * >(this));
2130 for (;;) {
2131 rtl::OUString url;
2132 if (!cppu::nextDirectoryItem(dir, &url)) {
2133 break;
2135 readRdbFile(url, false);
2139 void cppuhelper::TypeManager::readRdbFile(
2140 rtl::OUString const & uri, bool optional)
2142 try {
2143 manager_->addProvider(uri);
2144 } catch (unoidl::NoSuchFileException &) {
2145 if (!optional) {
2146 throw css::uno::DeploymentException(
2147 uri + ": no such file",
2148 static_cast< cppu::OWeakObject * >(this));
2150 SAL_INFO("cppuhelper", "Ignored optional " << uri);
2151 } catch (unoidl::FileFormatException & e) {
2152 throw css::uno::DeploymentException(
2153 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2154 + e.getDetail()),
2155 static_cast< cppu::OWeakObject * >(this));
2159 css::uno::Any cppuhelper::TypeManager::getSequenceType(
2160 rtl::OUString const & name)
2162 assert(name.startsWith("[]"));
2163 return css::uno::makeAny<
2164 css::uno::Reference< css::reflection::XTypeDescription > >(
2165 new SequenceTypeDescription(
2166 this, name, name.copy(std::strlen("[]"))));
2169 css::uno::Any cppuhelper::TypeManager::getInstantiatedStruct(
2170 rtl::OUString const & name, sal_Int32 separator)
2172 assert(name.indexOf('<') == separator && separator != -1);
2173 rtl::Reference< unoidl::Entity > ent(findEntity(name.copy(0, separator)));
2174 if (!ent.is()
2175 || (ent->getSort()
2176 != unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE))
2178 return css::uno::Any();
2180 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
2181 static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
2182 ent.get()));
2183 std::vector< rtl::OUString > args;
2184 sal_Int32 i = separator;
2185 do {
2186 ++i; // skip '<' or ','
2187 sal_Int32 j = i;
2188 for (sal_Int32 level = 0; j != name.getLength(); ++j) {
2189 sal_Unicode c = name[j];
2190 if (c == ',') {
2191 if (level == 0) {
2192 break;
2194 } else if (c == '<') {
2195 ++level;
2196 } else if (c == '>') {
2197 if (level == 0) {
2198 break;
2200 --level;
2203 if (j != name.getLength()) {
2204 args.push_back(name.copy(i, j - i));
2206 i = j;
2207 } while (i != name.getLength() && name[i] != '>');
2208 if (i != name.getLength() - 1 || name[i] != '>'
2209 || args.size() != ent2->getTypeParameters().size())
2211 return css::uno::Any();
2213 return css::uno::makeAny<
2214 css::uno::Reference< css::reflection::XTypeDescription > >(
2215 new InstantiatedPolymorphicStructTypeDescription(
2216 this, name, ent2, args));
2219 css::uno::Any cppuhelper::TypeManager::getInterfaceMember(
2220 rtl::OUString const & name, sal_Int32 separator)
2222 assert(name.indexOf("::") == separator && separator != -1);
2223 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > ifc(
2224 resolveTypedefs(find(name.copy(0, separator))), css::uno::UNO_QUERY);
2225 if (!ifc.is()) {
2226 return css::uno::Any();
2228 rtl::OUString member(name.copy(separator + std::strlen("::")));
2229 css::uno::Sequence<
2230 css::uno::Reference<
2231 css::reflection::XInterfaceMemberTypeDescription > > mems(
2232 ifc->getMembers());
2233 for (sal_Int32 i = 0; i != mems.getLength(); ++i) {
2234 if (mems[i]->getMemberName() == member) {
2235 return css::uno::makeAny<
2236 css::uno::Reference< css::reflection::XTypeDescription > >(
2237 mems[i]);
2240 return css::uno::Any();
2243 css::uno::Any cppuhelper::TypeManager::getNamed(
2244 rtl::OUString const & name, rtl::Reference< unoidl::Entity > const & entity)
2246 assert(entity.is());
2247 switch (entity->getSort()) {
2248 case unoidl::Entity::SORT_MODULE:
2249 return css::uno::makeAny<
2250 css::uno::Reference< css::reflection::XTypeDescription > >(
2251 new ModuleDescription(
2252 this, name,
2253 static_cast< unoidl::ModuleEntity * >(entity.get())));
2254 case unoidl::Entity::SORT_ENUM_TYPE:
2255 return css::uno::makeAny<
2256 css::uno::Reference< css::reflection::XTypeDescription > >(
2257 new EnumTypeDescription(
2258 name,
2259 static_cast< unoidl::EnumTypeEntity * >(entity.get())));
2260 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
2261 return css::uno::makeAny<
2262 css::uno::Reference< css::reflection::XTypeDescription > >(
2263 new PlainStructTypeDescription(
2264 this, name,
2265 static_cast< unoidl::PlainStructTypeEntity * >(
2266 entity.get())));
2267 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
2268 return css::uno::makeAny<
2269 css::uno::Reference< css::reflection::XTypeDescription > >(
2270 new PolymorphicStructTypeTemplateDescription(
2271 this, name,
2272 static_cast<
2273 unoidl::PolymorphicStructTypeTemplateEntity * >(
2274 entity.get())));
2275 case unoidl::Entity::SORT_EXCEPTION_TYPE:
2276 return css::uno::makeAny<
2277 css::uno::Reference< css::reflection::XTypeDescription > >(
2278 new ExceptionTypeDescription(
2279 this, name,
2280 static_cast< unoidl::ExceptionTypeEntity * >(
2281 entity.get())));
2282 case unoidl::Entity::SORT_INTERFACE_TYPE:
2283 return css::uno::makeAny<
2284 css::uno::Reference< css::reflection::XTypeDescription > >(
2285 new InterfaceTypeDescription(
2286 this, name,
2287 static_cast< unoidl::InterfaceTypeEntity * >(
2288 entity.get())));
2289 case unoidl::Entity::SORT_TYPEDEF:
2290 return css::uno::makeAny<
2291 css::uno::Reference< css::reflection::XTypeDescription > >(
2292 new TypedefDescription(
2293 this, name,
2294 static_cast< unoidl::TypedefEntity * >(entity.get())));
2295 case unoidl::Entity::SORT_CONSTANT_GROUP:
2296 return css::uno::makeAny<
2297 css::uno::Reference< css::reflection::XTypeDescription > >(
2298 new ConstantGroupDescription(
2299 name,
2300 static_cast< unoidl::ConstantGroupEntity * >(
2301 entity.get())));
2302 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
2303 return css::uno::makeAny<
2304 css::uno::Reference< css::reflection::XTypeDescription > >(
2305 new SingleInterfaceBasedServiceDescription(
2306 this, name,
2307 static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
2308 entity.get())));
2309 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
2310 return css::uno::makeAny<
2311 css::uno::Reference< css::reflection::XTypeDescription > >(
2312 new AccumulationBasedServiceDescription(
2313 this, name,
2314 static_cast< unoidl::AccumulationBasedServiceEntity * >(
2315 entity.get())));
2316 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
2317 return css::uno::makeAny<
2318 css::uno::Reference< css::reflection::XTypeDescription > >(
2319 new InterfaceBasedSingletonDescription(
2320 this, name,
2321 static_cast< unoidl::InterfaceBasedSingletonEntity * >(
2322 entity.get())));
2323 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
2324 return css::uno::makeAny<
2325 css::uno::Reference< css::reflection::XTypeDescription > >(
2326 new ServiceBasedSingletonDescription(
2327 this, name,
2328 static_cast< unoidl::ServiceBasedSingletonEntity * >(
2329 entity.get())));
2330 default:
2331 for (;;) { std::abort(); } // this cannot happen
2335 css::uno::Any cppuhelper::TypeManager::getEnumMember(
2336 rtl::Reference< unoidl::EnumTypeEntity > const & entity,
2337 rtl::OUString const & member)
2339 for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
2340 entity->getMembers().begin());
2341 i != entity->getMembers().end(); ++i)
2343 if (i->name == member) {
2344 return css::uno::makeAny(i->value);
2347 return css::uno::Any();
2350 css::uno::Any cppuhelper::TypeManager::getConstant(
2351 rtl::OUString const & constantGroupName,
2352 rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
2353 rtl::OUString const & member)
2355 for (std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator i(
2356 entity->getMembers().begin());
2357 i != entity->getMembers().end(); ++i)
2359 if (i->name == member) {
2360 return css::uno::makeAny<
2361 css::uno::Reference< css::reflection::XTypeDescription > >(
2362 new ConstantDescription(constantGroupName, *i));
2365 return css::uno::Any();
2368 rtl::Reference< unoidl::Entity > cppuhelper::TypeManager::findEntity(
2369 rtl::OUString const & name)
2371 try {
2372 return manager_->findEntity(name);
2373 } catch (unoidl::FileFormatException & e) {
2374 throw css::uno::DeploymentException(
2375 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2376 + e.getDetail()),
2377 static_cast< cppu::OWeakObject * >(this));
2381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */