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