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: PropertySetMerger.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_xmloff.hxx"
33 #include <com/sun/star/beans/XPropertyState.hpp>
34 #include "PropertySetMerger.hxx"
36 using ::rtl::OUString
;
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::lang
;
43 #ifndef _CPPUHELPER_IMPLBASE1_HXX_
44 #include <cppuhelper/implbase3.hxx>
47 class SvXMLAttrContainerItem_Impl
;
49 class PropertySetMergerImpl
: public ::cppu::WeakAggImplHelper3
< XPropertySet
, XPropertyState
, XPropertySetInfo
>
52 Reference
< XPropertySet
> mxPropSet1
;
53 Reference
< XPropertyState
> mxPropSet1State
;
54 Reference
< XPropertySetInfo
> mxPropSet1Info
;
56 Reference
< XPropertySet
> mxPropSet2
;
57 Reference
< XPropertyState
> mxPropSet2State
;
58 Reference
< XPropertySetInfo
> mxPropSet2Info
;
61 PropertySetMergerImpl( const Reference
< XPropertySet
> rPropSet1
, const Reference
< XPropertySet
> rPropSet2
);
62 virtual ~PropertySetMergerImpl();
65 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(RuntimeException
);
66 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
);
67 virtual Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
68 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& xListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
69 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& aListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
70 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
71 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
74 virtual PropertyState SAL_CALL
getPropertyState( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
);
75 virtual Sequence
< PropertyState
> SAL_CALL
getPropertyStates( const Sequence
< OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
);
76 virtual void SAL_CALL
setPropertyToDefault( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
);
77 virtual Any SAL_CALL
getPropertyDefault( const OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
80 virtual Sequence
< Property
> SAL_CALL
getProperties( ) throw(RuntimeException
);
81 virtual Property SAL_CALL
getPropertyByName( const OUString
& aName
) throw(UnknownPropertyException
, RuntimeException
);
82 virtual sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) throw(RuntimeException
);
85 // --------------------------------------------------------------------
86 // Interface implementation
87 // --------------------------------------------------------------------
89 PropertySetMergerImpl::PropertySetMergerImpl( Reference
< XPropertySet
> rPropSet1
, Reference
< XPropertySet
> rPropSet2
)
90 : mxPropSet1( rPropSet1
)
91 , mxPropSet1State( rPropSet1
, UNO_QUERY
)
92 , mxPropSet1Info( rPropSet1
->getPropertySetInfo() )
93 , mxPropSet2( rPropSet2
)
94 , mxPropSet2State( rPropSet2
, UNO_QUERY
)
95 , mxPropSet2Info( rPropSet2
->getPropertySetInfo() )
99 PropertySetMergerImpl::~PropertySetMergerImpl()
104 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetMergerImpl::getPropertySetInfo( ) throw(RuntimeException
)
109 void SAL_CALL
PropertySetMergerImpl::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
111 if( mxPropSet1Info
->hasPropertyByName( aPropertyName
) )
113 mxPropSet1
->setPropertyValue( aPropertyName
, aValue
);
117 mxPropSet2
->setPropertyValue( aPropertyName
, aValue
);
121 Any SAL_CALL
PropertySetMergerImpl::getPropertyValue( const OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
123 if( mxPropSet1Info
->hasPropertyByName( PropertyName
) )
125 return mxPropSet1
->getPropertyValue( PropertyName
);
129 return mxPropSet2
->getPropertyValue( PropertyName
);
133 void SAL_CALL
PropertySetMergerImpl::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*xListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
137 void SAL_CALL
PropertySetMergerImpl::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
141 void SAL_CALL
PropertySetMergerImpl::addVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
145 void SAL_CALL
PropertySetMergerImpl::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
150 PropertyState SAL_CALL
PropertySetMergerImpl::getPropertyState( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
152 if( mxPropSet1Info
->hasPropertyByName( PropertyName
) )
154 if( mxPropSet1State
.is() )
156 return mxPropSet1State
->getPropertyState( PropertyName
);
160 return PropertyState_DIRECT_VALUE
;
165 if( mxPropSet2State
.is() )
167 return mxPropSet2State
->getPropertyState( PropertyName
);
171 return PropertyState_DIRECT_VALUE
;
176 Sequence
< PropertyState
> SAL_CALL
PropertySetMergerImpl::getPropertyStates( const Sequence
< OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
)
178 const sal_Int32 nCount
= aPropertyName
.getLength();
179 Sequence
< PropertyState
> aPropStates( nCount
);
180 PropertyState
* pPropStates
= aPropStates
.getArray();
181 const OUString
* pPropNames
= aPropertyName
.getConstArray();
184 for( nIndex
= 0; nIndex
< nCount
; nIndex
++ )
185 *pPropStates
++ = getPropertyState( *pPropNames
++ );
190 void SAL_CALL
PropertySetMergerImpl::setPropertyToDefault( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
)
192 if( mxPropSet1State
.is() && mxPropSet1Info
->hasPropertyByName( PropertyName
) )
194 mxPropSet1State
->setPropertyToDefault( PropertyName
);
198 if( mxPropSet2State
.is() )
200 mxPropSet2State
->setPropertyToDefault( PropertyName
);
205 Any SAL_CALL
PropertySetMergerImpl::getPropertyDefault( const OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
207 if( mxPropSet1State
.is() && mxPropSet1Info
->hasPropertyByName( aPropertyName
) )
209 return mxPropSet1State
->getPropertyDefault( aPropertyName
);
213 if( mxPropSet2State
.is() )
215 return mxPropSet2State
->getPropertyDefault( aPropertyName
);
226 Sequence
< Property
> SAL_CALL
PropertySetMergerImpl::getProperties() throw(RuntimeException
)
228 Sequence
< Property
> aProps1( mxPropSet1Info
->getProperties() );
229 const Property
* pProps1
= aProps1
.getArray();
230 const sal_Int32 nCount1
= aProps1
.getLength();
232 Sequence
< Property
> aProps2( mxPropSet1Info
->getProperties() );
233 const Property
* pProps2
= aProps2
.getArray();
234 const sal_Int32 nCount2
= aProps2
.getLength();
236 Sequence
< Property
> aProperties( nCount1
+ nCount2
);
240 Property
* pProperties
= aProperties
.getArray();
242 for( nIndex
= 0; nIndex
< nCount1
; nIndex
++ )
243 *pProperties
++ = *pProps1
++;
245 for( nIndex
= 0; nIndex
< nCount2
; nIndex
++ )
246 *pProperties
++ = *pProps2
++;
251 Property SAL_CALL
PropertySetMergerImpl::getPropertyByName( const OUString
& aName
) throw(UnknownPropertyException
, RuntimeException
)
253 if( mxPropSet1Info
->hasPropertyByName( aName
) )
254 return mxPropSet1Info
->getPropertyByName( aName
);
256 return mxPropSet2Info
->getPropertyByName( aName
);
259 sal_Bool SAL_CALL
PropertySetMergerImpl::hasPropertyByName( const OUString
& Name
) throw(RuntimeException
)
261 if(mxPropSet1Info
->hasPropertyByName( Name
) )
264 return mxPropSet2Info
->hasPropertyByName( Name
);
267 Reference
< XPropertySet
> PropertySetMerger_CreateInstance( Reference
< XPropertySet
> rPropSet1
, Reference
< XPropertySet
> rPropSet2
) throw()
269 return new PropertySetMergerImpl( rPropSet1
, rPropSet2
);