1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "comphelper_module.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 30cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h> 31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 32cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 33cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 34cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 35cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <map> 39cdf0e10cSrcweir 40cdf0e10cSrcweir 41cdf0e10cSrcweir using namespace com::sun::star; 42cdf0e10cSrcweir 43cdf0e10cSrcweir DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence<beans::PropertyValue>, NamedPropertyValues ); 44cdf0e10cSrcweir 45cdf0e10cSrcweir class NamedPropertyValuesContainer : public cppu::WeakImplHelper2< container::XNameContainer, lang::XServiceInfo > 46cdf0e10cSrcweir { 47cdf0e10cSrcweir public: 48cdf0e10cSrcweir NamedPropertyValuesContainer() throw(); 49cdf0e10cSrcweir virtual ~NamedPropertyValuesContainer() throw(); 50cdf0e10cSrcweir 51cdf0e10cSrcweir // XNameContainer 52cdf0e10cSrcweir virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 53cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, 54cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 55cdf0e10cSrcweir virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) 56cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 57cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 58cdf0e10cSrcweir 59cdf0e10cSrcweir // XNameReplace 60cdf0e10cSrcweir virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 61cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, 62cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 63cdf0e10cSrcweir 64cdf0e10cSrcweir // XNameAccess 65cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) 66cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 67cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 68cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) 69cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 70cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) 71cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // XElementAccess 74cdf0e10cSrcweir virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) 75cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 76cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) 77cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException); 78cdf0e10cSrcweir 79cdf0e10cSrcweir //XServiceInfo 80cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 81cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 82cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 83cdf0e10cSrcweir 84cdf0e10cSrcweir // XServiceInfo - static versions (used for component registration) 85cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static(); 86cdf0e10cSrcweir static uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(); 87cdf0e10cSrcweir static uno::Reference< uno::XInterface > SAL_CALL Create( const uno::Reference< uno::XComponentContext >& ); 88cdf0e10cSrcweir 89cdf0e10cSrcweir private: 90cdf0e10cSrcweir NamedPropertyValues maProperties; 91cdf0e10cSrcweir }; 92cdf0e10cSrcweir 93cdf0e10cSrcweir NamedPropertyValuesContainer::NamedPropertyValuesContainer() throw() 94cdf0e10cSrcweir { 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir NamedPropertyValuesContainer::~NamedPropertyValuesContainer() throw() 98cdf0e10cSrcweir { 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir // XNameContainer 102cdf0e10cSrcweir void SAL_CALL NamedPropertyValuesContainer::insertByName( const rtl::OUString& aName, const uno::Any& aElement ) 103cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, 104cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir if( maProperties.find( aName ) != maProperties.end() ) 107cdf0e10cSrcweir throw container::ElementExistException(); 108cdf0e10cSrcweir 109cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aProps; 110cdf0e10cSrcweir if( !(aElement >>= aProps ) ) 111cdf0e10cSrcweir throw lang::IllegalArgumentException(); 112cdf0e10cSrcweir 113cdf0e10cSrcweir maProperties.insert( NamedPropertyValues::value_type(aName ,aProps) ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir void SAL_CALL NamedPropertyValuesContainer::removeByName( const ::rtl::OUString& Name ) 117cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 118cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( Name ); 121cdf0e10cSrcweir if( aIter == maProperties.end() ) 122cdf0e10cSrcweir throw container::NoSuchElementException(); 123cdf0e10cSrcweir 124cdf0e10cSrcweir maProperties.erase( aIter ); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir // XNameReplace 128cdf0e10cSrcweir void SAL_CALL NamedPropertyValuesContainer::replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 129cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, 130cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( aName ); 133cdf0e10cSrcweir if( aIter == maProperties.end() ) 134cdf0e10cSrcweir throw container::NoSuchElementException(); 135cdf0e10cSrcweir 136cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aProps; 137cdf0e10cSrcweir if( !(aElement >>= aProps) ) 138cdf0e10cSrcweir throw lang::IllegalArgumentException(); 139cdf0e10cSrcweir 140cdf0e10cSrcweir (*aIter).second = aProps; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir // XNameAccess 144cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL NamedPropertyValuesContainer::getByName( const ::rtl::OUString& aName ) 145cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, 146cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( aName ); 149cdf0e10cSrcweir if( aIter == maProperties.end() ) 150cdf0e10cSrcweir throw container::NoSuchElementException(); 151cdf0e10cSrcweir 152cdf0e10cSrcweir uno::Any aElement; 153cdf0e10cSrcweir 154cdf0e10cSrcweir aElement <<= (*aIter).second; 155cdf0e10cSrcweir 156cdf0e10cSrcweir return aElement; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getElementNames( ) 160cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.begin(); 163cdf0e10cSrcweir const NamedPropertyValues::iterator aEnd = maProperties.end(); 164cdf0e10cSrcweir 165cdf0e10cSrcweir uno::Sequence< rtl::OUString > aNames( maProperties.size() ); 166cdf0e10cSrcweir rtl::OUString* pNames = aNames.getArray(); 167cdf0e10cSrcweir 168cdf0e10cSrcweir while( aIter != aEnd ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir *pNames++ = (*aIter++).first; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir return aNames; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir sal_Bool SAL_CALL NamedPropertyValuesContainer::hasByName( const ::rtl::OUString& aName ) 177cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir NamedPropertyValues::iterator aIter = maProperties.find( aName ); 180cdf0e10cSrcweir return aIter != maProperties.end(); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir // XElementAccess 184cdf0e10cSrcweir ::com::sun::star::uno::Type SAL_CALL NamedPropertyValuesContainer::getElementType( ) 185cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir return ::getCppuType((uno::Sequence<beans::PropertyValue> *)0); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir sal_Bool SAL_CALL NamedPropertyValuesContainer::hasElements( ) 191cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir return !maProperties.empty(); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir //XServiceInfo 197cdf0e10cSrcweir ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir return getImplementationName_static(); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir ::rtl::OUString SAL_CALL NamedPropertyValuesContainer::getImplementationName_static( ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPropertyValuesContainer" ) ); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir sal_Bool SAL_CALL NamedPropertyValuesContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) ); 210cdf0e10cSrcweir return aServiceName == ServiceName; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir return getSupportedServiceNames_static(); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir 219cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL NamedPropertyValuesContainer::getSupportedServiceNames_static( ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.NamedPropertyValues" ) ); 222cdf0e10cSrcweir const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 ); 223cdf0e10cSrcweir return aSeq; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL NamedPropertyValuesContainer::Create( 227cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >&) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir return (cppu::OWeakObject*)new NamedPropertyValuesContainer(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir void createRegistryInfo_NamedPropertyValuesContainer() 233cdf0e10cSrcweir { 234cdf0e10cSrcweir static ::comphelper::module::OAutoRegistration< NamedPropertyValuesContainer > aAutoRegistration; 235cdf0e10cSrcweir } 236