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: UncachedDataSequence.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_chart2.hxx"
34 #include "UncachedDataSequence.hxx"
36 #include "PropertyHelper.hxx"
37 #include "CommonFunctors.hxx"
38 #include "ModifyListenerHelper.hxx"
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #include <rtl/math.hxx>
44 using namespace ::com::sun::star
;
46 using ::com::sun::star::uno::Sequence
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::Any
;
49 using ::rtl::OUString
;
50 using ::osl::MutexGuard
;
52 // necessary for MS compiler
53 using ::comphelper::OPropertyContainer
;
54 using ::chart::impl::UncachedDataSequence_Base
;
58 static const OUString
lcl_aServiceName(
59 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.UncachedDataSequence" ));
63 // PROP_SOURCE_IDENTIFIER,
64 PROP_NUMBERFORMAT_KEY
,
68 } // anonymous namespace
71 // ____________________
75 UncachedDataSequence::UncachedDataSequence(
76 const Reference
< chart2::XInternalDataProvider
> & xIntDataProv
,
77 const OUString
& rRangeRepresentation
)
78 : OPropertyContainer( GetBroadcastHelper()),
79 UncachedDataSequence_Base( GetMutex()),
80 m_nNumberFormatKey(0),
81 m_xDataProvider( xIntDataProv
),
82 m_aSourceRepresentation( rRangeRepresentation
),
83 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
88 UncachedDataSequence::UncachedDataSequence(
89 const Reference
< chart2::XInternalDataProvider
> & xIntDataProv
,
90 const OUString
& rRangeRepresentation
,
91 const OUString
& rRole
)
92 : OPropertyContainer( GetBroadcastHelper()),
93 UncachedDataSequence_Base( GetMutex()),
94 m_nNumberFormatKey(0),
95 m_xDataProvider( xIntDataProv
),
96 m_aSourceRepresentation( rRangeRepresentation
),
97 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
100 setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE
, uno::makeAny( rRole
));
103 UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence
& rSource
)
104 : ::comphelper::OMutexAndBroadcastHelper(),
105 OPropertyContainer( GetBroadcastHelper()),
106 ::comphelper::OPropertyArrayUsageHelper
< UncachedDataSequence
>(),
107 UncachedDataSequence_Base( GetMutex()),
108 m_nNumberFormatKey( rSource
.m_nNumberFormatKey
),
109 m_sRole( rSource
.m_sRole
),
110 m_xDataProvider( rSource
.m_xDataProvider
),
111 m_aSourceRepresentation( rSource
.m_aSourceRepresentation
),
112 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
114 registerProperties();
117 UncachedDataSequence::~UncachedDataSequence()
120 void UncachedDataSequence::registerProperties()
122 registerProperty( C2U( "NumberFormatKey" ),
123 PROP_NUMBERFORMAT_KEY
,
124 0, // PropertyAttributes
125 & m_nNumberFormatKey
,
126 ::getCppuType( & m_nNumberFormatKey
) );
128 registerProperty( C2U( "Role" ),
130 0, // PropertyAttributes
132 ::getCppuType( & m_sRole
) );
134 registerProperty( C2U( "CachedXMLRange" ),
136 0, // PropertyAttributes
138 ::getCppuType( & m_aXMLRange
) );
141 // ================================================================================
143 Sequence
< OUString
> UncachedDataSequence::getSupportedServiceNames_Static()
145 Sequence
< OUString
> aServices( 4 );
146 aServices
[ 0 ] = lcl_aServiceName
;
147 aServices
[ 1 ] = C2U( "com.sun.star.chart2.data.DataSequence" );
148 aServices
[ 2 ] = C2U( "com.sun.star.chart2.data.NumericalDataSequence" );
149 aServices
[ 3 ] = C2U( "com.sun.star.chart2.data.TextualDataSequence" );
153 IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence
, UncachedDataSequence_Base
, OPropertyContainer
)
154 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence
, UncachedDataSequence_Base
, OPropertyContainer
)
156 // ____ XPropertySet ____
157 Reference
< beans::XPropertySetInfo
> SAL_CALL
UncachedDataSequence::getPropertySetInfo()
158 throw(uno::RuntimeException
)
160 return Reference
< beans::XPropertySetInfo
>( createPropertySetInfo( getInfoHelper() ) );
163 // ____ ::comphelper::OPropertySetHelper ____
164 // __________________________________________
165 ::cppu::IPropertyArrayHelper
& UncachedDataSequence::getInfoHelper()
167 return *getArrayHelper();
170 // ____ ::comphelper::OPropertyArrayHelper ____
171 // ____________________________________________
172 ::cppu::IPropertyArrayHelper
* UncachedDataSequence::createArrayHelper() const
174 Sequence
< beans::Property
> aProps
;
175 // describes all properties which have been registered in the ctor
176 describeProperties( aProps
);
178 return new ::cppu::OPropertyArrayHelper( aProps
);
181 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
182 APPHELPER_XSERVICEINFO_IMPL( UncachedDataSequence
, lcl_aServiceName
)
184 // ================================================================================
186 // ________ XNumericalDataSequence ________
187 Sequence
< double > SAL_CALL
UncachedDataSequence::getNumericalData()
188 throw (uno::RuntimeException
)
190 Sequence
< double > aResult
;
192 MutexGuard
aGuard( GetMutex() );
193 if( m_xDataProvider
.is())
195 Sequence
< uno::Any
> aValues( m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
));
196 aResult
.realloc( aValues
.getLength());
197 ::std::transform( aValues
.getConstArray(), aValues
.getConstArray() + aValues
.getLength(),
198 aResult
.getArray(), CommonFunctors::AnyToDouble());
204 // ________ XTextualDataSequence ________
205 Sequence
< OUString
> SAL_CALL
UncachedDataSequence::getTextualData()
206 throw (uno::RuntimeException
)
208 Sequence
< OUString
> aResult
;
210 MutexGuard
aGuard( GetMutex() );
211 if( m_xDataProvider
.is())
213 Sequence
< uno::Any
> aValues( m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
));
214 aResult
.realloc( aValues
.getLength());
215 ::std::transform( aValues
.getConstArray(), aValues
.getConstArray() + aValues
.getLength(),
216 aResult
.getArray(), CommonFunctors::AnyToString());
222 // ________ XDataSequence ________
223 Sequence
< Any
> SAL_CALL
UncachedDataSequence::getData()
224 throw (uno::RuntimeException
)
227 MutexGuard
aGuard( GetMutex() );
228 if( m_xDataProvider
.is())
229 return m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
);
230 return Sequence
< Any
>();
234 OUString SAL_CALL
UncachedDataSequence::getSourceRangeRepresentation()
235 throw (uno::RuntimeException
)
241 Sequence
< OUString
> SAL_CALL
UncachedDataSequence::generateLabel( chart2::data::LabelOrigin
)
242 throw (uno::RuntimeException
)
244 // auto-generated label is an empty string
245 static const Sequence
< OUString
> aOneEmptyString( 1 );
246 return aOneEmptyString
;
249 ::sal_Int32 SAL_CALL
UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32
)
250 throw (lang::IndexOutOfBoundsException
,
251 uno::RuntimeException
)
253 return m_nNumberFormatKey
;
256 // ____ XIndexReplace ____
257 void SAL_CALL
UncachedDataSequence::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
)
258 throw (lang::IllegalArgumentException
,
259 lang::IndexOutOfBoundsException
,
260 lang::WrappedTargetException
,
261 uno::RuntimeException
)
264 MutexGuard
aGuard( GetMutex() );
265 Sequence
< Any
> aData( getData());
266 if( Index
< aData
.getLength() &&
267 m_xDataProvider
.is() )
269 aData
[Index
] = Element
;
270 m_xDataProvider
->setDataByRangeRepresentation( m_aSourceRepresentation
, aData
);
275 // ____ XIndexAccess (base of XIndexReplace) ____
276 ::sal_Int32 SAL_CALL
UncachedDataSequence::getCount()
277 throw (uno::RuntimeException
)
279 OSL_ENSURE( false, "Implement!" );
283 uno::Any SAL_CALL
UncachedDataSequence::getByIndex( ::sal_Int32
)
284 throw (lang::IndexOutOfBoundsException
,
285 lang::WrappedTargetException
,
286 uno::RuntimeException
)
288 OSL_ENSURE( false, "Implement!" );
292 // ____ XElementAccess (base of XIndexAccess) ____
293 uno::Type SAL_CALL
UncachedDataSequence::getElementType()
294 throw (uno::RuntimeException
)
296 return ::getCppuType( reinterpret_cast< uno::Any
* >(0));
299 ::sal_Bool SAL_CALL
UncachedDataSequence::hasElements()
300 throw (uno::RuntimeException
)
302 if( ! m_xDataProvider
.is())
304 return m_xDataProvider
->hasDataByRangeRepresentation( m_aSourceRepresentation
);
308 ::rtl::OUString SAL_CALL
UncachedDataSequence::getName()
309 throw (uno::RuntimeException
)
311 return m_aSourceRepresentation
;
314 void SAL_CALL
UncachedDataSequence::setName( const OUString
& aName
)
315 throw (uno::RuntimeException
)
317 m_aSourceRepresentation
= aName
;
323 Reference
< util::XCloneable
> SAL_CALL
UncachedDataSequence::createClone()
324 throw (uno::RuntimeException
)
326 UncachedDataSequence
* pNewSeq
= new UncachedDataSequence( *this );
327 return Reference
< util::XCloneable
>( pNewSeq
);
331 // ____ XModifiable ____
332 ::sal_Bool SAL_CALL
UncachedDataSequence::isModified()
333 throw (uno::RuntimeException
)
338 void SAL_CALL
UncachedDataSequence::setModified( ::sal_Bool bModified
)
339 throw (beans::PropertyVetoException
,
340 uno::RuntimeException
)
346 // ____ XModifyBroadcaster (base of XModifiable) ____
347 void SAL_CALL
UncachedDataSequence::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
348 throw (uno::RuntimeException
)
352 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
353 xBroadcaster
->addModifyListener( aListener
);
355 catch( const uno::Exception
& ex
)
357 ASSERT_EXCEPTION( ex
);
361 void SAL_CALL
UncachedDataSequence::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
362 throw (uno::RuntimeException
)
366 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
367 xBroadcaster
->removeModifyListener( aListener
);
369 catch( const uno::Exception
& ex
)
371 ASSERT_EXCEPTION( ex
);
375 void UncachedDataSequence::fireModifyEvent()
377 // @todo: currently never called, as data changes are not yet reported by
379 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));