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_comphelper.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "comphelper_module.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h> 35*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 37*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 38*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 39*cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <map> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace com::sun::star; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence<beans::PropertyValue>, NamedPropertyValues ); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir class NamedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XNameContainer, lang::XServiceInfo > 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir public: 52*cdf0e10cSrcweir NamedPropertyValuesContainer() throw(); 53*cdf0e10cSrcweir virtual ~NamedPropertyValuesContainer() throw(); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // XNameContainer 56*cdf0e10cSrcweir virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 57*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, 58*cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 59*cdf0e10cSrcweir virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) 60*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 61*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // XNameReplace 64*cdf0e10cSrcweir virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 65*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, 66*cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // XNameAccess 69*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) 70*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 71*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 72*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) 73*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 74*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) 75*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // XElementAccess 78*cdf0e10cSrcweir virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) 79*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 80*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) 81*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir //XServiceInfo 84*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 85*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 86*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // XServiceInfo - static versions (used for component registration) 89*cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static(); 90*cdf0e10cSrcweir static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(); 91*cdf0e10cSrcweir static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir private: 94*cdf0e10cSrcweir NamedPropertyValues maProperties; 95*cdf0e10cSrcweir }; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw() 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw() 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // XNameContainer 106*cdf0e10cSrcweir void SAL_CALL NamedPropertyValuesContainer::insertByName( const rtl::OUString& aName, const uno::Any& aElement ) 107*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, 108*cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir if( maProperties.find( aName ) != maProperties.end() ) 111*cdf0e10cSrcweir throw container::ElementExistException(); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aProps; 114*cdf0e10cSrcweir if( !(aElement >>= aProps ) ) 115*cdf0e10cSrcweir throw lang::IllegalArgumentException(); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir maProperties.insert( NamedPropertyValues::value_type(aName ,aProps) ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void SAL_CALL NamedPropertyValuesContainer::removeByName( const ::rtl::OUString& Name ) 121*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 122*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( Name ); 125*cdf0e10cSrcweir if( aIter == maProperties.end() ) 126*cdf0e10cSrcweir throw container::NoSuchElementException(); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir maProperties.erase( aIter ); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // XNameReplace 132*cdf0e10cSrcweir void SAL_CALL NamedPropertyValuesContainer::replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 133*cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, 134*cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( aName ); 137*cdf0e10cSrcweir if( aIter == maProperties.end() ) 138*cdf0e10cSrcweir throw container::NoSuchElementException(); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aProps; 141*cdf0e10cSrcweir if( !(aElement >>= aProps) ) 142*cdf0e10cSrcweir throw lang::IllegalArgumentException(); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir (*aIter).second = aProps; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // XNameAccess 148*cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL NamedPropertyValuesContainer::getByName( const ::rtl::OUString& aName ) 149*cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 150*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( aName ); 153*cdf0e10cSrcweir if( aIter == maProperties.end() ) 154*cdf0e10cSrcweir throw container::NoSuchElementException(); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir uno::Any aElement; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir aElement <<= (*aIter).second; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir return aElement; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames( ) 164*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.begin(); 167*cdf0e10cSrcweir const NamedPropertyValues::iterator aEnd = maProperties.end(); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aNames( maProperties.size() ); 170*cdf0e10cSrcweir rtl::OUString* pNames = aNames.getArray(); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir while( aIter != aEnd ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir *pNames++ = (*aIter++).first; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir return aNames; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const ::rtl::OUString& aName ) 181*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( aName ); 184*cdf0e10cSrcweir return aIter != maProperties.end(); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // XElementAccess 188*cdf0e10cSrcweir ::com::sun::star::uno::Type SAL_CALL NamedPropertyValuesContainer::getElementType( ) 189*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements( ) 195*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir return !maProperties.empty(); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //XServiceInfo 201*cdf0e10cSrcweir ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir return getImplementationName_static(); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static( ) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPropertyValuesContainer" ) ); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) ); 214*cdf0e10cSrcweir return aServiceName == ServiceName; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir return getSupportedServiceNames_static(); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static( ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) ); 226*cdf0e10cSrcweir const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 ); 227*cdf0e10cSrcweir return aSeq; 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL NamedPropertyValuesContainer::Create( 231*cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >&) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir return (cppu::OWeakObject*)new NamedPropertyValuesContainer(); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir void createRegistryInfo_NamedPropertyValuesContainer() 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir static ::comphelper::module::OAutoRegistration< NamedPropertyValuesContainer > aAutoRegistration; 239*cdf0e10cSrcweir } 240