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