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 "methoddescription.hxx"
28 
29 #include "com/sun/star/container/NoSuchElementException.hpp"
30 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
31 #include "com/sun/star/reflection/XParameter.hpp"
32 #include "com/sun/star/reflection/XTypeDescription.hpp"
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 "cppuhelper/implbase1.hxx"
37 #include "cppuhelper/weak.hxx"
38 #include "osl/mutex.hxx"
39 #include "registry/reader.hxx"
40 #include "registry/types.h"
41 #include "rtl/ustring.hxx"
42 #include "sal/types.h"
43 
44 namespace css = com::sun::star;
45 
46 using stoc::registry_tdprovider::MethodDescription;
47 
48 namespace {
49 
50 class Parameter: public cppu::WeakImplHelper1< css::reflection::XParameter > {
51 public:
Parameter(css::uno::Reference<css::container::XHierarchicalNameAccess> const & manager,rtl::OUString const & name,rtl::OUString const & typeName,RTParamMode mode,sal_Int32 position)52     Parameter(
53         css::uno::Reference< css::container::XHierarchicalNameAccess > const &
54             manager,
55         rtl::OUString const & name, rtl::OUString const & typeName,
56         RTParamMode mode, sal_Int32 position):
57         m_manager(manager), m_name(name),
58         m_typeName(typeName.replace('/', '.')), m_mode(mode),
59         m_position(position) {}
60 
~Parameter()61     virtual ~Parameter() {}
62 
getName()63     virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException)
64     { return m_name; }
65 
66     virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
67     getType() throw (css::uno::RuntimeException);
68 
isIn()69     virtual sal_Bool SAL_CALL isIn() throw (css::uno::RuntimeException)
70     { return (m_mode & RT_PARAM_IN) != 0; }
71 
isOut()72     virtual sal_Bool SAL_CALL isOut() throw (css::uno::RuntimeException)
73     { return (m_mode & RT_PARAM_OUT) != 0; }
74 
getPosition()75     virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException)
76     { return m_position; }
77 
isRestParameter()78     virtual sal_Bool SAL_CALL isRestParameter()
79         throw (css::uno::RuntimeException)
80     { return (m_mode & RT_PARAM_REST) != 0; }
81 
82 private:
83     Parameter(Parameter &); // not implemented
84     void operator =(Parameter); // not implemented
85 
86     css::uno::Reference< css::container::XHierarchicalNameAccess > m_manager;
87     rtl::OUString m_name;
88     rtl::OUString m_typeName;
89     RTParamMode m_mode;
90     sal_Int32 m_position;
91 };
92 
getType()93 css::uno::Reference< css::reflection::XTypeDescription > Parameter::getType()
94     throw (css::uno::RuntimeException)
95 {
96     try {
97         return css::uno::Reference< css::reflection::XTypeDescription >(
98             m_manager->getByHierarchicalName(m_typeName),
99             css::uno::UNO_QUERY_THROW);
100     } catch (css::container::NoSuchElementException & e) {
101         throw new css::uno::RuntimeException(
102             (rtl::OUString(
103                 RTL_CONSTASCII_USTRINGPARAM(
104                     "com.sun.star.container.NoSuchElementException: "))
105              + e.Message),
106             static_cast< cppu::OWeakObject * >(this));
107     }
108 }
109 
110 }
111 
MethodDescription(css::uno::Reference<css::container::XHierarchicalNameAccess> const & manager,rtl::OUString const & name,com::sun::star::uno::Sequence<sal_Int8> const & bytes,sal_uInt16 index)112 MethodDescription::MethodDescription(
113     css::uno::Reference< css::container::XHierarchicalNameAccess > const &
114         manager,
115     rtl::OUString const & name,
116     com::sun::star::uno::Sequence< sal_Int8 > const & bytes,
117     sal_uInt16 index):
118     FunctionDescription(manager, bytes, index), m_name(name),
119     m_parametersInit(false)
120 {}
121 
~MethodDescription()122 MethodDescription::~MethodDescription() {}
123 
124 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
getParameters() const125 MethodDescription::getParameters() const {
126     osl::MutexGuard guard(m_mutex);
127     if (!m_parametersInit) {
128         typereg::Reader reader(getReader());
129         sal_uInt16 n = reader.getMethodParameterCount(m_index);
130         m_parameters.realloc(n);
131         for (sal_uInt16 i = 0; i < n; ++i) {
132             m_parameters[i] = new Parameter(
133                 m_manager, reader.getMethodParameterName(m_index, i),
134                 reader.getMethodParameterTypeName(m_index, i),
135                 reader.getMethodParameterFlags(m_index, i), i);
136         }
137         m_parametersInit = true;
138     }
139     return m_parameters;
140 }
141