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