Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "functiondescription.hxx"
22 :
23 : #include "com/sun/star/container/NoSuchElementException.hpp"
24 : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
25 : #include "com/sun/star/reflection/XCompoundTypeDescription.hpp"
26 : #include "com/sun/star/uno/Any.hxx"
27 : #include "com/sun/star/uno/Reference.hxx"
28 : #include "com/sun/star/uno/RuntimeException.hpp"
29 : #include "com/sun/star/uno/Sequence.hxx"
30 : #include "com/sun/star/uno/TypeClass.hpp"
31 : #include "com/sun/star/uno/XInterface.hpp"
32 : #include "cppuhelper/implbase1.hxx"
33 : #include "osl/diagnose.h"
34 : #include "osl/mutex.hxx"
35 : #include "registry/reader.hxx"
36 : #include "registry/version.h"
37 : #include "rtl/ustring.h"
38 : #include "rtl/ustring.hxx"
39 : #include "sal/types.h"
40 :
41 : using stoc::registry_tdprovider::FunctionDescription;
42 :
43 10240 : FunctionDescription::FunctionDescription(
44 : css::uno::Reference< css::container::XHierarchicalNameAccess > const &
45 : manager,
46 : com::sun::star::uno::Sequence< sal_Int8 > const & bytes,
47 : sal_uInt16 index):
48 10240 : m_manager(manager), m_bytes(bytes), m_index(index), m_exceptionsInit(false)
49 10240 : {}
50 :
51 10157 : FunctionDescription::~FunctionDescription() {}
52 :
53 : css::uno::Sequence<
54 : css::uno::Reference< css::reflection::XCompoundTypeDescription > >
55 1499 : FunctionDescription::getExceptions() const {
56 : {
57 1499 : osl::MutexGuard guard(m_mutex);
58 1499 : if (m_exceptionsInit) {
59 2 : return m_exceptions;
60 1499 : }
61 : }
62 1497 : typereg::Reader reader(getReader());
63 1497 : sal_uInt16 n = reader.getMethodExceptionCount(m_index);
64 : css::uno::Sequence<
65 : css::uno::Reference< css::reflection::XCompoundTypeDescription > >
66 1497 : exceptions(n);
67 2457 : for (sal_uInt16 i = 0; i < n; ++i) {
68 : rtl::OUString name(
69 960 : reader.getMethodExceptionTypeName(m_index, i).replace('/', '.'));
70 960 : css::uno::Any any;
71 : try {
72 960 : any = m_manager->getByHierarchicalName(name);
73 0 : } catch (const css::container::NoSuchElementException & e) {
74 : throw new css::uno::RuntimeException(
75 : (rtl::OUString(
76 : RTL_CONSTASCII_USTRINGPARAM(
77 : "com.sun.star.container.NoSuchElementException: "))
78 0 : + e.Message),
79 0 : css::uno::Reference< css::uno::XInterface >()); //TODO
80 : }
81 1920 : if (!(any >>= exceptions[i])
82 960 : || exceptions[i]->getTypeClass() != css::uno::TypeClass_EXCEPTION)
83 : {
84 : throw new css::uno::RuntimeException(
85 : (rtl::OUString(
86 : RTL_CONSTASCII_USTRINGPARAM("not an exception type: "))
87 0 : + name),
88 0 : css::uno::Reference< css::uno::XInterface >()); //TODO
89 : }
90 : OSL_ASSERT(exceptions[i].is());
91 960 : }
92 1497 : osl::MutexGuard guard(m_mutex);
93 1497 : if (!m_exceptionsInit) {
94 1497 : m_exceptions = exceptions;
95 1497 : m_exceptionsInit = true;
96 : }
97 1497 : return m_exceptions;
98 : }
99 :
100 2960 : typereg::Reader FunctionDescription::getReader() const {
101 : return typereg::Reader(
102 2960 : m_bytes.getConstArray(), m_bytes.getLength(), false, TYPEREG_VERSION_1);
103 : }
104 :
105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|