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 "functiondescription.hxx" 32 33 #include "com/sun/star/container/NoSuchElementException.hpp" 34 #include "com/sun/star/container/XHierarchicalNameAccess.hpp" 35 #include "com/sun/star/reflection/XCompoundTypeDescription.hpp" 36 #include "com/sun/star/uno/Any.hxx" 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 "com/sun/star/uno/TypeClass.hpp" 41 #include "com/sun/star/uno/XInterface.hpp" 42 #include "cppuhelper/implbase1.hxx" 43 #include "osl/diagnose.h" 44 #include "osl/mutex.hxx" 45 #include "registry/reader.hxx" 46 #include "registry/version.h" 47 #include "rtl/ustring.h" 48 #include "rtl/ustring.hxx" 49 #include "sal/types.h" 50 51 namespace css = com::sun::star; 52 53 using stoc::registry_tdprovider::FunctionDescription; 54 55 FunctionDescription::FunctionDescription( 56 css::uno::Reference< css::container::XHierarchicalNameAccess > const & 57 manager, 58 com::sun::star::uno::Sequence< sal_Int8 > const & bytes, 59 sal_uInt16 index): 60 m_manager(manager), m_bytes(bytes), m_index(index), m_exceptionsInit(false) 61 {} 62 63 FunctionDescription::~FunctionDescription() {} 64 65 css::uno::Sequence< 66 css::uno::Reference< css::reflection::XCompoundTypeDescription > > 67 FunctionDescription::getExceptions() const { 68 { 69 osl::MutexGuard guard(m_mutex); 70 if (m_exceptionsInit) { 71 return m_exceptions; 72 } 73 } 74 typereg::Reader reader(getReader()); 75 sal_uInt16 n = reader.getMethodExceptionCount(m_index); 76 css::uno::Sequence< 77 css::uno::Reference< css::reflection::XCompoundTypeDescription > > 78 exceptions(n); 79 for (sal_uInt16 i = 0; i < n; ++i) { 80 rtl::OUString name( 81 reader.getMethodExceptionTypeName(m_index, i).replace('/', '.')); 82 css::uno::Any any; 83 try { 84 any = m_manager->getByHierarchicalName(name); 85 } catch (css::container::NoSuchElementException & e) { 86 throw new css::uno::RuntimeException( 87 (rtl::OUString( 88 RTL_CONSTASCII_USTRINGPARAM( 89 "com.sun.star.container.NoSuchElementException: ")) 90 + e.Message), 91 css::uno::Reference< css::uno::XInterface >()); //TODO 92 } 93 if (!(any >>= exceptions[i]) 94 || exceptions[i]->getTypeClass() != css::uno::TypeClass_EXCEPTION) 95 { 96 throw new css::uno::RuntimeException( 97 (rtl::OUString( 98 RTL_CONSTASCII_USTRINGPARAM("not an exception type: ")) 99 + name), 100 css::uno::Reference< css::uno::XInterface >()); //TODO 101 } 102 OSL_ASSERT(exceptions[i].is()); 103 } 104 osl::MutexGuard guard(m_mutex); 105 if (!m_exceptionsInit) { 106 m_exceptions = exceptions; 107 m_exceptionsInit = true; 108 } 109 return m_exceptions; 110 } 111 112 typereg::Reader FunctionDescription::getReader() const { 113 return typereg::Reader( 114 m_bytes.getConstArray(), m_bytes.getLength(), false, TYPEREG_VERSION_1); 115 } 116