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