xref: /trunk/main/unotools/source/property/propertysetinfo.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_unotools.hxx"
30 #include <tools/debug.hxx>
31 
32 #include "unotools/propertysetinfo.hxx"
33 
34 using namespace ::utl;
35 using namespace ::rtl;
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::lang;
40 
41 namespace utl
42 {
43 class PropertyMapImpl
44 {
45 public:
46     PropertyMapImpl() throw();
47     virtual ~PropertyMapImpl() throw();
48 
49     void add( PropertyMapEntry* pMap ) throw();
50     void remove( const OUString& aName ) throw();
51 
52     Sequence< Property > getProperties() throw();
53 
54     const PropertyMap* getPropertyMap() const throw();
55 
56     Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException );
57     sal_Bool hasPropertyByName( const OUString& aName ) throw();
58 
59 private:
60     PropertyMap maPropertyMap;
61     Sequence< Property > maProperties;
62 };
63 }
64 
65 PropertyMapImpl::PropertyMapImpl() throw()
66 {
67 }
68 
69 PropertyMapImpl::~PropertyMapImpl() throw()
70 {
71 }
72 
73 void PropertyMapImpl::add( PropertyMapEntry* pMap ) throw()
74 {
75     while( pMap->mpName )
76     {
77         OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
78 
79 #ifdef DBG_UTIL
80         PropertyMap::iterator aIter = maPropertyMap.find( aName );
81         if( aIter != maPropertyMap.end() )
82         {
83             DBG_ERROR( "Warning: PropertyMapEntry added twice, possible error!" );
84         }
85 #endif
86         if( NULL == pMap->mpType )
87         {
88             DBG_ERROR( "No type in PropertyMapEntry!" );
89             pMap->mpType = &::getCppuType((const sal_Int32*)0);
90         }
91 
92         maPropertyMap[aName] = pMap;
93 
94         if( maProperties.getLength() )
95             maProperties.realloc( 0 );
96 
97         pMap = &pMap[1];
98     }
99 }
100 
101 void PropertyMapImpl::remove( const OUString& aName ) throw()
102 {
103     maPropertyMap.erase( aName );
104 
105     if( maProperties.getLength() )
106         maProperties.realloc( 0 );
107 }
108 
109 Sequence< Property > PropertyMapImpl::getProperties() throw()
110 {
111     // maybe we have to generate the properties after
112     // a change in the property map or at first call
113     // to getProperties
114     if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() )
115     {
116         maProperties = Sequence< Property >( maPropertyMap.size() );
117         Property* pProperties = maProperties.getArray();
118 
119         PropertyMap::iterator aIter = maPropertyMap.begin();
120         const PropertyMap::iterator aEnd = maPropertyMap.end();
121         while( aIter != aEnd )
122         {
123             PropertyMapEntry* pEntry = (*aIter).second;
124 
125             pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US );
126             pProperties->Handle = pEntry->mnWhich;
127             pProperties->Type = *pEntry->mpType;
128             pProperties->Attributes = pEntry->mnFlags;
129             pProperties++;
130             aIter++;
131         }
132     }
133 
134     return maProperties;
135 }
136 
137 const PropertyMap* PropertyMapImpl::getPropertyMap() const throw()
138 {
139     return &maPropertyMap;
140 }
141 
142 Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException )
143 {
144     PropertyMap::iterator aIter = maPropertyMap.find( aName );
145 
146     if( maPropertyMap.end() == aIter )
147         throw UnknownPropertyException();
148 
149     PropertyMapEntry* pEntry = (*aIter).second;
150 
151     return Property( aName, pEntry->mnWhich, *pEntry->mpType, pEntry->mnFlags );
152 }
153 
154 sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw()
155 {
156     return maPropertyMap.find( aName ) != maPropertyMap.end();
157 }
158 
159 ///////////////////////////////////////////////////////////////////////
160 
161 PropertySetInfo::PropertySetInfo() throw()
162 {
163     mpMap = new PropertyMapImpl();
164 }
165 
166 PropertySetInfo::~PropertySetInfo() throw()
167 {
168     delete mpMap;
169 }
170 
171 void PropertySetInfo::add( PropertyMapEntry* pMap ) throw()
172 {
173     mpMap->add( pMap );
174 }
175 
176 void PropertySetInfo::remove( const rtl::OUString& aName ) throw()
177 {
178     mpMap->remove( aName );
179 }
180 
181 Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException)
182 {
183     return mpMap->getProperties();
184 }
185 
186 Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
187 {
188     return mpMap->getPropertyByName( aName );
189 }
190 
191 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException)
192 {
193     return mpMap->hasPropertyByName( Name );
194 }
195 
196 const PropertyMap* PropertySetInfo::getPropertyMap() const throw()
197 {
198     return mpMap->getPropertyMap();
199 }
200