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: definitioncontainer.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_dbaccess.hxx"
34 #ifndef _DBA_CORE_DEFINITIONCONTAINER_HXX_
35 #include "definitioncontainer.hxx"
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
40 #ifndef _DBASHARED_APITOOLS_HXX_
41 #include "apitools.hxx"
43 #ifndef _DBA_CORE_RESOURCE_HXX_
44 #include "core_resource.hxx"
46 #ifndef _DBA_CORE_RESOURCE_HRC_
47 #include "core_resource.hrc"
50 #ifndef _TOOLS_DEBUG_HXX
51 #include <tools/debug.hxx>
53 #ifndef TOOLS_DIAGNOSE_EX_H
54 #include <tools/diagnose_ex.h>
56 #ifndef _COMPHELPER_SEQUENCE_HXX_
57 #include <comphelper/sequence.hxx>
59 #ifndef _COMPHELPER_ENUMHELPER_HXX_
60 #include <comphelper/enumhelper.hxx>
62 #ifndef _COMPHELPER_EXTRACT_HXX_
63 #include <comphelper/extract.hxx>
65 #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
66 #include <com/sun/star/lang/XComponent.hpp>
68 #ifndef _COM_SUN_STAR_UCB_COMMANDINFO_HPP_
69 #include <com/sun/star/ucb/CommandInfo.hpp>
71 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
72 #include <com/sun/star/beans/XPropertySet.hpp>
74 #ifndef _COM_SUN_STAR_SDB_ERRORCONDITION_HPP_
75 #include <com/sun/star/sdb/ErrorCondition.hpp>
77 #ifndef _COMPHELPER_TYPES_HXX_
78 #include <comphelper/types.hxx>
80 #ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX
81 #include <ucbhelper/contentidentifier.hxx>
85 using namespace ::com::sun::star::uno
;
86 using namespace ::com::sun::star::lang
;
87 using namespace ::com::sun::star::util
;
88 using namespace ::com::sun::star::beans
;
89 using namespace ::com::sun::star::container
;
90 using namespace ::com::sun::star::sdbcx
;
91 using namespace ::com::sun::star::sdb
;
92 using namespace ::osl
;
93 using namespace ::comphelper
;
94 using namespace ::cppu
;
95 using namespace ::com::sun::star::ucb
;
97 //........................................................................
100 //........................................................................
102 //==========================================================================
103 //= ODefinitionContainer_Impl
104 //==========================================================================
105 //--------------------------------------------------------------------------
106 void ODefinitionContainer_Impl::erase( TContentPtr _pDefinition
)
108 NamedDefinitions::iterator aPos
= find( _pDefinition
);
110 m_aDefinitions
.erase( aPos
);
113 //--------------------------------------------------------------------------
114 ODefinitionContainer_Impl::const_iterator
ODefinitionContainer_Impl::find( TContentPtr _pDefinition
) const
116 return ::std::find_if(
117 m_aDefinitions
.begin(),
118 m_aDefinitions
.end(),
120 ::std::bind2nd( ::std::equal_to
< TContentPtr
>(), _pDefinition
),
121 ::std::select2nd
< NamedDefinitions::value_type
>()
126 //--------------------------------------------------------------------------
127 ODefinitionContainer_Impl::iterator
ODefinitionContainer_Impl::find( TContentPtr _pDefinition
)
129 return ::std::find_if(
130 m_aDefinitions
.begin(),
131 m_aDefinitions
.end(),
133 ::std::bind2nd( ::std::equal_to
< TContentPtr
>(), _pDefinition
),
134 ::std::select2nd
< NamedDefinitions::value_type
>()
139 //==========================================================================
140 //= ODefinitionContainer
141 //==========================================================================
142 DBG_NAME(ODefinitionContainer
)
143 //--------------------------------------------------------------------------
144 ODefinitionContainer::ODefinitionContainer( const Reference
< XMultiServiceFactory
>& _xORB
145 , const Reference
< XInterface
>& _xParentContainer
146 , const TContentPtr
& _pImpl
149 :OContentHelper(_xORB
,_xParentContainer
,_pImpl
)
150 ,m_aApproveListeners(m_aMutex
)
151 ,m_aContainerListeners(m_aMutex
)
152 ,m_bInPropertyChange(sal_False
)
153 ,m_bCheckSlash(_bCheckSlash
)
155 m_pImpl
->m_aProps
.bIsDocument
= sal_False
;
156 m_pImpl
->m_aProps
.bIsFolder
= sal_True
;
158 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
159 ODefinitionContainer_Impl::const_iterator aEnd
= rDefinitions
.end();
160 for ( ODefinitionContainer_Impl::const_iterator aDefinition
= rDefinitions
.begin();
164 m_aDocuments
.push_back(
165 m_aDocumentMap
.insert(
166 Documents::value_type( aDefinition
->first
, Documents::mapped_type() ) ).first
);
168 DBG_CTOR(ODefinitionContainer
, NULL
);
171 //--------------------------------------------------------------------------
172 void SAL_CALL
ODefinitionContainer::disposing()
174 OContentHelper::disposing();
176 MutexGuard
aGuard(m_aMutex
);
178 // say our listeners goobye
179 EventObject
aEvt(*this);
180 m_aApproveListeners
.disposeAndClear(aEvt
);
181 m_aContainerListeners
.disposeAndClear(aEvt
);
183 // dispose our elements
184 Documents::iterator aIter
= m_aDocumentMap
.begin();
185 Documents::iterator aEnd
= m_aDocumentMap
.end();
187 for (; aIter
!= aEnd
; ++aIter
)
189 Reference
<XContent
> xProp
= aIter
->second
;
192 removeObjectListener(xProp
);
193 ::comphelper::disposeComponent(xProp
);
197 // remove our elements
198 m_aDocuments
.clear();
199 // !!! do this before clearing the map which the vector elements refer to !!!
200 m_aDocumentMap
.clear();
203 //--------------------------------------------------------------------------
204 ODefinitionContainer::~ODefinitionContainer()
206 DBG_DTOR(ODefinitionContainer
, NULL
);
209 IMPLEMENT_FORWARD_XINTERFACE2( ODefinitionContainer
,OContentHelper
,ODefinitionContainer_Base
)
210 IMPLEMENT_TYPEPROVIDER2(ODefinitionContainer
,OContentHelper
,ODefinitionContainer_Base
);
212 //--------------------------------------------------------------------------
213 ::rtl::OUString SAL_CALL
ODefinitionContainer::getImplementationName( ) throw(RuntimeException
)
215 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.ODefinitionContainer"));
217 //--------------------------------------------------------------------------
218 Sequence
< ::rtl::OUString
> SAL_CALL
ODefinitionContainer::getSupportedServiceNames( ) throw(RuntimeException
)
220 Sequence
< ::rtl::OUString
> aReturn(2);
221 aReturn
.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DefinitionContainer"));
222 aReturn
.getArray()[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.Content"));
227 //--------------------------------------------------------------------------
228 void SAL_CALL
ODefinitionContainer::insertByName( const ::rtl::OUString
& _rName
, const Any
& aElement
) throw(IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
)
230 ResettableMutexGuard
aGuard(m_aMutex
);
232 // approve the new object
233 Reference
< XContent
> xNewElement(aElement
,UNO_QUERY
);
234 approveNewObject( _rName
, xNewElement
); // will throw if necessary
236 notifyByName( aGuard
, _rName
, xNewElement
, NULL
, E_INSERTED
, ApproveListeners
);
237 implAppend( _rName
, xNewElement
);
238 notifyByName( aGuard
, _rName
, xNewElement
, NULL
, E_INSERTED
, ContainerListemers
);
241 //--------------------------------------------------------------------------
242 void SAL_CALL
ODefinitionContainer::removeByName( const ::rtl::OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
244 ResettableMutexGuard
aGuard(m_aMutex
);
246 // check the arguments
247 if (!_rName
.getLength())
248 throw IllegalArgumentException();
250 if (!checkExistence(_rName
))
251 throw NoSuchElementException(_rName
,*this);
253 // the old element (for the notifications)
254 Reference
< XContent
> xOldElement
= implGetByName( _rName
, impl_haveAnyListeners_nothrow() );
257 notifyByName( aGuard
, _rName
, NULL
, xOldElement
, E_REMOVED
, ApproveListeners
);
258 implRemove( _rName
);
259 notifyByName( aGuard
, _rName
, NULL
, xOldElement
, E_REMOVED
, ContainerListemers
);
261 removeObjectListener( xOldElement
);
262 disposeComponent(xOldElement
);
266 //--------------------------------------------------------------------------
267 void SAL_CALL
ODefinitionContainer::replaceByName( const ::rtl::OUString
& _rName
, const Any
& aElement
) throw(IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
)
269 ResettableMutexGuard
aGuard(m_aMutex
);
271 // let derived classes approve the new object
272 Reference
< XContent
> xNewElement(aElement
,UNO_QUERY
);
273 approveNewObject( _rName
, xNewElement
); // will throw if necessary
275 // the old element (for the notifications)
276 Reference
< XContent
> xOldElement
= implGetByName( _rName
, impl_haveAnyListeners_nothrow() );
278 notifyByName( aGuard
, _rName
, xNewElement
, xOldElement
, E_REPLACED
, ApproveListeners
);
279 implReplace( _rName
, xNewElement
);
280 notifyByName( aGuard
, _rName
, xNewElement
, xOldElement
, E_REPLACED
, ContainerListemers
);
283 disposeComponent(xOldElement
);
286 // -----------------------------------------------------------------------------
289 typedef Reference
< XVeto
> ( SAL_CALL
XContainerApproveListener::*ContainerApprovalMethod
)( const ContainerEvent
& );
291 struct RaiseExceptionFromVeto
294 ContainerApprovalMethod m_pMethod
;
295 const ContainerEvent
& m_rEvent
;
298 RaiseExceptionFromVeto( ContainerApprovalMethod _pMethod
, const ContainerEvent
& _rEvent
)
299 :m_pMethod( _pMethod
)
304 void operator()( const Reference
< XContainerApproveListener
>& _Listener
) const
306 Reference
< XVeto
> xVeto
= (_Listener
.get()->*m_pMethod
)( m_rEvent
);
310 Any eVetoDetails
= xVeto
->getDetails();
312 IllegalArgumentException aIllegalArgumentError
;
313 if ( eVetoDetails
>>= aIllegalArgumentError
)
314 throw aIllegalArgumentError
;
316 WrappedTargetException aWrappedError
;
317 if ( eVetoDetails
>>= aWrappedError
)
320 throw WrappedTargetException( xVeto
->getReason(), _Listener
.get(), eVetoDetails
);
325 // -----------------------------------------------------------------------------
326 void ODefinitionContainer::notifyByName( ResettableMutexGuard
& _rGuard
, const ::rtl::OUString
& _rName
,
327 const Reference
< XContent
>& _xNewElement
, const Reference
< XContent
>& _xOldElement
,
328 ContainerOperation _eOperation
, ListenerType _eType
)
330 bool bApprove
= ( _eType
== ApproveListeners
);
332 ::cppu::OInterfaceContainerHelper
& rContainer( bApprove
? m_aApproveListeners
: m_aContainerListeners
);
333 if ( !rContainer
.getLength() )
336 ContainerEvent
aEvent( *this, makeAny( _rName
), makeAny( _xNewElement
), makeAny( _xOldElement
) );
339 switch ( _eOperation
)
343 rContainer
.forEach
< XContainerApproveListener
, RaiseExceptionFromVeto
>(
344 RaiseExceptionFromVeto( &XContainerApproveListener::approveInsertElement
, aEvent
) );
346 rContainer
.notifyEach( &XContainerListener::elementInserted
, aEvent
);
350 rContainer
.forEach
< XContainerApproveListener
, RaiseExceptionFromVeto
>(
351 RaiseExceptionFromVeto( &XContainerApproveListener::approveReplaceElement
, aEvent
) );
353 rContainer
.notifyEach( &XContainerListener::elementReplaced
, aEvent
);
357 rContainer
.forEach
< XContainerApproveListener
, RaiseExceptionFromVeto
>(
358 RaiseExceptionFromVeto( &XContainerApproveListener::approveRemoveElement
, aEvent
) );
360 rContainer
.notifyEach( &XContainerListener::elementRemoved
, aEvent
);
368 //--------------------------------------------------------------------------
369 void SAL_CALL
ODefinitionContainer::addContainerListener( const Reference
< XContainerListener
>& _rxListener
) throw(RuntimeException
)
371 if (_rxListener
.is())
372 m_aContainerListeners
.addInterface(_rxListener
);
375 //--------------------------------------------------------------------------
376 void SAL_CALL
ODefinitionContainer::removeContainerListener( const Reference
< XContainerListener
>& _rxListener
) throw(RuntimeException
)
378 if (_rxListener
.is())
379 m_aContainerListeners
.removeInterface(_rxListener
);
382 //--------------------------------------------------------------------------
383 void SAL_CALL
ODefinitionContainer::addContainerApproveListener( const Reference
< XContainerApproveListener
>& _Listener
) throw (RuntimeException
)
385 if ( _Listener
.is() )
386 m_aApproveListeners
.addInterface( _Listener
);
389 //--------------------------------------------------------------------------
390 void SAL_CALL
ODefinitionContainer::removeContainerApproveListener( const Reference
< XContainerApproveListener
>& _Listener
) throw (RuntimeException
)
392 if ( _Listener
.is() )
393 m_aApproveListeners
.removeInterface( _Listener
);
398 //--------------------------------------------------------------------------
399 Type SAL_CALL
ODefinitionContainer::getElementType( ) throw (RuntimeException
)
401 return ::getCppuType( static_cast< Reference
< XContent
>* >(NULL
) );
404 //--------------------------------------------------------------------------
405 sal_Bool SAL_CALL
ODefinitionContainer::hasElements( ) throw (RuntimeException
)
407 MutexGuard
aGuard(m_aMutex
);
408 return !m_aDocuments
.empty();
411 // XEnumerationAccess
412 //--------------------------------------------------------------------------
413 Reference
< XEnumeration
> SAL_CALL
ODefinitionContainer::createEnumeration( ) throw(RuntimeException
)
415 MutexGuard
aGuard(m_aMutex
);
416 return new ::comphelper::OEnumerationByIndex(static_cast<XIndexAccess
*>(this));
419 //--------------------------------------------------------------------------
421 sal_Int32 SAL_CALL
ODefinitionContainer::getCount( ) throw(RuntimeException
)
423 MutexGuard
aGuard(m_aMutex
);
424 return m_aDocuments
.size();
427 //--------------------------------------------------------------------------
428 Any SAL_CALL
ODefinitionContainer::getByIndex( sal_Int32 _nIndex
) throw(IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
430 MutexGuard
aGuard(m_aMutex
);
432 if ((_nIndex
< 0) || (_nIndex
>= (sal_Int32
)m_aDocuments
.size()))
433 throw IndexOutOfBoundsException();
435 Documents::iterator aPos
= m_aDocuments
[_nIndex
];
436 Reference
<XContent
> xProp
= aPos
->second
;
438 { // that's the first access to the object
440 xProp
= createObject(aPos
->first
);
441 aPos
->second
= Documents::mapped_type();
442 // and update the name-access map
445 return makeAny(xProp
);
448 //--------------------------------------------------------------------------
449 Any SAL_CALL
ODefinitionContainer::getByName( const ::rtl::OUString
& _rName
) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
451 MutexGuard
aGuard(m_aMutex
);
453 return makeAny( implGetByName( _rName
, sal_True
) );
456 //--------------------------------------------------------------------------
457 Reference
< XContent
> ODefinitionContainer::implGetByName(const ::rtl::OUString
& _rName
, sal_Bool _bReadIfNeccessary
) throw (NoSuchElementException
)
459 Documents::iterator aMapPos
= m_aDocumentMap
.find(_rName
);
460 if (aMapPos
== m_aDocumentMap
.end())
461 throw NoSuchElementException(_rName
,*this);
463 Reference
< XContent
> xProp
= aMapPos
->second
;
465 if (_bReadIfNeccessary
&& !xProp
.is())
466 { // the object has never been accessed before, so we have to read it now
467 // (that's the expensive part)
469 // create the object and insert it into the map
470 xProp
= createObject(_rName
);
471 aMapPos
->second
= xProp
;
472 addObjectListener(xProp
);
478 //--------------------------------------------------------------------------
479 Sequence
< ::rtl::OUString
> SAL_CALL
ODefinitionContainer::getElementNames( ) throw(RuntimeException
)
481 MutexGuard
aGuard(m_aMutex
);
483 Sequence
< ::rtl::OUString
> aNames(m_aDocumentMap
.size());
484 ::rtl::OUString
* pNames
= aNames
.getArray();
485 Documents::iterator aEnd
= m_aDocumentMap
.end();
486 for ( Documents::iterator aNameIter
= m_aDocumentMap
.begin();
488 ++pNames
, ++aNameIter
491 *pNames
= aNameIter
->first
;
497 //--------------------------------------------------------------------------
498 sal_Bool SAL_CALL
ODefinitionContainer::hasByName( const ::rtl::OUString
& _rName
) throw(RuntimeException
)
500 MutexGuard
aGuard(m_aMutex
);
502 return checkExistence(_rName
);
505 //--------------------------------------------------------------------------
506 void SAL_CALL
ODefinitionContainer::disposing( const EventObject
& _rSource
) throw(RuntimeException
)
508 MutexGuard
aGuard(m_aMutex
);
509 Reference
< XContent
> xSource(_rSource
.Source
, UNO_QUERY
);
510 // it's one of our documents ....
511 Documents::iterator aIter
= m_aDocumentMap
.begin();
512 Documents::iterator aEnd
= m_aDocumentMap
.end();
513 for (;aIter
!= aEnd
;++aIter
)
515 if ( xSource
== aIter
->second
.get() )
517 removeObjectListener(xSource
);
518 // and clear our document map/vector, so the object will be recreated on next access
519 aIter
->second
= Documents::mapped_type();
524 //--------------------------------------------------------------------------
525 void ODefinitionContainer::implRemove(const ::rtl::OUString
& _rName
)
527 // from the object maps
528 Documents::iterator aFind
= m_aDocumentMap
.find(_rName
);
529 if ( aFind
!= m_aDocumentMap
.end() )
531 m_aDocuments
.erase( ::std::find(m_aDocuments
.begin(),m_aDocuments
.end(),aFind
));
532 m_aDocumentMap
.erase(aFind
);
534 getDefinitions().erase( _rName
);
536 notifyDataSourceModified();
540 //--------------------------------------------------------------------------
543 bool lcl_ensureName( const Reference
< XContent
>& _rxContent
, const ::rtl::OUString
& _rName
)
545 if ( !_rxContent
.is() )
548 // ..........................................................
549 // obtain the current name. If it's the same as the new one,
553 Reference
< XPropertySet
> xProps( _rxContent
, UNO_QUERY
);
556 ::rtl::OUString sCurrentName
;
557 OSL_VERIFY( xProps
->getPropertyValue( PROPERTY_NAME
) >>= sCurrentName
);
558 if ( sCurrentName
.equals( _rName
) )
562 catch( const Exception
& )
564 OSL_ENSURE( sal_False
, "lcl_ensureName: caught an exception while obtaining the current name!" );
567 // ..........................................................
569 Reference
< XRename
> xRename( _rxContent
, UNO_QUERY
);
570 OSL_ENSURE( xRename
.is(), "lcl_ensureName: invalid content (not renameable)!" );
575 xRename
->rename( _rName
);
578 catch( const Exception
& )
580 OSL_ENSURE( sal_False
, "lcl_ensureName: caught an exception!" );
585 //--------------------------------------------------------------------------
586 void ODefinitionContainer::implAppend(const ::rtl::OUString
& _rName
, const Reference
< XContent
>& _rxNewObject
)
588 MutexGuard
aGuard(m_aMutex
);
591 Reference
<XChild
> xChild(_rxNewObject
,UNO_QUERY
);
593 xChild
->setParent(static_cast<OWeakObject
*>(this));
595 ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
596 ODefinitionContainer_Impl::const_iterator aFind
= rDefinitions
.find( _rName
);
597 if ( aFind
== rDefinitions
.end() )
599 // ensure that the new object thas the proper name.
600 // Somebody could create an object with name "foo", and insert it as "bar"
601 // into a container. In this case, we need to ensure that the object name
603 // #i44786# / 2005-03-11 / frank.schoenheit@sun.com
604 lcl_ensureName( _rxNewObject
, _rName
);
606 ::rtl::Reference
< OContentHelper
> pContent
= OContentHelper::getImplementation( _rxNewObject
);
609 TContentPtr pImpl
= pContent
->getImpl();
610 rDefinitions
.erase( pImpl
);
611 pImpl
->m_aProps
.aTitle
= _rName
;
612 rDefinitions
.insert( _rName
, pImpl
);
617 m_aDocuments
.push_back(m_aDocumentMap
.insert(Documents::value_type(_rName
,_rxNewObject
)).first
);
618 notifyDataSourceModified();
619 // now update our structures
620 if ( _rxNewObject
.is() )
621 addObjectListener(_rxNewObject
);
625 DBG_ERROR("ODefinitionContainer::implAppend: caught something !");
629 //--------------------------------------------------------------------------
630 void ODefinitionContainer::implReplace(const ::rtl::OUString
& _rName
, const Reference
< XContent
>& _rxNewObject
)
632 DBG_ASSERT(checkExistence(_rName
), "ODefinitionContainer::implReplace : invalid name !");
634 Documents::iterator aFind
= m_aDocumentMap
.find(_rName
);
635 removeObjectListener(aFind
->second
);
636 aFind
->second
= _rxNewObject
;
637 addObjectListener(aFind
->second
);
640 // -----------------------------------------------------------------------------
641 void ODefinitionContainer::approveNewObject(const ::rtl::OUString
& _sName
,const Reference
< XContent
>& _rxObject
) const
643 // check the arguments
644 if ( !_sName
.getLength() )
645 throw IllegalArgumentException(
646 DBA_RES( RID_STR_NAME_MUST_NOT_BE_EMPTY
),
650 if ( m_bCheckSlash
&& _sName
.indexOf( '/' ) != -1 )
651 throw IllegalArgumentException(
652 m_aErrorHelper
.getErrorMessage( ErrorCondition::DB_OBJECT_NAME_WITH_SLASHES
),
656 if ( !_rxObject
.is() )
657 throw IllegalArgumentException(
658 DBA_RES( RID_STR_NO_NULL_OBJECTS_IN_CONTAINER
),
662 const ODefinitionContainer_Impl
& rDefinitions( getDefinitions() );
663 if ( rDefinitions
.find( _sName
) != rDefinitions
.end() )
664 throw ElementExistException(
665 DBA_RES( RID_STR_NAME_ALREADY_USED
),
668 ::rtl::Reference
< OContentHelper
> pContent( OContentHelper::getImplementation( _rxObject
) );
669 if ( !pContent
.is() )
670 throw IllegalArgumentException(
671 DBA_RES( RID_STR_OBJECT_CONTAINER_MISMATCH
),
675 if ( rDefinitions
.find( pContent
->getImpl() ) != rDefinitions
.end() )
676 throw ElementExistException(
677 DBA_RES( RID_STR_OBJECT_ALREADY_CONTAINED
),
681 // -----------------------------------------------------------------------------
682 // XPropertyChangeListener
683 void SAL_CALL
ODefinitionContainer::propertyChange( const PropertyChangeEvent
& evt
) throw (RuntimeException
)
685 ClearableMutexGuard
aGuard(m_aMutex
);
686 if(evt
.PropertyName
== (rtl::OUString
) PROPERTY_NAME
|| evt
.PropertyName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ))
688 m_bInPropertyChange
= sal_True
;
691 ::rtl::OUString sNewName
,sOldName
;
692 evt
.OldValue
>>= sOldName
;
693 evt
.NewValue
>>= sNewName
;
694 Reference
<XContent
> xContent( evt
.Source
, UNO_QUERY
);
695 removeObjectListener( xContent
);
696 implRemove( sOldName
);
697 implAppend( sNewName
, xContent
);
699 catch(const Exception
&)
701 DBG_UNHANDLED_EXCEPTION();
702 throw RuntimeException();
704 m_bInPropertyChange
= sal_False
;
707 // -----------------------------------------------------------------------------
708 // XVetoableChangeListener
709 void SAL_CALL
ODefinitionContainer::vetoableChange( const PropertyChangeEvent
& aEvent
) throw (PropertyVetoException
, RuntimeException
)
711 MutexGuard
aGuard(m_aMutex
);
713 if(aEvent
.PropertyName
== (rtl::OUString
) PROPERTY_NAME
|| aEvent
.PropertyName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
715 ::rtl::OUString sNewName
;
716 aEvent
.NewValue
>>= sNewName
;
717 if(hasByName(sNewName
))
718 throw PropertyVetoException();
721 // -----------------------------------------------------------------------------
722 void ODefinitionContainer::addObjectListener(const Reference
< XContent
>& _xNewObject
)
724 OSL_ENSURE(_xNewObject
.is(),"ODefinitionContainer::addObjectListener: Object is null!");
725 Reference
<XPropertySet
> xProp(_xNewObject
,UNO_QUERY
);
728 xProp
->addPropertyChangeListener(PROPERTY_NAME
, this);
729 xProp
->addVetoableChangeListener(PROPERTY_NAME
, this);
730 //::rtl::OUString sTitle(RTL_CONSTASCII_USTRINGPARAM( "Title" ));
731 //xProp->addPropertyChangeListener(sTitle, this);
732 //xProp->addVetoableChangeListener(sTitle, this);
733 } // if ( xProp.is() )
735 // -----------------------------------------------------------------------------
736 void ODefinitionContainer::removeObjectListener(const Reference
< XContent
>& _xNewObject
)
738 OSL_ENSURE(_xNewObject
.is(),"ODefinitionContainer::addObjectListener: Object is null!");
739 Reference
<XPropertySet
> xProp(_xNewObject
,UNO_QUERY
);
742 xProp
->removePropertyChangeListener(PROPERTY_NAME
, this);
743 xProp
->removeVetoableChangeListener(PROPERTY_NAME
, this);
744 //::rtl::OUString sTitle(RTL_CONSTASCII_USTRINGPARAM( "Title" ));
745 //xProp->removePropertyChangeListener(sTitle, this);
746 //xProp->removeVetoableChangeListener(sTitle, this);
749 // -----------------------------------------------------------------------------
750 sal_Bool
ODefinitionContainer::checkExistence(const ::rtl::OUString
& _rName
)
752 return m_aDocumentMap
.find(_rName
) != m_aDocumentMap
.end();
755 //........................................................................
757 // namespace dbaccess
758 //........................................................................