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
10*dde7d3faSAndrew Rist  *
11*dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*dde7d3faSAndrew Rist  *
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.
19*dde7d3faSAndrew Rist  *
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 #include <comphelper/ChainablePropertySetInfo.hxx>
27cdf0e10cSrcweir #include <comphelper/TypeGeneration.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir using ::rtl::OUString;
30cdf0e10cSrcweir using ::comphelper::PropertyInfo;
31cdf0e10cSrcweir using ::comphelper::GenerateCppuType;
32cdf0e10cSrcweir using ::comphelper::ChainablePropertySetInfo;
33cdf0e10cSrcweir using ::com::sun::star::uno::Any;
34cdf0e10cSrcweir using ::com::sun::star::uno::Type;
35cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
36cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
37cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
38cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
39cdf0e10cSrcweir using ::com::sun::star::beans::Property;
40cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySetInfo;
41cdf0e10cSrcweir using ::com::sun::star::beans::UnknownPropertyException;
42cdf0e10cSrcweir 
ChainablePropertySetInfo()43cdf0e10cSrcweir ChainablePropertySetInfo::ChainablePropertySetInfo()
44cdf0e10cSrcweir 	throw()
45cdf0e10cSrcweir {
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
ChainablePropertySetInfo(PropertyInfo * pMap)48cdf0e10cSrcweir ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap )
49cdf0e10cSrcweir 	throw()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 	add ( pMap );
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
~ChainablePropertySetInfo()54cdf0e10cSrcweir ChainablePropertySetInfo::~ChainablePropertySetInfo()
55cdf0e10cSrcweir 	throw()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
add(PropertyInfo * pMap,sal_Int32 nCount)59cdf0e10cSrcweir void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount )
60cdf0e10cSrcweir 	throw()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	// nCount < 0	=> add all
63cdf0e10cSrcweir 	// nCount == 0	=> add nothing
64cdf0e10cSrcweir 	// nCount > 0	=> add at most nCount entries
65cdf0e10cSrcweir 	if( maProperties.getLength() )
66cdf0e10cSrcweir 		maProperties.realloc( 0 );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
69cdf0e10cSrcweir 	{
70cdf0e10cSrcweir 		OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #ifdef DBG_UTIL
73cdf0e10cSrcweir 		PropertyInfoHash::iterator aIter = maMap.find( aName );
74cdf0e10cSrcweir 		if( aIter != maMap.end() )
75cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir 		maMap[aName] = pMap++;
78cdf0e10cSrcweir 	}
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
remove(const rtl::OUString & aName)81cdf0e10cSrcweir void ChainablePropertySetInfo::remove( const rtl::OUString& aName )
82cdf0e10cSrcweir 	throw()
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	maMap.erase ( aName );
85cdf0e10cSrcweir 	if ( maProperties.getLength() )
86cdf0e10cSrcweir 		 maProperties.realloc( 0 );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
getProperties()89cdf0e10cSrcweir Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties()
90cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	sal_Int32 nSize = maMap.size();
93cdf0e10cSrcweir 	if( maProperties.getLength() != nSize )
94cdf0e10cSrcweir 	{
95cdf0e10cSrcweir 		maProperties.realloc ( nSize );
96cdf0e10cSrcweir 		Property* pProperties = maProperties.getArray();
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		PropertyInfoHash::iterator aIter = maMap.begin();
99cdf0e10cSrcweir 		const PropertyInfoHash::iterator aEnd = maMap.end();
100cdf0e10cSrcweir 		for ( ; aIter != aEnd; ++aIter, ++pProperties)
101cdf0e10cSrcweir 		{
102cdf0e10cSrcweir 			PropertyInfo* pInfo = (*aIter).second;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 			pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
105cdf0e10cSrcweir 			pProperties->Handle = pInfo->mnHandle;
106cdf0e10cSrcweir 			const Type* pType;
107cdf0e10cSrcweir 			GenerateCppuType ( pInfo->meCppuType, pType);
108cdf0e10cSrcweir 			pProperties->Type = *pType;
109cdf0e10cSrcweir 			pProperties->Attributes = pInfo->mnAttributes;
110cdf0e10cSrcweir 		}
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 	return maProperties;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
getPropertyByName(const::rtl::OUString & rName)115cdf0e10cSrcweir Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
116cdf0e10cSrcweir 	throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	PropertyInfoHash::iterator aIter = maMap.find( rName );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	if ( maMap.end() == aIter )
121cdf0e10cSrcweir 		throw UnknownPropertyException( rName, *this );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	PropertyInfo *pInfo = (*aIter).second;
124cdf0e10cSrcweir 	Property aProperty;
125cdf0e10cSrcweir 	aProperty.Name   = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
126cdf0e10cSrcweir 	aProperty.Handle = pInfo->mnHandle;
127cdf0e10cSrcweir 	const Type* pType = &aProperty.Type;
128cdf0e10cSrcweir 	GenerateCppuType ( pInfo->meCppuType, pType );
129cdf0e10cSrcweir 	aProperty.Type = *pType;
130cdf0e10cSrcweir 	aProperty.Attributes = pInfo->mnAttributes;
131cdf0e10cSrcweir 	return aProperty;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
hasPropertyByName(const::rtl::OUString & rName)134cdf0e10cSrcweir sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
135cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
138cdf0e10cSrcweir }
139