xref: /AOO41X/main/xmloff/source/style/SinglePropertySetInfoCache.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
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_xmloff.hxx"
26 #include <com/sun/star/lang/XTypeProvider.hpp>
27 #include <cppuhelper/weakref.hxx>
28 
29 #ifndef _XMLOFF_SINGLEPROPERTYSETINFOCACHE_HXX
30 #include <xmloff/SinglePropertySetInfoCache.hxx>
31 #endif
32 
33 using namespace ::com::sun::star::uno;
34 using ::com::sun::star::lang::XTypeProvider;
35 using ::com::sun::star::beans::XPropertySet;
36 using ::com::sun::star::beans::XPropertySetInfo;
37 
hasProperty(const Reference<XPropertySet> & rPropSet,Reference<XPropertySetInfo> & rPropSetInfo)38 sal_Bool SinglePropertySetInfoCache::hasProperty(
39         const Reference< XPropertySet >& rPropSet,
40         Reference< XPropertySetInfo >& rPropSetInfo )
41 {
42     if( !rPropSetInfo.is() )
43         rPropSetInfo = rPropSet->getPropertySetInfo();
44     sal_Bool bRet = sal_False, bValid = sal_False;
45     Reference < XTypeProvider > xTypeProv( rPropSet, UNO_QUERY );
46     Sequence< sal_Int8 > aImplId;
47     if( xTypeProv.is() )
48     {
49         aImplId = xTypeProv->getImplementationId();
50         if( aImplId.getLength() == 16 )
51         {
52             // The key must not be created outside this block, because it
53             // keeps a reference to the property set info.
54             PropertySetInfoKey aKey( rPropSetInfo, aImplId );
55             iterator aIter = find( aKey );
56             if( aIter != end() )
57             {
58                 bRet = (*aIter).second;
59                 bValid = sal_True;
60             }
61         }
62     }
63     if( !bValid )
64     {
65         bRet = rPropSetInfo->hasPropertyByName( sName );
66         if( xTypeProv.is() && aImplId.getLength() == 16 )
67         {
68             // Check whether the property set info is destroyed if it is
69             // assigned to a weak reference only. If it is destroyed, then
70             // every instance of getPropertySetInfo returns a new object.
71             // Such property set infos must not be cached.
72             WeakReference < XPropertySetInfo > xWeakInfo( rPropSetInfo );
73             rPropSetInfo = 0;
74             rPropSetInfo = xWeakInfo;
75             if( rPropSetInfo.is() )
76             {
77                 PropertySetInfoKey aKey( rPropSetInfo, aImplId );
78                 value_type aValue( aKey, bRet );
79                 insert( aValue );
80             }
81         }
82     }
83 
84     return bRet;
85 }
86