1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b5088357SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b5088357SAndrew Rist  * distributed with this work for additional information
6*b5088357SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b5088357SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist  * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b5088357SAndrew Rist  *
11*b5088357SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist  *
13*b5088357SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist  * software distributed under the License is distributed on an
15*b5088357SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b5088357SAndrew Rist  * specific language governing permissions and limitations
18*b5088357SAndrew Rist  * under the License.
19*b5088357SAndrew Rist  *
20*b5088357SAndrew Rist  *************************************************************/
21*b5088357SAndrew Rist 
22*b5088357SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "unotools/propertysetinfo.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::utl;
31cdf0e10cSrcweir using namespace ::rtl;
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir using namespace ::com::sun::star::uno;
34cdf0e10cSrcweir using namespace ::com::sun::star::beans;
35cdf0e10cSrcweir using namespace ::com::sun::star::lang;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace utl
38cdf0e10cSrcweir {
39cdf0e10cSrcweir class PropertyMapImpl
40cdf0e10cSrcweir {
41cdf0e10cSrcweir public:
42cdf0e10cSrcweir 	PropertyMapImpl() throw();
43cdf0e10cSrcweir 	virtual ~PropertyMapImpl() throw();
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	void add( PropertyMapEntry* pMap ) throw();
46cdf0e10cSrcweir 	void remove( const OUString& aName ) throw();
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	Sequence< Property > getProperties() throw();
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	const PropertyMap* getPropertyMap() const throw();
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
53cdf0e10cSrcweir 	sal_Bool hasPropertyByName( const OUString& aName ) throw();
54cdf0e10cSrcweir 
55cdf0e10cSrcweir private:
56cdf0e10cSrcweir 	PropertyMap maPropertyMap;
57cdf0e10cSrcweir 	Sequence< Property > maProperties;
58cdf0e10cSrcweir };
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
PropertyMapImpl()61cdf0e10cSrcweir PropertyMapImpl::PropertyMapImpl() throw()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
~PropertyMapImpl()65cdf0e10cSrcweir PropertyMapImpl::~PropertyMapImpl() throw()
66cdf0e10cSrcweir {
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
add(PropertyMapEntry * pMap)69cdf0e10cSrcweir void PropertyMapImpl::add( PropertyMapEntry* pMap ) throw()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	while( pMap->mpName )
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 		OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #ifdef DBG_UTIL
76cdf0e10cSrcweir 		PropertyMap::iterator aIter = maPropertyMap.find( aName );
77cdf0e10cSrcweir 		if( aIter != maPropertyMap.end() )
78cdf0e10cSrcweir 		{
79cdf0e10cSrcweir 			DBG_ERROR( "Warning: PropertyMapEntry added twice, possible error!" );
80cdf0e10cSrcweir 		}
81cdf0e10cSrcweir #endif
82cdf0e10cSrcweir 		if( NULL == pMap->mpType )
83cdf0e10cSrcweir 		{
84cdf0e10cSrcweir 			DBG_ERROR( "No type in PropertyMapEntry!" );
85cdf0e10cSrcweir 			pMap->mpType = &::getCppuType((const sal_Int32*)0);
86cdf0e10cSrcweir 		}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 		maPropertyMap[aName] = pMap;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 		if( maProperties.getLength() )
91cdf0e10cSrcweir 			maProperties.realloc( 0 );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		pMap = &pMap[1];
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
remove(const OUString & aName)97cdf0e10cSrcweir void PropertyMapImpl::remove( const OUString& aName ) throw()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	maPropertyMap.erase( aName );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	if( maProperties.getLength() )
102cdf0e10cSrcweir 		maProperties.realloc( 0 );
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
getProperties()105cdf0e10cSrcweir Sequence< Property > PropertyMapImpl::getProperties() throw()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	// maybe we have to generate the properties after
108cdf0e10cSrcweir 	// a change in the property map or at first call
109cdf0e10cSrcweir 	// to getProperties
110cdf0e10cSrcweir 	if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		maProperties = Sequence< Property >( maPropertyMap.size() );
113cdf0e10cSrcweir 		Property* pProperties = maProperties.getArray();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		PropertyMap::iterator aIter = maPropertyMap.begin();
116cdf0e10cSrcweir 		const PropertyMap::iterator aEnd = maPropertyMap.end();
117cdf0e10cSrcweir 		while( aIter != aEnd )
118cdf0e10cSrcweir 		{
119cdf0e10cSrcweir 			PropertyMapEntry* pEntry = (*aIter).second;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 			pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US );
122cdf0e10cSrcweir 			pProperties->Handle = pEntry->mnWhich;
123cdf0e10cSrcweir 			pProperties->Type = *pEntry->mpType;
124cdf0e10cSrcweir 			pProperties->Attributes = pEntry->mnFlags;
125cdf0e10cSrcweir             pProperties++;
126cdf0e10cSrcweir 			aIter++;
127cdf0e10cSrcweir 		}
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	return maProperties;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
getPropertyMap() const133cdf0e10cSrcweir const PropertyMap* PropertyMapImpl::getPropertyMap() const throw()
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	return &maPropertyMap;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
getPropertyByName(const OUString & aName)138cdf0e10cSrcweir Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	PropertyMap::iterator aIter = maPropertyMap.find( aName );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	if( maPropertyMap.end() == aIter )
143cdf0e10cSrcweir 		throw UnknownPropertyException();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	PropertyMapEntry* pEntry = (*aIter).second;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	return Property( aName, pEntry->mnWhich, *pEntry->mpType, pEntry->mnFlags );
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
hasPropertyByName(const OUString & aName)150cdf0e10cSrcweir sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	return maPropertyMap.find( aName ) != maPropertyMap.end();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
156cdf0e10cSrcweir 
PropertySetInfo()157cdf0e10cSrcweir PropertySetInfo::PropertySetInfo() throw()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	mpMap = new PropertyMapImpl();
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
~PropertySetInfo()162cdf0e10cSrcweir PropertySetInfo::~PropertySetInfo() throw()
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	delete mpMap;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
add(PropertyMapEntry * pMap)167cdf0e10cSrcweir void PropertySetInfo::add( PropertyMapEntry* pMap ) throw()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir 	mpMap->add( pMap );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
remove(const rtl::OUString & aName)172cdf0e10cSrcweir void PropertySetInfo::remove( const rtl::OUString& aName ) throw()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	mpMap->remove( aName );
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
getProperties()177cdf0e10cSrcweir Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	return mpMap->getProperties();
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
getPropertyByName(const::rtl::OUString & aName)182cdf0e10cSrcweir Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	return mpMap->getPropertyByName( aName );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
hasPropertyByName(const::rtl::OUString & Name)187cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	return mpMap->hasPropertyByName( Name );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
getPropertyMap() const192cdf0e10cSrcweir const PropertyMap* PropertySetInfo::getPropertyMap() const throw()
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	return mpMap->getPropertyMap();
195cdf0e10cSrcweir }
196