1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*647a425cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*647a425cSAndrew Rist * distributed with this work for additional information
6*647a425cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*647a425cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist * with the License. You may obtain a copy of the License at
10*647a425cSAndrew Rist *
11*647a425cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist *
13*647a425cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist * software distributed under the License is distributed on an
15*647a425cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist * KIND, either express or implied. See the License for the
17*647a425cSAndrew Rist * specific language governing permissions and limitations
18*647a425cSAndrew Rist * under the License.
19*647a425cSAndrew Rist *
20*647a425cSAndrew Rist *************************************************************/
21*647a425cSAndrew Rist
22*647a425cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "functiondescription.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "com/sun/star/container/NoSuchElementException.hpp"
30cdf0e10cSrcweir #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
31cdf0e10cSrcweir #include "com/sun/star/reflection/XCompoundTypeDescription.hpp"
32cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
33cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
34cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
35cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
36cdf0e10cSrcweir #include "com/sun/star/uno/TypeClass.hpp"
37cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
38cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
39cdf0e10cSrcweir #include "osl/diagnose.h"
40cdf0e10cSrcweir #include "osl/mutex.hxx"
41cdf0e10cSrcweir #include "registry/reader.hxx"
42cdf0e10cSrcweir #include "registry/version.h"
43cdf0e10cSrcweir #include "rtl/ustring.h"
44cdf0e10cSrcweir #include "rtl/ustring.hxx"
45cdf0e10cSrcweir #include "sal/types.h"
46cdf0e10cSrcweir
47cdf0e10cSrcweir namespace css = com::sun::star;
48cdf0e10cSrcweir
49cdf0e10cSrcweir using stoc::registry_tdprovider::FunctionDescription;
50cdf0e10cSrcweir
FunctionDescription(css::uno::Reference<css::container::XHierarchicalNameAccess> const & manager,com::sun::star::uno::Sequence<sal_Int8> const & bytes,sal_uInt16 index)51cdf0e10cSrcweir FunctionDescription::FunctionDescription(
52cdf0e10cSrcweir css::uno::Reference< css::container::XHierarchicalNameAccess > const &
53cdf0e10cSrcweir manager,
54cdf0e10cSrcweir com::sun::star::uno::Sequence< sal_Int8 > const & bytes,
55cdf0e10cSrcweir sal_uInt16 index):
56cdf0e10cSrcweir m_manager(manager), m_bytes(bytes), m_index(index), m_exceptionsInit(false)
57cdf0e10cSrcweir {}
58cdf0e10cSrcweir
~FunctionDescription()59cdf0e10cSrcweir FunctionDescription::~FunctionDescription() {}
60cdf0e10cSrcweir
61cdf0e10cSrcweir css::uno::Sequence<
62cdf0e10cSrcweir css::uno::Reference< css::reflection::XCompoundTypeDescription > >
getExceptions() const63cdf0e10cSrcweir FunctionDescription::getExceptions() const {
64cdf0e10cSrcweir {
65cdf0e10cSrcweir osl::MutexGuard guard(m_mutex);
66cdf0e10cSrcweir if (m_exceptionsInit) {
67cdf0e10cSrcweir return m_exceptions;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir }
70cdf0e10cSrcweir typereg::Reader reader(getReader());
71cdf0e10cSrcweir sal_uInt16 n = reader.getMethodExceptionCount(m_index);
72cdf0e10cSrcweir css::uno::Sequence<
73cdf0e10cSrcweir css::uno::Reference< css::reflection::XCompoundTypeDescription > >
74cdf0e10cSrcweir exceptions(n);
75cdf0e10cSrcweir for (sal_uInt16 i = 0; i < n; ++i) {
76cdf0e10cSrcweir rtl::OUString name(
77cdf0e10cSrcweir reader.getMethodExceptionTypeName(m_index, i).replace('/', '.'));
78cdf0e10cSrcweir css::uno::Any any;
79cdf0e10cSrcweir try {
80cdf0e10cSrcweir any = m_manager->getByHierarchicalName(name);
81cdf0e10cSrcweir } catch (css::container::NoSuchElementException & e) {
82cdf0e10cSrcweir throw new css::uno::RuntimeException(
83cdf0e10cSrcweir (rtl::OUString(
84cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
85cdf0e10cSrcweir "com.sun.star.container.NoSuchElementException: "))
86cdf0e10cSrcweir + e.Message),
87cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); //TODO
88cdf0e10cSrcweir }
89cdf0e10cSrcweir if (!(any >>= exceptions[i])
90cdf0e10cSrcweir || exceptions[i]->getTypeClass() != css::uno::TypeClass_EXCEPTION)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir throw new css::uno::RuntimeException(
93cdf0e10cSrcweir (rtl::OUString(
94cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("not an exception type: "))
95cdf0e10cSrcweir + name),
96cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >()); //TODO
97cdf0e10cSrcweir }
98cdf0e10cSrcweir OSL_ASSERT(exceptions[i].is());
99cdf0e10cSrcweir }
100cdf0e10cSrcweir osl::MutexGuard guard(m_mutex);
101cdf0e10cSrcweir if (!m_exceptionsInit) {
102cdf0e10cSrcweir m_exceptions = exceptions;
103cdf0e10cSrcweir m_exceptionsInit = true;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir return m_exceptions;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
getReader() const108cdf0e10cSrcweir typereg::Reader FunctionDescription::getReader() const {
109cdf0e10cSrcweir return typereg::Reader(
110cdf0e10cSrcweir m_bytes.getConstArray(), m_bytes.getLength(), false, TYPEREG_VERSION_1);
111cdf0e10cSrcweir }
112