xref: /AOO41X/main/xmloff/source/core/PropertySetMerger.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
27cdf0e10cSrcweir #include "PropertySetMerger.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir using ::rtl::OUString;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace ::com::sun::star;
32cdf0e10cSrcweir using namespace ::com::sun::star::uno;
33cdf0e10cSrcweir using namespace ::com::sun::star::beans;
34cdf0e10cSrcweir using namespace ::com::sun::star::lang;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE1_HXX_
37cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir class SvXMLAttrContainerItem_Impl;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class PropertySetMergerImpl : public ::cppu::WeakAggImplHelper3< XPropertySet, XPropertyState, XPropertySetInfo >
43cdf0e10cSrcweir {
44cdf0e10cSrcweir private:
45cdf0e10cSrcweir 	Reference< XPropertySet > mxPropSet1;
46cdf0e10cSrcweir 	Reference< XPropertyState > mxPropSet1State;
47cdf0e10cSrcweir 	Reference< XPropertySetInfo > mxPropSet1Info;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	Reference< XPropertySet > mxPropSet2;
50cdf0e10cSrcweir 	Reference< XPropertyState > mxPropSet2State;
51cdf0e10cSrcweir 	Reference< XPropertySetInfo > mxPropSet2Info;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir public:
54cdf0e10cSrcweir 	PropertySetMergerImpl( const Reference< XPropertySet > rPropSet1, const Reference< XPropertySet > rPropSet2 );
55cdf0e10cSrcweir 	virtual ~PropertySetMergerImpl();
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     // XPropertySet
58cdf0e10cSrcweir     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(RuntimeException);
59cdf0e10cSrcweir     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
60cdf0e10cSrcweir     virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
61cdf0e10cSrcweir     virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
62cdf0e10cSrcweir     virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
63cdf0e10cSrcweir     virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
64cdf0e10cSrcweir     virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     // XPropertyState
67cdf0e10cSrcweir     virtual PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException);
68cdf0e10cSrcweir     virtual Sequence< PropertyState > SAL_CALL getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException);
69cdf0e10cSrcweir     virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException);
70cdf0e10cSrcweir     virtual Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     // XPropertySetInfo
73cdf0e10cSrcweir     virtual Sequence< Property > SAL_CALL getProperties(  ) throw(RuntimeException);
74cdf0e10cSrcweir     virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw(UnknownPropertyException, RuntimeException);
75cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw(RuntimeException);
76cdf0e10cSrcweir };
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // --------------------------------------------------------------------
79cdf0e10cSrcweir // Interface implementation
80cdf0e10cSrcweir // --------------------------------------------------------------------
81cdf0e10cSrcweir 
PropertySetMergerImpl(Reference<XPropertySet> rPropSet1,Reference<XPropertySet> rPropSet2)82cdf0e10cSrcweir PropertySetMergerImpl::PropertySetMergerImpl( Reference< XPropertySet > rPropSet1, Reference< XPropertySet > rPropSet2 )
83cdf0e10cSrcweir : mxPropSet1( rPropSet1 )
84cdf0e10cSrcweir , mxPropSet1State( rPropSet1, UNO_QUERY )
85cdf0e10cSrcweir , mxPropSet1Info( rPropSet1->getPropertySetInfo() )
86cdf0e10cSrcweir , mxPropSet2( rPropSet2 )
87cdf0e10cSrcweir , mxPropSet2State( rPropSet2, UNO_QUERY )
88cdf0e10cSrcweir , mxPropSet2Info( rPropSet2->getPropertySetInfo() )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
~PropertySetMergerImpl()92cdf0e10cSrcweir PropertySetMergerImpl::~PropertySetMergerImpl()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir // XPropertySet
getPropertySetInfo()97cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL PropertySetMergerImpl::getPropertySetInfo(  ) throw(RuntimeException)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	return this;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
setPropertyValue(const OUString & aPropertyName,const Any & aValue)102cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	if( mxPropSet1Info->hasPropertyByName( aPropertyName ) )
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		mxPropSet1->setPropertyValue( aPropertyName, aValue );
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir 	else
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		mxPropSet2->setPropertyValue( aPropertyName, aValue );
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
getPropertyValue(const OUString & PropertyName)114cdf0e10cSrcweir Any SAL_CALL PropertySetMergerImpl::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		return mxPropSet1->getPropertyValue( PropertyName );
119cdf0e10cSrcweir 	}
120cdf0e10cSrcweir 	else
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		return mxPropSet2->getPropertyValue( PropertyName );
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)126cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)130cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)134cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)138cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir // XPropertyState
getPropertyState(const OUString & PropertyName)143cdf0e10cSrcweir PropertyState SAL_CALL PropertySetMergerImpl::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		if( mxPropSet1State.is() )
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			return mxPropSet1State->getPropertyState( PropertyName );
150cdf0e10cSrcweir 		}
151cdf0e10cSrcweir 		else
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			return PropertyState_DIRECT_VALUE;
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 	}
156cdf0e10cSrcweir 	else
157cdf0e10cSrcweir 	{
158cdf0e10cSrcweir 		if( mxPropSet2State.is() )
159cdf0e10cSrcweir 		{
160cdf0e10cSrcweir 			return mxPropSet2State->getPropertyState( PropertyName );
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 		else
163cdf0e10cSrcweir 		{
164cdf0e10cSrcweir 			return PropertyState_DIRECT_VALUE;
165cdf0e10cSrcweir 		}
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
getPropertyStates(const Sequence<OUString> & aPropertyName)169cdf0e10cSrcweir Sequence< PropertyState > SAL_CALL PropertySetMergerImpl::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	const sal_Int32 nCount = aPropertyName.getLength();
172cdf0e10cSrcweir 	Sequence< PropertyState > aPropStates( nCount );
173cdf0e10cSrcweir 	PropertyState* pPropStates = aPropStates.getArray();
174cdf0e10cSrcweir 	const OUString* pPropNames = aPropertyName.getConstArray();
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	sal_Int32 nIndex;
177cdf0e10cSrcweir 	for( nIndex = 0; nIndex < nCount; nIndex++ )
178cdf0e10cSrcweir 		*pPropStates++ = getPropertyState( *pPropNames++ );
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	return aPropStates;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
setPropertyToDefault(const OUString & PropertyName)183cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( PropertyName ) )
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		mxPropSet1State->setPropertyToDefault( PropertyName );
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 	else
190cdf0e10cSrcweir 	{
191cdf0e10cSrcweir 		if( mxPropSet2State.is() )
192cdf0e10cSrcweir 		{
193cdf0e10cSrcweir 			mxPropSet2State->setPropertyToDefault( PropertyName );
194cdf0e10cSrcweir 		}
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
getPropertyDefault(const OUString & aPropertyName)198cdf0e10cSrcweir Any SAL_CALL PropertySetMergerImpl::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( aPropertyName ) )
201cdf0e10cSrcweir 	{
202cdf0e10cSrcweir 		return mxPropSet1State->getPropertyDefault( aPropertyName );
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 	else
205cdf0e10cSrcweir 	{
206cdf0e10cSrcweir 		if( mxPropSet2State.is() )
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			return mxPropSet2State->getPropertyDefault( aPropertyName );
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 		else
211cdf0e10cSrcweir 		{
212cdf0e10cSrcweir 			Any aAny;
213cdf0e10cSrcweir 			return aAny;
214cdf0e10cSrcweir 		}
215cdf0e10cSrcweir 	}
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir // XPropertySetInfo
getProperties()219cdf0e10cSrcweir Sequence< Property > SAL_CALL PropertySetMergerImpl::getProperties() throw(RuntimeException)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir 	Sequence< Property > aProps1( mxPropSet1Info->getProperties() );
222cdf0e10cSrcweir 	const Property* pProps1 = aProps1.getArray();
223cdf0e10cSrcweir 	const sal_Int32 nCount1 = aProps1.getLength();
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	Sequence< Property > aProps2( mxPropSet1Info->getProperties() );
226cdf0e10cSrcweir 	const Property* pProps2 = aProps2.getArray();
227cdf0e10cSrcweir 	const sal_Int32 nCount2 = aProps2.getLength();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	Sequence< Property > aProperties( nCount1 + nCount2 );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	sal_Int32 nIndex;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	Property* pProperties = aProperties.getArray();
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	for( nIndex = 0; nIndex < nCount1; nIndex++ )
236cdf0e10cSrcweir 		*pProperties++ = *pProps1++;
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	for( nIndex = 0; nIndex < nCount2; nIndex++ )
239cdf0e10cSrcweir 		*pProperties++ = *pProps2++;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 	return aProperties;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
getPropertyByName(const OUString & aName)244cdf0e10cSrcweir Property SAL_CALL PropertySetMergerImpl::getPropertyByName( const OUString& aName ) throw(UnknownPropertyException, RuntimeException)
245cdf0e10cSrcweir {
246cdf0e10cSrcweir 	if( mxPropSet1Info->hasPropertyByName( aName ) )
247cdf0e10cSrcweir 		return mxPropSet1Info->getPropertyByName( aName );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	return mxPropSet2Info->getPropertyByName( aName );
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
hasPropertyByName(const OUString & Name)252cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetMergerImpl::hasPropertyByName( const OUString& Name ) throw(RuntimeException)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	if(mxPropSet1Info->hasPropertyByName( Name ) )
255cdf0e10cSrcweir 		return sal_True;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	return mxPropSet2Info->hasPropertyByName( Name );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
PropertySetMerger_CreateInstance(Reference<XPropertySet> rPropSet1,Reference<XPropertySet> rPropSet2)260cdf0e10cSrcweir Reference< XPropertySet > PropertySetMerger_CreateInstance( Reference< XPropertySet > rPropSet1, Reference< XPropertySet > rPropSet2 ) throw()
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	return new PropertySetMergerImpl( rPropSet1, rPropSet2 );
263cdf0e10cSrcweir }
264