1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertysetinfo.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_unotools.hxx"
33 #include <tools/debug.hxx>
35 #include "unotools/propertysetinfo.hxx"
37 using namespace ::utl
;
38 using namespace ::rtl
;
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::beans
;
42 using namespace ::com::sun::star::lang
;
49 PropertyMapImpl() throw();
50 virtual ~PropertyMapImpl() throw();
52 void add( PropertyMapEntry
* pMap
) throw();
53 void remove( const OUString
& aName
) throw();
55 Sequence
< Property
> getProperties() throw();
57 const PropertyMap
* getPropertyMap() const throw();
59 Property
getPropertyByName( const OUString
& aName
) throw( UnknownPropertyException
);
60 sal_Bool
hasPropertyByName( const OUString
& aName
) throw();
63 PropertyMap maPropertyMap
;
64 Sequence
< Property
> maProperties
;
68 PropertyMapImpl::PropertyMapImpl() throw()
72 PropertyMapImpl::~PropertyMapImpl() throw()
76 void PropertyMapImpl::add( PropertyMapEntry
* pMap
) throw()
80 OUString
aName( pMap
->mpName
, pMap
->mnNameLen
, RTL_TEXTENCODING_ASCII_US
);
83 PropertyMap::iterator aIter
= maPropertyMap
.find( aName
);
84 if( aIter
!= maPropertyMap
.end() )
86 DBG_ERROR( "Warning: PropertyMapEntry added twice, possible error!" );
89 if( NULL
== pMap
->mpType
)
91 DBG_ERROR( "No type in PropertyMapEntry!" );
92 pMap
->mpType
= &::getCppuType((const sal_Int32
*)0);
95 maPropertyMap
[aName
] = pMap
;
97 if( maProperties
.getLength() )
98 maProperties
.realloc( 0 );
104 void PropertyMapImpl::remove( const OUString
& aName
) throw()
106 maPropertyMap
.erase( aName
);
108 if( maProperties
.getLength() )
109 maProperties
.realloc( 0 );
112 Sequence
< Property
> PropertyMapImpl::getProperties() throw()
114 // maybe we have to generate the properties after
115 // a change in the property map or at first call
117 if( maProperties
.getLength() != (sal_Int32
)maPropertyMap
.size() )
119 maProperties
= Sequence
< Property
>( maPropertyMap
.size() );
120 Property
* pProperties
= maProperties
.getArray();
122 PropertyMap::iterator aIter
= maPropertyMap
.begin();
123 const PropertyMap::iterator aEnd
= maPropertyMap
.end();
124 while( aIter
!= aEnd
)
126 PropertyMapEntry
* pEntry
= (*aIter
).second
;
128 pProperties
->Name
= OUString( pEntry
->mpName
, pEntry
->mnNameLen
, RTL_TEXTENCODING_ASCII_US
);
129 pProperties
->Handle
= pEntry
->mnWhich
;
130 pProperties
->Type
= *pEntry
->mpType
;
131 pProperties
->Attributes
= pEntry
->mnFlags
;
140 const PropertyMap
* PropertyMapImpl::getPropertyMap() const throw()
142 return &maPropertyMap
;
145 Property
PropertyMapImpl::getPropertyByName( const OUString
& aName
) throw( UnknownPropertyException
)
147 PropertyMap::iterator aIter
= maPropertyMap
.find( aName
);
149 if( maPropertyMap
.end() == aIter
)
150 throw UnknownPropertyException();
152 PropertyMapEntry
* pEntry
= (*aIter
).second
;
154 return Property( aName
, pEntry
->mnWhich
, *pEntry
->mpType
, pEntry
->mnFlags
);
157 sal_Bool
PropertyMapImpl::hasPropertyByName( const OUString
& aName
) throw()
159 return maPropertyMap
.find( aName
) != maPropertyMap
.end();
162 ///////////////////////////////////////////////////////////////////////
164 PropertySetInfo::PropertySetInfo() throw()
166 mpMap
= new PropertyMapImpl();
169 PropertySetInfo::~PropertySetInfo() throw()
174 void PropertySetInfo::add( PropertyMapEntry
* pMap
) throw()
179 void PropertySetInfo::remove( const rtl::OUString
& aName
) throw()
181 mpMap
->remove( aName
);
184 Sequence
< ::com::sun::star::beans::Property
> SAL_CALL
PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException
)
186 return mpMap
->getProperties();
189 Property SAL_CALL
PropertySetInfo::getPropertyByName( const ::rtl::OUString
& aName
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
)
191 return mpMap
->getPropertyByName( aName
);
194 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName( const ::rtl::OUString
& Name
) throw(::com::sun::star::uno::RuntimeException
)
196 return mpMap
->hasPropertyByName( Name
);
199 const PropertyMap
* PropertySetInfo::getPropertyMap() const throw()
201 return mpMap
->getPropertyMap();