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