1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_stoc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "methoddescription.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "com/sun/star/container/NoSuchElementException.hpp" 34*cdf0e10cSrcweir #include "com/sun/star/container/XHierarchicalNameAccess.hpp" 35*cdf0e10cSrcweir #include "com/sun/star/reflection/XParameter.hpp" 36*cdf0e10cSrcweir #include "com/sun/star/reflection/XTypeDescription.hpp" 37*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx" 38*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 39*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx" 40*cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx" 41*cdf0e10cSrcweir #include "cppuhelper/weak.hxx" 42*cdf0e10cSrcweir #include "osl/mutex.hxx" 43*cdf0e10cSrcweir #include "registry/reader.hxx" 44*cdf0e10cSrcweir #include "registry/types.h" 45*cdf0e10cSrcweir #include "rtl/ustring.hxx" 46*cdf0e10cSrcweir #include "sal/types.h" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir namespace css = com::sun::star; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using stoc::registry_tdprovider::MethodDescription; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir namespace { 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir class Parameter: public cppu::WeakImplHelper1< css::reflection::XParameter > { 55*cdf0e10cSrcweir public: 56*cdf0e10cSrcweir Parameter( 57*cdf0e10cSrcweir css::uno::Reference< css::container::XHierarchicalNameAccess > const & 58*cdf0e10cSrcweir manager, 59*cdf0e10cSrcweir rtl::OUString const & name, rtl::OUString const & typeName, 60*cdf0e10cSrcweir RTParamMode mode, sal_Int32 position): 61*cdf0e10cSrcweir m_manager(manager), m_name(name), 62*cdf0e10cSrcweir m_typeName(typeName.replace('/', '.')), m_mode(mode), 63*cdf0e10cSrcweir m_position(position) {} 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir virtual ~Parameter() {} 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException) 68*cdf0e10cSrcweir { return m_name; } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL 71*cdf0e10cSrcweir getType() throw (css::uno::RuntimeException); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isIn() throw (css::uno::RuntimeException) 74*cdf0e10cSrcweir { return (m_mode & RT_PARAM_IN) != 0; } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isOut() throw (css::uno::RuntimeException) 77*cdf0e10cSrcweir { return (m_mode & RT_PARAM_OUT) != 0; } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException) 80*cdf0e10cSrcweir { return m_position; } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isRestParameter() 83*cdf0e10cSrcweir throw (css::uno::RuntimeException) 84*cdf0e10cSrcweir { return (m_mode & RT_PARAM_REST) != 0; } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir private: 87*cdf0e10cSrcweir Parameter(Parameter &); // not implemented 88*cdf0e10cSrcweir void operator =(Parameter); // not implemented 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir css::uno::Reference< css::container::XHierarchicalNameAccess > m_manager; 91*cdf0e10cSrcweir rtl::OUString m_name; 92*cdf0e10cSrcweir rtl::OUString m_typeName; 93*cdf0e10cSrcweir RTParamMode m_mode; 94*cdf0e10cSrcweir sal_Int32 m_position; 95*cdf0e10cSrcweir }; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir css::uno::Reference< css::reflection::XTypeDescription > Parameter::getType() 98*cdf0e10cSrcweir throw (css::uno::RuntimeException) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir try { 101*cdf0e10cSrcweir return css::uno::Reference< css::reflection::XTypeDescription >( 102*cdf0e10cSrcweir m_manager->getByHierarchicalName(m_typeName), 103*cdf0e10cSrcweir css::uno::UNO_QUERY_THROW); 104*cdf0e10cSrcweir } catch (css::container::NoSuchElementException & e) { 105*cdf0e10cSrcweir throw new css::uno::RuntimeException( 106*cdf0e10cSrcweir (rtl::OUString( 107*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 108*cdf0e10cSrcweir "com.sun.star.container.NoSuchElementException: ")) 109*cdf0e10cSrcweir + e.Message), 110*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >(this)); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir MethodDescription::MethodDescription( 117*cdf0e10cSrcweir css::uno::Reference< css::container::XHierarchicalNameAccess > const & 118*cdf0e10cSrcweir manager, 119*cdf0e10cSrcweir rtl::OUString const & name, 120*cdf0e10cSrcweir com::sun::star::uno::Sequence< sal_Int8 > const & bytes, 121*cdf0e10cSrcweir sal_uInt16 index): 122*cdf0e10cSrcweir FunctionDescription(manager, bytes, index), m_name(name), 123*cdf0e10cSrcweir m_parametersInit(false) 124*cdf0e10cSrcweir {} 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir MethodDescription::~MethodDescription() {} 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > 129*cdf0e10cSrcweir MethodDescription::getParameters() const { 130*cdf0e10cSrcweir osl::MutexGuard guard(m_mutex); 131*cdf0e10cSrcweir if (!m_parametersInit) { 132*cdf0e10cSrcweir typereg::Reader reader(getReader()); 133*cdf0e10cSrcweir sal_uInt16 n = reader.getMethodParameterCount(m_index); 134*cdf0e10cSrcweir m_parameters.realloc(n); 135*cdf0e10cSrcweir for (sal_uInt16 i = 0; i < n; ++i) { 136*cdf0e10cSrcweir m_parameters[i] = new Parameter( 137*cdf0e10cSrcweir m_manager, reader.getMethodParameterName(m_index, i), 138*cdf0e10cSrcweir reader.getMethodParameterTypeName(m_index, i), 139*cdf0e10cSrcweir reader.getMethodParameterFlags(m_index, i), i); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir m_parametersInit = true; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir return m_parameters; 144*cdf0e10cSrcweir } 145