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