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 <string.h>
21 : #include "ContentHelper.hxx"
22 : #include <ucbhelper/cancelcommandexecution.hxx>
23 : #include <comphelper/property.hxx>
24 : #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
25 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 : #include <com/sun/star/lang/IllegalAccessException.hpp>
27 : #include <com/sun/star/io/XOutputStream.hpp>
28 : #include <com/sun/star/io/XActiveDataSink.hpp>
29 : #include <com/sun/star/beans/PropertyAttribute.hpp>
30 : #include <ucbhelper/propertyvalueset.hxx>
31 : #include <ucbhelper/contentidentifier.hxx>
32 : #include "myucp_resultset.hxx"
33 : #include <com/sun/star/container/XNameContainer.hpp>
34 : #include "sdbcoretools.hxx"
35 : #include "dbastrings.hrc"
36 : #include <tools/debug.hxx>
37 :
38 :
39 : namespace dbaccess
40 : {
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::ucb;
43 : using namespace ::com::sun::star::beans;
44 : using namespace ::com::sun::star::lang;
45 : using namespace ::com::sun::star::sdbc;
46 : using namespace ::com::sun::star::io;
47 : using namespace ::com::sun::star::util;
48 : using namespace ::com::sun::star::embed;
49 : using namespace ::com::sun::star::container;
50 : using namespace ::comphelper;
51 : using namespace ::cppu;
52 :
53 : DBG_NAME(OContentHelper_Impl)
54 0 : OContentHelper_Impl::OContentHelper_Impl()
55 : {
56 : DBG_CTOR(OContentHelper_Impl,NULL);
57 0 : }
58 :
59 0 : OContentHelper_Impl::~OContentHelper_Impl()
60 : {
61 : DBG_DTOR(OContentHelper_Impl,NULL);
62 0 : }
63 :
64 0 : OContentHelper::OContentHelper(const Reference< XMultiServiceFactory >& _xORB
65 : ,const Reference< XInterface >& _xParentContainer
66 : ,const TContentPtr& _pImpl)
67 : : OContentHelper_COMPBASE(m_aMutex)
68 : ,m_aContentListeners(m_aMutex)
69 : ,m_aPropertyChangeListeners(m_aMutex)
70 : ,m_xParentContainer(_xParentContainer)
71 : ,m_aContext( _xORB )
72 : ,m_aErrorHelper( m_aContext.getUNOContext() )
73 : ,m_pImpl(_pImpl)
74 0 : ,m_nCommandId(0)
75 : {
76 0 : }
77 :
78 0 : void SAL_CALL OContentHelper::disposing()
79 : {
80 0 : ::osl::MutexGuard aGuard(m_aMutex);
81 :
82 : // say goodbye to our listeners
83 0 : EventObject aEvt(*this);
84 0 : m_aContentListeners.disposeAndClear(aEvt);
85 :
86 0 : m_xParentContainer = NULL;
87 0 : }
88 :
89 0 : IMPLEMENT_SERVICE_INFO1(OContentHelper,"com.sun.star.comp.sdb.Content","com.sun.star.ucb.Content");
90 0 : IMPLEMENT_IMPLEMENTATION_ID(OContentHelper)
91 :
92 : // XContent
93 0 : Reference< XContentIdentifier > SAL_CALL OContentHelper::getIdentifier( ) throw (RuntimeException)
94 : {
95 0 : ::osl::MutexGuard aGuard(m_aMutex);
96 0 : ::rtl::OUStringBuffer aIdentifier;
97 0 : aIdentifier.appendAscii( "private:" );
98 0 : aIdentifier.append( impl_getHierarchicalName( true ) );
99 0 : return new ::ucbhelper::ContentIdentifier( aIdentifier.makeStringAndClear() );
100 : }
101 :
102 0 : ::rtl::OUString OContentHelper::impl_getHierarchicalName( bool _includingRootContainer ) const
103 : {
104 0 : ::rtl::OUStringBuffer aHierarchicalName( m_pImpl->m_aProps.aTitle );
105 0 : Reference< XInterface > xParent = m_xParentContainer;
106 0 : while( xParent.is() )
107 : {
108 0 : Reference<XPropertySet> xProp( xParent, UNO_QUERY );
109 0 : Reference< XChild > xChild( xParent, UNO_QUERY );
110 0 : xParent.set( xChild.is() ? xChild->getParent() : Reference< XInterface >(), UNO_QUERY );
111 0 : if ( xProp.is() && xParent.is() )
112 : {
113 0 : ::rtl::OUString sName;
114 0 : xProp->getPropertyValue( PROPERTY_NAME ) >>= sName;
115 :
116 0 : ::rtl::OUString sPrevious = aHierarchicalName.makeStringAndClear();
117 0 : aHierarchicalName.append( sName );
118 0 : aHierarchicalName.append( sal_Unicode( '/' ) );
119 0 : aHierarchicalName.append( sPrevious );
120 : }
121 0 : }
122 0 : ::rtl::OUString sHierarchicalName( aHierarchicalName.makeStringAndClear() );
123 0 : if ( !_includingRootContainer )
124 0 : sHierarchicalName = sHierarchicalName.copy( sHierarchicalName.indexOf( '/' ) + 1 );
125 0 : return sHierarchicalName;
126 : }
127 :
128 0 : ::rtl::OUString SAL_CALL OContentHelper::getContentType() throw (RuntimeException)
129 : {
130 0 : ::osl::MutexGuard aGuard(m_aMutex);
131 :
132 0 : if ( !m_pImpl->m_aProps.aContentType )
133 : { // content type not yet retrieved
134 0 : m_pImpl->m_aProps.aContentType.reset( determineContentType() );
135 : }
136 :
137 0 : return *m_pImpl->m_aProps.aContentType;
138 : }
139 :
140 0 : void SAL_CALL OContentHelper::addContentEventListener( const Reference< XContentEventListener >& _rxListener ) throw (RuntimeException)
141 : {
142 0 : ::osl::MutexGuard aGuard(m_aMutex);
143 0 : if ( _rxListener.is() )
144 0 : m_aContentListeners.addInterface(_rxListener);
145 0 : }
146 :
147 0 : void SAL_CALL OContentHelper::removeContentEventListener( const Reference< XContentEventListener >& _rxListener ) throw (RuntimeException)
148 : {
149 0 : ::osl::MutexGuard aGuard(m_aMutex);
150 0 : if (_rxListener.is())
151 0 : m_aContentListeners.removeInterface(_rxListener);
152 0 : }
153 :
154 : // XCommandProcessor
155 0 : sal_Int32 SAL_CALL OContentHelper::createCommandIdentifier( ) throw (RuntimeException)
156 : {
157 0 : ::osl::MutexGuard aGuard(m_aMutex);
158 : // Just increase counter on every call to generate an identifier.
159 0 : return ++m_nCommandId;
160 : }
161 :
162 0 : Any SAL_CALL OContentHelper::execute( const Command& aCommand, sal_Int32 /*CommandId*/, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException)
163 : {
164 0 : Any aRet;
165 0 : if ( aCommand.Name.compareToAscii( "getPropertyValues" ) == 0 )
166 : {
167 : //////////////////////////////////////////////////////////////////
168 : // getPropertyValues
169 : //////////////////////////////////////////////////////////////////
170 :
171 0 : Sequence< Property > Properties;
172 0 : if ( !( aCommand.Argument >>= Properties ) )
173 : {
174 : OSL_FAIL( "Wrong argument type!" );
175 : ucbhelper::cancelCommandExecution(
176 : makeAny( IllegalArgumentException(
177 : rtl::OUString(),
178 : static_cast< cppu::OWeakObject * >( this ),
179 : -1 ) ),
180 0 : Environment );
181 : // Unreachable
182 : }
183 0 : aRet <<= getPropertyValues( Properties);
184 : }
185 0 : else if ( aCommand.Name.compareToAscii( "setPropertyValues" ) == 0 )
186 : {
187 : //////////////////////////////////////////////////////////////////
188 : // setPropertyValues
189 : //////////////////////////////////////////////////////////////////
190 :
191 0 : Sequence< PropertyValue > aProperties;
192 0 : if ( !( aCommand.Argument >>= aProperties ) )
193 : {
194 : OSL_FAIL( "Wrong argument type!" );
195 : ucbhelper::cancelCommandExecution(
196 : makeAny( IllegalArgumentException(
197 : rtl::OUString(),
198 : static_cast< cppu::OWeakObject * >( this ),
199 : -1 ) ),
200 0 : Environment );
201 : // Unreachable
202 : }
203 :
204 0 : if ( !aProperties.getLength() )
205 : {
206 : OSL_FAIL( "No properties!" );
207 : ucbhelper::cancelCommandExecution(
208 : makeAny( IllegalArgumentException(
209 : rtl::OUString(),
210 : static_cast< cppu::OWeakObject * >( this ),
211 : -1 ) ),
212 0 : Environment );
213 : // Unreachable
214 : }
215 :
216 0 : aRet <<= setPropertyValues( aProperties, Environment );
217 : }
218 0 : else if ( aCommand.Name.compareToAscii( "getPropertySetInfo" ) == 0 )
219 : {
220 : //////////////////////////////////////////////////////////////////
221 : // getPropertySetInfo
222 : //////////////////////////////////////////////////////////////////
223 :
224 0 : Reference<XPropertySet> xProp(*this,UNO_QUERY);
225 0 : if ( xProp.is() )
226 0 : aRet <<= xProp->getPropertySetInfo();
227 : // aRet <<= getPropertySetInfo(); // TODO
228 : }
229 : else
230 : {
231 : //////////////////////////////////////////////////////////////////
232 : // Unsupported command
233 : //////////////////////////////////////////////////////////////////
234 :
235 : OSL_FAIL( "Content::execute - unsupported command!" );
236 :
237 : ucbhelper::cancelCommandExecution(
238 : makeAny( UnsupportedCommandException(
239 : rtl::OUString(),
240 : static_cast< cppu::OWeakObject * >( this ) ) ),
241 0 : Environment );
242 : // Unreachable
243 : }
244 :
245 0 : return aRet;
246 : }
247 :
248 0 : void SAL_CALL OContentHelper::abort( sal_Int32 /*CommandId*/ ) throw (RuntimeException)
249 : {
250 0 : }
251 :
252 : // XPropertiesChangeNotifier
253 0 : void SAL_CALL OContentHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >& PropertyNames, const Reference< XPropertiesChangeListener >& Listener ) throw (RuntimeException)
254 : {
255 0 : ::osl::MutexGuard aGuard(m_aMutex);
256 0 : sal_Int32 nCount = PropertyNames.getLength();
257 0 : if ( !nCount )
258 : {
259 : // Note: An empty sequence means a listener for "all" properties.
260 0 : m_aPropertyChangeListeners.addInterface(::rtl::OUString(), Listener );
261 : }
262 : else
263 : {
264 0 : const ::rtl::OUString* pSeq = PropertyNames.getConstArray();
265 :
266 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
267 : {
268 0 : const ::rtl::OUString& rName = pSeq[ n ];
269 0 : if ( !rName.isEmpty() )
270 0 : m_aPropertyChangeListeners.addInterface(rName, Listener );
271 : }
272 0 : }
273 0 : }
274 :
275 0 : void SAL_CALL OContentHelper::removePropertiesChangeListener( const Sequence< ::rtl::OUString >& PropertyNames, const Reference< XPropertiesChangeListener >& Listener ) throw (RuntimeException)
276 : {
277 0 : ::osl::MutexGuard aGuard(m_aMutex);
278 0 : sal_Int32 nCount = PropertyNames.getLength();
279 0 : if ( !nCount )
280 : {
281 : // Note: An empty sequence means a listener for "all" properties.
282 0 : m_aPropertyChangeListeners.removeInterface( ::rtl::OUString(), Listener );
283 : }
284 : else
285 : {
286 0 : const ::rtl::OUString* pSeq = PropertyNames.getConstArray();
287 :
288 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
289 : {
290 0 : const ::rtl::OUString& rName = pSeq[ n ];
291 0 : if ( !rName.isEmpty() )
292 0 : m_aPropertyChangeListeners.removeInterface( rName, Listener );
293 : }
294 0 : }
295 0 : }
296 :
297 : // XPropertyContainer
298 0 : void SAL_CALL OContentHelper::addProperty( const ::rtl::OUString& /*Name*/, sal_Int16 /*Attributes*/, const Any& /*DefaultValue*/ ) throw (PropertyExistException, IllegalTypeException, IllegalArgumentException, RuntimeException)
299 : {
300 : OSL_FAIL( "OContentHelper::addProperty: not implemented!" );
301 0 : }
302 :
303 0 : void SAL_CALL OContentHelper::removeProperty( const ::rtl::OUString& /*Name*/ ) throw (UnknownPropertyException, NotRemoveableException, RuntimeException)
304 : {
305 : OSL_FAIL( "OContentHelper::removeProperty: not implemented!" );
306 0 : }
307 :
308 : // XInitialization
309 0 : void SAL_CALL OContentHelper::initialize( const Sequence< Any >& _aArguments ) throw(Exception, RuntimeException)
310 : {
311 0 : const Any* pBegin = _aArguments.getConstArray();
312 0 : const Any* pEnd = pBegin + _aArguments.getLength();
313 0 : PropertyValue aValue;
314 0 : for(;pBegin != pEnd;++pBegin)
315 : {
316 0 : *pBegin >>= aValue;
317 0 : if ( aValue.Name == "Parent" )
318 : {
319 0 : m_xParentContainer.set(aValue.Value,UNO_QUERY);
320 : }
321 0 : else if ( aValue.Name.equalsAsciiL(PROPERTY_NAME.ascii, PROPERTY_NAME.length) )
322 : {
323 0 : aValue.Value >>= m_pImpl->m_aProps.aTitle;
324 : }
325 0 : else if ( aValue.Name.equalsAsciiL(PROPERTY_PERSISTENT_NAME.ascii, PROPERTY_PERSISTENT_NAME.length) )
326 : {
327 0 : aValue.Value >>= m_pImpl->m_aProps.sPersistentName;
328 : }
329 0 : }
330 0 : }
331 :
332 0 : Sequence< Any > OContentHelper::setPropertyValues(const Sequence< PropertyValue >& rValues,const Reference< XCommandEnvironment >& /*xEnv*/ )
333 : {
334 0 : osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
335 :
336 0 : Sequence< Any > aRet( rValues.getLength() );
337 0 : Sequence< PropertyChangeEvent > aChanges( rValues.getLength() );
338 0 : sal_Int32 nChanged = 0;
339 :
340 0 : PropertyChangeEvent aEvent;
341 0 : aEvent.Source = static_cast< cppu::OWeakObject * >( this );
342 0 : aEvent.Further = sal_False;
343 0 : aEvent.PropertyHandle = -1;
344 :
345 0 : const PropertyValue* pValues = rValues.getConstArray();
346 0 : sal_Int32 nCount = rValues.getLength();
347 :
348 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
349 : {
350 0 : const PropertyValue& rValue = pValues[ n ];
351 :
352 0 : if ( rValue.Name == "ContentType" )
353 : {
354 : // Read-only property!
355 0 : aRet[ n ] <<= IllegalAccessException(
356 : ::rtl::OUString(
357 : RTL_CONSTASCII_USTRINGPARAM("Property is read-only!")
358 : ),
359 0 : static_cast< cppu::OWeakObject * >( this ) );
360 : }
361 0 : else if ( rValue.Name == "IsDocument" )
362 : {
363 : // Read-only property!
364 0 : aRet[ n ] <<= IllegalAccessException(
365 : ::rtl::OUString(
366 : RTL_CONSTASCII_USTRINGPARAM("Property is read-only!")
367 : ),
368 0 : static_cast< cppu::OWeakObject * >( this ) );
369 : }
370 0 : else if ( rValue.Name == "IsFolder" )
371 : {
372 : // Read-only property!
373 0 : aRet[ n ] <<= IllegalAccessException(
374 : ::rtl::OUString(
375 : RTL_CONSTASCII_USTRINGPARAM("Property is read-only!")
376 : ),
377 0 : static_cast< cppu::OWeakObject * >( this ) );
378 : }
379 0 : else if ( rValue.Name == "Title" )
380 : {
381 0 : rtl::OUString aNewValue;
382 0 : if ( rValue.Value >>= aNewValue )
383 : {
384 0 : if ( aNewValue != m_pImpl->m_aProps.aTitle )
385 : {
386 0 : aEvent.PropertyName = rValue.Name;
387 0 : aEvent.OldValue = makeAny( m_pImpl->m_aProps.aTitle );
388 :
389 : try
390 : {
391 0 : impl_rename_throw( aNewValue ,false);
392 : OSL_ENSURE( m_pImpl->m_aProps.aTitle == aNewValue, "OContentHelper::setPropertyValues('Title'): rename did not work!" );
393 :
394 0 : aEvent.NewValue = makeAny( aNewValue );
395 0 : aChanges.getArray()[ nChanged ] = aEvent;
396 0 : nChanged++;
397 : }
398 0 : catch( const Exception& )
399 : {
400 : OSL_FAIL( "OContentHelper::setPropertyValues('Title'): caught an exception while renaming!" );
401 : }
402 : }
403 : else
404 : {
405 : // Old value equals new value. No error!
406 : }
407 : }
408 : else
409 : {
410 0 : aRet[ n ] <<= IllegalTypeException(
411 : ::rtl::OUString(
412 : RTL_CONSTASCII_USTRINGPARAM("Property value has wrong type!")
413 : ),
414 0 : static_cast< cppu::OWeakObject * >( this ) );
415 0 : }
416 : }
417 :
418 : else
419 : {
420 0 : aRet[ n ] <<= Exception(
421 : ::rtl::OUString(
422 : RTL_CONSTASCII_USTRINGPARAM("No property set for storing the value!")
423 : ),
424 0 : static_cast< cppu::OWeakObject * >( this ) );
425 : }
426 : }
427 :
428 0 : if ( nChanged > 0 )
429 : {
430 0 : notifyDataSourceModified();
431 0 : aGuard.clear();
432 0 : aChanges.realloc( nChanged );
433 0 : notifyPropertiesChange( aChanges );
434 : }
435 :
436 0 : return aRet;
437 : }
438 :
439 : //=========================================================================
440 : // static
441 0 : Reference< XRow > OContentHelper::getPropertyValues( const Sequence< Property >& rProperties)
442 : {
443 : // Note: Empty sequence means "get values of all supported properties".
444 :
445 0 : rtl::Reference< ::ucbhelper::PropertyValueSet > xRow = new ::ucbhelper::PropertyValueSet( m_aContext.getUNOContext() );
446 :
447 0 : sal_Int32 nCount = rProperties.getLength();
448 0 : if ( nCount )
449 : {
450 0 : const Property* pProps = rProperties.getConstArray();
451 0 : for ( sal_Int32 n = 0; n < nCount; ++n )
452 : {
453 0 : const Property& rProp = pProps[ n ];
454 :
455 : // Process Core properties.
456 :
457 0 : if ( rProp.Name == "ContentType" )
458 : {
459 0 : xRow->appendString ( rProp, getContentType() );
460 : }
461 0 : else if ( rProp.Name == "Title" )
462 : {
463 0 : xRow->appendString ( rProp, m_pImpl->m_aProps.aTitle );
464 : }
465 0 : else if ( rProp.Name == "IsDocument" )
466 : {
467 0 : xRow->appendBoolean( rProp, m_pImpl->m_aProps.bIsDocument );
468 : }
469 0 : else if ( rProp.Name == "IsFolder" )
470 : {
471 0 : xRow->appendBoolean( rProp, m_pImpl->m_aProps.bIsFolder );
472 : }
473 : else
474 0 : xRow->appendVoid(rProp);
475 : }
476 : }
477 : else
478 : {
479 : // Append all Core Properties.
480 : xRow->appendString (
481 : Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContentType")),
482 : -1,
483 0 : getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
484 : PropertyAttribute::BOUND
485 : | PropertyAttribute::READONLY ),
486 0 : getContentType() );
487 : xRow->appendString (
488 : Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title" )),
489 : -1,
490 0 : getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
491 : PropertyAttribute::BOUND ),
492 0 : m_pImpl->m_aProps.aTitle );
493 : xRow->appendBoolean(
494 : Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsDocument")),
495 : -1,
496 0 : getCppuBooleanType(),
497 : PropertyAttribute::BOUND
498 : | PropertyAttribute::READONLY ),
499 0 : m_pImpl->m_aProps.bIsDocument );
500 : xRow->appendBoolean(
501 : Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsFolder")),
502 : -1,
503 0 : getCppuBooleanType(),
504 : PropertyAttribute::BOUND
505 : | PropertyAttribute::READONLY ),
506 0 : m_pImpl->m_aProps.bIsFolder );
507 :
508 : // @@@ Append other properties supported directly.
509 : }
510 :
511 0 : return Reference< XRow >( xRow.get() );
512 : }
513 :
514 0 : void OContentHelper::notifyPropertiesChange( const Sequence< PropertyChangeEvent >& evt ) const
515 : {
516 :
517 0 : sal_Int32 nCount = evt.getLength();
518 0 : if ( nCount )
519 : {
520 : // First, notify listeners interested in changes of every property.
521 0 : OInterfaceContainerHelper* pAllPropsContainer = m_aPropertyChangeListeners.getContainer( ::rtl::OUString() );
522 0 : if ( pAllPropsContainer )
523 : {
524 0 : OInterfaceIteratorHelper aIter( *pAllPropsContainer );
525 0 : while ( aIter.hasMoreElements() )
526 : {
527 : // Propagate event.
528 0 : Reference< XPropertiesChangeListener > xListener( aIter.next(), UNO_QUERY );
529 0 : if ( xListener.is() )
530 0 : xListener->propertiesChange( evt );
531 0 : }
532 : }
533 :
534 : typedef Sequence< PropertyChangeEvent > PropertyEventSequence;
535 : typedef ::std::map< XPropertiesChangeListener*, PropertyEventSequence* > PropertiesEventListenerMap;
536 0 : PropertiesEventListenerMap aListeners;
537 :
538 0 : const PropertyChangeEvent* propertyChangeEvent = evt.getConstArray();
539 :
540 0 : for ( sal_Int32 n = 0; n < nCount; ++n, ++propertyChangeEvent )
541 : {
542 0 : const PropertyChangeEvent& rEvent = *propertyChangeEvent;
543 0 : const ::rtl::OUString& rName = rEvent.PropertyName;
544 :
545 0 : OInterfaceContainerHelper* pPropsContainer = m_aPropertyChangeListeners.getContainer( rName );
546 0 : if ( pPropsContainer )
547 : {
548 0 : OInterfaceIteratorHelper aIter( *pPropsContainer );
549 0 : while ( aIter.hasMoreElements() )
550 : {
551 0 : PropertyEventSequence* propertyEvents = NULL;
552 :
553 0 : XPropertiesChangeListener* pListener = static_cast< XPropertiesChangeListener * >( aIter.next() );
554 0 : PropertiesEventListenerMap::iterator it = aListeners.find( pListener );
555 0 : if ( it == aListeners.end() )
556 : {
557 : // Not in map - create and insert new entry.
558 0 : propertyEvents = new PropertyEventSequence( nCount );
559 0 : aListeners[ pListener ] = propertyEvents;
560 : }
561 : else
562 0 : propertyEvents = (*it).second;
563 :
564 0 : if ( propertyEvents )
565 0 : (*propertyEvents)[n] = rEvent;
566 0 : }
567 : }
568 : }
569 :
570 : // Notify listeners.
571 0 : PropertiesEventListenerMap::iterator it = aListeners.begin();
572 0 : while ( !aListeners.empty() )
573 : {
574 : XPropertiesChangeListener* pListener =
575 0 : static_cast< XPropertiesChangeListener * >( (*it).first );
576 0 : PropertyEventSequence* pSeq = (*it).second;
577 :
578 : // Remove current element.
579 0 : aListeners.erase( it );
580 :
581 : // Propagate event.
582 0 : pListener->propertiesChange( *pSeq );
583 :
584 0 : delete pSeq;
585 :
586 0 : it = aListeners.begin();
587 0 : }
588 : }
589 0 : }
590 :
591 : // com::sun::star::lang::XUnoTunnel
592 0 : sal_Int64 OContentHelper::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
593 : {
594 0 : if (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
595 0 : return reinterpret_cast<sal_Int64>(this);
596 :
597 0 : return 0;
598 : }
599 :
600 0 : OContentHelper* OContentHelper::getImplementation( const Reference< XInterface >& _rxComponent )
601 : {
602 0 : OContentHelper* pContent( NULL );
603 :
604 0 : Reference< XUnoTunnel > xUnoTunnel( _rxComponent, UNO_QUERY );
605 0 : if ( xUnoTunnel.is() )
606 0 : pContent = reinterpret_cast< OContentHelper* >( xUnoTunnel->getSomething( getUnoTunnelImplementationId() ) );
607 :
608 0 : return pContent;
609 : }
610 :
611 0 : Reference< XInterface > SAL_CALL OContentHelper::getParent( ) throw (RuntimeException)
612 : {
613 0 : ::osl::MutexGuard aGuard(m_aMutex);
614 0 : return m_xParentContainer;
615 : }
616 :
617 0 : void SAL_CALL OContentHelper::setParent( const Reference< XInterface >& _xParent ) throw (NoSupportException, RuntimeException)
618 : {
619 0 : ::osl::MutexGuard aGuard(m_aMutex);
620 0 : m_xParentContainer = _xParent;
621 0 : }
622 :
623 0 : void OContentHelper::impl_rename_throw(const ::rtl::OUString& _sNewName,bool _bNotify )
624 : {
625 0 : osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
626 0 : if ( _sNewName.equals( m_pImpl->m_aProps.aTitle ) )
627 0 : return;
628 : try
629 : {
630 0 : Sequence< PropertyChangeEvent > aChanges( 1 );
631 :
632 0 : aChanges[0].Source = static_cast< cppu::OWeakObject * >( this );
633 0 : aChanges[0].Further = sal_False;
634 0 : aChanges[0].PropertyName = PROPERTY_NAME;
635 0 : aChanges[0].PropertyHandle = PROPERTY_ID_NAME;
636 0 : aChanges[0].OldValue <<= m_pImpl->m_aProps.aTitle;
637 0 : aChanges[0].NewValue <<= _sNewName;
638 :
639 0 : aGuard.clear();
640 :
641 0 : m_pImpl->m_aProps.aTitle = _sNewName;
642 0 : if ( _bNotify )
643 0 : notifyPropertiesChange( aChanges );
644 0 : notifyDataSourceModified();
645 : }
646 0 : catch(const PropertyVetoException&)
647 : {
648 0 : throw ElementExistException(_sNewName,*this);
649 0 : }
650 : }
651 :
652 0 : void SAL_CALL OContentHelper::rename( const ::rtl::OUString& newName ) throw (SQLException, ElementExistException, RuntimeException)
653 : {
654 :
655 0 : impl_rename_throw(newName);
656 :
657 0 : }
658 :
659 0 : void OContentHelper::notifyDataSourceModified()
660 : {
661 0 : ::dbaccess::notifyDataSourceModified(m_xParentContainer,sal_True);
662 0 : }
663 :
664 : } // namespace dbaccess
665 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|