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