1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_comphelper.hxx"
26 #ifndef _COMPHELPER_CHAINABLEPROPERTYSETINFO_HXX_
27 #include <comphelper/MasterPropertySetInfo.hxx>
28 #endif
29 #include <comphelper/TypeGeneration.hxx>
30 
31 using ::rtl::OUString;
32 using ::comphelper::PropertyInfo;
33 using ::comphelper::GenerateCppuType;
34 using ::comphelper::MasterPropertySetInfo;
35 using ::com::sun::star::uno::Any;
36 using ::com::sun::star::uno::Type;
37 using ::com::sun::star::uno::Sequence;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::XInterface;
40 using ::com::sun::star::uno::RuntimeException;
41 using ::com::sun::star::beans::Property;
42 using ::com::sun::star::beans::XPropertySetInfo;
43 using ::com::sun::star::beans::UnknownPropertyException;
44 
MasterPropertySetInfo()45 MasterPropertySetInfo::MasterPropertySetInfo()
46 	throw()
47 {
48 }
49 
MasterPropertySetInfo(PropertyInfo * pMap)50 MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap )
51 	throw()
52 {
53 	add ( pMap );
54 }
55 
~MasterPropertySetInfo()56 MasterPropertySetInfo::~MasterPropertySetInfo()
57 	throw()
58 {
59 	PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin();
60 	while (aIter != aEnd )
61 	{
62 		delete (*aIter).second;
63 		aIter++;
64 	}
65 }
66 
add(PropertyInfo * pMap,sal_Int32 nCount,sal_uInt8 nMapId)67 void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId )
68 	throw()
69 {
70 	// nCount < 0	=> add all
71 	// nCount == 0	=> add nothing
72 	// nCount > 0	=> add at most nCount entries
73 	if( maProperties.getLength() )
74 		maProperties.realloc( 0 );
75 
76 	for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap )
77 	{
78 		OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
79 
80 #ifdef DBG_UTIL
81 		PropertyDataHash::iterator aIter = maMap.find( aName );
82 		if( aIter != maMap.end() )
83 			OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
84 #endif
85 		maMap[aName] = new PropertyData ( nMapId, pMap );
86 	}
87 }
88 
add(PropertyInfoHash & rHash,sal_uInt8 nMapId)89 void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId )
90 	throw()
91 {
92 	if( maProperties.getLength() )
93 		maProperties.realloc( 0 );
94 	PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end();
95 
96 	while ( aIter != aEnd )
97 	{
98 #ifdef DBG_UTIL
99 		PropertyDataHash::iterator aDebugIter = maMap.find( (*aIter).first );
100 		if( aDebugIter != maMap.end() )
101 			OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
102 #endif
103 		maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second );
104 		aIter++;
105 	}
106 }
107 
remove(const rtl::OUString & aName)108 void MasterPropertySetInfo::remove( const rtl::OUString& aName )
109 	throw()
110 {
111 	maMap.erase ( aName );
112 	if ( maProperties.getLength() )
113 		 maProperties.realloc( 0 );
114 }
115 
getProperties()116 Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties()
117 	throw(::com::sun::star::uno::RuntimeException)
118 {
119 	sal_Int32 nSize = maMap.size();
120 	if( maProperties.getLength() != nSize )
121 	{
122 		maProperties.realloc ( nSize );
123 		Property* pProperties = maProperties.getArray();
124 
125 		PropertyDataHash::iterator aIter = maMap.begin();
126 		const PropertyDataHash::iterator aEnd = maMap.end();
127 		for ( ; aIter != aEnd; ++aIter, ++pProperties)
128 		{
129 			PropertyInfo* pInfo = (*aIter).second->mpInfo;
130 
131 			pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
132 			pProperties->Handle = pInfo->mnHandle;
133 			const Type* pType;
134 			GenerateCppuType ( pInfo->meCppuType, pType);
135 			pProperties->Type = *pType;
136 			pProperties->Attributes = pInfo->mnAttributes;
137 		}
138 	}
139 	return maProperties;
140 }
141 
getPropertyByName(const::rtl::OUString & rName)142 Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
143 	throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
144 {
145 	PropertyDataHash::iterator aIter = maMap.find( rName );
146 
147 	if ( maMap.end() == aIter )
148 		throw UnknownPropertyException( rName, *this );
149 
150 	PropertyInfo *pInfo = (*aIter).second->mpInfo;
151 	Property aProperty;
152 	aProperty.Name   = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
153 	aProperty.Handle = pInfo->mnHandle;
154 	const Type* pType;
155 	GenerateCppuType ( pInfo->meCppuType, pType );
156 	aProperty.Type = *pType;
157 
158 	aProperty.Attributes = pInfo->mnAttributes;
159 	return aProperty;
160 }
161 
hasPropertyByName(const::rtl::OUString & rName)162 sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
163 	throw(::com::sun::star::uno::RuntimeException)
164 {
165 	return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );
166 }
167